Allow wrapping expressions in parentheses
This commit is contained in:
parent
f3921ba87c
commit
f486d87976
@ -5,9 +5,9 @@ cards = {
|
||||
}
|
||||
|
||||
is_ready_to_solve = (cards <map>) <bool> {
|
||||
length(cards:suspects) == 1
|
||||
&& length(cards:rooms) == 1
|
||||
&& length(cards:weapons) == 1
|
||||
(length(cards:suspects) == 1)
|
||||
&& (length(cards:rooms) == 1)
|
||||
&& (length(cards:weapons) == 1)
|
||||
}
|
||||
|
||||
remove_card = (cards <map>, opponent_card <str>) <none> {
|
||||
@ -19,7 +19,7 @@ remove_card = (cards <map>, opponent_card <str>) <none> {
|
||||
make_guess = (cards <map>, current_room <str>) <none> {
|
||||
if is_ready_to_solve(cards) {
|
||||
output(
|
||||
'It was '
|
||||
'I accuse '
|
||||
+ cards:suspects:0
|
||||
+ ' in the '
|
||||
+ cards:rooms:0
|
||||
@ -29,7 +29,7 @@ make_guess = (cards <map>, current_room <str>) <none> {
|
||||
)
|
||||
} else {
|
||||
output(
|
||||
'I accuse '
|
||||
'I question '
|
||||
+ random(cards:suspects)
|
||||
+ ' in the '
|
||||
+ current_room
|
||||
|
@ -1,4 +1,4 @@
|
||||
data = (from_json (read 'examples/assets/jq_data.json'))
|
||||
data = from_json(read('examples/assets/jq_data.json'))
|
||||
|
||||
new_data = []
|
||||
|
||||
|
@ -34,27 +34,11 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(logic
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
@ -63,7 +47,23 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))))))))))
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(block
|
||||
(statement
|
||||
(expression
|
||||
|
199
tree-sitter-dust/corpus/logic.txt
Normal file
199
tree-sitter-dust/corpus/logic.txt
Normal file
@ -0,0 +1,199 @@
|
||||
================================================================================
|
||||
Simple Logic
|
||||
================================================================================
|
||||
|
||||
true && false
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(boolean)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(boolean)))))))
|
||||
|
||||
================================================================================
|
||||
Logic Sequence
|
||||
================================================================================
|
||||
|
||||
1 == 2 || false
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(boolean)))))))
|
||||
|
||||
================================================================================
|
||||
Complex Logic Sequence
|
||||
================================================================================
|
||||
|
||||
(length(suspects) == 1)
|
||||
&& (length(rooms) == 1)
|
||||
&& (length(weapons) == 1)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(identifier
|
||||
(built_in_function)))
|
||||
(expression
|
||||
(identifier))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(identifier
|
||||
(built_in_function)))
|
||||
(expression
|
||||
(identifier))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(identifier
|
||||
(built_in_function)))
|
||||
(expression
|
||||
(identifier))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))))))
|
||||
|
||||
================================================================================
|
||||
\==
|
||||
================================================================================
|
||||
|
||||
3 == 1 + 1 + 1
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))))
|
||||
|
||||
================================================================================
|
||||
&&
|
||||
================================================================================
|
||||
|
||||
4 + 2 == 42 && true
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(boolean)))))))
|
||||
|
||||
================================================================================
|
||||
\||
|
||||
================================================================================
|
||||
|
||||
4 + 2 == 42 || true
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(boolean)))))))
|
@ -1,95 +0,0 @@
|
||||
================================================================================
|
||||
\==
|
||||
================================================================================
|
||||
|
||||
3 == 1 + 1 + 1
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))))))
|
||||
|
||||
================================================================================
|
||||
&&
|
||||
================================================================================
|
||||
|
||||
4 + 2 == 42 && true
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(boolean)))))))))
|
||||
|
||||
================================================================================
|
||||
\||
|
||||
================================================================================
|
||||
|
||||
4 + 2 == 42 || true
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(value
|
||||
(boolean)))))))))
|
@ -109,19 +109,19 @@ x = 3 == 1 + 2 + 2
|
||||
(identifier)
|
||||
(assignment_operator)
|
||||
(statement
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(logic
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(logic_operator)
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(math
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(integer)))))
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
@ -129,4 +129,4 @@ x = 3 == 1 + 2 + 2
|
||||
(math_operator)
|
||||
(expression
|
||||
(value
|
||||
(integer)))))))))))
|
||||
(integer)))))))))
|
||||
|
@ -38,6 +38,16 @@ module.exports = grammar({
|
||||
),
|
||||
|
||||
expression: $ =>
|
||||
choice(
|
||||
$._expression_kind,
|
||||
seq(
|
||||
'(',
|
||||
$._expression_kind,
|
||||
')',
|
||||
),
|
||||
),
|
||||
|
||||
_expression_kind: $ =>
|
||||
prec.right(
|
||||
choice(
|
||||
$.function_call,
|
||||
@ -214,7 +224,7 @@ module.exports = grammar({
|
||||
choice('+', '-', '*', '/', '%'),
|
||||
|
||||
logic: $ =>
|
||||
prec.right(
|
||||
prec.left(
|
||||
seq(
|
||||
$.expression,
|
||||
$.logic_operator,
|
||||
|
@ -112,6 +112,32 @@
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression_kind"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression_kind"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"_expression_kind": {
|
||||
"type": "PREC_RIGHT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
@ -660,7 +686,7 @@
|
||||
]
|
||||
},
|
||||
"logic": {
|
||||
"type": "PREC_RIGHT",
|
||||
"type": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user