Class: Twig::ExpressionParser::Infix::Function
- Inherits:
-
Twig::ExpressionParser::InfixExpressionParser
- Object
- Base
- Twig::ExpressionParser::InfixExpressionParser
- Twig::ExpressionParser::Infix::Function
- Includes:
- ParsesArguments
- Defined in:
- lib/twig/expression_parser/infix/function.rb
Constant Summary
Constants inherited from Twig::ExpressionParser::InfixExpressionParser
Twig::ExpressionParser::InfixExpressionParser::LEFT, Twig::ExpressionParser::InfixExpressionParser::RIGHT
Instance Method Summary collapse
- #associativity ⇒ Object
- #description ⇒ Object
- #name ⇒ Object
- #parse(parser, left, token) ⇒ Object
- #precedence ⇒ Object
Methods inherited from Twig::ExpressionParser::InfixExpressionParser
Methods inherited from Base
Instance Method Details
#associativity ⇒ Object
61 62 63 |
# File 'lib/twig/expression_parser/infix/function.rb', line 61 def associativity LEFT end |
#description ⇒ Object
53 54 55 |
# File 'lib/twig/expression_parser/infix/function.rb', line 53 def description 'Twig function call' end |
#name ⇒ Object
49 50 51 |
# File 'lib/twig/expression_parser/infix/function.rb', line 49 def name '(' end |
#parse(parser, left, token) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/twig/expression_parser/infix/function.rb', line 9 def parse(parser, left, token) line = token.lineno unless left.is_a?(Node::Expression::Variable::Context) raise Error::Syntax.new( "Function name must be an identifier. got #{left.inspect}", line, parser.stream.source ) end name = left.attributes[:name] if (aliased = parser.imported_symbol(:function, name)) return Node::Expression::MacroReference.new( aliased[:node].nodes[:var], aliased[:name], parse_callable_arguments(parser, line, parse_open_parenthesis: false), line ) end args = parse_named_arguments(parser, parse_open_parenthesis: false) function = parser.function(name, args, line) # Helper method returned if function.is_a?(Node::Expression::Base) return function end if (callable = function.parser_callable) fake_node = Node::Empty.new(line) fake_node.source_context = parser.stream.source return callable.call(parser, fake_node, args, line) end function.node_class.new(function, args, line) end |
#precedence ⇒ Object
57 58 59 |
# File 'lib/twig/expression_parser/infix/function.rb', line 57 def precedence 512 end |