more tests; add function expressions
This commit is contained in:
10
grammar.js
10
grammar.js
@@ -58,7 +58,7 @@ module.exports = grammar({
|
|||||||
$.literal_value,
|
$.literal_value,
|
||||||
$.collection_value,
|
$.collection_value,
|
||||||
$.variable_expr,
|
$.variable_expr,
|
||||||
// $.function_call,
|
$.function_call,
|
||||||
$.for_expr,
|
$.for_expr,
|
||||||
seq($.expr_term, $.index),
|
seq($.expr_term, $.index),
|
||||||
seq($.expr_term, $.get_attr),
|
seq($.expr_term, $.get_attr),
|
||||||
@@ -154,6 +154,14 @@ module.exports = grammar({
|
|||||||
|
|
||||||
variable_expr: $ => $.identifier,
|
variable_expr: $ => $.identifier,
|
||||||
|
|
||||||
|
function_call: $ => seq($.identifier, '(', optional($.function_arguments), ')'),
|
||||||
|
|
||||||
|
function_arguments: $ => seq(
|
||||||
|
$.expression,
|
||||||
|
repeat(seq(',', $.expression)),
|
||||||
|
optional(choice(',', '...'))
|
||||||
|
),
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
||||||
comment: $ => token(choice(
|
comment: $ => token(choice(
|
||||||
seq('#', /.*/),
|
seq('#', /.*/),
|
||||||
|
|||||||
@@ -152,6 +152,10 @@
|
|||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "variable_expr"
|
"name": "variable_expr"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "function_call"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "for_expr"
|
"name": "for_expr"
|
||||||
@@ -686,6 +690,81 @@
|
|||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "identifier"
|
"name": "identifier"
|
||||||
},
|
},
|
||||||
|
"function_call": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "("
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "function_arguments"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ")"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"function_arguments": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ","
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ","
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "..."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"comment": {
|
"comment": {
|
||||||
"type": "TOKEN",
|
"type": "TOKEN",
|
||||||
"content": {
|
"content": {
|
||||||
|
|||||||
@@ -156,6 +156,10 @@
|
|||||||
"type": "for_expr",
|
"type": "for_expr",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "function_call",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "get_attr",
|
"type": "get_attr",
|
||||||
"named": true
|
"named": true
|
||||||
@@ -312,6 +316,40 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "function_arguments",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "expression",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "function_call",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "function_arguments",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "identifier",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "get_attr",
|
"type": "get_attr",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
|||||||
3717
src/parser.c
3717
src/parser.c
File diff suppressed because it is too large
Load Diff
43
test/corpus/collections.txt
Normal file
43
test/corpus/collections.txt
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
==================
|
||||||
|
collection value tuple
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = [1, 2, "foo"]
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(collection_value
|
||||||
|
(tuple
|
||||||
|
(expression (expr_term (literal_value (numeric_lit))))
|
||||||
|
(expression (expr_term (literal_value (numeric_lit))))
|
||||||
|
(expression (expr_term (literal_value (string_lit)))))))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
collection value object
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = {1: 2, "foo"="bar"}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(collection_value
|
||||||
|
(object
|
||||||
|
(object_elem
|
||||||
|
(expression (expr_term (literal_value (numeric_lit))))
|
||||||
|
(expression (expr_term (literal_value (numeric_lit)))))
|
||||||
|
(object_elem
|
||||||
|
(expression (expr_term (literal_value (string_lit))))
|
||||||
|
(expression (expr_term (literal_value (string_lit))))))))))))
|
||||||
|
|
||||||
86
test/corpus/function_calls.txt
Normal file
86
test/corpus/function_calls.txt
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
==================
|
||||||
|
nonary function call
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar()
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(function_call
|
||||||
|
(identifier)))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
unary function call
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar("foo")
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(function_call
|
||||||
|
(identifier)
|
||||||
|
(function_arguments
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(literal_value
|
||||||
|
(string_lit)))))))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
variadic function call
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar(x...)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(function_call
|
||||||
|
(identifier)
|
||||||
|
(function_arguments
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(variable_expr
|
||||||
|
(identifier)))))))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
multiline function call
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar(
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"c"
|
||||||
|
)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(function_call
|
||||||
|
(identifier)
|
||||||
|
(function_arguments
|
||||||
|
(expression (expr_term (literal_value (string_lit))))
|
||||||
|
(expression (expr_term (literal_value (string_lit))))
|
||||||
|
(expression (expr_term (literal_value (string_lit)))))))))))
|
||||||
|
|
||||||
@@ -118,6 +118,24 @@ foo = "bar"
|
|||||||
(literal_value
|
(literal_value
|
||||||
(string_lit)))))))
|
(string_lit)))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
string literal escaped newline
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = "bar\nbaz"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(literal_value
|
||||||
|
(string_lit)))))))
|
||||||
|
|
||||||
|
|
||||||
==================
|
==================
|
||||||
string literal multi line error
|
string literal multi line error
|
||||||
==================
|
==================
|
||||||
@@ -187,22 +205,3 @@ foo = null
|
|||||||
(literal_value
|
(literal_value
|
||||||
(null_lit)))))))
|
(null_lit)))))))
|
||||||
|
|
||||||
==================
|
|
||||||
collection value tuple
|
|
||||||
==================
|
|
||||||
|
|
||||||
foo = [1, 2, "foo"]
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(config_file
|
|
||||||
(body
|
|
||||||
(attribute
|
|
||||||
(identifier)
|
|
||||||
(expression
|
|
||||||
(expr_term
|
|
||||||
(collection_value
|
|
||||||
(tuple
|
|
||||||
(expression (expr_term (literal_value (numeric_lit))))
|
|
||||||
(expression (expr_term (literal_value (numeric_lit))))
|
|
||||||
(expression (expr_term (literal_value (string_lit)))))))))))
|
|
||||||
86
test/corpus/splat.txt
Normal file
86
test/corpus/splat.txt
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
==================
|
||||||
|
get attr
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar.baz
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(expr_term
|
||||||
|
(variable_expr
|
||||||
|
(identifier)))
|
||||||
|
(get_attr
|
||||||
|
(identifier)))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
get index
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar[1]
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(expr_term
|
||||||
|
(variable_expr
|
||||||
|
(identifier)))
|
||||||
|
(index
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(literal_value
|
||||||
|
(numeric_lit))))))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
attr splat
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar.*.foo
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(expr_term
|
||||||
|
(variable_expr
|
||||||
|
(identifier)))
|
||||||
|
(splat
|
||||||
|
(attr_splat
|
||||||
|
(get_attr
|
||||||
|
(identifier)))))))))
|
||||||
|
|
||||||
|
==================
|
||||||
|
full splat
|
||||||
|
==================
|
||||||
|
|
||||||
|
foo = bar[*].foo
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(expr_term
|
||||||
|
(expr_term
|
||||||
|
(variable_expr
|
||||||
|
(identifier)))
|
||||||
|
(splat
|
||||||
|
(full_splat
|
||||||
|
(get_attr
|
||||||
|
(identifier)))))))))
|
||||||
Reference in New Issue
Block a user