1
0

Rework structs; Add enums; Remove yield statements

This commit is contained in:
Jeff 2024-02-14 20:23:33 -05:00
parent 390d1aa504
commit 4323c50d32
7 changed files with 30618 additions and 31123 deletions

View File

@ -0,0 +1,86 @@
================================================================================
Simple Enum
================================================================================
enum Foobar {
Foo,
Bar,
}
--------------------------------------------------------------------------------
(root
(statement
(type_definition
(enum_definition
(identifier)
(identifier)
(identifier)))))
================================================================================
Nested Enum
================================================================================
enum Foobar {
Foo(str),
Bar(enum BazBuff {
Baz,
Buff,
})
}
--------------------------------------------------------------------------------
(root
(statement
(type_definition
(enum_definition
(identifier)
(identifier)
(type)
(identifier)
(type_definition
(enum_definition
(identifier)
(identifier)
(identifier)))))))
================================================================================
Simple Enum Instance
================================================================================
new Foobar:Foo
--------------------------------------------------------------------------------
(root
(statement
(expression
(value
(enum_instance
(identifier)
(identifier))))))
================================================================================
Nested Enum Instance
================================================================================
new Foobar:Bar(new BazBuf:Baz(123))
--------------------------------------------------------------------------------
(root
(statement
(expression
(value
(enum_instance
(identifier)
(identifier)
(expression
(value
(enum_instance
(identifier)
(identifier)
(expression
(value
(integer)))))))))))

View File

@ -2,7 +2,7 @@
Simple Structure
================================================================================
struct {
struct Foo {
x <int>
y <float>
}
@ -11,21 +11,21 @@ struct {
(root
(statement
(expression
(value
(structure
(type_definition
(struct_definition
(identifier)
(identifier)
(type_specification
(type))
(identifier)
(type_specification
(type)))))))
(type))))))
================================================================================
Complex Structure
Nested Structure
================================================================================
Foo = struct {
struct Foo {
x <int>
y <float> = 0.0
@ -38,13 +38,9 @@ Foo = struct {
(root
(statement
(assignment
(type_definition
(struct_definition
(identifier)
(assignment_operator)
(statement
(expression
(value
(structure
(identifier)
(type_specification
(type))
@ -61,10 +57,12 @@ Foo = struct {
(identifier)))
(statement
(expression
(new
(value
(struct_instance
(identifier)
(map
(identifier)
(statement
(expression
(value
(integer))))))))))))))
(integer)))))))))))))

View File

@ -1,67 +0,0 @@
================================================================================
Simple Yield
================================================================================
1 -> output
--------------------------------------------------------------------------------
(root
(statement
(expression
(yield
(expression
(value
(integer)))
(function_expression
(value
(built_in_value)))))))
================================================================================
Yield Chain
================================================================================
x -> foo -> bar -> abc
--------------------------------------------------------------------------------
(root
(statement
(expression
(yield
(expression
(yield
(expression
(yield
(expression
(identifier))
(function_expression
(identifier))))
(function_expression
(identifier))))
(function_expression
(identifier))))))
================================================================================
Yielded Function Call
================================================================================
x -> foo(1)()
--------------------------------------------------------------------------------
(root
(statement
(expression
(function_call
(function_expression
(function_call
(function_expression
(yield
(expression
(identifier))
(function_expression
(identifier))))
(expression
(value
(integer)))))))))

View File

