8#include <ext/algorithm>
31 unsigned m_forceLexerReadNext = { 0 };
35 void clearCheckOptions ( ) {
36 m_checkedOptions.clear ( );
40 return m_checkedOptions;
44 m_checkedOptions = std::move ( checkOptions );
47 std::string lineInfo ( )
const {
52 Parser (
cli::Lexer lexer ) : m_lexer (
std::move ( lexer ) ), m_current ( m_lexer.nextToken ( true ) ) {
57 m_lexer.
putback ( std::move ( m_current ) );
58 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
62 template <
class ... TokenTypes >
63 bool check ( TokenTypes ... tokens ) {
64 m_checkedOptions.merge ( std::set < cli::Lexer::Token > {
cli::Lexer::Token {
"",
"", tokens } ... } );
65 return ( ... || ( m_current.
m_type == tokens ) );
68 template <
class ... NonreservedTokens >
74 template <
class ... TokenTypes >
76 if ( !
check ( token, tokens ... ) )
78 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
82 template <
class ... NonreservedTokens >
85 throw exception::CommonException ( lineInfo ( ) +
"Mismatched token while matching a non reseved keyword: " + ( kw + ... + (
", " + kws ) ) +
". Tokens in active set " +
ext::to_string ( getCheckOptions ( ) ) +
"." );
86 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
90 template <
class ... TokenTypes >
92 if ( !
check ( token, tokens ... ) )
95 match ( token, tokens ... );
99 template <
class ... NonreservedTokens >
112 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
120 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
128 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
136 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
143 int res = ext::from_string < int > ( m_current.
m_value );
144 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
151 double res = ext::from_string < double > ( m_current.
m_value );
152 m_current = m_lexer.
nextToken ( m_forceLexerReadNext > 0 );
161 ++ m_forceLexerReadNext;
165 -- m_forceLexerReadNext;
169 return m_forceLexerReadNext == 0;
198 std::unique_ptr < Expression >
atom ( );
208 std::unique_ptr < Arg >
file ( );
210 std::unique_ptr < Arg >
type ( );
212 std::unique_ptr < Arg >
arg ( );
224 std::shared_ptr < Statement >
common ( );
226 std::shared_ptr < Statement >
param ( );
228 std::shared_ptr < Statement >
statement ( );
238 std::unique_ptr < CommandList >
block ( );
240 std::unique_ptr < Expression >
expression ( );
242 std::unique_ptr < Expression >
batch ( );
248 std::pair < abstraction::TypeQualifiers::TypeQualifierSet, std::unique_ptr < Arg > >
qualifiedType ( );
250 std::pair < abstraction::TypeQualifiers::TypeQualifierSet, std::unique_ptr < Arg > >
runnableParam ( );
252 std::unique_ptr < Command >
command ( );
256 std::unique_ptr < CommandList >
parse ( );
Hint
Definition: Lexer.h:23
void setHint(Hint hint)
Definition: Lexer.h:238
static std::string tokenTypeToString(TokenType type)
Definition: Lexer.h:90
void putback(Token &&token)
Definition: Lexer.h:234
Token nextToken(bool readNextLine=false)
Definition: Lexer.cpp:12
TokenType
Definition: Lexer.h:34
std::pair< abstraction::TypeQualifiers::TypeQualifierSet, std::unique_ptr< Arg > > runnableParam()
Definition: Parser.cpp:405
std::string matchString()
Definition: Parser.h:116
bool match_nonreserved_kw(const std::string &kw, const NonreservedTokens &... kws)
Definition: Parser.h:83
std::unique_ptr< Expression > assign_expression()
Definition: Parser.cpp:640
std::string matchFile()
Definition: Parser.h:132
std::string matchIdentifier()
Definition: Parser.h:108
std::unique_ptr< Arg > optional_variable()
Definition: Parser.cpp:137
bool check(TokenTypes ... tokens)
Definition: Parser.h:63
std::unique_ptr< Expression > equality_expression()
Definition: Parser.cpp:718
std::unique_ptr< Expression > atom()
Definition: Parser.cpp:836
std::unique_ptr< Expression > prefix_expression()
Definition: Parser.cpp:782
std::unique_ptr< Arg > template_arg()
Definition: Parser.cpp:132
std::unique_ptr< Expression > cast_expression()
std::unique_ptr< CommandList > parse()
Definition: Parser.cpp:624
std::pair< abstraction::TypeQualifiers::TypeQualifierSet, std::unique_ptr< Arg > > qualifiedType()
Definition: Parser.cpp:389
std::string matchType()
Definition: Parser.h:124
std::unique_ptr< Expression > expression()
Definition: Parser.cpp:362
void setHint(Lexer::Hint hint)
Definition: Parser.h:55
const std::string & getTokenValue() const
Definition: Parser.h:156
std::unique_ptr< Arg > arg()
Definition: Parser.cpp:114
std::pair< bool, bool > introspect_cast_from_to()
Definition: Parser.cpp:290
std::unique_ptr< Arg > type()
Definition: Parser.cpp:106
std::unique_ptr< Expression > bitwise_or_expression()
Definition: Parser.cpp:679
std::unique_ptr< Expression > relational_expression()
Definition: Parser.cpp:731
std::unique_ptr< Command > command()
Definition: Parser.cpp:414
std::vector< std::unique_ptr< Expression > > bracketed_expression_list()
Definition: Parser.cpp:868
bool check_then_match_nonreserved_kw(const std::string &kw, const NonreservedTokens &... kws)
Definition: Parser.h:100
int matchInteger()
Definition: Parser.h:140
std::unique_ptr< Command > introspect_command()
Definition: Parser.cpp:308
std::unique_ptr< Arg > optional_binding()
Definition: Parser.cpp:147
std::shared_ptr< StatementList > statement_list()
Definition: Parser.cpp:276
bool globalScope() const
Definition: Parser.h:168
std::unique_ptr< Expression > batch()
Definition: Parser.cpp:366
std::shared_ptr< Statement > param()
Definition: Parser.cpp:230
bool match(cli::Lexer::TokenType token, TokenTypes ... tokens)
Definition: Parser.h:75
std::unique_ptr< Statement > out_redirect()
Definition: Parser.cpp:179
std::unique_ptr< TypeOption > type_option()
Definition: Parser.cpp:76
bool check_then_match(cli::Lexer::TokenType token, TokenTypes ... tokens)
Definition: Parser.h:91
std::unique_ptr< Expression > and_expression()
Definition: Parser.cpp:666
Parser(cli::Lexer lexer)
Definition: Parser.h:52
bool check_nonreserved_kw(const NonreservedTokens &... kw)
Definition: Parser.h:69
std::unique_ptr< Expression > or_expression()
Definition: Parser.cpp:653
std::shared_ptr< Statement > statement()
Definition: Parser.cpp:249
double matchDouble()
Definition: Parser.h:148
void incNestedLevel()
Definition: Parser.h:160
std::unique_ptr< Expression > mul_expression()
Definition: Parser.cpp:764
std::unique_ptr< Arg > optional_arg()
Definition: Parser.cpp:125
std::unique_ptr< Expression > bitwise_and_expression()
Definition: Parser.cpp:692
std::unique_ptr< Expression > suffix_expression()
Definition: Parser.cpp:813
std::unique_ptr< CommandList > block()
Definition: Parser.cpp:341
std::unique_ptr< Arg > file()
Definition: Parser.cpp:93
std::shared_ptr< Statement > common()
Definition: Parser.cpp:195
std::unique_ptr< Expression > expression_or_batch()
Definition: Parser.cpp:371
std::shared_ptr< Statement > in_redirect()
Definition: Parser.cpp:157
std::unique_ptr< Expression > bitwise_xor_expression()
Definition: Parser.cpp:705
std::unique_ptr< Command > semicolon_command()
Definition: Parser.cpp:354
void decNestedLevel()
Definition: Parser.h:164
std::unique_ptr< TypeOption > optional_type_option()
Definition: Parser.cpp:86
std::unique_ptr< Expression > batch_or_expression()
Definition: Parser.cpp:380
std::unique_ptr< CategoryOption > category_option()
Definition: Parser.cpp:66
std::unique_ptr< Expression > add_expression()
Definition: Parser.cpp:748
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
return res
Definition: MinimizeByPartitioning.h:145
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
void hint(Hint hint)
Definition: measurements.cpp:37
Definition: FordFulkerson.hpp:16
TokenType m_type
Definition: Lexer.h:196
size_t m_line
Definition: Lexer.h:198
size_t m_position
Definition: Lexer.h:199
std::string m_value
Definition: Lexer.h:194