Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(parser): Add ternary support to the static parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdeboer committed Nov 26, 2013
1 parent 7e6e32d commit e37bd8f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
51 changes: 50 additions & 1 deletion bin/parser_generator_for_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,55 @@ main(arguments) {
"'Foo'|uppercase",
"1|increment:2",
"'abcd'|substring:1:offset",
"'abcd'|substring:1:3|uppercase"
"'abcd'|substring:1:3|uppercase",
"3*4~/2%5",
"7==3+4?10:20",
"false?10:20",
"5?10:20",
"null?10:20",
"true||false?10:20",
"true&&false?10:20",
"true?a=10:a=20",
"b=true?a=false?11:c=12:a=13",
'0?0:2',
'1?0:2',
'0?0?0:0:2',
'1?0?0:0:2',
'0?1?0:0:2',
'0?0?1:0:2',
'0?0?0:2:3',
'1?1?0:0:2',
'1?1?1:0:2',
'1?1?1:2:3',
'0?0:0?0:2',
'1?0:0?0:2',
'0?1:0?0:2',
'0?0:1?0:2',
'0?0:0?2:3',
'1?1:0?0:2',
'1?1:1?0:2',
'1?1:1?2:3',
'0&&1?0:1',
'1||0?0:0',
'0?0&&1:2',
'0?1&&1:2',
'0?0||0:1',
'0?0||1:2',
'1?0&&1:2',
'1?1&&1:2',
'1?0||0:1',
'1?0||1:2',
'0?1:0&&1',
'0?2:1&&1',
'0?1:0||0',
'0?2:0||1',
'1?1:0&&1',
'1?2:1&&1',
'1?1:0||0',
'1?2:0||1',
'returnTrue() ? returnString() : returnInt()',
'returnFalse() ? returnString() : returnInt()',
'identity(returnFalse() ? returnString() : returnInt())',
"taxRate ~/ 100 * subTotal"
]);
}
3 changes: 3 additions & 0 deletions lib/tools/parser_generator/dart_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class DartCodeGen implements ParserBackend {
// Returns the Dart code for a particular operator.
_op(fn) => fn == "undefined" ? "null" : fn;

Code ternaryFn(Code cond, Code trueBranch, Code falseBranch) =>
new Code("toBool(${cond.exp}) ? ${trueBranch.exp} : ${falseBranch.exp}");

Code binaryFn(Code left, String fn, Code right) {
if (fn == '+') {
return new Code("autoConvertAdd(${left.exp}, ${right.exp})");
Expand Down

0 comments on commit e37bd8f

Please sign in to comment.