Compare commits

..

No commits in common. "96d0e967681147ff4255ab8b1d517b7d482fcd57" and "17ba01c0dc3f1f45f868dde8085f473bdd0abf35" have entirely different histories.

12 changed files with 7327 additions and 10570 deletions

@ -1 +1 @@
Subproject commit b476818ba3a5e005684fe3e3ee144b1014a6d5d0 Subproject commit 1f829d930a8a5d4683ac41c6a2085c5f482868cd

View File

@ -9,15 +9,17 @@ if true then "True"
(root (root
(item (item
(statement (statement
(expression (open_statement
(control_flow (expression
(expression (control_flow
(value
(boolean)))
(statement
(expression (expression
(value (value
(string))))))))) (boolean)))
(statement
(open_statement
(expression
(value
(string)))))))))))
================== ==================
@ -31,16 +33,20 @@ x = if true then 1
(root (root
(item (item
(statement (statement
(expression (open_statement
(assignment (expression
(identifier) (operation
(expression (expression
(control_flow (identifier))
(expression (operator)
(value (expression
(boolean))) (control_flow
(statement
(expression (expression
(value (value
(integer))))))))))) (boolean)))
(statement
(open_statement
(expression
(value
(integer)))))))))))))

View File

@ -10,13 +10,15 @@ function { "Hiya" }
(root (root
(item (item
(statement (statement
(expression (open_statement
(value (expression
(function (value
(statement (function
(expression (statement
(value (open_statement
(string)))))))))) (expression
(value
(string))))))))))))
================== ==================
Function Call Function Call
@ -29,11 +31,12 @@ foobar <"Hiya">
(root (root
(item (item
(statement (statement
(expression (open_statement
(function_call (expression
(identifier) (function_call
(value (identifier)
(string))))))) (value
(string))))))))
================== ==================
Complex Function Complex Function
@ -49,20 +52,25 @@ function <message, number> {
(root (root
(item (item
(statement (statement
(expression (open_statement
(value (expression
(function (value
(identifier) (function
(identifier) (identifier)
(statement (identifier)
(expression (statement
(identifier))) (open_statement
(statement (expression
(expression (identifier))))
(identifier))) (statement
(statement (open_statement
(expression (expression
(identifier))) (identifier))))
(statement (statement
(expression (open_statement
(identifier))))))))) (expression
(identifier))))
(statement
(open_statement
(expression
(identifier)))))))))))

View File

@ -9,13 +9,14 @@ List Declaration
(root (root
(item (item
(statement (statement
(expression (open_statement
(value (expression
(list (value
(value (list
(string)) (value
(value (string))
(integer)))))))) (value
(integer)))))))))
================== ==================
List Assignment List Assignment
@ -27,17 +28,77 @@ foobar = ['answer', 42]
(root (root
(item (item
(statement (statement
(expression (open_statement
(assignment (expression
(identifier) (operation
(expression (expression
(value (identifier))
(list (operator)
(value (expression
(string)) (value
(value (list
(integer)))))))))) (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)))))))))
================== ==================
List Nesting List Nesting
@ -50,19 +111,22 @@ foobar = ['answers', [42, [666]]]
(root (root
(item (item
(statement (statement
(expression (open_statement
(assignment (expression
(identifier) (operation
(expression (expression
(value (identifier))
(list (operator)
(value (expression
(string)) (value
(value (list
(list (value
(value (string))
(integer)) (value
(value (list
(list (value
(value (integer))
(integer)))))))))))))) (value
(list
(value
(integer)))))))))))))))

View File

@ -1,5 +1,5 @@
================== ==================
Simple Map Simple Maps
================== ==================
map { map {
@ -11,12 +11,13 @@ map {
(root (root
(item (item
(statement (statement
(expression (open_statement
(value (expression
(map (value
(identifier) (map
(value (identifier)
(integer)))))))) (value
(integer)))))))))
================== ==================
Map Assignment Map Assignment
@ -31,27 +32,48 @@ x = map {
(root (root
(item (item
(statement (statement
(expression (open_statement
(assignment (expression
(identifier) (operation
(expression (expression
(value (identifier))
(map (operator)
(identifier) (expression
(value (value
(integer)))))))))) (map
(identifier)
(value
(integer)))))))))))
================== ==================
Map Access Map Access
================== ==================
x = map {
answer = 42
}
x.answer x.answer
--- ---
(root (root
(item (item
(statement (statement
(open_statement
(expression (expression
(identifier))))) (operation
(expression
(identifier))
(operator)
(expression
(value
(map
(identifier)
(value
(integer))))))))))
(item
(statement
(open_statement
(expression
(identifier))))))

View File

@ -1,4 +1,4 @@
raw_data = download <"https://api.sampleapis.com/futurama/cast"> raw_data = download("https://api.sampleapis.com/futurama/cast");
dust_data = from_json <raw_data> data = from_json(raw_data);
assert_equal <"Billy West", data.0.name> assert_equal("Billy West", data.0.name);

View File

@ -1,34 +0,0 @@
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>

View File

@ -1,7 +1,12 @@
numbers = [1, 2 3] # Lists are created by grouping items in partheses and separating them with
# commas.
x = numbers.0 numbers = (1, 2, 3);
y = numbers.1
z = numbers.2
assert_equal <x + y, z> # 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);

View File

@ -35,8 +35,6 @@ module.exports = grammar({
$.assignment, $.assignment,
$.math, $.math,
$.logic, $.logic,
$.loop,
$.match,
)), )),
identifier: $ => /[a-z|_|.]+[0-9]?/, identifier: $ => /[a-z|_|.]+[0-9]?/,
@ -58,6 +56,8 @@ module.exports = grammar({
string: $ => /(".*?")|('.*?')|(`.*?`)/, string: $ => /(".*?")|('.*?')|(`.*?`)/,
empty: $ => '()',
boolean: $ => choice( boolean: $ => choice(
'true', 'true',
'false', 'false',
@ -123,7 +123,7 @@ module.exports = grammar({
assignment: $ => prec.right(seq( assignment: $ => prec.right(seq(
$.identifier, $.identifier,
choice("=", "+=", "-="), choice("=", "+=", "-="),
$.statement, $.expression,
)), )),
select: $ => prec.right(seq( select: $ => prec.right(seq(
@ -162,33 +162,5 @@ 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)),
'}',
),
} }
}); });

View File

@ -143,14 +143,6 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "logic" "name": "logic"
},
{
"type": "SYMBOL",
"name": "loop"
},
{
"type": "SYMBOL",
"name": "match"
} }
] ]
} }
@ -212,6 +204,10 @@
"type": "PATTERN", "type": "PATTERN",
"value": "(\".*?\")|('.*?')|(`.*?`)" "value": "(\".*?\")|('.*?')|(`.*?`)"
}, },
"empty": {
"type": "STRING",
"value": "()"
},
"boolean": { "boolean": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -550,7 +546,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "expression"
} }
] ]
} }
@ -732,106 +728,6 @@
} }
] ]
} }
},
"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": [ "extras": [

View File

@ -8,11 +8,11 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "identifier", "type": "expression",
"named": true "named": true
}, },
{ {
"type": "statement", "type": "identifier",
"named": true "named": true
} }
] ]
@ -23,21 +23,6 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "break_loop",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "statement",
"named": true
}
]
}
},
{ {
"type": "comment", "type": "comment",
"named": true, "named": true,
@ -94,14 +79,6 @@
"type": "logic", "type": "logic",
"named": true "named": true
}, },
{
"type": "loop",
"named": true
},
{
"type": "match",
"named": true
},
{ {
"type": "math", "type": "math",
"named": true "named": true
@ -236,25 +213,6 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "loop",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "break_loop",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
},
{ {
"type": "map", "type": "map",
"named": true, "named": true,
@ -274,25 +232,6 @@
] ]
} }
}, },
{
"type": "match",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
}
},
{ {
"type": "math", "type": "math",
"named": true, "named": true,
@ -432,25 +371,6 @@
] ]
} }
}, },
{
"type": "while_loop",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
}
},
{ {
"type": "yield", "type": "yield",
"named": true, "named": true,
@ -530,10 +450,6 @@
"type": "==", "type": "==",
"named": false "named": false
}, },
{
"type": "=>",
"named": false
},
{ {
"type": ">", "type": ">",
"named": false "named": false
@ -590,18 +506,10 @@
"type": "into", "type": "into",
"named": false "named": false
}, },
{
"type": "loop",
"named": false
},
{ {
"type": "map", "type": "map",
"named": false "named": false
}, },
{
"type": "match",
"named": false
},
{ {
"type": "or", "type": "or",
"named": false "named": false
@ -630,10 +538,6 @@
"type": "where", "type": "where",
"named": false "named": false
}, },
{
"type": "while",
"named": false
},
{ {
"type": "{", "type": "{",
"named": false "named": false

17292
src/parser.c

File diff suppressed because it is too large Load Diff