Skip to content

Commit

Permalink
Add recognition of multi-line field expression (tree-sitter#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevanmilic committed Aug 31, 2021
1 parent 98ef644 commit 3bc5cbd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,39 @@ def f() = {
(assignment_expression (identifier) (infix_expression (identifier) (operator_identifier) (identifier)))
(enumerator (identifier) (call_expression (identifier) (arguments)) (guard (identifier))))
(block (call_expression (identifier) (arguments (identifier) (identifier))))))))

===============================
Chained expressions
===============================

def main() {
val myList = List(1, 2, 3)

myList.map(_ * 2)

myList
.map(_ * 2)

myList
.length
}

---

(compilation_unit
(function_definition
(identifier)
(parameters)
(block
(val_definition (identifier) (call_expression
(identifier)
(arguments (integer_literal) (integer_literal) (integer_literal))))
(call_expression
(field_expression (identifier) (identifier))
(arguments (infix_expression
(identifier) (operator_identifier) (integer_literal))))
(call_expression
(field_expression (identifier) (identifier))
(arguments (infix_expression
(identifier) (operator_identifier) (integer_literal))))
(field_expression (identifier) (identifier)))))
4 changes: 4 additions & 0 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ bool tree_sitter_scala_external_scanner_scan(void *payload, TSLexer *lexer,
}

if (valid_symbols[AUTOMATIC_SEMICOLON] && newline_count > 0) {
// NOTE: When there's a dot after a new line it could be a multi-line field
// expression, in which case we don't recognize it as an automatic semicolon.
if (lexer->lookahead == '.') return false;

lexer->mark_end(lexer);
lexer->result_symbol = AUTOMATIC_SEMICOLON;

Expand Down

0 comments on commit 3bc5cbd

Please sign in to comment.