Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit 74c86a8

Browse files
committed
Add boolean data type
1 parent 6587fb6 commit 74c86a8

File tree

4 files changed

+267
-231
lines changed

4 files changed

+267
-231
lines changed

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ var evalParseTree = function (tree) {
191191
return parseMathExpression(parseTree(subtree.left), parseTree(subtree.right), subtree.operator);
192192
case 'UnaryExpression':
193193
return !parseTree(subtree.argument);
194+
case 'BooleanValue':
195+
return subtree.value;
194196
case 'ColorValue':
195197
subtree.value = color(subtree.value).toHexString();
196198
return subtree;

parser.jison

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
%lex
55
%%
66
\s+ /* skip whitespace */
7+
"true" return 'BOOL';
8+
"TRUE" return 'BOOL';
9+
"false" return 'BOOL';
10+
"FALSE" return 'BOOL';
711
"AND" return 'OP';
812
"and" yytext = yytext.toUpperCase(); return 'OP';
913
"OR" return 'OP';
@@ -233,6 +237,7 @@ expr
233237
| unary_expression { $$ = $1; }
234238
| LPAREN unary_expression RPAREN { $$ = $2; }
235239
| math_expression { $$ = $1; }
240+
| bool_value { $$ = $1; }
236241
| string { $$ = $1; }
237242
;
238243

@@ -258,10 +263,15 @@ math_expression
258263
| math_expression DIV math_expression { $$ = { type: 'MathematicalExpression', operator: $2, left: $1, right: $3 }; }
259264
| LPAREN math_expression RPAREN { $$ = $2; }
260265
| css_value { $$ = $1; }
261-
| color_value { $$ = $1; }
266+
| color_value { $$ = $1; }
262267
| value { $$ = $1; }
263268
;
264269

270+
bool_value
271+
: BOOL { $$ = { type: 'BooleanValue', value: $1.toLowerCase() == "true" }; }
272+
| LPAREN bool_value RPAREN { $$ = $2; }
273+
;
274+
265275
value
266276
: NUMBER { $$ = { type: 'Value', value: $1 }; }
267277
| SUB NUMBER { $$ = { type: 'Value', value: -$2 }; }

0 commit comments

Comments
 (0)