@ -25,6 +25,7 @@ module.exports = grammar({
$.return,
$.pipe,
$.while,
$.type_definition,
),
optional(';'),
),
@ -50,8 +51,6 @@ module.exports = grammar({
$.logic,
$.math,
$.value,
$.yield,
$.new,
$.command,
),
),
@ -125,61 +124,13 @@ module.exports = grammar({
$.map,
$.option,
$.built_in_value,
$.structure,
$.range,
$.struct_instance,
$.enum_instance,
),
range: $ => /\d+[.]{2}\d+/,
structure: $ =>
seq(
'struct',
'{',
repeat(
choice(
seq(
$.identifier,
$.type_specification,
),
seq(
$.identifier,
'=',
$.statement,
),
seq(
$.identifier,
$.type_specification,
'=',
$.statement,
),
),
),
'}',
),
new: $ =>
seq(
'new',
$.identifier,
'{',
repeat(
choice(
seq(
$.identifier,
'=',
$.statement,
),
seq(
$.identifier,
$.type_specification,
'=',
$.statement,
),
),
),
'}',
),
integer: $ => /[-]?\d+/,
float: $ =>
@ -453,7 +404,6 @@ module.exports = grammar({
$.identifier,
$.index,
$.value,
$.yield,
),
),
@ -467,22 +417,85 @@ module.exports = grammar({
),
),
yield: $ =>
prec.left(
1,
type_definition: $ =>
choice(
$.enum_definition,
$.struct_definition,
),
enum_definition: $ =>
prec.right(
seq(
$.expression,
'->',
$.function_expression,
'enum',
$.identifier,
repeat(
seq(
'{',
repeat1(
seq(
$.identifier,
optional(
seq(
'(',
$._expression_list,
choice(
$.type,
$.type_definition,
),
')',
),
),
optional(','),
),
),
'}',
),
),
),
),
enum_instance: $ =>
prec.right(
seq(
'new',
$.identifier,
':',
$.identifier,
optional(
seq('(', $.expression, ')'),
),
),
),
struct_definition: $ =>
seq(
'struct',
$.identifier,
'{',
repeat(
choice(
seq(
$.identifier,
$.type_specification,
),
seq(
$.identifier,
'=',
$.statement,
),
seq(
$.identifier,
$.type_specification,
'=',
$.statement,
),
),
),
'}',
),
struct_instance: $ =>
seq('new', $.identifier, $.map),
built_in_value: $ =>
choice(

View File

@ -65,6 +65,10 @@
{
"type": "SYMBOL",
"name": "while"
},
{
"type": "SYMBOL",
"name": "type_definition"
}
]
},
@ -143,14 +147,6 @@
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "yield"
},
{
"type": "SYMBOL",
"name": "new"
},
{
"type": "SYMBOL",
"name": "command"
@ -364,11 +360,15 @@
},
{
"type": "SYMBOL",
"name": "structure"
"name": "range"
},
{
"type": "SYMBOL",
"name": "range"
"name": "struct_instance"
},
{
"type": "SYMBOL",
"name": "enum_instance"
}
]
},
@ -376,149 +376,6 @@
"type": "PATTERN",
"value": "\\d+[.]{2}\\d+"
},
"structure": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "struct"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "type_specification"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "type_specification"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
}
]
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"new": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "new"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "type_specification"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
}
]
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"integer": {
"type": "PATTERN",
"value": "[-]?\\d+"
@ -1406,10 +1263,6 @@
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "yield"
}
]
}
@ -1447,23 +1300,131 @@
]
}
},
"yield": {
"type": "PREC_LEFT",
"value": 1,
"type_definition": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "enum_definition"
},
{
"type": "SYMBOL",
"name": "struct_definition"
}
]
},
"enum_definition": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "enum"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "->"
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type"
},
{
"type": "SYMBOL",
"name": "function_expression"
"name": "type_definition"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
}
}
]
}
},
"enum_instance": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "new"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
@ -1477,7 +1438,7 @@
},
{
"type": "SYMBOL",
"name": "_expression_list"
"name": "expression"
},
{
"type": "STRING",
@ -1493,6 +1454,103 @@
]
}
},
"struct_definition": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "struct"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "type_specification"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "type_specification"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
}
]
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"struct_instance": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "new"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "map"
}
]
},
"built_in_value": {
"type": "CHOICE",
"members": [

View File

@ -133,6 +133,48 @@
]
}
},
{
"type": "enum_definition",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_definition",
"named": true
}
]
}
},
{
"type": "enum_instance",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "expression",
"named": true,
@ -169,17 +211,9 @@
"type": "math",
"named": true
},
{
"type": "new",
"named": true
},
{
"type": "value",
"named": true
},
{
"type": "yield",
"named": true
}
]
}
@ -277,10 +311,6 @@
{
"type": "value",
"named": true
},
{
"type": "yield",
"named": true
}
]
}
@ -501,29 +531,6 @@
"named": true,
"fields": {}
},
{
"type": "new",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "statement",
"named": true
},
{
"type": "type_specification",
"named": true
}
]
}
},
{
"type": "option",
"named": true,
@ -636,6 +643,10 @@
"type": "return",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "while",
"named": true
@ -649,12 +660,12 @@
"fields": {}
},
{
"type": "structure",
"type": "struct_definition",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "identifier",
@ -671,6 +682,25 @@
]
}
},
{
"type": "struct_instance",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "map",
"named": true
}
]
}
},
{
"type": "type",
"named": true,
@ -690,6 +720,25 @@
]
}
},
{
"type": "type_definition",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "enum_definition",
"named": true
},
{
"type": "struct_definition",
"named": true
}
]
}
},
{
"type": "type_specification",
"named": true,
@ -721,6 +770,10 @@
"type": "built_in_value",
"named": true
},
{
"type": "enum_instance",
"named": true
},
{
"type": "float",
"named": true
@ -754,7 +807,7 @@
"named": true
},
{
"type": "structure",
"type": "struct_instance",
"named": true
}
]
@ -779,25 +832,6 @@
]
}
},
{
"type": "yield",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "function_expression",
"named": true
}
]
}
},
{
"type": "!=",
"named": false
@ -950,6 +984,10 @@
"type": "else if",
"named": false
},
{
"type": "enum",
"named": false
},
{
"type": "env",
"named": false

File diff suppressed because it is too large Load Diff