Add calls
This commit is contained in:
parent
ff43112b5f
commit
5004b7fc38
@ -55,6 +55,21 @@ or = x \/ y;
|
||||
(assignment_item (identifier) (binary_operation (identifier) (identifier)))
|
||||
(assignment_item (identifier) (binary_operation (identifier) (identifier))))
|
||||
|
||||
====
|
||||
Call
|
||||
====
|
||||
|
||||
no_args = my_fn();
|
||||
single_arg = my_fn(1);
|
||||
mult_args = my_fn(2, "test");
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(assignment_item (identifier) (call (identifier)))
|
||||
(assignment_item (identifier) (call (identifier) (integer_literal)))
|
||||
(assignment_item (identifier) (call (identifier) (integer_literal) (string_literal))))
|
||||
|
||||
================
|
||||
Index Expression
|
||||
================
|
||||
|
20
grammar.js
20
grammar.js
@ -26,7 +26,7 @@ module.exports = grammar({
|
||||
word: $ => $.identifier,
|
||||
|
||||
rules: {
|
||||
source_file: $ => seq(sepBy(';', $._items), optional(';')),
|
||||
source_file: $ => seq(sepBy(';', $._items)),
|
||||
|
||||
_items: $ => choice(
|
||||
$.assignment_item,
|
||||
@ -44,6 +44,7 @@ module.exports = grammar({
|
||||
$._literal,
|
||||
|
||||
$.binary_operation,
|
||||
$.call,
|
||||
$.index_expression,
|
||||
$.unary_operation,
|
||||
// TODO: Other expression types
|
||||
@ -77,6 +78,13 @@ module.exports = grammar({
|
||||
))));
|
||||
},
|
||||
|
||||
call: $ => prec(PREC.call, seq(
|
||||
field('name', $.identifier),
|
||||
'(',
|
||||
field('arguments', sepBy(',', $._expression)),
|
||||
')',
|
||||
)),
|
||||
|
||||
index_expression: $ => prec(PREC.call, seq(
|
||||
field('collection', $._expression),
|
||||
'[',
|
||||
@ -100,7 +108,7 @@ module.exports = grammar({
|
||||
),
|
||||
|
||||
absent: $ => '<>',
|
||||
array_literal: $ => seq('[', repeat(seq($._expression, ',')), optional($._expression), ']'),
|
||||
array_literal: $ => seq('[', sepBy(',', $._expression), ']'),
|
||||
boolean_literal: $ => choice('true', 'false'),
|
||||
float_literal: $ => token(choice(
|
||||
/\d+\.\d+/,
|
||||
@ -113,7 +121,7 @@ module.exports = grammar({
|
||||
/0b[01]+/,
|
||||
/0o[0-7]+/
|
||||
)),
|
||||
set_literal: $ => seq('{', repeat(seq($._expression, ',')), optional($._expression), '}'),
|
||||
set_literal: $ => seq('{', sepBy(',', $._expression), '}'),
|
||||
|
||||
string_literal: $ => seq(
|
||||
'"',
|
||||
@ -142,10 +150,6 @@ module.exports = grammar({
|
||||
}
|
||||
});
|
||||
|
||||
function sepBy1(sep, rule) {
|
||||
return seq(rule, repeat(seq(sep, rule)))
|
||||
}
|
||||
|
||||
function sepBy(sep, rule) {
|
||||
return optional(sepBy1(sep, rule))
|
||||
return seq(repeat(seq(rule, sep)), optional(rule))
|
||||
}
|
||||
|
314
src/grammar.json
vendored
314
src/grammar.json
vendored
@ -6,47 +6,35 @@
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_items"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_items"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_items"
|
||||
}
|
||||
]
|
||||
}
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -101,6 +89,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "binary_operation"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "call"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "index_expression"
|
||||
@ -111,60 +103,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"index_expression": {
|
||||
"type": "PREC",
|
||||
"value": 15,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "collection",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "indices",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"binary_operation": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
@ -745,6 +683,122 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"call": {
|
||||
"type": "PREC",
|
||||
"value": 15,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "arguments",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"index_expression": {
|
||||
"type": "PREC",
|
||||
"value": 15,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "collection",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "indices",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"unary_operation": {
|
||||
"type": "PREC",
|
||||
"value": 13,
|
||||
@ -824,30 +878,35 @@
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -918,30 +977,35 @@
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
114
src/node-types.json
vendored
114
src/node-types.json
vendored
@ -23,6 +23,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -78,6 +82,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -144,6 +152,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -320,6 +332,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -357,6 +373,80 @@
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"arguments": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "absent",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_operation",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "index_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "set_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_operation",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "index_expression",
|
||||
"named": true,
|
||||
@ -381,6 +471,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -435,6 +529,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -491,6 +589,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -595,6 +697,10 @@
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float_literal",
|
||||
"named": true
|
||||
@ -634,6 +740,14 @@
|
||||
"type": "\"",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "(",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ")",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "*",
|
||||
"named": false
|
||||
|
5170
src/parser.c
vendored
5170
src/parser.c
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user