Add new tests and grammar

This commit is contained in:
Jeff 2023-08-24 09:31:26 -04:00
parent 10086fcf59
commit 3aa005530f
5 changed files with 948 additions and 523 deletions

View File

@ -46,40 +46,20 @@ x.x
Operators
==================
x = y
x + y
x | y
x - y
x / y
x ; y
x = y + y;
---
(source_file
(expression
(identifier)
(operator)
(identifier))
(expression
(identifier)
(operator)
(expression
(identifier))
(expression
(identifier)
(operator)
(expression
(identifier))
(expression
(identifier)
(operator)
(identifier))
(expression
(identifier)
(operator)
(identifier))
(expression
(identifier)
(operator)
(identifier)))
(operator))
==================
String
@ -105,6 +85,19 @@ Integer
(expression
(integer)))
==================
Float
==================
1.0
---
(source_file
(expression
(float)))
==================
List
==================
@ -121,5 +114,31 @@ List
(expression
(integer)))))
==================
Empty
==================
()
---
(source_file
(expression
(empty)))
==================
Tool
==================
random_boolean();
---
(source_file
(expression
(tool))
(expression
(empty))
(operator))

View File

@ -2,17 +2,18 @@ module.exports = grammar({
name: 'dust',
rules: {
source_file: $ => repeat(choice($.comment, $.expression)),
source_file: $ => repeat(choice($.comment, $.expression, $.operator)),
comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice(
$.identifier,
$.integer,
$.float,
$.string,
$.list,
$.macro,
seq($.identifier, $.operator, $.identifier)
$.tool,
$.empty,
),
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
@ -27,21 +28,28 @@ module.exports = grammar({
'&'
),
integer: $ => /\d/,
tool: $ => choice(
"random",
"random_boolean",
"random_integer",
"random_string",
"random_float"
),
float: $ => /\d+\.\d*/,
integer: $ => /\d+/,
string: $ => /"(.*?)\"/,
function: $ => /'(.*?)\'/,
empty: $ => "()",
list: $ => seq(
'(',
repeat1(seq($.expression, optional(','))),
')'
),
macro: $ => choice(
"assert",
"assert_equal"
)
}
});

View File

@ -13,6 +13,10 @@
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "operator"
}
]
}
@ -32,6 +36,10 @@
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "string"
@ -42,24 +50,11 @@
},
{
"type": "SYMBOL",
"name": "macro"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"name": "tool"
},
{
"type": "SYMBOL",
"name": "operator"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
"name": "empty"
}
]
},
@ -100,9 +95,38 @@
}
]
},
"tool": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "random"
},
{
"type": "STRING",
"value": "random_boolean"
},
{
"type": "STRING",
"value": "random_integer"
},
{
"type": "STRING",
"value": "random_string"
},
{
"type": "STRING",
"value": "random_float"
}
]
},
"float": {
"type": "PATTERN",
"value": "\\d+\\.\\d*"
},
"integer": {
"type": "PATTERN",
"value": "\\d"
"value": "\\d+"
},
"string": {
"type": "PATTERN",
@ -112,6 +136,10 @@
"type": "PATTERN",
"value": "'(.*?)\\'"
},
"empty": {
"type": "STRING",
"value": "()"
},
"list": {
"type": "SEQ",
"members": [
@ -148,19 +176,6 @@
"value": ")"
}
]
},
"macro": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "assert"
},
{
"type": "STRING",
"value": "assert_equal"
}
]
}
},
"extras": [

View File

@ -4,9 +4,17 @@
"named": true,
"fields": {},
"children": {
"multiple": true,
"multiple": false,
"required": true,
"types": [
{
"type": "empty",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "identifier",
"named": true
@ -19,17 +27,13 @@
"type": "list",
"named": true
},
{
"type": "macro",
"named": true
},
{
"type": "operator",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "tool",
"named": true
}
]
}
@ -49,11 +53,6 @@
]
}
},
{
"type": "macro",
"named": true,
"fields": {}
},
{
"type": "operator",
"named": true,
@ -74,10 +73,19 @@
{
"type": "expression",
"named": true
},
{
"type": "operator",
"named": true
}
]
}
},
{
"type": "tool",
"named": true,
"fields": {}
},
{
"type": "&",
"named": false
@ -114,18 +122,18 @@
"type": "=",
"named": false
},
{
"type": "assert",
"named": false
},
{
"type": "assert_equal",
"named": false
},
{
"type": "comment",
"named": true
},
{
"type": "empty",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "identifier",
"named": true
@ -134,6 +142,26 @@
"type": "integer",
"named": true
},
{
"type": "random",
"named": false
},
{
"type": "random_boolean",
"named": false
},
{
"type": "random_float",
"named": false
},
{
"type": "random_integer",
"named": false
},
{
"type": "random_string",
"named": false
},
{
"type": "string",
"named": true

File diff suppressed because it is too large Load Diff