Skip to content

Commit

Permalink
Try fixing ambiguity with local definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
gruhn committed Oct 13, 2024
1 parent b71e07c commit 2d0c099
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
5 changes: 3 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ module.exports = grammar({
},


lambda_expr: $ => prec.right(1, seq(
lambda_expr: $ => prec.right('lambda', seq(
choice(
$.identifier,
// TODO: can lambdas args have type annotations?
Expand Down Expand Up @@ -384,10 +384,11 @@ module.exports = grammar({
'braced_any',
'local_def',
'if_else', // TODO: docs don't specify precedence
'lambda',
],
[
'tuple',
'parens',
'tuple',
],
[
'function_type',
Expand Down
54 changes: 41 additions & 13 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ action _ = all {
(qualified_identifier
(identifier))))))))))

=========================================
UFCS Application - Multi Line
=========================================

def _ = list
.filter(f)
.map(g)

---


=========================================
List Access via Index
=========================================
Expand Down Expand Up @@ -454,9 +465,9 @@ action _ = {
(qualified_identifier
(identifier))))))))))

==========================
Local Variable Definition
==========================
============================
Local Variable Definition 1
============================

def _ = and {
val coins = GetAllBalances(addr)
Expand Down Expand Up @@ -502,6 +513,16 @@ def _ = and {
(expr
(int_literal)))))))))))))))

============================
Local Variable Definition 2
============================

def _ = val test = foo.bar() 42
def _ = val test = foo.bar ()

---


===========================
Map Constructor
===========================
Expand Down Expand Up @@ -626,32 +647,39 @@ Tuple Constructor
============================

val _ = ()
val _ = (e_1)
val _ = (e_1) // <-- not a tuple
val _ = (e_1, e_2, e_3)

---

(source_file
(operator_definition
(qualified_identifier (identifier))
(qualified_identifier
(identifier))
(expr
(tuple_literal)))
(operator_definition
(qualified_identifier (identifier))
(qualified_identifier
(identifier))
(expr
(tuple_literal
(expr
(qualified_identifier (identifier))))))
(expr
(qualified_identifier
(identifier))))
(comment))
(operator_definition
(qualified_identifier (identifier))
(qualified_identifier
(identifier))
(expr
(tuple_literal
(expr
(qualified_identifier (identifier)))
(qualified_identifier
(identifier)))
(expr
(qualified_identifier (identifier)))
(qualified_identifier
(identifier)))
(expr
(qualified_identifier (identifier)))))))
(qualified_identifier
(identifier)))))))

============================
Match Expression
Expand Down
1 change: 1 addition & 0 deletions test/corpus/module-level-constructs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const N: int
const Proc: Set[str]

---

(source_file
(constant_declaration
(qualified_identifier (identifier))
Expand Down

0 comments on commit 2d0c099

Please sign in to comment.