This commit is contained in:
Jeff 2023-09-25 09:00:27 -04:00
commit 07bd2dbdfa
5 changed files with 1069 additions and 1067 deletions

View File

@ -4,15 +4,13 @@ Comments
# x = 1;
# unassigned_variable
x # xyz
#xyz
---
(source_file
(source
(comment)
(comment)
(expression
(identifier))
(comment))
==================
@ -28,19 +26,13 @@ x.x
---
(source_file
(expression
(source
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier))
(expression
(identifier))
(expression
(identifier))
(expression
(identifier))
(expression
(identifier))
(expression
(identifier)))
==================
Operators
@ -50,56 +42,58 @@ x = y + y;
---
(source_file
(expression
(source
(identifier)
(operator)
(expression
(identifier)
(operator)
(expression
(identifier))))
(chain))
(identifier)
(operator))
==================
String
==================
"string"
'string'
---
(source_file
(expression
(source
(value
(string))))
(string))
(value
(string)))
==================
Integer
==================
1
123
---
(source_file
(expression
(source
(value
(integer))))
(integer))
(value
(integer)))
==================
Float
==================
1.0
123.123
---
(source_file
(expression
(source
(value
(float))))
(float))
(value
(float)))
==================
List
@ -109,16 +103,13 @@ List
---
(source_file
(expression
(source
(value
(list
(expression
(value
(integer)))
(expression
(integer))
(value
(integer)))))))
(integer)))))
==================
Empty
@ -128,10 +119,9 @@ Empty
---
(source_file
(expression
(source
(value
(empty))))
(empty)))
==================
Tool
@ -141,13 +131,11 @@ random_boolean();
---
(source_file
(expression
(tool))
(expression
(source
(tool)
(value
(empty)))
(chain))
(empty))
(operator))
==================
Boolean
@ -157,26 +145,8 @@ true false
---
(source_file
(expression
(source
(value
(boolean))
(value
(boolean)))
(expression
(value
(boolean))))
==================
Function
==================
{ output "hi" }
---
(source_file
(expression
(value
(boolean)))
(expression
(value
(boolean))))

View File

@ -2,19 +2,17 @@ module.exports = grammar({
name: 'dust',
rules: {
source_file: $ => repeat(choice(
source: $ => repeat(choice(
$.comment,
$.expression,
$.yield,
$.chain
$.identifier,
$.value,
$.tool,
$.operator,
)),
expression: $ => choice(
prec(2, $.value),
prec(1, $.identifier),
$.tool,
seq($.identifier, $.operator, $.expression),
),
comment: $ => seq('#', /.*/),
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
value: $ => choice(
$.integer,
@ -23,23 +21,7 @@ module.exports = grammar({
$.list,
$.empty,
$.boolean,
),
comment: $ => /(#)(.+?)([\n\r])/,
yield: $ => "->",
chain: $ => ";",
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
operator: $ => choice(
'=',
'-',
'+',
'/',
'|',
'&'
$.function,
),
tool: $ => choice(
@ -47,20 +29,27 @@ module.exports = grammar({
"random_boolean",
"random_integer",
"random_string",
"random_float"
"random_float",
),
operator: $ => choice(
'=',
'-',
'+',
'/',
'|',
'&',
';',
"->",
),
float: $ => /\d+\.\d*/,
integer: $ => /\d+/,
string: $ => seq(
'"',
repeat(),
'"'
),
string: $ => /("|')(.*?)("|')/,
function: $ => /\{(.*?)\}/,
function: $ => /{(.*?)}/,
empty: $ => "()",
@ -71,7 +60,7 @@ module.exports = grammar({
list: $ => seq(
'(',
repeat1(seq($.expression, optional(','))),
repeat1(seq($.value, optional(','))),
')'
),
}

View File

@ -1,7 +1,7 @@
{
"name": "dust",
"rules": {
"source_file": {
"source": {
"type": "REPEAT",
"content": {
"type": "CHOICE",
@ -12,60 +12,39 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "yield"
},
{
"type": "SYMBOL",
"name": "chain"
}
]
}
},
"expression": {
"type": "CHOICE",
"members": [
{
"type": "PREC",
"value": 2,
"content": {
"type": "SYMBOL",
"name": "value"
}
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
"name": "tool"
},
{
"type": "SYMBOL",
"name": "operator"
}
]
}
},
"comment": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"type": "STRING",
"value": "#"
},
{
"type": "SYMBOL",
"name": "operator"
"type": "PATTERN",
"value": ".*"
}
]
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
]
"identifier": {
"type": "PATTERN",
"value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*"
},
"value": {
"type": "CHOICE",
@ -93,51 +72,10 @@
{
"type": "SYMBOL",
"name": "boolean"
}
]
},
"comment": {
"type": "PATTERN",
"value": "(#)(.+?)([\\n\\r])"
},
"yield": {
"type": "STRING",
"value": "->"
},
"chain": {
"type": "STRING",
"value": ";"
},
"identifier": {
"type": "PATTERN",
"value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*"
},
"operator": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "|"
},
{
"type": "STRING",
"value": "&"
"type": "SYMBOL",
"name": "function"
}
]
},
@ -166,6 +104,43 @@
}
]
},
"operator": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "|"
},
{
"type": "STRING",
"value": "&"
},
{
"type": "STRING",
"value": ";"
},
{
"type": "STRING",
"value": "->"
}
]
},
"float": {
"type": "PATTERN",
"value": "\\d+\\.\\d*"
@ -176,11 +151,11 @@
},
"string": {
"type": "PATTERN",
"value": "\"(.*?)\\\""
"value": "(\"|')(.*?)(\"|')"
},
"function": {
"type": "PATTERN",
"value": "'(.*?)\\'"
"value": "{(.*?)}"
},
"empty": {
"type": "STRING",
@ -213,7 +188,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "value"
},
{
"type": "CHOICE",

View File

@ -5,7 +5,12 @@
"fields": {}
},
{
"type": "expression",
"type": "comment",
"named": true,
"fields": {}
},
{
"type": "list",
"named": true,
"fields": {},
"children": {
@ -13,7 +18,27 @@
"required": true,
"types": [
{
"type": "expression",
"type": "value",
"named": true
}
]
}
},
{
"type": "operator",
"named": true,
"fields": {}
},
{
"type": "source",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "comment",
"named": true
},
{
@ -35,53 +60,6 @@
]
}
},
{
"type": "list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
},
{
"type": "operator",
"named": true,
"fields": {}
},
{
"type": "source_file",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "chain",
"named": true
},
{
"type": "comment",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "yield",
"named": true
}
]
}
},
{
"type": "tool",
"named": true,
@ -107,6 +85,10 @@
"type": "float",
"named": true
},
{
"type": "function",
"named": true
},
{
"type": "integer",
"named": true
@ -122,6 +104,10 @@
]
}
},
{
"type": "#",
"named": false
},
{
"type": "&",
"named": false
@ -146,22 +132,22 @@
"type": "-",
"named": false
},
{
"type": "->",
"named": false
},
{
"type": "/",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "=",
"named": false
},
{
"type": "chain",
"named": true
},
{
"type": "comment",
"named": true
},
{
"type": "empty",
"named": true
@ -174,6 +160,10 @@
"type": "float",
"named": true
},
{
"type": "function",
"named": true
},
{
"type": "identifier",
"named": true
@ -210,10 +200,6 @@
"type": "true",
"named": false
},
{
"type": "yield",
"named": true
},
{
"type": "|",
"named": false

File diff suppressed because it is too large Load Diff