Class: Twig::ExpressionParser::Infix::ConditionalTernary
Constant Summary
Twig::ExpressionParser::InfixExpressionParser::LEFT, Twig::ExpressionParser::InfixExpressionParser::RIGHT
Instance Method Summary
collapse
#left?, #right?, #type
Methods inherited from Base
#aliases, #to_s, #type
Instance Method Details
#associativity ⇒ Object
33
34
35
|
# File 'lib/twig/expression_parser/infix/conditional_ternary.rb', line 33
def associativity
LEFT
end
|
#description ⇒ Object
25
26
27
|
# File 'lib/twig/expression_parser/infix/conditional_ternary.rb', line 25
def description
'Conditional operator (a ? b : c)'
end
|
#name ⇒ Object
21
22
23
|
# File 'lib/twig/expression_parser/infix/conditional_ternary.rb', line 21
def name
'?'
end
|
#parse(parser, left, token) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/twig/expression_parser/infix/conditional_ternary.rb', line 7
def parse(parser, left, token)
then_expr = parser.parse_expression(precedence)
else_expr = if parser.stream.next_if(Token::PUNCTUATION_TYPE, ':')
parser.parse_expression(precedence)
else
Node::Expression::Constant.new('', token.lineno)
end
Node::Expression::Ternary.new(left, then_expr, else_expr, token.lineno)
end
|
#precedence ⇒ Object
29
30
31
|
# File 'lib/twig/expression_parser/infix/conditional_ternary.rb', line 29
def precedence
0
end
|