From 55bedfc8ed029efe58419204cdc253a38e5e2237 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Wed, 2 Aug 2017 19:42:29 +0200
Subject: [PATCH] rename and add some more statements and params

---
 ...edVariableParam.h => VariableValueParam.h} | 10 +++----
 .../src/ast/statements/BindedFileStatement.h  | 25 ++++++++++++++++
 .../ast/statements/ImmediateFileStatement.h   | 25 ++++++++++++++++
 ...ement.h => ResultImmediateFileStatement.h} | 10 +++----
 ...leStatement.h => VariableValueStatement.h} | 10 +++----
 alib2cli/src/parser/Parser.cpp                | 29 +++++++++++++++----
 alib2cli/src/parser/Parser.h                  |  2 ++
 7 files changed, 90 insertions(+), 21 deletions(-)
 rename alib2cli/src/ast/params/{BindedVariableParam.h => VariableValueParam.h} (62%)
 create mode 100644 alib2cli/src/ast/statements/BindedFileStatement.h
 create mode 100644 alib2cli/src/ast/statements/ImmediateFileStatement.h
 rename alib2cli/src/ast/statements/{ResultFileStatement.h => ResultImmediateFileStatement.h} (62%)
 rename alib2cli/src/ast/statements/{VariableStatement.h => VariableValueStatement.h} (58%)

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 330d89fb76..1de983d3d2 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 0000000000..d386882428
--- /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 0000000000..71c1b1c12c
--- /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 b28852e042..3196a1de3b 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 ab5afdac8f..74850c6067 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 2b0016d9ef..b1bcb15bbf 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 15a7de2bc0..829024d65f 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 ( );
-- 
GitLab