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

rename and add some more statements and params

parent 934443be
No related branches found
No related tags found
No related merge requests found
#ifndef _CLI_BINDED_VARIABLE_PARAM_H_ #ifndef _CLI_VARIABLE_VALUE_PARAM_H_
#define _CLI_BINDED_VARIABLE_PARAM_H_ #define _CLI_VARIABLE_VALUE_PARAM_H_
   
#include <ast/Param.h> #include <ast/Param.h>
#include <abstraction/Registry.h> #include <abstraction/Registry.h>
   
namespace cli { namespace cli {
   
class BindedVariableParam : public Param { class VariableValueParam : public Param {
std::string m_name; std::string m_name;
   
public: 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 { virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override {
...@@ -20,4 +20,4 @@ public: ...@@ -20,4 +20,4 @@ public:
   
} /* namespace cli */ } /* namespace cli */
   
#endif /* _CLI_BINDED_VARIABLE_PARAM_H_ */ #endif /* _CLI_VARIABLE_VALUE_PARAM_H_ */
#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_ */
#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_ */
#ifndef _CLI_RESULT_FILE_STATEMENT_H_ #ifndef _CLI_RESULT_IMMEDIATE_FILE_STATEMENT_H_
#define _CLI_RESULT_FILE_STATEMENT_H_ #define _CLI_RESULT_IMMEDIATE_FILE_STATEMENT_H_
   
#include <ast/Statement.h> #include <ast/Statement.h>
   
namespace cli { namespace cli {
   
class ResultFileStatement : public Statement { class ResultImmediateFileStatement : public Statement {
std::string m_name; std::string m_name;
   
public: 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 { virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override {
...@@ -23,4 +23,4 @@ public: ...@@ -23,4 +23,4 @@ public:
   
} /* namespace cli */ } /* namespace cli */
   
#endif /* _CLI_RESULT_FILE_STATEMENT_H_ */ #endif /* _CLI_RESULT_IMMEDIATE_FILE_STATEMENT_H_ */
#ifndef _CLI_VARIABLE_STATEMENT_H_ #ifndef _CLI_VARIABLE_VALUE_STATEMENT_H_
#define _CLI_VARIABLE_STATEMENT_H_ #define _CLI_VARIABLE_VALUE_STATEMENT_H_
   
#include <string> #include <string>
#include <ast/Statement.h> #include <ast/Statement.h>
   
namespace cli { namespace cli {
   
class VariableStatement : public Statement { class VariableValueStatement : public Statement {
std::string m_name; std::string m_name;
   
public: 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 { virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override {
...@@ -20,4 +20,4 @@ public: ...@@ -20,4 +20,4 @@ public:
   
} /* namespace cli */ } /* namespace cli */
   
#endif /* _CLI_VARIABLE_STATEMENT_H_ */ #endif /* _CLI_VARIABLE_VALUE_STATEMENT_H_ */
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
   
#include <ast/statements/CastStatement.h> #include <ast/statements/CastStatement.h>
#include <ast/statements/SingleStatement.h> #include <ast/statements/SingleStatement.h>
#include <ast/statements/ResultFileStatement.h> #include <ast/statements/ResultImmediateFileStatement.h>
#include <ast/statements/ResultBindedFileStatement.h> #include <ast/statements/ResultBindedFileStatement.h>
#include <ast/statements/ResultVariableStatement.h> #include <ast/statements/ResultVariableStatement.h>
#include <ast/statements/ResultPrintStatement.h> #include <ast/statements/ResultPrintStatement.h>
#include <ast/statements/VariableStatement.h> #include <ast/statements/VariableValueStatement.h>
#include <ast/statements/BindedValueStatement.h> #include <ast/statements/BindedValueStatement.h>
#include <ast/statements/BindedFileStatement.h>
#include <ast/statements/ImmediateFileStatement.h>
   
#include <ast/params/StatementParam.h> #include <ast/params/StatementParam.h>
#include <ast/params/ImmediateFileParam.h> #include <ast/params/ImmediateFileParam.h>
...@@ -15,7 +17,7 @@ ...@@ -15,7 +17,7 @@
#include <ast/params/PreviousResultParam.h> #include <ast/params/PreviousResultParam.h>
#include <ast/params/ImmediateValueParam.h> #include <ast/params/ImmediateValueParam.h>
#include <ast/params/BindedValueParam.h> #include <ast/params/BindedValueParam.h>
#include <ast/params/BindedVariableParam.h> #include <ast/params/VariableValueParam.h>
#include <ast/params/CastParam.h> #include <ast/params/CastParam.h>
   
#include <command/ExecuteCommand.h> #include <command/ExecuteCommand.h>
...@@ -72,21 +74,36 @@ std::unique_ptr < Param > Parser::param ( ) { ...@@ -72,21 +74,36 @@ std::unique_ptr < Param > Parser::param ( ) {
match ( cli::Lexer::TokenType::DOLAR_SIGN ); match ( cli::Lexer::TokenType::DOLAR_SIGN );
std::string name = getTokenValue ( ); std::string name = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER ); 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 { } else {
throw exception::CommonException ( "Mismatched set while expanding param rule." ); 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 ( ) { std::shared_ptr < Statement > Parser::single_statement ( ) {
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::string name = matchIdentifier ( ); 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 ) ) { } else if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) {
match ( cli::Lexer::TokenType::COLON_SIGN ); match ( cli::Lexer::TokenType::COLON_SIGN );
std::string name = matchIdentifier ( ); std::string name = matchIdentifier ( );
return std::make_shared < BindedValueStatement > ( std::move ( name ) ); 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 ) ) { } else if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) {
match ( cli::Lexer::TokenType::LEFT_PAREN ); match ( cli::Lexer::TokenType::LEFT_PAREN );
std::string type = matchIdentifier ( ); std::string type = matchIdentifier ( );
...@@ -134,7 +151,7 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) { ...@@ -134,7 +151,7 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) {
list->append ( std::make_unique < ResultVariableStatement > ( std::move ( name ) ) ); list->append ( std::make_unique < ResultVariableStatement > ( std::move ( name ) ) );
} else { } else {
std::string filename = matchIdentifier ( ); std::string filename = matchIdentifier ( );
list->append ( std::make_unique < ResultFileStatement > ( std::move ( filename ) ) ); list->append ( std::make_unique < ResultImmediateFileStatement > ( std::move ( filename ) ) );
} }
} }
   
......
...@@ -72,6 +72,8 @@ public: ...@@ -72,6 +72,8 @@ public:
   
std::unique_ptr < Param > param ( ); std::unique_ptr < Param > param ( );
   
std::shared_ptr < Statement > in_redirect_statement ( );
std::shared_ptr < Statement > single_statement ( ); std::shared_ptr < Statement > single_statement ( );
   
std::shared_ptr < StatementList > statement_list ( ); std::shared_ptr < StatementList > statement_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