Add meta-variables

This is an EPITA extension of the language, used mostly by internal
compiler machinery.
This commit is contained in:
Bruno BELANYI 2022-06-04 20:25:41 +02:00
parent 1cfcc43469
commit 572dab6f4b
5 changed files with 6785 additions and 4090 deletions

View file

@ -29,6 +29,7 @@ module.exports = grammar({
conflicts: ($) => [
[$._lvalue, $.array_expression],
[$._lvalue, $.record_expression],
[$._lvalue, $._type_identifier],
],
@ -73,6 +74,9 @@ module.exports = grammar({
$.for_expression,
$.break_expression,
$.let_expression,
$.meta_cast,
$.meta_expression,
),
nil_literal: (_) => "nil",
@ -88,7 +92,10 @@ module.exports = grammar({
// NOTE: includes reserved identifiers
identifier: (_) => /[_a-zA-Z0-9]+/,
_type_identifier: ($) => alias($.identifier, $.type_identifier),
_type_identifier: ($) => choice(
alias($.identifier, $.type_identifier),
$.meta_type_identifier,
),
_field_identifier: ($) => alias($.identifier, $.field_identifier),
@ -112,6 +119,7 @@ module.exports = grammar({
$.identifier,
$.record_value,
$.array_value,
$.meta_lvalue,
),
record_value: ($) => seq(
@ -245,7 +253,12 @@ module.exports = grammar({
// Declarations {{{
_declaration_chunks: ($) => repeat1($._declaration_chunk),
_declaration_chunks: ($) => repeat1(
choice(
$.meta_chunks,
$._declaration_chunk,
),
),
_declaration_chunk: ($) => prec.left(
choice(
@ -335,6 +348,47 @@ module.exports = grammar({
),
// }}}
// Meta-variables {{{
meta_chunks: ($) => seq(
"_chunks",
"(",
field("index", $.integer_literal),
")",
),
meta_cast: ($) => seq(
"_cast",
"(",
field("expression", $._expr),
",",
field("type", $._type),
")",
),
meta_expression: ($) => seq(
"_exp",
"(",
field("index", $.integer_literal),
")",
),
meta_lvalue: ($) => seq(
"_lvalue",
"(",
field("index", $.integer_literal),
")",
),
meta_type_identifier: ($) => seq(
"_namety",
"(",
$.integer_literal,
")",
),
// }}}
}
});

View file

@ -89,6 +89,14 @@
{
"type": "SYMBOL",
"name": "let_expression"
},
{
"type": "SYMBOL",
"name": "meta_cast"
},
{
"type": "SYMBOL",
"name": "meta_expression"
}
]
},
@ -134,13 +142,22 @@
"value": "[_a-zA-Z0-9]+"
},
"_type_identifier": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "identifier"
},
"named": true,
"value": "type_identifier"
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "identifier"
},
"named": true,
"value": "type_identifier"
},
{
"type": "SYMBOL",
"name": "meta_type_identifier"
}
]
},
"_field_identifier": {
"type": "ALIAS",
@ -245,6 +262,10 @@
{
"type": "SYMBOL",
"name": "array_value"
},
{
"type": "SYMBOL",
"name": "meta_lvalue"
}
]
},
@ -1063,8 +1084,17 @@
"_declaration_chunks": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_declaration_chunk"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "meta_chunks"
},
{
"type": "SYMBOL",
"name": "_declaration_chunk"
}
]
}
},
"_declaration_chunk": {
@ -1513,6 +1543,139 @@
}
}
]
},
"meta_chunks": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "_chunks"
},
{
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "index",
"content": {
"type": "SYMBOL",
"name": "integer_literal"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"meta_cast": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "_cast"
},
{
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "expression",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
},
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"meta_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "_exp"
},
{
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "index",
"content": {
"type": "SYMBOL",
"name": "integer_literal"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"meta_lvalue": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "_lvalue"
},
{
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "index",
"content": {
"type": "SYMBOL",
"name": "integer_literal"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"meta_type_identifier": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "_namety"
},
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "integer_literal"
},
{
"type": "STRING",
"value": ")"
}
]
}
},
"extras": [
@ -1530,6 +1693,10 @@
"_lvalue",
"array_expression"
],
[
"_lvalue",
"record_expression"
],
[
"_lvalue",
"_type_identifier"

View file

@ -51,6 +51,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -129,6 +141,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -163,6 +187,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -179,6 +207,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -203,6 +235,10 @@
"type": "identifier",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "record_value",
"named": true
@ -257,6 +293,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -305,6 +353,10 @@
"type": "identifier",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "record_value",
"named": true
@ -359,6 +411,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -453,6 +517,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -541,6 +617,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -625,6 +713,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -703,6 +803,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -791,6 +903,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -889,6 +1013,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -983,6 +1119,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1037,6 +1185,10 @@
"multiple": false,
"required": false,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -1097,6 +1249,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1175,6 +1339,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1253,6 +1429,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1357,6 +1545,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1399,6 +1599,10 @@
"type": "import_declaration",
"named": true
},
{
"type": "meta_chunks",
"named": true
},
{
"type": "primitive_declaration",
"named": true
@ -1415,6 +1619,183 @@
}
}
},
{
"type": "meta_cast",
"named": true,
"fields": {
"expression": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "break_expression",
"named": true
},
{
"type": "for_expression",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "if_expression",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "record_value",
"named": true
},
{
"type": "sequence_expression",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_type",
"named": true
},
{
"type": "record_type",
"named": true
},
{
"type": "type_alias",
"named": true
}
]
}
}
},
{
"type": "meta_chunks",
"named": true,
"fields": {
"index": {
"multiple": false,
"required": true,
"types": [
{
"type": "integer_literal",
"named": true
}
]
}
}
},
{
"type": "meta_expression",
"named": true,
"fields": {
"index": {
"multiple": false,
"required": true,
"types": [
{
"type": "integer_literal",
"named": true
}
]
}
}
},
{
"type": "meta_lvalue",
"named": true,
"fields": {
"index": {
"multiple": false,
"required": true,
"types": [
{
"type": "integer_literal",
"named": true
}
]
}
}
},
{
"type": "meta_type_identifier",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "integer_literal",
"named": true
}
]
}
},
{
"type": "parameters",
"named": true,
@ -1433,6 +1814,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -1469,6 +1854,10 @@
"multiple": false,
"required": false,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -1539,6 +1928,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1573,6 +1974,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -1599,6 +2004,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -1633,6 +2042,10 @@
"type": "identifier",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "record_value",
"named": true
@ -1693,6 +2106,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1784,6 +2209,22 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_chunks",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -1850,6 +2291,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -1943,6 +2388,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -2003,6 +2460,10 @@
"multiple": false,
"required": false,
"types": [
{
"type": "meta_type_identifier",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -2057,6 +2518,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -2151,6 +2624,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -2229,6 +2714,18 @@
"type": "let_expression",
"named": true
},
{
"type": "meta_cast",
"named": true
},
{
"type": "meta_expression",
"named": true
},
{
"type": "meta_lvalue",
"named": true
},
{
"type": "nil_literal",
"named": true
@ -2301,6 +2798,26 @@
"type": "]",
"named": false
},
{
"type": "_cast",
"named": false
},
{
"type": "_chunks",
"named": false
},
{
"type": "_exp",
"named": false
},
{
"type": "_lvalue",
"named": false
},
{
"type": "_namety",
"named": false
},
{
"type": "array",
"named": false

10050
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,65 @@
================================================================================
Meta chunks
================================================================================
_chunks(42)
--------------------------------------------------------------------------------
(source_file
(meta_chunks
index: (integer_literal)))
================================================================================
Cast
================================================================================
_cast(42, string)
--------------------------------------------------------------------------------
(source_file
(meta_cast
expression: (integer_literal)
type: (type_alias
(type_identifier))))
================================================================================
Meta expression
================================================================================
_exp(42)
--------------------------------------------------------------------------------
(source_file
(meta_expression
index: (integer_literal)))
================================================================================
Meta lvalue
================================================================================
_lvalue(42)
--------------------------------------------------------------------------------
(source_file
(meta_lvalue
index: (integer_literal)))
================================================================================
Meta type identifier
================================================================================
var a : _namety(42) := "I'm So Meta Even This Acronym"
--------------------------------------------------------------------------------
(source_file
(variable_declaration
name: (identifier)
type: (meta_type_identifier
(integer_literal))
(operator)
value: (string_literal)))