test expression edge-cases

pull/625/head
Nikolaj Sidorenco 2023-02-26 12:48:59 +07:00
parent 94d923b40b
commit 7264d90bef
5 changed files with 611077 additions and 560371 deletions

@ -742,3 +742,131 @@ do
(const (int))))
(return_expression
(const (unit)))))))
================================================================================
call function form list of functions
================================================================================
let x =
let fs = [id]
fs[0] 0
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier (identifier))))
(declaration_expression
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier (identifier))))
(list_expression
(long_identifier_or_op
(long_identifier
(identifier)))))
(application_expression
(index_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(const (int)))
(const (int)))))))
================================================================================
index list with value declaration
================================================================================
let x =
let ys = [1;2]
ys[
let x = 1
x
]
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier (identifier))))
(declaration_expression
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier (identifier))))
(list_expression
(const (int))
(const (int))))
(index_expression
(long_identifier_or_op
(long_identifier (identifier)))
(declaration_expression
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier (identifier))))
(const (int)))
(long_identifier_or_op
(long_identifier (identifier)))))))))
================================================================================
apply value declaration to function
================================================================================
let x =
id
(let x = 1
x)
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier (identifier))))
(application_expression
(long_identifier_or_op
(long_identifier (identifier)))
(paren_expression
(declaration_expression
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const (int)))
(long_identifier_or_op
(long_identifier (identifier)))))))))
================================================================================
apply value to function declaration
================================================================================
let x =
(let f = id
id) 4
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern (long_identifier (identifier))))
(application_expression
(paren_expression
(declaration_expression
(function_or_value_defn
(value_declaration_left
(identifier_pattern (long_identifier (identifier))))
(long_identifier_or_op (long_identifier (identifier))))
(long_identifier_or_op (long_identifier (identifier)))))
(const (int))))))

@ -479,15 +479,21 @@ module.exports = grammar({
"}",
)),
infix_expression: $ =>
_infix_expression_inner: $ =>
prec.left(PREC.SPECIAL_INFIX,
seq(
$._expression_inner,
optional($._virtual_end_decl),
$.infix_op,
$._expression_inner,
)),
infix_expression: $ =>
prec.left(PREC.SPECIAL_INFIX,
seq(
$._expression_inner,
repeat1($._infix_expression_inner),
)),
literal_expression: $ =>
prec(PREC.PAREN_EXPR,
choice(
@ -510,7 +516,7 @@ module.exports = grammar({
begin_end_expression: $ => prec(PREC.PAREN_EXPR, seq("begin", $._expressions, "end")),
paren_expression: $ => prec(PREC.PAREN_EXPR, seq("(", $._expressions, ")")),
paren_expression: $ => prec(PREC.PAREN_EXPR, seq("(", $._virtual_open_section, $._expressions, $._virtual_end_section, ")")),
for_expression: $ =>
prec.left(
@ -638,10 +644,12 @@ module.exports = grammar({
$._expression_inner,
optional(imm(".")),
imm("["),
$._virtual_open_section,
choice(
field("index", $._expression_inner),
field("index", $._expressions),
$.slice_ranges,
),
$._virtual_end_section,
"]",
)),
@ -928,8 +936,8 @@ module.exports = grammar({
// repeat(seq("|", $.comp_rule)),
// )),
slice_ranges: $ => prec.left(PREC.COMMA,
seq($.slice_range, repeat(seq(",", $.slice_range)))),
slice_ranges: $ =>
seq($.slice_range, repeat(seq(",", $.slice_range))),
_slice_range_special: $ =>
prec.left(PREC.DOTDOT_SLICE,
@ -941,12 +949,11 @@ module.exports = grammar({
),
slice_range: $ =>
prec(PREC.DOTDOT_SLICE,
choice(
$._slice_range_special,
$._expressions,
"*",
)),
),
//
// Computation expression (END)
@ -1524,7 +1531,7 @@ module.exports = grammar({
triple_quoted_string: $ => seq('"""', repeat($._simple_or_escape_char), imm('"""')),
_newline: $ => /\r?\n/,
unit: $ => seq("(", ")"),
unit: $ => seq("(", optional(seq($._virtual_open_section, $._virtual_end_section)), ")"),
const: $ => choice(
$.sbyte, $.int16, $.int32, $.int64, $.byte, $.uint16, $.uint32, $.int,

@ -1714,16 +1714,12 @@
]
}
},
"infix_expression": {
"_infix_expression_inner": {
"type": "PREC_LEFT",
"value": 16,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression_inner"
},
{
"type": "CHOICE",
"members": [
@ -1747,6 +1743,26 @@
]
}
},
"infix_expression": {
"type": "PREC_LEFT",
"value": 16,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression_inner"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_infix_expression_inner"
}
}
]
}
},
"literal_expression": {
"type": "PREC",
"value": 21,
@ -1859,10 +1875,18 @@
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_virtual_open_section"
},
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "SYMBOL",
"name": "_virtual_end_section"
},
{
"type": "STRING",
"value": ")"
@ -2382,6 +2406,10 @@
"value": "["
}
},
{
"type": "SYMBOL",
"name": "_virtual_open_section"
},
{
"type": "CHOICE",
"members": [
@ -2390,7 +2418,7 @@
"name": "index",
"content": {
"type": "SYMBOL",
"name": "_expression_inner"
"name": "_expressions"
}
},
{
@ -2399,6 +2427,10 @@
}
]
},
{
"type": "SYMBOL",
"name": "_virtual_end_section"
},
{
"type": "STRING",
"value": "]"
@ -2869,33 +2901,29 @@
]
},
"slice_ranges": {
"type": "PREC_LEFT",
"value": 13,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "slice_range"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "slice_range"
}
]
}
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "slice_range"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "slice_range"
}
]
}
]
}
}
]
},
"_slice_range_special": {
"type": "PREC_LEFT",
@ -2950,25 +2978,21 @@
}
},
"slice_range": {
"type": "PREC",
"value": 22,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_slice_range_special"
},
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "STRING",
"value": "*"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_slice_range_special"
},
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "STRING",
"value": "*"
}
]
},
"type": {
"type": "PREC",
@ -6010,6 +6034,27 @@
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_virtual_open_section"
},
{
"type": "SYMBOL",
"name": "_virtual_end_section"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"

@ -1610,7 +1610,7 @@
"named": true,
"fields": {
"index": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{

1171146
src/parser.c

File diff suppressed because it is too large Load Diff