Correct grammar

This commit is contained in:
Jeff 2023-08-24 10:12:08 -04:00
parent f8c1c3d9b4
commit 7a80c89dc7
5 changed files with 1014 additions and 661 deletions

View File

@ -52,14 +52,14 @@ x = y + y;
(source_file
(expression
(identifier))
(identifier)
(operator)
(expression
(identifier))
(identifier)
(operator)
(expression
(identifier))
(operator))
(identifier))))
(chain))
==================
String
@ -70,7 +70,7 @@ String
---
(source_file
(expression
(value
(string)))
==================
@ -82,7 +82,7 @@ Integer
---
(source_file
(expression
(value
(integer)))
==================
@ -94,7 +94,7 @@ Float
---
(source_file
(expression
(value
(float)))
@ -107,12 +107,12 @@ List
---
(source_file
(expression
(value
(list
(expression
(integer))
(expression
(integer)))))
(value
(integer)))
(value
(integer))))
==================
Empty
@ -123,7 +123,7 @@ Empty
---
(source_file
(expression
(value
(empty)))
==================
@ -137,8 +137,8 @@ random_boolean();
(source_file
(expression
(tool))
(expression
(value
(empty))
(operator))
(chain))

View File

@ -1,28 +1,42 @@
module.exports = grammar({
name: 'dust',
name: 'Dust',
rules: {
source_file: $ => repeat(choice($.comment, $.expression, $.operator)),
source_file: $ => repeat(choice(
$.comment,
$.expression,
$.value,
$.yield,
$.chain
)),
comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice(
$.identifier,
$.tool,
seq($.identifier, $.operator, $.expression),
seq($.value, $.operator, $.value)
),
value: $ => choice(
$.integer,
$.float,
$.string,
$.list,
$.tool,
$.empty,
),
yield: $ => "->",
chain: $ => ";",
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
operator: $ => choice(
'=',
'-',
'+',
';',
'/',
'|',
'&'

View File

@ -1,5 +1,5 @@
{
"name": "dust",
"name": "Dust",
"rules": {
"source_file": {
"type": "REPEAT",
@ -16,7 +16,15 @@
},
{
"type": "SYMBOL",
"name": "operator"
"name": "value"
},
{
"type": "SYMBOL",
"name": "yield"
},
{
"type": "SYMBOL",
"name": "chain"
}
]
}
@ -32,6 +40,49 @@
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "tool"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "operator"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "operator"
},
{
"type": "SYMBOL",
"name": "value"
}
]
}
]
},
"value": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "integer"
@ -48,16 +99,20 @@
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "tool"
},
{
"type": "SYMBOL",
"name": "empty"
}
]
},
"yield": {
"type": "STRING",
"value": "->"
},
"chain": {
"type": "STRING",
"value": ";"
},
"identifier": {
"type": "PATTERN",
"value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*"
@ -77,10 +132,6 @@
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": ";"
},
{
"type": "STRING",
"value": "/"

View File

@ -4,15 +4,11 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": "empty",
"named": true
},
{
"type": "float",
"type": "expression",
"named": true
},
{
@ -20,20 +16,16 @@
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "list",
"named": true
},
{
"type": "string",
"type": "operator",
"named": true
},
{
"type": "tool",
"named": true
},
{
"type": "value",
"named": true
}
]
}
@ -66,6 +58,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "chain",
"named": true
},
{
"type": "comment",
"named": true
@ -75,7 +71,11 @@
"named": true
},
{
"type": "operator",
"type": "value",
"named": true
},
{
"type": "yield",
"named": true
}
]
@ -86,6 +86,37 @@
"named": true,
"fields": {}
},
{
"type": "value",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "empty",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "list",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{
"type": "&",
"named": false
@ -115,12 +146,12 @@
"named": false
},
{
"type": ";",
"type": "=",
"named": false
},
{
"type": "=",
"named": false
"type": "chain",
"named": true
},
{
"type": "comment",
@ -166,6 +197,10 @@
"type": "string",
"named": true
},
{
"type": "yield",
"named": true
},
{
"type": "|",
"named": false

File diff suppressed because it is too large Load Diff