/////////////////////////////////////////////////////////////////////////// Some values are expressions, which need to be lexed. The best way to determine whether an expression is either a single value, or needs to be lexed, is to lex it and count the tokens. For example: now+1d This should be lexed and surrounded by parentheses: ( now + 1d )
| 1861 | // 1d |
| 1862 | // ) |
| 1863 | std::vector<A2> CLI2::lexExpression(const std::string& expression) { |
| 1864 | std::vector<A2> lexed; |
| 1865 | std::string lexeme; |
| 1866 | Lexer::Type type; |
| 1867 | Lexer lex(expression); |
| 1868 | while (lex.token(lexeme, type)) { |
| 1869 | A2 token(lexeme, type); |
| 1870 | token.tag("FILTER"); |
| 1871 | lexed.push_back(token); |
| 1872 | } |
| 1873 | |
| 1874 | // If there were multiple tokens, parenthesize, because this expression will |
| 1875 | // be used as a value. |
| 1876 | if (lexed.size() > 1) { |
| 1877 | A2 openParen("(", Lexer::Type::op); |
| 1878 | openParen.tag("FILTER"); |
| 1879 | A2 closeParen(")", Lexer::Type::op); |
| 1880 | closeParen.tag("FILTER"); |
| 1881 | |
| 1882 | lexed.insert(lexed.begin(), openParen); |
| 1883 | lexed.push_back(closeParen); |
| 1884 | } |
| 1885 | |
| 1886 | return lexed; |
| 1887 | } |
| 1888 | |
| 1889 | //////////////////////////////////////////////////////////////////////////////// |
| 1890 |