| 8 | ) |
| 9 | |
| 10 | func (tree *ParserT) parseExpression(exec, incLogicalOps bool) error { |
| 11 | for ; tree.charPos < len(tree.expression); tree.charPos++ { |
| 12 | r := tree.expression[tree.charPos] |
| 13 | switch r { |
| 14 | case '#': |
| 15 | tree.charPos-- |
| 16 | return nil |
| 17 | |
| 18 | case ' ', '\t', '\r': |
| 19 | // whitespace. do nothing |
| 20 | |
| 21 | case '\n': |
| 22 | if len(tree.ast) == 0 { |
| 23 | // do nothing if just empty lines |
| 24 | tree.crLf() |
| 25 | continue |
| 26 | } |
| 27 | tree.charPos-- |
| 28 | return nil |
| 29 | |
| 30 | case ';': |
| 31 | // end expression |
| 32 | tree.charPos-- |
| 33 | return nil |
| 34 | |
| 35 | case '?': |
| 36 | switch tree.nextChar() { |
| 37 | case '?': |
| 38 | // null coalescing |
| 39 | tree.appendAst(symbols.NullCoalescing) |
| 40 | tree.charPos++ |
| 41 | case ':': |
| 42 | // elvis |
| 43 | tree.appendAst(symbols.Elvis) |
| 44 | tree.charPos++ |
| 45 | default: |
| 46 | // end expression |
| 47 | // (deprecated: :) |
| 48 | tree.charPos-- |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | case '|': |
| 53 | if incLogicalOps && tree.nextChar() == '|' { |
| 54 | // logic or |
| 55 | tree.appendAst(symbols.LogicalOr) |
| 56 | tree.charPos++ |
| 57 | } else { |
| 58 | // end expression |
| 59 | tree.charPos-- |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | case '&': |
| 64 | if tree.nextChar() == '&' { |
| 65 | if incLogicalOps { |
| 66 | // logic and |
| 67 | tree.appendAst(symbols.LogicalAnd) |