1
0

Allow wrapping expressions in parentheses

This commit is contained in:
Jeff 2023-12-29 21:53:26 -05:00
parent f3921ba87c
commit f486d87976
9 changed files with 13991 additions and 12805 deletions

View File

@ -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

View File

@ -1,4 +1,4 @@
data = (from_json (read 'examples/assets/jq_data.json'))
data = from_json(read('examples/assets/jq_data.json'))
new_data = []

View File

@ -33,28 +33,12 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
(if
(expression
(logic
(expression
(value
(integer)))
(logic_operator)
(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

View 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)))))))

View File

@ -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)))))))))

View File

@ -110,23 +110,23 @@ x = 3 == 1 + 2 + 2
(assignment_operator)
(statement
(expression
(logic
(expression
(value
(integer)))
(logic_operator)
(math
(expression
(math
(expression
(math
(logic
(expression
(value
(integer)))
(math_operator)
(logic_operator)
(expression
(value
(integer)))))
(math_operator)
(expression
(value
(integer)))))))))))
(integer)))))
(math_operator)
(expression
(value
(integer)))))))))

View File

@ -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,

View File

@ -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