diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp index 6fb6b7b9095a022a65c76b2cb1936f68dbf93a7c..8474fcadf94861ef3a5975b6f7dc0e101dc386b1 100644 --- a/alib2cli/src/parser/Parser.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -59,8 +59,7 @@ namespace cli { std::unique_ptr < CategoryOption > Parser::category_option ( ) { - if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { - match ( cli::Lexer::TokenType::COLON_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::COLON_SIGN ) ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < CategoryOption > ( value ); @@ -70,8 +69,7 @@ std::unique_ptr < CategoryOption > Parser::category_option ( ) { } std::unique_ptr < TypeOption > Parser::type_option ( ) { - if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { - match ( cli::Lexer::TokenType::COLON_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::COLON_SIGN ) ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < TypeOption > ( std::move ( value ) ); @@ -81,17 +79,15 @@ std::unique_ptr < TypeOption > Parser::type_option ( ) { } std::unique_ptr < TypeOption > Parser::optional_type_option ( ) { - if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { + if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) return type_option ( ); - } else { + else return nullptr; - } } std::unique_ptr < Arg > Parser::file ( ) { setHint ( Lexer::Hint::FILE ); - if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) { - match ( cli::Lexer::TokenType::HASH_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::HASH_SIGN ) ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < BindedArg > ( std::move ( value ) ); @@ -106,14 +102,12 @@ std::unique_ptr < Arg > Parser::type ( ) { setHint ( Lexer::Hint::TYPE ); if ( check ( cli::Lexer::TokenType::STRING ) ) return std::make_unique < ImmediateArg > ( matchString ( ) ); - else { + else return std::make_unique < ImmediateArg > ( matchType ( ) ); - } } std::unique_ptr < Arg > Parser::arg ( ) { - if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) { - match ( cli::Lexer::TokenType::HASH_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::HASH_SIGN ) ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < BindedArg > ( std::move ( value ) ); @@ -124,11 +118,10 @@ std::unique_ptr < Arg > Parser::arg ( ) { } std::unique_ptr < Arg > Parser::optional_arg ( ) { - if ( check ( cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::IDENTIFIER ) ) { + if ( check ( cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::IDENTIFIER ) ) return arg ( ); - } else { + else return nullptr; - } } std::unique_ptr < Arg > Parser::template_arg ( ) { @@ -137,8 +130,7 @@ std::unique_ptr < Arg > Parser::template_arg ( ) { } std::unique_ptr < Arg > Parser::optional_variable ( ) { - if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { - match ( cli::Lexer::TokenType::DOLLAR_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < ImmediateArg > ( value ); @@ -148,8 +140,7 @@ std::unique_ptr < Arg > Parser::optional_variable ( ) { } std::unique_ptr < Arg > Parser::optional_binding ( ) { - if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) { - match ( cli::Lexer::TokenType::HASH_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::HASH_SIGN ) ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < ImmediateArg > ( value ); @@ -159,40 +150,35 @@ std::unique_ptr < Arg > Parser::optional_binding ( ) { } std::shared_ptr < Statement > Parser::in_redirect ( ) { - if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { - match ( cli::Lexer::TokenType::LEFT_PAREN ); + if ( check_then_match ( cli::Lexer::TokenType::LEFT_PAREN ) ) { std::shared_ptr < StatementList > res = statement_list ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); return res; } else { std::unique_ptr < Arg > fileType; - if ( check ( cli::Lexer::TokenType::LEFT_BRACKET ) ) { - match ( cli::Lexer::TokenType::LEFT_BRACKET ); + if ( check_then_match ( cli::Lexer::TokenType::LEFT_BRACKET ) ) { fileType = arg ( ); match ( cli::Lexer::TokenType::RIGHT_BRACKET ); } std::unique_ptr < TypeOption > type = optional_type_option ( ); ext::vector < std::unique_ptr < cli::Arg > > templateArgs; - while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) { + while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) templateArgs.emplace_back ( template_arg ( ) ); - } return std::make_shared < FileStatement > ( file ( ), std::move ( fileType ), std::move ( type ), std::move ( templateArgs ) ); } } std::unique_ptr < Statement > Parser::out_redirect ( ) { - if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { - match ( cli::Lexer::TokenType::DOLLAR_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { std::unique_ptr < Arg > name = arg ( ); return std::make_unique < ResultVariableStatement > ( std::move ( name ) ); } else { std::unique_ptr < Arg > fileType; - if ( check ( cli::Lexer::TokenType::LEFT_BRACKET ) ) { - match ( cli::Lexer::TokenType::LEFT_BRACKET ); + if ( check_then_match ( cli::Lexer::TokenType::LEFT_BRACKET ) ) { fileType = arg ( ); match ( cli::Lexer::TokenType::RIGHT_BRACKET ); } @@ -203,12 +189,10 @@ std::unique_ptr < Statement > Parser::out_redirect ( ) { std::shared_ptr < Statement > Parser::common ( ) { clearCheckOptions ( ); - if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { - match ( cli::Lexer::TokenType::DOLLAR_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { std::unique_ptr < Arg > name = arg ( ); return std::make_shared < VariableStatement > ( std::move ( name ) ); - } else if ( check ( cli::Lexer::TokenType::LESS_THAN ) ) { - match ( cli::Lexer::TokenType::LESS_THAN ); + } else if ( check_then_match ( cli::Lexer::TokenType::LESS_THAN ) ) { return in_redirect ( ); } else if ( check ( cli::Lexer::TokenType::STRING ) ) { std::string value = matchString ( ); @@ -216,19 +200,16 @@ std::shared_ptr < Statement > Parser::common ( ) { } else if ( check ( cli::Lexer::TokenType::UNSIGNED ) ) { int value = matchInteger ( ); return std::make_shared < ImmediateStatement < int > > ( value ); - } else if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) { - match ( cli::Lexer::TokenType::HASH_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::HASH_SIGN ) ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_shared < ValueStatement > ( std::make_unique < BindedArg > ( std::move ( value ) ) ); - } else if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) { - match ( cli::Lexer::TokenType::LEFT_BRACE ); + } else if ( check_then_match ( cli::Lexer::TokenType::LEFT_BRACE ) ) { std::unique_ptr < TypeOption > type = type_option ( ); ext::vector < std::shared_ptr < Statement > > params; - while ( ! check ( cli::Lexer::TokenType::RIGHT_BRACE ) ) { + while ( ! check ( cli::Lexer::TokenType::RIGHT_BRACE ) ) params.emplace_back ( param ( ) ); - } std::shared_ptr < Statement > res = std::make_shared < ContainerStatement > ( "Set", std::move ( params ), std::move ( type ) ); match ( cli::Lexer::TokenType::RIGHT_BRACE ); @@ -242,14 +223,12 @@ std::shared_ptr < Statement > Parser::param ( ) { clearCheckOptions ( ); if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN, cli::Lexer::TokenType::LESS_THAN, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) { return common ( ); - } else if ( check ( cli::Lexer::TokenType::MINUS_SIGN ) ) { - match ( cli::Lexer::TokenType::MINUS_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::MINUS_SIGN ) ) { return std::make_shared < PreviousResultStatement > ( ); } else if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) { std::string value = matchIdentifier ( ); return std::make_shared < ImmediateStatement < std::string > > ( value ); - } else if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { - match ( cli::Lexer::TokenType::LEFT_PAREN ); + } else if ( check_then_match ( cli::Lexer::TokenType::LEFT_PAREN ) ) { std::unique_ptr < Arg > result_type = type ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); std::shared_ptr < Statement > castedParam = param ( ); @@ -266,9 +245,8 @@ std::shared_ptr < Statement > Parser::statement ( ) { } else if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) { std::unique_ptr < Arg > name = std::make_unique < ImmediateArg > ( matchIdentifier ( ) ); ext::vector < std::unique_ptr < cli::Arg > > templateArgs; - while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) { + while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) templateArgs.emplace_back ( template_arg ( ) ); - } std::unique_ptr < CategoryOption > category = category_option ( ); ext::vector < std::shared_ptr < Statement > > params; @@ -277,8 +255,7 @@ std::shared_ptr < Statement > Parser::statement ( ) { } return std::make_shared < SingleStatement > ( std::move ( name ), std::move ( templateArgs ), std::move ( params ), std::move ( category ) ); - } else if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { - match ( cli::Lexer::TokenType::LEFT_PAREN ); + } else if ( check_then_match ( cli::Lexer::TokenType::LEFT_PAREN ) ) { std::unique_ptr < Arg > result_type = type ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); std::shared_ptr < Statement > castedStatement = statement ( ); @@ -292,8 +269,7 @@ std::shared_ptr < StatementList > Parser::statement_list ( ) { ext::vector < std::shared_ptr < Statement > > list; list.emplace_back ( statement ( ) ); while ( check ( cli::Lexer::TokenType::PIPE_SIGN, cli::Lexer::TokenType::MORE_THAN ) ) { - if ( check ( cli::Lexer::TokenType::PIPE_SIGN ) ) { - match ( cli::Lexer::TokenType::PIPE_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::PIPE_SIGN ) ) { list.emplace_back ( statement ( ) ); } else { match ( cli::Lexer::TokenType::MORE_THAN ); @@ -306,9 +282,7 @@ std::shared_ptr < StatementList > Parser::statement_list ( ) { std::pair < bool, bool > Parser::introspect_cast_from_to ( ) { bool from = false; bool to = false; - while ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { - match ( cli::Lexer::TokenType::COLON_SIGN ); - + while ( check_then_match ( cli::Lexer::TokenType::COLON_SIGN ) ) { clearCheckOptions ( ); if ( check_nonreserved_kw ( "from" ) ) { match_nonreserved_kw ( "from" ); @@ -325,38 +299,30 @@ std::pair < bool, bool > Parser::introspect_cast_from_to ( ) { std::unique_ptr < Command > Parser::introspect_command ( ) { clearCheckOptions ( ); - if ( check_nonreserved_kw ( "algorithms" ) ) { - match_nonreserved_kw ( "algorithms" ); + if ( check_then_match_nonreserved_kw ( "algorithms" ) ) { std::unique_ptr < cli::Arg > param = optional_arg ( ); return std::make_unique < AlgorithmsIntrospectionCommand > ( std::move ( param ) ); - } else if ( check_nonreserved_kw ( "overloads" ) ) { - match_nonreserved_kw ( "overloads" ); + } else if ( check_then_match_nonreserved_kw ( "overloads" ) ) { std::unique_ptr < cli::Arg > param = arg ( ); ext::vector < std::unique_ptr < cli::Arg > > templateArgs; - while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) { + while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) templateArgs.emplace_back ( template_arg ( ) ); - } return std::make_unique < OverloadsIntrospectionCommand > ( std::move ( param ), std::move ( templateArgs ) ); - } else if ( check_nonreserved_kw ( "operators" ) ) { - match_nonreserved_kw ( "operators" ); + } else if ( check_then_match_nonreserved_kw ( "operators" ) ) { return std::make_unique < OperatorsIntrospectionCommand > ( ); - } else if ( check_nonreserved_kw ( "datatypes" ) ) { - match_nonreserved_kw ( "datatypes" ); + } else if ( check_then_match_nonreserved_kw ( "datatypes" ) ) { std::unique_ptr < cli::Arg > param = optional_arg ( ); return std::make_unique < DataTypesIntrospectionCommand > ( std::move ( param ) ); - } else if ( check_nonreserved_kw ( "casts" ) ) { - match_nonreserved_kw ( "casts" ); + } else if ( check_then_match_nonreserved_kw ( "casts" ) ) { std::pair < bool, bool > from_to = introspect_cast_from_to ( ); std::unique_ptr < cli::Arg > param = optional_arg ( ); return std::make_unique < CastsIntrospectionCommand > ( std::move ( param ), from_to.first, from_to.second ); - } else if ( check_nonreserved_kw ( "variables" ) ) { - match_nonreserved_kw ( "variables" ); + } else if ( check_then_match_nonreserved_kw ( "variables" ) ) { std::unique_ptr < cli::Arg > param = optional_variable ( ); return std::make_unique < VariablesIntrospectionCommand > ( std::move ( param ) ); - } else if ( check_nonreserved_kw ( "bindings" ) ) { - match_nonreserved_kw ( "bindings" ); + } else if ( check_then_match_nonreserved_kw ( "bindings" ) ) { std::unique_ptr < cli::Arg > param = optional_arg ( ); return std::make_unique < BindingsIntrospectionCommand > ( std::move ( param ) ); } else { @@ -369,9 +335,8 @@ std::unique_ptr < CommandList > Parser::block ( ) { match_nonreserved_kw ( "begin" ); ext::vector < std::unique_ptr < Command > > list; - while ( ! check_nonreserved_kw ( "end" ) ) { + while ( ! check_nonreserved_kw ( "end" ) ) list.emplace_back ( semicolon_command ( ) ); - } decNestedLevel ( ); match_nonreserved_kw ( "end" ); @@ -396,23 +361,19 @@ std::unique_ptr < Expression > Parser::batch ( ) { } std::unique_ptr < Expression > Parser::expression_or_batch ( ) { - if ( check_nonreserved_kw ( "batch" ) ) { - match_nonreserved_kw ( "batch" ); + if ( check_then_match_nonreserved_kw ( "batch" ) ) { return batch ( ); } else { - if ( check_nonreserved_kw ( "expression" ) ) - match_nonreserved_kw ( "expression" ); + check_then_match_nonreserved_kw ( "expression" ); // optional token return expression ( ); } } std::unique_ptr < Expression > Parser::batch_or_expression ( ) { - if ( check_nonreserved_kw ( "expression" ) ) { - match_nonreserved_kw ( "expression" ); + if ( check_then_match_nonreserved_kw ( "expression" ) ) { return expression ( ); } else { - if ( check_nonreserved_kw ( "batch" ) ) - match_nonreserved_kw ( "batch" ); + check_then_match_nonreserved_kw ( "batch" ); // optional token return batch ( ); } } @@ -420,20 +381,15 @@ std::unique_ptr < Expression > Parser::batch_or_expression ( ) { std::pair < abstraction::TypeQualifiers::TypeQualifierSet, std::unique_ptr < Arg > > Parser::qualifiedType ( ) { abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers = abstraction::TypeQualifiers::TypeQualifierSet::NONE; - if ( check_nonreserved_kw ( "const" ) ) { - match_nonreserved_kw ( "const" ); + if ( check_then_match_nonreserved_kw ( "const" ) ) typeQualifiers = typeQualifiers | abstraction::TypeQualifiers::TypeQualifierSet::CONST; - } std::unique_ptr < Arg > type = arg ( ); - if ( check ( cli::Lexer::TokenType::AND ) ) { - match ( cli::Lexer::TokenType::AND ); + if ( check_then_match ( cli::Lexer::TokenType::AND ) ) typeQualifiers = typeQualifiers | abstraction::TypeQualifiers::TypeQualifierSet::RREF; - } else if ( check ( cli::Lexer::TokenType::AMPERSAND_SIGN ) ) { - match ( cli::Lexer::TokenType::AMPERSAND_SIGN ); + else if ( check_then_match ( cli::Lexer::TokenType::AMPERSAND_SIGN ) ) typeQualifiers = typeQualifiers | abstraction::TypeQualifiers::TypeQualifierSet::LREF; - } return std::make_pair ( typeQualifiers, std::move ( type ) ); } @@ -449,94 +405,69 @@ std::pair < abstraction::TypeQualifiers::TypeQualifierSet, std::unique_ptr < Arg std::unique_ptr < Command > Parser::command ( ) { clearCheckOptions ( ); - if ( check_nonreserved_kw ( "execute" ) ) { - match_nonreserved_kw ( "execute" ); + if ( check_then_match_nonreserved_kw ( "execute" ) ) { std::unique_ptr < Expression > expr = batch_or_expression ( ); return std::make_unique < ExecuteCommand > ( std::move ( expr ) ); - } else if ( check_nonreserved_kw ( "print" ) ) { - match_nonreserved_kw ( "print" ); + } else if ( check_then_match_nonreserved_kw ( "print" ) ) { std::unique_ptr < Expression > expr = batch_or_expression ( ); return std::make_unique < PrintCommand > ( std::move ( expr ) ); - } else if ( check_nonreserved_kw ( "quit" ) ) { - match_nonreserved_kw ( "quit" ); - + } else if ( check_then_match_nonreserved_kw ( "quit" ) ) { std::unique_ptr < Expression > expr; if ( ! check ( cli::Lexer::TokenType::EOS, cli::Lexer::TokenType::EOT, cli::Lexer::TokenType::SEMICOLON_SIGN ) ) expr = batch_or_expression ( ); return std::make_unique < QuitCommand > ( std::move ( expr ) ); - } else if ( check_nonreserved_kw ( "exit" ) ) { - match_nonreserved_kw ( "exit" ); - + } else if ( check_then_match_nonreserved_kw ( "exit" ) ) { std::unique_ptr < Expression > expr; if ( ! check ( cli::Lexer::TokenType::EOS, cli::Lexer::TokenType::EOT, cli::Lexer::TokenType::SEMICOLON_SIGN ) ) expr = batch_or_expression ( ); return std::make_unique < QuitCommand > ( std::move ( expr ) ); - } else if ( check_nonreserved_kw ( "return" ) ) { - match_nonreserved_kw ( "return" ); - + } else if ( check_then_match_nonreserved_kw ( "return" ) ) { std::unique_ptr < Expression > expr; if ( ! check ( cli::Lexer::TokenType::EOS, cli::Lexer::TokenType::EOT, cli::Lexer::TokenType::SEMICOLON_SIGN ) ) expr = expression ( ); return std::make_unique < ReturnCommand > ( std::move ( expr ) ); - } else if ( check_nonreserved_kw ( "help" ) ) { - match_nonreserved_kw ( "help" ); + } else if ( check_then_match_nonreserved_kw ( "help" ) ) { std::unique_ptr < cli::Arg > command = optional_arg ( ); return std::make_unique < HelpCommand > ( std::move ( command ) ); - } else if ( check_nonreserved_kw ( "introspect" ) ) { - match_nonreserved_kw ( "introspect" ); - std::unique_ptr < Command > command = introspect_command ( ); - return command; - } else if ( check_nonreserved_kw ( "set" ) ) { - match_nonreserved_kw ( "set" ); + } else if ( check_then_match_nonreserved_kw ( "introspect" ) ) { + return introspect_command ( ); + } else if ( check_then_match_nonreserved_kw ( "set" ) ) { std::string param = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER, cli::Lexer::TokenType::STRING ); return std::make_unique < SetCommand > ( std::move ( param ), std::move ( value ) ); - } else if ( check_nonreserved_kw ( "show" ) ) { - match_nonreserved_kw ( "show" ); + } else if ( check_then_match_nonreserved_kw ( "show" ) ) { std::string param = getTokenValue ( ); match_nonreserved_kw ( "measurements" ); match_nonreserved_kw ( "as" ); - if ( check_nonreserved_kw ( "list" ) ) { - match_nonreserved_kw ( "list" ); + if ( check_then_match_nonreserved_kw ( "list" ) ) { return std::make_unique < ShowMeasurements > ( measurements::MeasurementFormat::LIST ); } else { match_nonreserved_kw ( "tree" ); return std::make_unique < ShowMeasurements > ( measurements::MeasurementFormat::TREE ); } - } else if ( check_nonreserved_kw ( "clear" ) ) { - match_nonreserved_kw ( "clear" ); - std::string param = getTokenValue ( ); + } else if ( check_then_match_nonreserved_kw ( "clear" ) ) { match_nonreserved_kw ( "measurements" ); return std::make_unique < ClearMeasurements > ( ); - } else if ( check_nonreserved_kw ( "start" ) ) { - match_nonreserved_kw ( "start" ); - + } else if ( check_then_match_nonreserved_kw ( "start" ) ) { measurements::Type type; - if ( check_nonreserved_kw ( "root" ) ) { - match_nonreserved_kw ( "root" ); + if ( check_then_match_nonreserved_kw ( "root" ) ) { type = measurements::Type::ROOT; - } else if ( check_nonreserved_kw ( "overall" ) ) { - match_nonreserved_kw ( "overall" ); + } else if ( check_then_match_nonreserved_kw ( "overall" ) ) { type = measurements::Type::OVERALL; - } else if ( check_nonreserved_kw ( "init" ) ) { - match_nonreserved_kw ( "init" ); + } else if ( check_then_match_nonreserved_kw ( "init" ) ) { type = measurements::Type::INIT; - } else if ( check_nonreserved_kw ( "finalize" ) ) { - match_nonreserved_kw ( "finalize" ); + } else if ( check_then_match_nonreserved_kw ( "finalize" ) ) { type = measurements::Type::FINALIZE; - } else if ( check_nonreserved_kw ( "main" ) ) { - match_nonreserved_kw ( "main" ); + } else if ( check_then_match_nonreserved_kw ( "main" ) ) { type = measurements::Type::MAIN; - } else if ( check_nonreserved_kw ( "auxiliary" ) ) { - match_nonreserved_kw ( "auxiliary" ); + } else if ( check_then_match_nonreserved_kw ( "auxiliary" ) ) { type = measurements::Type::AUXILIARY; - } else if ( check_nonreserved_kw ( "preprocess" ) ) { - match_nonreserved_kw ( "preprocess" ); + } else if ( check_then_match_nonreserved_kw ( "preprocess" ) ) { type = measurements::Type::PREPROCESS; } else { match_nonreserved_kw ( "algorithm" ); @@ -549,52 +480,41 @@ std::unique_ptr < Command > Parser::command ( ) { std::string frameName = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < StartMeasurementFrame > ( std::move ( frameName ), type ); - } else if ( check_nonreserved_kw ( "stop" ) ) { - match_nonreserved_kw ( "stop" ); + } else if ( check_then_match_nonreserved_kw ( "stop" ) ) { match_nonreserved_kw ( "measurement" ); match_nonreserved_kw ( "frame" ); return std::make_unique < StopMeasurementFrame > ( ); - } else if ( check_nonreserved_kw ( "load" ) ) { - match_nonreserved_kw ( "load" ); - + } else if ( check_then_match_nonreserved_kw ( "load" ) ) { setHint ( Lexer::Hint::FILE ); std::string libraryName = getTokenValue ( ); match ( cli::Lexer::TokenType::FILE, cli::Lexer::TokenType::STRING ); return std::make_unique < LoadCommand > ( std::move ( libraryName ) ); - } else if ( check_nonreserved_kw ( "unload" ) ) { - match_nonreserved_kw ( "unload" ); - + } else if ( check_then_match_nonreserved_kw ( "unload" ) ) { setHint ( Lexer::Hint::FILE ); std::string libraryName = getTokenValue ( ); match ( cli::Lexer::TokenType::FILE, cli::Lexer::TokenType::STRING ); return std::make_unique < UnloadCommand > ( std::move ( libraryName ) ); - } else if ( check_nonreserved_kw ( "calc" ) ) { - match_nonreserved_kw ( "calc" ); - + } else if ( check_then_match_nonreserved_kw ( "calc" ) ) { std::unique_ptr < Expression > expr = expression ( ); return std::make_unique < CalcCommand > ( std::move ( expr ) ); } else if ( check_nonreserved_kw ( "begin" ) ) { return std::make_unique < BlockCommand > ( block ( ) ); - } else if ( check_nonreserved_kw ( "eval" ) ) { - match_nonreserved_kw ( "eval" ); + } else if ( check_then_match_nonreserved_kw ( "eval" ) ) { std::string evalString = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER, cli::Lexer::TokenType::STRING ); return std::make_unique < EvalCommand > ( std::move ( evalString ) ); - } else if ( check_nonreserved_kw ( "interpret" ) ) { - match_nonreserved_kw ( "interpret" ); - + } else if ( check_then_match_nonreserved_kw ( "interpret" ) ) { setHint ( Lexer::Hint::FILE ); std::string fileName = getTokenValue ( ); match ( cli::Lexer::TokenType::FILE, cli::Lexer::TokenType::STRING ); return std::make_unique < InterpretCommand > ( std::move ( fileName ) ); - } else if ( check_nonreserved_kw ( "if" ) ) { + } else if ( check_then_match_nonreserved_kw ( "if" ) ) { if ( globalScope ( ) ) throw exception::CommonException ( "Statement not available in global scope." ); - match_nonreserved_kw ( "if" ); match ( cli::Lexer::TokenType::LEFT_PAREN ); std::unique_ptr < Expression > condition = expression_or_batch ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); @@ -609,10 +529,10 @@ std::unique_ptr < Command > Parser::command ( ) { } return std::make_unique < IfCommand > ( std::move ( condition ), std::move ( thenBranch ), std::move ( elseBranch ) ); - } else if ( check_nonreserved_kw ( "while" ) ) { + } else if ( check_then_match_nonreserved_kw ( "while" ) ) { if ( globalScope ( ) ) throw exception::CommonException ( "Statement not available in global scope." ); - match_nonreserved_kw ( "while" ); + match ( cli::Lexer::TokenType::LEFT_PAREN ); std::unique_ptr < Expression > condition = expression_or_batch ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); @@ -621,19 +541,15 @@ std::unique_ptr < Command > Parser::command ( ) { std::unique_ptr < Command > body = semicolon_command ( ); return std::make_unique < WhileCommand > ( std::move ( condition ), std::move ( body ) ); - } else if ( check_nonreserved_kw ( "break" ) ) { + } else if ( check_then_match_nonreserved_kw ( "break" ) ) { if ( globalScope ( ) ) throw exception::CommonException ( "Statement not available in global scope." ); - match_nonreserved_kw ( "break" ); return std::make_unique < BreakCommand > ( ); - } else if ( check_nonreserved_kw ( "continue" ) ) { + } else if ( check_then_match_nonreserved_kw ( "continue" ) ) { if ( globalScope ( ) ) throw exception::CommonException ( "Statement not available in global scope." ); - match_nonreserved_kw ( "continue" ); return std::make_unique < ContinueCommand > ( ); - } else if ( check_nonreserved_kw ( "declare" ) ) { - match_nonreserved_kw ( "declare" ); - + } else if ( check_then_match_nonreserved_kw ( "declare" ) ) { std::pair < abstraction::TypeQualifiers::TypeQualifierSet, std::unique_ptr < Arg > > qualType = qualifiedType ( ); match ( cli::Lexer::TokenType::DOLLAR_SIGN ); @@ -644,10 +560,9 @@ std::unique_ptr < Command > Parser::command ( ) { std::unique_ptr < Expression > expr = expression ( ); return std::make_unique < VarDeclareCommand > ( std::move ( name ), qualType.first, std::move ( expr ) ); - } else if ( check_nonreserved_kw ( "procedure" ) ) { + } else if ( check_then_match_nonreserved_kw ( "procedure" ) ) { if ( ! globalScope ( ) ) throw exception::CommonException ( "Statement available in global scope only." ); - match_nonreserved_kw ( "procedure" ); std::string routineName = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER, cli::Lexer::TokenType::STRING ); @@ -667,10 +582,9 @@ std::unique_ptr < Command > Parser::command ( ) { std::unique_ptr < Command > body = command ( ); return std::make_unique < DeclareRunnableCommand > ( std::move ( routineName ), std::move ( params ), std::move ( body ) ); - } else if ( check_nonreserved_kw ( "function" ) ) { + } else if ( check_then_match_nonreserved_kw ( "function" ) ) { if ( ! globalScope ( ) ) throw exception::CommonException ( "Statement available in global scope only." ); - match_nonreserved_kw ( "function" ); std::string routineName = getTokenValue ( ); match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER, cli::Lexer::TokenType::STRING ); @@ -708,22 +622,19 @@ std::unique_ptr < CommandList > Parser::parse ( ) { } list.emplace_back ( command ( ) ); - while ( check ( cli::Lexer::TokenType::SEMICOLON_SIGN ) ) { - match ( cli::Lexer::TokenType::SEMICOLON_SIGN ); + while ( check_then_match ( cli::Lexer::TokenType::SEMICOLON_SIGN ) ) list.emplace_back ( command ( ) ); - } + match ( cli::Lexer::TokenType::EOS, cli::Lexer::TokenType::EOT ); return std::make_unique < CommandList > ( std::move ( list ) ); } std::unique_ptr < Expression > Parser::assign_expression ( ) { std::unique_ptr < Expression > res = or_expression ( ); - if ( check ( cli::Lexer::TokenType::ASSIGN ) ) { + if ( check_then_match ( cli::Lexer::TokenType::ASSIGN ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - match ( cli::Lexer::TokenType::ASSIGN ); - res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::ASSIGN, std::move ( res ), assign_expression ( ) ); restoreCheckOptions ( checkOptions ); @@ -733,12 +644,10 @@ std::unique_ptr < Expression > Parser::assign_expression ( ) { std::unique_ptr < Expression > Parser::or_expression ( ) { std::unique_ptr < Expression > res = and_expression ( ); - while ( check ( cli::Lexer::TokenType::OR ) ) { + while ( check_then_match ( cli::Lexer::TokenType::OR ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - match ( cli::Lexer::TokenType::OR ); - res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::LOGICAL_OR, std::move ( res ), and_expression ( ) ); restoreCheckOptions ( checkOptions ); @@ -748,12 +657,10 @@ std::unique_ptr < Expression > Parser::or_expression ( ) { std::unique_ptr < Expression > Parser::and_expression ( ) { std::unique_ptr < Expression > res = bitwise_or_expression ( ); - while ( check ( cli::Lexer::TokenType::AND ) ) { + while ( check_then_match ( cli::Lexer::TokenType::AND ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - match ( cli::Lexer::TokenType::AND ); - res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::LOGICAL_AND, std::move ( res ), bitwise_or_expression ( ) ); restoreCheckOptions ( checkOptions ); @@ -763,12 +670,10 @@ std::unique_ptr < Expression > Parser::and_expression ( ) { std::unique_ptr < Expression > Parser::bitwise_or_expression ( ) { std::unique_ptr < Expression > res = bitwise_and_expression ( ); - while ( check ( cli::Lexer::TokenType::PIPE_SIGN ) ) { + while ( check_then_match ( cli::Lexer::TokenType::PIPE_SIGN ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - match ( cli::Lexer::TokenType::PIPE_SIGN ); - res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::BINARY_OR, std::move ( res ), bitwise_and_expression ( ) ); restoreCheckOptions ( checkOptions ); @@ -778,12 +683,10 @@ std::unique_ptr < Expression > Parser::bitwise_or_expression ( ) { std::unique_ptr < Expression > Parser::bitwise_and_expression ( ) { std::unique_ptr < Expression > res = bitwise_xor_expression ( ); - while ( check ( cli::Lexer::TokenType::AMPERSAND_SIGN ) ) { + while ( check_then_match ( cli::Lexer::TokenType::AMPERSAND_SIGN ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - match ( cli::Lexer::TokenType::AMPERSAND_SIGN ); - res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::BINARY_AND, std::move ( res ), bitwise_xor_expression ( ) ); restoreCheckOptions ( checkOptions ); @@ -793,12 +696,10 @@ std::unique_ptr < Expression > Parser::bitwise_and_expression ( ) { std::unique_ptr < Expression > Parser::bitwise_xor_expression ( ) { std::unique_ptr < Expression > res = equality_expression ( ); - while ( check ( cli::Lexer::TokenType::CARET_SIGN ) ) { + while ( check_then_match ( cli::Lexer::TokenType::CARET_SIGN ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - match ( cli::Lexer::TokenType::CARET_SIGN ); - res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::BINARY_XOR, std::move ( res ), equality_expression ( ) ); restoreCheckOptions ( checkOptions ); @@ -810,11 +711,9 @@ std::unique_ptr < Expression > Parser::equality_expression ( ) { std::unique_ptr < Expression > res = relational_expression ( ); auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - if ( check ( cli::Lexer::TokenType::EQUAL ) ) { - match ( cli::Lexer::TokenType::EQUAL ); + if ( check_then_match ( cli::Lexer::TokenType::EQUAL ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::EQUALS, std::move ( res ), relational_expression ( ) ); - } else if ( check ( cli::Lexer::TokenType::NOT_EQUAL ) ) { - match ( cli::Lexer::TokenType::NOT_EQUAL ); + } else if ( check_then_match ( cli::Lexer::TokenType::NOT_EQUAL ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::NOT_EQUALS, std::move ( res ), relational_expression ( ) ); } restoreCheckOptions ( checkOptions ); @@ -825,17 +724,13 @@ std::unique_ptr < Expression > Parser::relational_expression ( ) { std::unique_ptr < Expression > res = add_expression ( ); auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - if ( check ( cli::Lexer::TokenType::LESS_THAN ) ) { - match ( cli::Lexer::TokenType::LESS_THAN ); + if ( check_then_match ( cli::Lexer::TokenType::LESS_THAN ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::LESS, std::move ( res ), add_expression ( ) ); - } else if ( check ( cli::Lexer::TokenType::LESS_THAN_OR_EQUAL ) ) { - match ( cli::Lexer::TokenType::LESS_THAN_OR_EQUAL ); + } else if ( check_then_match ( cli::Lexer::TokenType::LESS_THAN_OR_EQUAL ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::LESS_OR_EQUAL, std::move ( res ), add_expression ( ) ); - } else if ( check ( cli::Lexer::TokenType::MORE_THAN ) ) { - match ( cli::Lexer::TokenType::MORE_THAN ); + } else if ( check_then_match ( cli::Lexer::TokenType::MORE_THAN ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::MORE, std::move ( res ), add_expression ( ) ); - } else if ( check ( cli::Lexer::TokenType::MORE_THAN_OR_EQUAL ) ) { - match ( cli::Lexer::TokenType::MORE_THAN_OR_EQUAL ); + } else if ( check_then_match ( cli::Lexer::TokenType::MORE_THAN_OR_EQUAL ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::MORE_OR_EQUAL, std::move ( res ), add_expression ( ) ); } restoreCheckOptions ( checkOptions ); @@ -847,8 +742,7 @@ std::unique_ptr < Expression > Parser::add_expression ( ) { while ( check ( cli::Lexer::TokenType::PLUS_SIGN, cli::Lexer::TokenType::MINUS_SIGN ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - if ( check ( cli::Lexer::TokenType::PLUS_SIGN ) ) { - match ( cli::Lexer::TokenType::PLUS_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::PLUS_SIGN ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::ADD, std::move ( res ), mul_expression ( ) ); } else { match ( cli::Lexer::TokenType::MINUS_SIGN ); @@ -864,11 +758,9 @@ std::unique_ptr < Expression > Parser::mul_expression ( ) { while ( check ( cli::Lexer::TokenType::ASTERISK_SIGN, cli::Lexer::TokenType::PERCENTAGE_SIGN, cli::Lexer::TokenType::SLASH_SIGN ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - if ( check ( cli::Lexer::TokenType::ASTERISK_SIGN ) ) { - match ( cli::Lexer::TokenType::ASTERISK_SIGN ); + if ( check_then_match ( cli::Lexer::TokenType::ASTERISK_SIGN ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::MUL, std::move ( res ), prefix_expression ( ) ); - } else if ( check ( cli::Lexer::TokenType::PERCENTAGE_SIGN ) ) { - match ( cli::Lexer::TokenType::PERCENTAGE_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::PERCENTAGE_SIGN ) ) { res = std::make_unique < BinaryExpression > ( abstraction::Operators::BinaryOperators::MOD, std::move ( res ), prefix_expression ( ) ); } else { match ( cli::Lexer::TokenType::SLASH_SIGN ); @@ -881,35 +773,28 @@ std::unique_ptr < Expression > Parser::mul_expression ( ) { std::unique_ptr < Expression > Parser::prefix_expression ( ) { clearCheckOptions ( ); - if ( check_nonreserved_kw ( "cast" ) ) { - match_nonreserved_kw ( "cast" ); + if ( check_then_match_nonreserved_kw ( "cast" ) ) { match ( cli::Lexer::TokenType::LEFT_PAREN ); std::unique_ptr < Arg > result_type = type ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); std::unique_ptr < Expression > expression = prefix_expression ( ); return std::make_unique < CastExpression > ( std::move ( result_type ), std::move ( expression ) ); - } else if ( check ( cli::Lexer::TokenType::PLUS_SIGN ) ) { - match ( cli::Lexer::TokenType::PLUS_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::PLUS_SIGN ) ) { std::unique_ptr < Expression > expression = prefix_expression ( ); return std::make_unique < PrefixExpression > ( abstraction::Operators::PrefixOperators::PLUS, std::move ( expression ) ); - } else if ( check ( cli::Lexer::TokenType::MINUS_SIGN ) ) { - match ( cli::Lexer::TokenType::MINUS_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::MINUS_SIGN ) ) { std::unique_ptr < Expression > expression = prefix_expression ( ); return std::make_unique < PrefixExpression > ( abstraction::Operators::PrefixOperators::MINUS, std::move ( expression ) ); - } else if ( check ( cli::Lexer::TokenType::EXCLAMATION_SIGN ) ) { - match ( cli::Lexer::TokenType::EXCLAMATION_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::EXCLAMATION_SIGN ) ) { std::unique_ptr < Expression > expression = prefix_expression ( ); return std::make_unique < PrefixExpression > ( abstraction::Operators::PrefixOperators::LOGICAL_NOT, std::move ( expression ) ); - } else if ( check ( cli::Lexer::TokenType::TILDE_SIGN ) ) { - match ( cli::Lexer::TokenType::TILDE_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::TILDE_SIGN ) ) { std::unique_ptr < Expression > expression = prefix_expression ( ); return std::make_unique < PrefixExpression > ( abstraction::Operators::PrefixOperators::BINARY_NEG, std::move ( expression ) ); - } else if ( check ( cli::Lexer::TokenType::INC ) ) { - match ( cli::Lexer::TokenType::INC ); + } else if ( check_then_match ( cli::Lexer::TokenType::INC ) ) { std::unique_ptr < Expression > expression = prefix_expression ( ); return std::make_unique < PrefixExpression > ( abstraction::Operators::PrefixOperators::INCREMENT, std::move ( expression ) ); - } else if ( check ( cli::Lexer::TokenType::DEC ) ) { - match ( cli::Lexer::TokenType::DEC ); + } else if ( check_then_match ( cli::Lexer::TokenType::DEC ) ) { std::unique_ptr < Expression > expression = prefix_expression ( ); return std::make_unique < PrefixExpression > ( abstraction::Operators::PrefixOperators::DECREMENT, std::move ( expression ) ); } else { @@ -923,17 +808,14 @@ std::unique_ptr < Expression > Parser::suffix_expression ( ) { while ( check ( cli::Lexer::TokenType::DOT, cli::Lexer::TokenType::INC, cli::Lexer::TokenType::DEC ) ) { auto checkOptions = getCheckOptions ( ); clearCheckOptions ( ); - if ( check ( cli::Lexer::TokenType::DOT ) ) { - match ( cli::Lexer::TokenType::DOT ); + if ( check_then_match ( cli::Lexer::TokenType::DOT ) ) { std::string memberName = getTokenValue ( ); match ( cli::Lexer::TokenType::IDENTIFIER ); std::vector < std::unique_ptr < Expression > > params = bracketed_expression_list ( ); res = std::make_unique < MethodCallExpression > ( std::move ( res ), std::move ( memberName ), std::move ( params ) ); - } else if ( check ( cli::Lexer::TokenType::INC ) ){ - match ( cli::Lexer::TokenType::INC ); + } else if ( check_then_match ( cli::Lexer::TokenType::INC ) ){ res = std::make_unique < PostfixExpression > ( abstraction::Operators::PostfixOperators::INCREMENT, std::move ( res ) ); - } else if ( check ( cli::Lexer::TokenType::DEC ) ){ - match ( cli::Lexer::TokenType::DEC ); + } else if ( check_then_match ( cli::Lexer::TokenType::DEC ) ){ res = std::make_unique < PostfixExpression > ( abstraction::Operators::PostfixOperators::DECREMENT, std::move ( res ) ); } else { throw exception::CommonException ( "Mismatched set " + ext::to_string ( getCheckOptions ( ) ) + " while expanding suffix_expression rule. Token is " + ( ( std::string ) m_current ) + "." ); @@ -944,8 +826,7 @@ std::unique_ptr < Expression > Parser::suffix_expression ( ) { } std::unique_ptr < Expression > Parser::atom ( ) { - if ( check_nonreserved_kw ( "type" ) ) { - match_nonreserved_kw ( "type" ); + if ( check_then_match_nonreserved_kw ( "type" ) ) { match ( cli::Lexer::TokenType::LEFT_PAREN ); std::unique_ptr < Expression > expr = expression ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); @@ -955,12 +836,10 @@ std::unique_ptr < Expression > Parser::atom ( ) { match ( cli::Lexer::TokenType::IDENTIFIER ); std::vector < std::unique_ptr < Expression > > params = bracketed_expression_list ( ); return std::make_unique < FunctionCallExpression > ( routineName, std::move ( params ) ); - } else if ( check ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { - match ( cli::Lexer::TokenType::DOLLAR_SIGN ); + } else if ( check_then_match ( cli::Lexer::TokenType::DOLLAR_SIGN ) ) { std::unique_ptr < Arg > name = arg ( ); return std::make_unique < VariableExpression > ( std::move ( name ) ); - } else if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { - match ( cli::Lexer::TokenType::LEFT_PAREN ); + } else if ( check_then_match ( cli::Lexer::TokenType::LEFT_PAREN ) ) { std::unique_ptr < Expression > expr = expression ( ); match ( cli::Lexer::TokenType::RIGHT_PAREN ); return expr; @@ -980,10 +859,8 @@ std::vector < std::unique_ptr < Expression > > Parser::bracketed_expression_list match ( cli::Lexer::TokenType::LEFT_PAREN ); if ( ! check ( cli::Lexer::TokenType::RIGHT_PAREN ) ) { res.push_back ( expression ( ) ); - while ( check ( cli::Lexer::TokenType::COMMA ) ) { - match ( cli::Lexer::TokenType::COMMA ); + while ( check_then_match ( cli::Lexer::TokenType::COMMA ) ) res.push_back ( expression ( ) ); - } } match ( cli::Lexer::TokenType::RIGHT_PAREN ); return res; diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h index 9ce3050895818a84a21fbc6d39e142a886016314..fae6ceaa8c1213a75b5812d71364e522a93f7d21 100644 --- a/alib2cli/src/parser/Parser.h +++ b/alib2cli/src/parser/Parser.h @@ -90,10 +90,10 @@ public: template < class ... NonreservedTokens > bool check_then_match_nonreserved_kw ( const std::string & kw, const NonreservedTokens & ... kws ) { - if ( ! check ( kw, kws ... ) ) + if ( ! check_nonreserved_kw ( kw, kws ... ) ) return false; - match ( kw, kws ... ); + match_nonreserved_kw ( kw, kws ... ); return true; }