Skip to content
Snippets Groups Projects
Commit 9ba0c651 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

wip input and output redirection in cli

parent 6d3a2c66
No related branches found
No related tags found
No related merge requests found
...@@ -93,13 +93,8 @@ std::unique_ptr < Arg > Parser::template_arg ( ) { ...@@ -93,13 +93,8 @@ std::unique_ptr < Arg > Parser::template_arg ( ) {
return arg ( ); return arg ( );
} }
   
std::shared_ptr < Statement > Parser::in_redirect ( ) { std::shared_ptr < Statement > Parser::in_redirect_file ( ) {
if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) {
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 ) ) {
match ( cli::Lexer::TokenType::LEFT_BRACE ); match ( cli::Lexer::TokenType::LEFT_BRACE );
std::unique_ptr < TypeOption > type = type_option ( ); std::unique_ptr < TypeOption > type = type_option ( );
match ( cli::Lexer::TokenType::RIGHT_BRACE ); match ( cli::Lexer::TokenType::RIGHT_BRACE );
...@@ -113,6 +108,17 @@ std::shared_ptr < Statement > Parser::in_redirect ( ) { ...@@ -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 ( ) { std::shared_ptr < Statement > Parser::common ( ) {
if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) { if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) {
match ( cli::Lexer::TokenType::DOLAR_SIGN ); match ( cli::Lexer::TokenType::DOLAR_SIGN );
...@@ -214,12 +220,18 @@ std::shared_ptr < StatementList > Parser::statement_list ( ) { ...@@ -214,12 +220,18 @@ std::shared_ptr < StatementList > Parser::statement_list ( ) {
return std::make_shared < StatementList > ( 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 ) ) { if ( check ( cli::Lexer::TokenType::LEFT_BRACKET ) ) {
match ( cli::Lexer::TokenType::LEFT_BRACKET ); match ( cli::Lexer::TokenType::LEFT_BRACKET );
std::unique_ptr < Arg > name = arg ( ); std::unique_ptr < Arg > name = arg ( );
match ( cli::Lexer::TokenType::RIGHT_BRACKET ); 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 ) ) { if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) {
match ( cli::Lexer::TokenType::DOLAR_SIGN ); match ( cli::Lexer::TokenType::DOLAR_SIGN );
std::unique_ptr < Arg > name = arg ( ); std::unique_ptr < Arg > name = arg ( );
...@@ -227,8 +239,7 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) { ...@@ -227,8 +239,7 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) {
} else if ( check ( cli::Lexer::TokenType::END ) ) { } else if ( check ( cli::Lexer::TokenType::END ) ) {
return; return;
} else { } else {
std::unique_ptr < Arg > file = arg ( ); out_redirect_file ( list );
list->append ( std::make_unique < ResultFileStatement > ( std::move ( file ) ) );
} }
} }
   
......
...@@ -93,6 +93,8 @@ public: ...@@ -93,6 +93,8 @@ public:
   
bool move_arg ( ); bool move_arg ( );
   
std::shared_ptr < Statement > in_redirect_file ( );
std::shared_ptr < Statement > in_redirect ( ); std::shared_ptr < Statement > in_redirect ( );
   
std::shared_ptr < Statement > common ( ); std::shared_ptr < Statement > common ( );
...@@ -103,6 +105,8 @@ public: ...@@ -103,6 +105,8 @@ public:
   
std::shared_ptr < StatementList > statement_list ( ); std::shared_ptr < StatementList > statement_list ( );
   
void out_redirect_file ( std::shared_ptr < StatementList > & list );
void out_redirect ( std::shared_ptr < StatementList > & list ); void out_redirect ( std::shared_ptr < StatementList > & list );
   
void result ( std::shared_ptr < StatementList > & list ); void result ( std::shared_ptr < StatementList > & list );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment