Compare commits
2 Commits
17ba01c0dc
...
96d0e96768
Author | SHA1 | Date | |
---|---|---|---|
96d0e96768 | |||
8c05154e43 |
@ -1 +1 @@
|
||||
Subproject commit 1f829d930a8a5d4683ac41c6a2085c5f482868cd
|
||||
Subproject commit b476818ba3a5e005684fe3e3ee144b1014a6d5d0
|
@ -9,17 +9,15 @@ if true then "True"
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(control_flow
|
||||
(expression
|
||||
(control_flow
|
||||
(expression
|
||||
(value
|
||||
(boolean)))
|
||||
(statement
|
||||
(expression
|
||||
(value
|
||||
(boolean)))
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(value
|
||||
(string)))))))))))
|
||||
(string)))))))))
|
||||
|
||||
|
||||
==================
|
||||
@ -33,20 +31,16 @@ x = if true then 1
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(control_flow
|
||||
(expression
|
||||
(assignment
|
||||
(identifier)
|
||||
(expression
|
||||
(control_flow
|
||||
(expression
|
||||
(value
|
||||
(boolean)))
|
||||
(statement
|
||||
(expression
|
||||
(value
|
||||
(boolean)))
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(value
|
||||
(integer)))))))))))))
|
||||
(integer)))))))))))
|
||||
|
||||
|
@ -10,15 +10,13 @@ function { "Hiya" }
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(value
|
||||
(function
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(value
|
||||
(string))))))))))))
|
||||
(expression
|
||||
(value
|
||||
(function
|
||||
(statement
|
||||
(expression
|
||||
(value
|
||||
(string))))))))))
|
||||
|
||||
==================
|
||||
Function Call
|
||||
@ -31,12 +29,11 @@ foobar <"Hiya">
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(function_call
|
||||
(identifier)
|
||||
(value
|
||||
(string))))))))
|
||||
(expression
|
||||
(function_call
|
||||
(identifier)
|
||||
(value
|
||||
(string)))))))
|
||||
|
||||
==================
|
||||
Complex Function
|
||||
@ -52,25 +49,20 @@ function <message, number> {
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(value
|
||||
(function
|
||||
(identifier)
|
||||
(identifier)
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(identifier))))
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(identifier))))
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(identifier))))
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(identifier)))))))))))
|
||||
(expression
|
||||
(value
|
||||
(function
|
||||
(identifier)
|
||||
(identifier)
|
||||
(statement
|
||||
(expression
|
||||
(identifier)))
|
||||
(statement
|
||||
(expression
|
||||
(identifier)))
|
||||
(statement
|
||||
(expression
|
||||
(identifier)))
|
||||
(statement
|
||||
(expression
|
||||
(identifier)))))))))
|
132
corpus/lists.txt
132
corpus/lists.txt
@ -9,14 +9,13 @@ List Declaration
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(string))
|
||||
(value
|
||||
(integer)))))))))
|
||||
(expression
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(string))
|
||||
(value
|
||||
(integer))))))))
|
||||
|
||||
==================
|
||||
List Assignment
|
||||
@ -28,77 +27,17 @@ foobar = ['answer', 42]
|
||||
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(string))
|
||||
(value
|
||||
(integer)))))))))))
|
||||
|
||||
==================
|
||||
List Access
|
||||
==================
|
||||
|
||||
x = foobar.0
|
||||
|
||||
---
|
||||
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(identifier))))))))
|
||||
|
||||
==================
|
||||
List Mutation
|
||||
==================
|
||||
|
||||
foobar = ['answer', 42]
|
||||
foobar += 'hiya'
|
||||
|
||||
---
|
||||
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(string))
|
||||
(value
|
||||
(integer))))))))))
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(value
|
||||
(string)))))))))
|
||||
(statement
|
||||
(expression
|
||||
(assignment
|
||||
(identifier)
|
||||
(expression
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(string))
|
||||
(value
|
||||
(integer))))))))))
|
||||
|
||||
==================
|
||||
List Nesting
|
||||
@ -111,22 +50,19 @@ foobar = ['answers', [42, [666]]]
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(string))
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(integer))
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(integer)))))))))))))))
|
||||
(expression
|
||||
(assignment
|
||||
(identifier)
|
||||
(expression
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(string))
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(integer))
|
||||
(value
|
||||
(list
|
||||
(value
|
||||
(integer))))))))))))))
|
@ -1,5 +1,5 @@
|
||||
==================
|
||||
Simple Maps
|
||||
Simple Map
|
||||
==================
|
||||
|
||||
map {
|
||||
@ -11,13 +11,12 @@ map {
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(value
|
||||
(map
|
||||
(identifier)
|
||||
(value
|
||||
(integer)))))))))
|
||||
(expression
|
||||
(value
|
||||
(map
|
||||
(identifier)
|
||||
(value
|
||||
(integer))))))))
|
||||
|
||||
==================
|
||||
Map Assignment
|
||||
@ -32,48 +31,27 @@ x = map {
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(value
|
||||
(map
|
||||
(identifier)
|
||||
(value
|
||||
(integer)))))))))))
|
||||
(expression
|
||||
(assignment
|
||||
(identifier)
|
||||
(expression
|
||||
(value
|
||||
(map
|
||||
(identifier)
|
||||
(value
|
||||
(integer))))))))))
|
||||
|
||||
==================
|
||||
Map Access
|
||||
==================
|
||||
|
||||
x = map {
|
||||
answer = 42
|
||||
}
|
||||
|
||||
x.answer
|
||||
|
||||
---
|
||||
|
||||
(root
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(item
|
||||
(statement
|
||||
(expression
|
||||
(operation
|
||||
(expression
|
||||
(identifier))
|
||||
(operator)
|
||||
(expression
|
||||
(value
|
||||
(map
|
||||
(identifier)
|
||||
(value
|
||||
(integer))))))))))
|
||||
(item
|
||||
(statement
|
||||
(open_statement
|
||||
(expression
|
||||
(identifier))))))
|
||||
(identifier)))))
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
raw_data = download("https://api.sampleapis.com/futurama/cast");
|
||||
data = from_json(raw_data);
|
||||
raw_data = download <"https://api.sampleapis.com/futurama/cast">
|
||||
dust_data = from_json <raw_data>
|
||||
|
||||
assert_equal("Billy West", data.0.name);
|
||||
assert_equal <"Billy West", data.0.name>
|
||||
|
34
examples/fizzbuzz.ds
Normal file
34
examples/fizzbuzz.ds
Normal file
@ -0,0 +1,34 @@
|
||||
fizzbuzz_basic = function <limit> {
|
||||
count = 1
|
||||
|
||||
while count < limit {
|
||||
count += 1
|
||||
|
||||
if count % 3 == 0 && count % 5 == 0 {
|
||||
output 'fizzbuzz'
|
||||
} else {
|
||||
if count % 3 == 0 {
|
||||
output 'fizz'
|
||||
}
|
||||
|
||||
if count % 5 == 0 {
|
||||
output 'buzz'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fizzbuzz_match <limit> {
|
||||
count = 1
|
||||
|
||||
while count < 1 {
|
||||
output match [count % 3 == 0, count % 5 == 0] {
|
||||
[true, false] => 'fizz'
|
||||
[false, true] => 'buzz'
|
||||
[true, true] => 'fizzbuzz'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fizzbuzz_basic<15>
|
||||
fizzbuzz_match<15>
|
@ -1,12 +1,7 @@
|
||||
# Lists are created by grouping items in partheses and separating them with
|
||||
# commas.
|
||||
numbers = [1, 2 3]
|
||||
|
||||
numbers = (1, 2, 3);
|
||||
x = numbers.0
|
||||
y = numbers.1
|
||||
z = numbers.2
|
||||
|
||||
# To access the values in a list, use an integer as an index.
|
||||
|
||||
x = numbers.0;
|
||||
y = numbers.1;
|
||||
z = numbers.2;
|
||||
|
||||
assert_equal(x + y, z);
|
||||
assert_equal <x + y, z>
|
||||
|
34
grammar.js
34
grammar.js
@ -35,6 +35,8 @@ module.exports = grammar({
|
||||
$.assignment,
|
||||
$.math,
|
||||
$.logic,
|
||||
$.loop,
|
||||
$.match,
|
||||
)),
|
||||
|
||||
identifier: $ => /[a-z|_|.]+[0-9]?/,
|
||||
@ -56,8 +58,6 @@ module.exports = grammar({
|
||||
|
||||
string: $ => /(".*?")|('.*?')|(`.*?`)/,
|
||||
|
||||
empty: $ => '()',
|
||||
|
||||
boolean: $ => choice(
|
||||
'true',
|
||||
'false',
|
||||
@ -123,7 +123,7 @@ module.exports = grammar({
|
||||
assignment: $ => prec.right(seq(
|
||||
$.identifier,
|
||||
choice("=", "+=", "-="),
|
||||
$.expression,
|
||||
$.statement,
|
||||
)),
|
||||
|
||||
select: $ => prec.right(seq(
|
||||
@ -162,5 +162,33 @@ module.exports = grammar({
|
||||
),
|
||||
'>',
|
||||
)),
|
||||
|
||||
loop: $ => choice(
|
||||
$.break_loop,
|
||||
$.while_loop,
|
||||
),
|
||||
|
||||
while_loop: $ => seq(
|
||||
'while',
|
||||
$.expression,
|
||||
'{',
|
||||
$.statement,
|
||||
'}',
|
||||
),
|
||||
|
||||
break_loop: $ => seq(
|
||||
'loop',
|
||||
'{',
|
||||
$.statement,
|
||||
'}',
|
||||
),
|
||||
|
||||
match: $ => seq(
|
||||
'match',
|
||||
$.expression,
|
||||
'{',
|
||||
repeat1(seq($.expression, '=>', $.statement)),
|
||||
'}',
|
||||
),
|
||||
}
|
||||
});
|
||||
|
114
src/grammar.json
114
src/grammar.json
@ -143,6 +143,14 @@
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "logic"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "loop"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "match"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -204,10 +212,6 @@
|
||||
"type": "PATTERN",
|
||||
"value": "(\".*?\")|('.*?')|(`.*?`)"
|
||||
},
|
||||
"empty": {
|
||||
"type": "STRING",
|
||||
"value": "()"
|
||||
},
|
||||
"boolean": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
@ -546,7 +550,7 @@
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
"name": "statement"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -728,6 +732,106 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"loop": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "break_loop"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "while_loop"
|
||||
}
|
||||
]
|
||||
},
|
||||
"while_loop": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "while"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "statement"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"break_loop": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "loop"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "statement"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"match": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "match"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "=>"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "statement"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
|
@ -8,11 +8,11 @@
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "statement",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
@ -23,6 +23,21 @@
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "break_loop",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "statement",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "comment",
|
||||
"named": true,
|
||||
@ -79,6 +94,14 @@
|
||||
"type": "logic",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "loop",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "match",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "math",
|
||||
"named": true
|
||||
@ -213,6 +236,25 @@
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "loop",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "break_loop",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "while_loop",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "map",
|
||||
"named": true,
|
||||
@ -232,6 +274,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "match",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "statement",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "math",
|
||||
"named": true,
|
||||
@ -371,6 +432,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "while_loop",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "statement",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "yield",
|
||||
"named": true,
|
||||
@ -450,6 +530,10 @@
|
||||
"type": "==",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "=>",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ">",
|
||||
"named": false
|
||||
@ -506,10 +590,18 @@
|
||||
"type": "into",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "loop",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "map",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "match",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "or",
|
||||
"named": false
|
||||
@ -538,6 +630,10 @@
|
||||
"type": "where",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "while",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "{",
|
||||
"named": false
|
||||
|
18154
src/parser.c
18154
src/parser.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user