@@ -1002,6 +1002,7 @@ struct Token {
10021002 GreaterEqual, // >=
10031003 LessThan, // <
10041004 LessEqual, // <=
1005+ Pipe, // |
10051006 Unknown,
10061007 Eof,
10071008 };
@@ -1138,6 +1139,8 @@ class Lexer {
11381139 return make_token (Token::Kind::Comma);
11391140 case ' :' :
11401141 return make_token (Token::Kind::Colon);
1142+ case ' |' :
1143+ return make_token (Token::Kind::Pipe);
11411144 case ' (' :
11421145 return make_token (Token::Kind::LeftParen);
11431146 case ' )' :
@@ -1797,6 +1800,47 @@ class Parser {
17971800 }
17981801 arguments.emplace_back (expr);
17991802 } break ;
1803+
1804+ // parse function call pipe syntax
1805+ case Token::Kind::Pipe: {
1806+ // get function name
1807+ get_next_token ();
1808+ if (tok.kind != Token::Kind::Id) {
1809+ throw_parser_error (" expected function name, got '" + tok.describe () + " '" );
1810+ }
1811+ auto func = std::make_shared<FunctionNode>(tok.text , tok.text .data () - tmpl.content .c_str ());
1812+ // add first parameter as last value from arguments
1813+ func->number_args += 1 ;
1814+ func->arguments .emplace_back (arguments.back ());
1815+ arguments.pop_back ();
1816+ get_peek_token ();
1817+ if (peek_tok.kind == Token::Kind::LeftParen) {
1818+ get_next_token ();
1819+ // parse additional parameters
1820+ do {
1821+ get_next_token ();
1822+ auto expr = parse_expression (tmpl);
1823+ if (!expr) {
1824+ break ;
1825+ }
1826+ func->number_args += 1 ;
1827+ func->arguments .emplace_back (expr);
1828+ } while (tok.kind == Token::Kind::Comma);
1829+ if (tok.kind != Token::Kind::RightParen) {
1830+ throw_parser_error (" expected right parenthesis, got '" + tok.describe () + " '" );
1831+ }
1832+ }
1833+ // search store for defined function with such name and number of args
1834+ auto function_data = function_storage.find_function (func->name , func->number_args );
1835+ if (function_data.operation == FunctionStorage::Operation::None) {
1836+ throw_parser_error (" unknown function " + func->name );
1837+ }
1838+ func->operation = function_data.operation ;
1839+ if (function_data.operation == FunctionStorage::Operation::Callback) {
1840+ func->callback = function_data.callback ;
1841+ }
1842+ arguments.emplace_back (func);
1843+ } break ;
18001844 default :
18011845 goto break_loop;
18021846 }
0 commit comments