diff --git a/alib2cli/src/ast/params/BindedVariableParam.h b/alib2cli/src/ast/params/VariableValueParam.h similarity index 62% rename from alib2cli/src/ast/params/BindedVariableParam.h rename to alib2cli/src/ast/params/VariableValueParam.h index 330d89fb769f97352868b77e7f535a37aa680f81..1de983d3d2800b72e253c0bb3d49203df2d740ff 100644 --- a/alib2cli/src/ast/params/BindedVariableParam.h +++ b/alib2cli/src/ast/params/VariableValueParam.h @@ -1,16 +1,16 @@ -#ifndef _CLI_BINDED_VARIABLE_PARAM_H_ -#define _CLI_BINDED_VARIABLE_PARAM_H_ +#ifndef _CLI_VARIABLE_VALUE_PARAM_H_ +#define _CLI_VARIABLE_VALUE_PARAM_H_ #include <ast/Param.h> #include <abstraction/Registry.h> namespace cli { -class BindedVariableParam : public Param { +class VariableValueParam : public Param { std::string m_name; public: - BindedVariableParam ( std::string name ) : m_name ( name ) { + VariableValueParam ( std::string name ) : m_name ( name ) { } virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override { @@ -20,4 +20,4 @@ public: } /* namespace cli */ -#endif /* _CLI_BINDED_VARIABLE_PARAM_H_ */ +#endif /* _CLI_VARIABLE_VALUE_PARAM_H_ */ diff --git a/alib2cli/src/ast/statements/BindedFileStatement.h b/alib2cli/src/ast/statements/BindedFileStatement.h new file mode 100644 index 0000000000000000000000000000000000000000..d3868824287e2e8b86006e9fe634824d82e4716c --- /dev/null +++ b/alib2cli/src/ast/statements/BindedFileStatement.h @@ -0,0 +1,25 @@ +#ifndef _CLI_BINDED_FILE_STATEMENT_H_ +#define _CLI_BINDED_FILE_STATEMENT_H_ + +#include <ast/Statement.h> +#include <abstraction/Registry.h> + +namespace cli { + +class BindedFileStatement : public Statement { + std::string m_bind; + +public: + BindedFileStatement ( std::string bind ) : m_bind ( bind ) { + } + + virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override { + std::deque < sax::Token > tokens = sax::FromXMLParserHelper::parseInput ( environment.getBinding ( m_bind ) ); + std::string type = tokens [ 0 ].getData ( ); + return abstraction::Registry::getXmlParserAbstraction ( type, tokens ); + } +}; + +} /* namespace cli */ + +#endif /* _CLI_BINDED_FILE_STATEMENT_H_ */ diff --git a/alib2cli/src/ast/statements/ImmediateFileStatement.h b/alib2cli/src/ast/statements/ImmediateFileStatement.h new file mode 100644 index 0000000000000000000000000000000000000000..71c1b1c12cee26ae16ee9e47967c7c861e1aa9f9 --- /dev/null +++ b/alib2cli/src/ast/statements/ImmediateFileStatement.h @@ -0,0 +1,25 @@ +#ifndef _CLI_IMMEDIATE_FILE_STATEMENT_H_ +#define _CLI_IMMEDIATE_FILE_STATEMENT_H_ + +#include <ast/Statement.h> +#include <abstraction/Registry.h> + +namespace cli { + +class ImmediateFileStatement : public Statement { + std::string m_name; + +public: + ImmediateFileStatement ( std::string name ) : m_name ( name ) { + } + + virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & ) const override { + std::deque < sax::Token > tokens = sax::FromXMLParserHelper::parseInput ( m_name ); + std::string type = tokens [ 0 ].getData ( ); + return abstraction::Registry::getXmlParserAbstraction ( type, tokens ); + } +}; + +} /* namespace cli */ + +#endif /* _CLI_IMMEDIATE_FILE_STATEMENT_H_ */ diff --git a/alib2cli/src/ast/statements/ResultFileStatement.h b/alib2cli/src/ast/statements/ResultImmediateFileStatement.h similarity index 62% rename from alib2cli/src/ast/statements/ResultFileStatement.h rename to alib2cli/src/ast/statements/ResultImmediateFileStatement.h index b28852e042890c2262a7cc09aec16442bcb87a2f..3196a1de3b8090923ea0304d984ba0f508d012ab 100644 --- a/alib2cli/src/ast/statements/ResultFileStatement.h +++ b/alib2cli/src/ast/statements/ResultImmediateFileStatement.h @@ -1,15 +1,15 @@ -#ifndef _CLI_RESULT_FILE_STATEMENT_H_ -#define _CLI_RESULT_FILE_STATEMENT_H_ +#ifndef _CLI_RESULT_IMMEDIATE_FILE_STATEMENT_H_ +#define _CLI_RESULT_IMMEDIATE_FILE_STATEMENT_H_ #include <ast/Statement.h> namespace cli { -class ResultFileStatement : public Statement { +class ResultImmediateFileStatement : public Statement { std::string m_name; public: - ResultFileStatement ( std::string name ) : m_name ( name ) { + ResultImmediateFileStatement ( std::string name ) : m_name ( name ) { } virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override { @@ -23,4 +23,4 @@ public: } /* namespace cli */ -#endif /* _CLI_RESULT_FILE_STATEMENT_H_ */ +#endif /* _CLI_RESULT_IMMEDIATE_FILE_STATEMENT_H_ */ diff --git a/alib2cli/src/ast/statements/VariableStatement.h b/alib2cli/src/ast/statements/VariableValueStatement.h similarity index 58% rename from alib2cli/src/ast/statements/VariableStatement.h rename to alib2cli/src/ast/statements/VariableValueStatement.h index ab5afdac8f589ac5fd1fafe69b3140d30268324c..74850c60676e9e269ea3be228985d5997ef96c62 100644 --- a/alib2cli/src/ast/statements/VariableStatement.h +++ b/alib2cli/src/ast/statements/VariableValueStatement.h @@ -1,16 +1,16 @@ -#ifndef _CLI_VARIABLE_STATEMENT_H_ -#define _CLI_VARIABLE_STATEMENT_H_ +#ifndef _CLI_VARIABLE_VALUE_STATEMENT_H_ +#define _CLI_VARIABLE_VALUE_STATEMENT_H_ #include <string> #include <ast/Statement.h> namespace cli { -class VariableStatement : public Statement { +class VariableValueStatement : public Statement { std::string m_name; public: - VariableStatement ( std::string name ) : m_name ( std::move ( name ) ) { + VariableValueStatement ( std::string name ) : m_name ( std::move ( name ) ) { } virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override { @@ -20,4 +20,4 @@ public: } /* namespace cli */ -#endif /* _CLI_VARIABLE_STATEMENT_H_ */ +#endif /* _CLI_VARIABLE_VALUE_STATEMENT_H_ */ diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp index 2b0016d9efb4914a7e869782b271c39ddc83386b..b1bcb15bbf52515869bb53be274a69832cf5cf82 100644 --- a/alib2cli/src/parser/Parser.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -2,12 +2,14 @@ #include <ast/statements/CastStatement.h> #include <ast/statements/SingleStatement.h> -#include <ast/statements/ResultFileStatement.h> +#include <ast/statements/ResultImmediateFileStatement.h> #include <ast/statements/ResultBindedFileStatement.h> #include <ast/statements/ResultVariableStatement.h> #include <ast/statements/ResultPrintStatement.h> -#include <ast/statements/VariableStatement.h> +#include <ast/statements/VariableValueStatement.h> #include <ast/statements/BindedValueStatement.h> +#include <ast/statements/BindedFileStatement.h> +#include <ast/statements/ImmediateFileStatement.h> #include <ast/params/StatementParam.h> #include <ast/params/ImmediateFileParam.h> @@ -15,7 +17,7 @@ #include <ast/params/PreviousResultParam.h> #include <ast/params/ImmediateValueParam.h> #include <ast/params/BindedValueParam.h> -#include <ast/params/BindedVariableParam.h> +#include <ast/params/VariableValueParam.h> #include <ast/params/CastParam.h> #include <command/ExecuteCommand.h> @@ -72,21 +74,36 @@ std::unique_ptr < Param > Parser::param ( ) { match ( cli::Lexer::TokenType::DOLAR_SIGN ); std::string name = getTokenValue ( ); match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER ); - return std::make_unique < BindedVariableParam > ( std::move ( name ) ); + return std::make_unique < VariableValueParam > ( std::move ( name ) ); } else { throw exception::CommonException ( "Mismatched set while expanding param rule." ); } } +std::shared_ptr < Statement > Parser::in_redirect_statement ( ) { + if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { + match ( cli::Lexer::TokenType::COLON_SIGN ); + std::string name = getTokenValue ( ); + match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER ); + return std::make_unique < BindedFileStatement > ( std::move ( name ) ); + } else { + std::string filename = matchIdentifier ( ); + return std::make_unique < ImmediateFileStatement > ( filename ); + } +} + std::shared_ptr < Statement > Parser::single_statement ( ) { if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) { match ( cli::Lexer::TokenType::DOLAR_SIGN ); std::string name = matchIdentifier ( ); - return std::make_shared < VariableStatement > ( std::move ( name ) ); + return std::make_shared < VariableValueStatement > ( std::move ( name ) ); } else if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { match ( cli::Lexer::TokenType::COLON_SIGN ); std::string name = matchIdentifier ( ); return std::make_shared < BindedValueStatement > ( std::move ( name ) ); + } else if ( check ( cli::Lexer::TokenType::IN_REDIRECT ) ) { + match ( cli::Lexer::TokenType::IN_REDIRECT ); + return in_redirect_statement ( ); } else if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) { match ( cli::Lexer::TokenType::LEFT_PAREN ); std::string type = matchIdentifier ( ); @@ -134,7 +151,7 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) { list->append ( std::make_unique < ResultVariableStatement > ( std::move ( name ) ) ); } else { std::string filename = matchIdentifier ( ); - list->append ( std::make_unique < ResultFileStatement > ( std::move ( filename ) ) ); + list->append ( std::make_unique < ResultImmediateFileStatement > ( std::move ( filename ) ) ); } } diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h index 15a7de2bc077d4ed9e55cbd7777c418782d86281..829024d65faae275db9ebe83ac6fe925bb6e2f10 100644 --- a/alib2cli/src/parser/Parser.h +++ b/alib2cli/src/parser/Parser.h @@ -72,6 +72,8 @@ public: std::unique_ptr < Param > param ( ); + std::shared_ptr < Statement > in_redirect_statement ( ); + std::shared_ptr < Statement > single_statement ( ); std::shared_ptr < StatementList > statement_list ( );