@@ -987,6 +987,7 @@ struct Token {
987
987
GreaterEqual, // >=
988
988
LessThan, // <
989
989
LessEqual, // <=
990
+ Pipe, // |
990
991
Unknown,
991
992
Eof,
992
993
};
@@ -1123,6 +1124,8 @@ class Lexer {
1123
1124
return make_token (Token::Kind::Comma);
1124
1125
case ' :' :
1125
1126
return make_token (Token::Kind::Colon);
1127
+ case ' |' :
1128
+ return make_token (Token::Kind::Pipe);
1126
1129
case ' (' :
1127
1130
return make_token (Token::Kind::LeftParen);
1128
1131
case ' )' :
@@ -1781,6 +1784,47 @@ class Parser {
1781
1784
}
1782
1785
arguments.emplace_back (expr);
1783
1786
} break ;
1787
+
1788
+ // parse function call pipe syntax
1789
+ case Token::Kind::Pipe: {
1790
+ // get function name
1791
+ get_next_token ();
1792
+ if (tok.kind != Token::Kind::Id) {
1793
+ throw_parser_error (" expected function name, got '" + tok.describe () + " '" );
1794
+ }
1795
+ auto func = std::make_shared<FunctionNode>(tok.text , tok.text .data () - tmpl.content .c_str ());
1796
+ // add first parameter as last value from arguments
1797
+ func->number_args += 1 ;
1798
+ func->arguments .emplace_back (arguments.back ());
1799
+ arguments.pop_back ();
1800
+ get_peek_token ();
1801
+ if (peek_tok.kind == Token::Kind::LeftParen) {
1802
+ get_next_token ();
1803
+ // parse additional parameters
1804
+ do {
1805
+ get_next_token ();
1806
+ auto expr = parse_expression (tmpl);
1807
+ if (!expr) {
1808
+ break ;
1809
+ }
1810
+ func->number_args += 1 ;
1811
+ func->arguments .emplace_back (expr);
1812
+ } while (tok.kind == Token::Kind::Comma);
1813
+ if (tok.kind != Token::Kind::RightParen) {
1814
+ throw_parser_error (" expected right parenthesis, got '" + tok.describe () + " '" );
1815
+ }
1816
+ }
1817
+ // search store for defined function with such name and number of args
1818
+ auto function_data = function_storage.find_function (func->name , func->number_args );
1819
+ if (function_data.operation == FunctionStorage::Operation::None) {
1820
+ throw_parser_error (" unknown function " + func->name );
1821
+ }
1822
+ func->operation = function_data.operation ;
1823
+ if (function_data.operation == FunctionStorage::Operation::Callback) {
1824
+ func->callback = function_data.callback ;
1825
+ }
1826
+ arguments.emplace_back (func);
1827
+ } break ;
1784
1828
default :
1785
1829
goto break_loop;
1786
1830
}
0 commit comments