From 16cd0cfe2044069cbfafc7cd8eef1392cd654cd6 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 24 Jan 2019 14:47:44 +0100
Subject: [PATCH] fix cli parser

---
 alib2cli/src/parser/Parser.cpp | 10 +++++++++-
 alib2cli/src/parser/Parser.h   |  3 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp
index e17125823a..3d83c5c5fa 100644
--- a/alib2cli/src/parser/Parser.cpp
+++ b/alib2cli/src/parser/Parser.cpp
@@ -44,6 +44,14 @@ std::unique_ptr < TypeOption > Parser::type_option ( ) {
 		std::string value = getTokenValue ( );
 		match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
 		return std::make_unique < TypeOption > ( std::move ( value ) );
+	} else {
+		throw exception::CommonException ( "Mismatched colon sign while expanding type_option rule." );
+	}
+}
+
+std::unique_ptr < TypeOption > Parser::optional_type_option ( ) {
+	if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) {
+		return type_option ( );
 	} else {
 		return nullptr;
 	}
@@ -92,7 +100,7 @@ std::shared_ptr < Statement > Parser::in_redirect_file ( ) {
 		match ( cli::Lexer::TokenType::RIGHT_BRACKET );
 	}
 
-	std::unique_ptr < TypeOption > type = type_option ( );
+	std::unique_ptr < TypeOption > type = optional_type_option ( );
 	ext::vector < std::unique_ptr < cli::Arg > > templateArgs;
 	while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) {
 		templateArgs.emplace_back ( template_arg ( ) );
diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h
index 2a5c7b18aa..2b5335cbe1 100644
--- a/alib2cli/src/parser/Parser.h
+++ b/alib2cli/src/parser/Parser.h
@@ -86,8 +86,11 @@ public:
 	}
 
 	std::unique_ptr < CategoryOption > category_option ( );
+
 	std::unique_ptr < TypeOption > type_option ( );
 
+	std::unique_ptr < TypeOption > optional_type_option ( );
+
 	std::unique_ptr < Arg > arg ( );
 
 	std::unique_ptr < Arg > optional_arg ( );
-- 
GitLab