From 1a92e7f1c064ef308672801ab5373750885d0520 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 18 Jan 2018 21:18:08 +0100
Subject: [PATCH] allow immediate value as base of execute colon

---
 .../src/ast/statements/ImmediateStatement.h   | 24 +++++++++++++++++++
 alib2cli/src/parser/Parser.cpp                | 16 +++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 alib2cli/src/ast/statements/ImmediateStatement.h

diff --git a/alib2cli/src/ast/statements/ImmediateStatement.h b/alib2cli/src/ast/statements/ImmediateStatement.h
new file mode 100644
index 0000000000..3aa7d419bb
--- /dev/null
+++ b/alib2cli/src/ast/statements/ImmediateStatement.h
@@ -0,0 +1,24 @@
+#ifndef _IMMEDIATE_STATEMENT_H_
+#define _IMMEDIATE_STATEMENT_H_
+
+#include <ast/Statement.h>
+#include <abstraction/ImmediateValueAbstraction.hpp>
+
+namespace cli {
+
+template < class Type >
+class ImmediateStatement final : public Statement {
+	Type m_data;
+
+public:
+	ImmediateStatement ( Type value ) : m_data ( std::move ( value ) ) {
+	}
+
+	virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & ) const override {
+		return std::make_shared < abstraction::ImmediateValueAbstraction < Type > > ( m_data );
+	}
+};
+
+} /* namespace cli */
+
+#endif /* _IMMEDIATE_STATEMENT_H_ */
diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp
index 3d5fec731b..a1da50dfed 100644
--- a/alib2cli/src/parser/Parser.cpp
+++ b/alib2cli/src/parser/Parser.cpp
@@ -10,6 +10,7 @@
 #include <ast/statements/VariableStatement.h>
 #include <ast/statements/ValueStatement.h>
 #include <ast/statements/FileStatement.h>
+#include <ast/statements/ImmediateStatement.h>
 
 #include <ast/params/StatementParam.h>
 #include <ast/params/FileParam.h>
@@ -134,6 +135,15 @@ std::unique_ptr < Param > Parser::move_param ( ) {
 		match ( cli::Lexer::TokenType::DOLAR_SIGN );
 		std::unique_ptr < Arg > name = arg ( );
 		return std::make_unique < VariableParam > ( std::move ( name ), true );
+	} else if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) {
+		std::string value = matchIdentifier ( );
+		return std::make_unique < ImmediateParam < std::string > > ( value );
+	} else if ( check ( cli::Lexer::TokenType::STRING ) ) {
+		std::string value = matchString ( );
+		return std::make_unique < ImmediateParam < std::string > > ( value );
+	} else if ( check ( cli::Lexer::TokenType::INTEGER ) ) {
+		int value = matchInteger ( );
+		return std::make_unique < ImmediateParam < int > > ( value );
 	} else {
 		throw exception::CommonException ( "Mismatched set while expanding move_param rule." );
 	}
@@ -220,6 +230,12 @@ std::shared_ptr < Statement > Parser::single_statement ( ) {
 		}
 
 		return std::make_shared < SingleStatement > ( std::move ( name ), std::move ( templateParams ), std::move ( params ), std::move ( category ) );
+	} else if ( check ( cli::Lexer::TokenType::STRING ) ) {
+		std::string value = matchString ( );
+		return std::make_unique < ImmediateStatement < std::string > > ( value );
+	} else if ( check ( cli::Lexer::TokenType::INTEGER ) ) {
+		int value = matchInteger ( );
+		return std::make_unique < ImmediateStatement < int > > ( value );
 	} else if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) {
 		match ( cli::Lexer::TokenType::LEFT_BRACE );
 		std::unique_ptr < TypeOption > type = type_option ( );
-- 
GitLab