fix: argument pattern vs pattern

pull/625/head^2
Nikolaj Sidorenco 2024-04-20 15:30:00 +07:00
parent 006922183e
commit 81281b6024
No known key found for this signature in database
5 changed files with 75 additions and 60 deletions

@ -1,5 +1,2 @@
let x =
(
1
2
)
let f x =
x + 1

@ -250,7 +250,7 @@ module.exports = grammar({
),
function_declaration_left: $ =>
prec.left(2, seq(
prec.left(3, seq(
optional('inline'),
optional($.access_modifier),
$._identifier_or_op,
@ -334,7 +334,11 @@ module.exports = grammar({
conjunct_pattern: $ => prec.left(0, seq($._pattern, '&', $._pattern)),
typed_pattern: $ => prec.left(3, seq($._pattern, ':', $.type)),
argument_patterns: $ => repeat1($._atomic_pattern),
argument_patterns: $ =>
// argument patterns are generally no different from normal patterns.
// however, any time an argument pattern is a valid node, (i.e. inside a beginning fun decl)
// it is always the correct node to construct.
prec(1000, repeat1($._atomic_pattern)),
field_pattern: $ => prec(1, seq($.long_identifier, '=', $._pattern)),
@ -635,13 +639,12 @@ module.exports = grammar({
)),
match_expression: $ =>
prec(PREC.MATCH_EXPR,
seq(
choice('match', 'match!'),
$._expression,
'with',
$.rules,
)),
seq(
choice('match', 'match!'),
$._expression,
'with',
$.rules,
),
function_expression: $ =>
prec(PREC.MATCH_EXPR,

72
src/grammar.json generated

@ -642,7 +642,7 @@
},
"function_declaration_left": {
"type": "PREC_LEFT",
"value": 2,
"value": 3,
"content": {
"type": "SEQ",
"members": [
@ -1165,10 +1165,14 @@
}
},
"argument_patterns": {
"type": "REPEAT1",
"type": "PREC",
"value": 1000,
"content": {
"type": "SYMBOL",
"name": "_atomic_pattern"
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_atomic_pattern"
}
}
},
"field_pattern": {
@ -2439,38 +2443,34 @@
}
},
"match_expression": {
"type": "PREC",
"value": 8,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "match"
},
{
"type": "STRING",
"value": "match!"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": "with"
},
{
"type": "SYMBOL",
"name": "rules"
}
]
}
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "match"
},
{
"type": "STRING",
"value": "match!"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": "with"
},
{
"type": "SYMBOL",
"name": "rules"
}
]
},
"function_expression": {
"type": "PREC",

@ -87,16 +87,6 @@ static inline bool is_bracket_end(TSLexer *lexer) {
case ']':
case '}':
return true;
case '|':
skip(lexer);
switch (lexer->lookahead) {
case ')':
case ']':
case '}':
return true;
default:
return false;
}
default:
return false;
}

@ -1931,6 +1931,31 @@ do
(const
(unit)))))))
================================================================================
simple function declaration
================================================================================
let f x =
x + 1
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(const
(int))))))
================================================================================
multi-line Array.map
================================================================================