From 9ba0c65146b7f14a38d2601d360b5d13af0f6180 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 22 May 2018 13:13:13 +0200 Subject: [PATCH] wip input and output redirection in cli --- alib2cli/src/parser/Parser.cpp | 31 +++++++++++++++++++++---------- alib2cli/src/parser/Parser.h | 4 ++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp index c0b408992a..1827e31d6f 100644 --- a/alib2cli/src/parser/Parser.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -93,13 +93,8 @@ std::unique_ptr < Arg > Parser::template_arg ( ) { return arg ( ); } -std::shared_ptr < Statement > Parser::in_redirect ( ) { - if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { - match ( cli::Lexer::TokenType::LEFT_PAREN ); - std::shared_ptr < StatementList > res = statement_list ( ); - match ( cli::Lexer::TokenType::RIGHT_PAREN ); - return res; - } else if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) { +std::shared_ptr < Statement > Parser::in_redirect_file ( ) { + if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) { match ( cli::Lexer::TokenType::LEFT_BRACE ); std::unique_ptr < TypeOption > type = type_option ( ); match ( cli::Lexer::TokenType::RIGHT_BRACE ); @@ -113,6 +108,17 @@ std::shared_ptr < Statement > Parser::in_redirect ( ) { } } +std::shared_ptr < Statement > Parser::in_redirect ( ) { + if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { + match ( cli::Lexer::TokenType::LEFT_PAREN ); + std::shared_ptr < StatementList > res = statement_list ( ); + match ( cli::Lexer::TokenType::RIGHT_PAREN ); + return res; + } else { + return in_redirect_file ( ); + } +} + std::shared_ptr < Statement > Parser::common ( ) { if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) { match ( cli::Lexer::TokenType::DOLAR_SIGN ); @@ -214,12 +220,18 @@ std::shared_ptr < StatementList > Parser::statement_list ( ) { return std::make_shared < StatementList > ( list ); } -void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) { +void Parser::out_redirect_file ( std::shared_ptr < StatementList > & list ) { if ( check ( cli::Lexer::TokenType::LEFT_BRACKET ) ) { match ( cli::Lexer::TokenType::LEFT_BRACKET ); std::unique_ptr < Arg > name = arg ( ); match ( cli::Lexer::TokenType::RIGHT_BRACKET ); } + + std::unique_ptr < Arg > file = arg ( ); + list->append ( std::make_unique < ResultFileStatement > ( std::move ( file ) ) ); +} + +void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) { if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) { match ( cli::Lexer::TokenType::DOLAR_SIGN ); std::unique_ptr < Arg > name = arg ( ); @@ -227,8 +239,7 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) { } else if ( check ( cli::Lexer::TokenType::END ) ) { return; } else { - std::unique_ptr < Arg > file = arg ( ); - list->append ( std::make_unique < ResultFileStatement > ( std::move ( file ) ) ); + out_redirect_file ( list ); } } diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h index b727946594..4d769dad9f 100644 --- a/alib2cli/src/parser/Parser.h +++ b/alib2cli/src/parser/Parser.h @@ -93,6 +93,8 @@ public: bool move_arg ( ); + std::shared_ptr < Statement > in_redirect_file ( ); + std::shared_ptr < Statement > in_redirect ( ); std::shared_ptr < Statement > common ( ); @@ -103,6 +105,8 @@ public: std::shared_ptr < StatementList > statement_list ( ); + void out_redirect_file ( std::shared_ptr < StatementList > & list ); + void out_redirect ( std::shared_ptr < StatementList > & list ); void result ( std::shared_ptr < StatementList > & list ); -- GitLab