Add binary expressions

This commit is contained in:
Max Brunsfeld 2018-10-26 09:44:27 -07:00
parent 3e106ca94e
commit 8ba3d11be0
4 changed files with 3006 additions and 2478 deletions

View File

@ -54,6 +54,28 @@ a {
(declaration (property_name) (float_value (unit))) (declaration (property_name) (float_value (unit)))
(declaration (property_name) (integer_value (unit)))))) (declaration (property_name) (integer_value (unit))))))
============================
Binary arithmetic operators
============================
a {
width: calc(100% - 80px);
aspect-ratio: 1/2;
}
---
(stylesheet
(rule_set
(selectors (tag_name))
(block
(declaration
(property_name)
(call_expression (function_name) (arguments (binary_expression (integer_value (unit)) (integer_value (unit))))))
(declaration
(property_name)
(binary_expression (integer_value) (integer_value))))))
============================ ============================
Strings Strings
============================ ============================

View File

@ -185,6 +185,7 @@ module.exports = grammar({
$.integer_value, $.integer_value,
$.float_value, $.float_value,
$.string_value, $.string_value,
$.binary_expression,
$.call_expression $.call_expression
), ),
@ -223,6 +224,12 @@ module.exports = grammar({
$.arguments $.arguments
), ),
binary_expression: $ => prec.left(seq(
$._value,
choice('+', '-', '*', '/'),
$._value
)),
arguments: $ => seq( arguments: $ => seq(
token.immediate('('), token.immediate('('),
commaSep($._value), commaSep($._value),

42
src/grammar.json vendored
View File

@ -786,6 +786,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "string_value" "name": "string_value"
}, },
{
"type": "SYMBOL",
"name": "binary_expression"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "call_expression" "name": "call_expression"
@ -1039,6 +1043,44 @@
} }
] ]
}, },
"binary_expression": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_value"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "/"
}
]
},
{
"type": "SYMBOL",
"name": "_value"
}
]
}
},
"arguments": { "arguments": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [

5413
src/parser.c vendored

File diff suppressed because it is too large Load Diff