From 3f0cca47d5d735fd07c0a74f69c201ff959b0137 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 22 May 2018 15:12:51 +0200 Subject: [PATCH] CLI: allow set construction in parameter --- alib2cli/src/parser/Parser.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp index 1827e31d6f..af0085ea7d 100644 --- a/alib2cli/src/parser/Parser.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -138,13 +138,27 @@ std::shared_ptr < Statement > Parser::common ( ) { std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::INTEGER, 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 ); + std::unique_ptr < TypeOption > type = type_option ( ); + + ext::vector < std::shared_ptr < Statement > > params; + ext::vector < bool > moves; + while ( ! check ( cli::Lexer::TokenType::RIGHT_BRACE ) ) { + moves.push_back ( move_arg ( ) ); + params.emplace_back ( param ( ) ); + } + + std::shared_ptr < Statement > res = std::make_shared < ContainerStatement > ( "Set", std::move ( params ), std::move ( type ), std::move ( moves ) ); + match ( cli::Lexer::TokenType::RIGHT_BRACE ); + return res; } else { throw exception::CommonException ( "Mismatched set while expanding common rule." ); } } std::shared_ptr < Statement > Parser::param ( ) { - if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::IN_REDIRECT, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::HASH_SIGN ) ) { + if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::IN_REDIRECT, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) { return common ( ); } else if ( check ( cli::Lexer::TokenType::DASH_SIGN ) ) { match ( cli::Lexer::TokenType::DASH_SIGN ); @@ -165,7 +179,7 @@ std::shared_ptr < Statement > Parser::param ( ) { } std::shared_ptr < Statement > Parser::statement ( ) { - if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::IN_REDIRECT, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::HASH_SIGN ) ) { + if ( check ( cli::Lexer::TokenType::DOLAR_SIGN, cli::Lexer::TokenType::IN_REDIRECT, cli::Lexer::TokenType::STRING, cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::HASH_SIGN, cli::Lexer::TokenType::LEFT_BRACE ) ) { return common ( ); } else if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) { std::unique_ptr < Arg > name = std::make_unique < ImmediateArg > ( matchIdentifier ( ) ); @@ -190,20 +204,6 @@ std::shared_ptr < Statement > Parser::statement ( ) { bool move = move_arg ( ); std::shared_ptr < Statement > castedStatement = statement ( ); return std::make_shared < CastStatement > ( std::move ( type ), castedStatement, move ); - } else if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) { - match ( cli::Lexer::TokenType::LEFT_BRACE ); - std::unique_ptr < TypeOption > type = type_option ( ); - - ext::vector < std::shared_ptr < Statement > > params; - ext::vector < bool > moves; - while ( ! check ( cli::Lexer::TokenType::RIGHT_BRACE ) ) { - moves.push_back ( move_arg ( ) ); - params.emplace_back ( param ( ) ); - } - - std::shared_ptr < Statement > res = std::make_shared < ContainerStatement > ( "Set", std::move ( params ), std::move ( type ), std::move ( moves ) ); - match ( cli::Lexer::TokenType::RIGHT_BRACE ); - return res; } else { // TODO builtin statement type to get string type throw exception::CommonException ( "Mismatched set while expanding param statement." ); -- GitLab