Skip to content

Commit

Permalink
Merge pull request Wilfred#12 from alaviss/infix_inline
Browse files Browse the repository at this point in the history
Put infix operators as inline within the grammar

This allows us to remove 11 external scanning nodes. Tie breaking against command call & prefix is now done solely on the prefix operator.

Symbolic operators are now exposed as nodes to allow syntax queries to match against them.

Due to size explosion, Unicode operators are disabled.

Included are some fixes for scanner flags reset on new line.
  • Loading branch information
alaviss authored May 7, 2023
2 parents 5192f32 + 5a41b96 commit 485dbe9
Show file tree
Hide file tree
Showing 7 changed files with 3,207 additions and 587 deletions.
5 changes: 5 additions & 0 deletions corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ type
values: (expression_list
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier)))
(field_declaration_list
(field_declaration
Expand All @@ -409,6 +410,7 @@ type
values: (expression_list
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier)))
(field_declaration_list
(field_declaration
Expand All @@ -420,6 +422,7 @@ type
values: (expression_list
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier))
(identifier)
(identifier)
Expand Down Expand Up @@ -648,6 +651,7 @@ type
(infix_expression
left: (infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier))
right: (identifier))
(infix_expression
Expand Down Expand Up @@ -787,6 +791,7 @@ proc bar
body: (statement_list
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier))))
(macro_declaration
name: (identifier)
Expand Down
74 changes: 71 additions & 3 deletions corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,32 @@ not a.c

!a.u:b

echo $a

--------------------------------------------------------------------------------

(source_file
(prefix_expression
operator: (prefix_operator)
(identifier))
(prefix_expression
operator: (prefix_operator)
(identifier))
(prefix_expression
operator: (prefix_operator)
(identifier))
(prefix_expression
operator: (prefix_operator)
(dot_expression
left: (identifier)
right: (identifier)))
(dot_expression
left: (prefix_expression
operator: (prefix_operator)
(identifier))
right: (identifier))
(prefix_expression
operator: (prefix_operator)
(parenthesized
(dot_expression
left: (identifier)
Expand All @@ -78,10 +86,16 @@ not a.c
left: (identifier)
right: (identifier)))
(prefix_expression
operator: (prefix_operator)
(dot_expression
left: (identifier)
right: (identifier))
(statement_list
(identifier)))
(call
function: (identifier)
(prefix_expression
operator: (prefix_operator)
(identifier))))

================================================================================
Expand All @@ -104,7 +118,7 @@ z ==> xyz + def => cd

$a + b

1 2 and 3 1 or false
1 * 2 and 3 * 1 or false

(1 + 2) * (2 + 3)

Expand All @@ -117,87 +131,123 @@ c of RootObj
1 + 1: 3
else: 4

1+1

1+ 1

--------------------------------------------------------------------------------

(source_file
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal))
(infix_expression
left: (identifier)
right: (identifier))
(infix_expression
left: (infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal))
operator: (infix_operator)
right: (infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal)))
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier))
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal)))
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier)))
(infix_expression
left: (infix_expression
left: (identifier)
operator: (infix_operator)
right: (infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier)))
operator: (infix_operator)
right: (identifier))
(infix_expression
left: (prefix_expression
operator: (prefix_operator)
(identifier))
operator: (infix_operator)
right: (identifier))
(infix_expression
left: (infix_expression
left: (infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal))
right: (infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal)))
right: (identifier))
(infix_expression
left: (parenthesized
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal)))
operator: (infix_operator)
right: (parenthesized
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal))))
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier)))
(infix_expression
left: (identifier)
right: (identifier))
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (call
function: (identifier)
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (identifier))))
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal)
(statement_list
(integer_literal))
(else_branch
(statement_list
(integer_literal)))))
(integer_literal))))
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal))
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal)))

================================================================================
Dot expressions
Expand All @@ -213,22 +263,29 @@ a.b"string"
a.b "string"
a.b#[]#"string"

a(
b
).c

--------------------------------------------------------------------------------

(source_file
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (dot_expression
left: (identifier)
right: (identifier)))
(infix_expression
left: (dot_expression
left: (identifier)
right: (identifier))
operator: (infix_operator)
right: (dot_expression
left: (identifier)
right: (identifier)))
(prefix_expression
operator: (prefix_operator)
(dot_expression
left: (identifier)
right: (identifier)))
Expand All @@ -247,7 +304,12 @@ a.b#[]#"string"
left: (identifier)
right: (identifier))
(comment)
(string_literal)))
(string_literal))
(dot_expression
left: (call
function: (identifier)
(identifier))
right: (identifier)))

================================================================================
Bracket expressions
Expand All @@ -268,6 +330,7 @@ a.b[c]
(identifier)))
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (bracket_expression
left: (identifier)
right: (argument_list
Expand All @@ -292,6 +355,7 @@ a + 2{c}[a]
(identifier)))
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (bracket_expression
left: (curly_expression
left: (integer_literal)
Expand Down Expand Up @@ -396,6 +460,7 @@ collect(for x in s:
(statement_list
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (integer_literal))
(identifier))
(else_branch
Expand Down Expand Up @@ -432,6 +497,7 @@ collect(for x in s:
body: (statement_list
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier)))))
(call
function: (identifier)
Expand Down Expand Up @@ -604,6 +670,7 @@ foo {x}
function: (identifier)
(infix_expression
left: (integer_literal)
operator: (infix_operator)
right: (call
function: (identifier)))
(identifier))
Expand Down Expand Up @@ -1200,6 +1267,7 @@ iterator: T
body: (statement_list
(infix_expression
left: (identifier)
operator: (infix_operator)
right: (integer_literal))))
(iterator_expression
parameters: (parameter_declaration_list
Expand Down
1 change: 1 addition & 0 deletions corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ from X/Y import Y
(import_from_statement
module: (infix_expression
left: (identifier)
operator: (infix_operator)
right: (identifier))
(expression_list
(identifier))))
Expand Down
Loading

0 comments on commit 485dbe9

Please sign in to comment.