diff --git a/aarbology2/src/aarbology.cpp b/aarbology2/src/aarbology.cpp index 1ee609ca39b72fe1075e46c91af784b795484ede..cedbd20e50f7847a917b46575a754e79bd3a7c4f 100644 --- a/aarbology2/src/aarbology.cpp +++ b/aarbology2/src/aarbology.cpp @@ -140,7 +140,7 @@ int main ( int argc, char * argv[] ) { input = subtreeWildcardInput.getValue ( ); environment.setBinding ( "inputSubtreeWildcard", input ); - cli::Parser parser ( cli::Lexer ( "execute <:type ranked_symbol #inputSubtreeWildcard > $subtreeWildcard" ) ); + cli::Parser parser ( cli::Lexer ( "execute <:ranked_symbol #inputSubtreeWildcard > $subtreeWildcard" ) ); parser.parse ( )->run ( environment ); } @@ -152,7 +152,7 @@ int main ( int argc, char * argv[] ) { input = nonlinearVariablesInput.getValue ( ); environment.setBinding ( "inputNonlinearVariables", input ); - cli::Parser parser ( cli::Lexer ( "execute <{:type ranked_symbol}#inputNonlinearVariables > $nonlinearVariables" ) ); + cli::Parser parser ( cli::Lexer ( "execute <{:ranked_symbol} #inputNonlinearVariables > $nonlinearVariables" ) ); parser.parse ( )->run ( environment ); } diff --git a/aintrospection2/src/aintrospection.cpp b/aintrospection2/src/aintrospection.cpp index 38e1c38177dc9e32d48de60843789d674a658fa9..2011614521368527f65e405d3ea47ee0e0f77bc4 100644 --- a/aintrospection2/src/aintrospection.cpp +++ b/aintrospection2/src/aintrospection.cpp @@ -13,6 +13,7 @@ #include <lexer/Lexer.h> #include <parser/Parser.h> #include <factory/XmlDataFactory.hpp> +#include <abstraction/Registry.h> int main ( int argc, char * argv[] ) { try { diff --git a/alib2cli/src/ast/Option.h b/alib2cli/src/ast/Option.h index 32b991662016b4c2984e71d6d09e52132a8d5327..48a1f21691d89d3164c90047fb51637109961fde 100644 --- a/alib2cli/src/ast/Option.h +++ b/alib2cli/src/ast/Option.h @@ -1,23 +1,12 @@ #ifndef _CLI_OPTION_H_ #define _CLI_OPTION_H_ -#include <ast/Ast.h> -#include <ast/statements/SingleStatement.h> -#include <ast/statements/ContainerStatement.h> -#include <ast/statements/ContainerFileStatement.h> -#include <ast/statements/FileStatement.h> - namespace cli { class Option { public: virtual ~Option ( ) noexcept { } - - virtual void eval ( SingleStatement & statement ) const = 0; - virtual void eval ( ContainerStatement & statement ) const = 0; - virtual void eval ( ContainerFileStatement & statement ) const = 0; - virtual void eval ( FileStatement & statement ) const = 0; }; } /* namespace cli */ diff --git a/alib2cli/src/ast/options/CategoryOption.h b/alib2cli/src/ast/options/CategoryOption.h index 85d8bf3dbe2ffc8232048b1f0868213ed40f4b11..98437f9fbc33cebd5f993f7f2a21ddad1a4ce037 100644 --- a/alib2cli/src/ast/options/CategoryOption.h +++ b/alib2cli/src/ast/options/CategoryOption.h @@ -14,21 +14,10 @@ public: CategoryOption ( std::string key ) : m_key ( std::move ( key ) ) { } - virtual void eval ( SingleStatement & statement ) const override { - statement.setCategory ( abstraction::AlgorithmCategories::algorithmCategory ( m_key ) ); + abstraction::AlgorithmCategories::AlgorithmCategory getCategory ( ) const { + return abstraction::AlgorithmCategories::algorithmCategory ( m_key ); } - virtual void eval ( ContainerStatement & ) const override { - throw exception::CommonException ( "ContainerStatement cannot be categorized." ); - } - - virtual void eval ( ContainerFileStatement & ) const override { - throw exception::CommonException ( "ContainerFileStatement cannot be categorized." ); - } - - virtual void eval ( FileStatement & ) const override { - throw exception::CommonException ( "FileStatement cannot be categorized." ); - } }; } /* namespace cli */ diff --git a/alib2cli/src/ast/options/HL3Option.h b/alib2cli/src/ast/options/HL3Option.h deleted file mode 100644 index 6dba5a8131e4175b7babd4f3ee68f8a2047cab74..0000000000000000000000000000000000000000 --- a/alib2cli/src/ast/options/HL3Option.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _CLI_HL3_OPTION_H_ -#define _CLI_HL3_OPTION_H_ - -#include <ast/Option.h> - -namespace cli { - -class HL3Option final : public Option { -public: - virtual void eval ( SingleStatement & ) const override { - std::cout << "The cake is a lie, as well as the release date of HL3. GLaDOS told me." << std::endl; - } - - virtual void eval ( ContainerStatement & ) const override { - std::cout << "The cake is a lie, as well as the release date of HL3. GLaDOS told me." << std::endl; - } - - virtual void eval ( ContainerFileStatement & ) const override { - std::cout << "The cake is a lie, as well as the release date of HL3. GLaDOS told me." << std::endl; - } - - virtual void eval ( FileStatement & ) const override { - std::cout << "The cake is a lie, as well as the release date of HL3. GLaDOS told me." << std::endl; - } -}; - -} /* namespace cli */ - -#endif /* _CLI_HL3_OPTION_H_ */ diff --git a/alib2cli/src/ast/options/TypeOption.h b/alib2cli/src/ast/options/TypeOption.h index f70d3095002a8f98b0e502d63377bd34fce339b2..e8e91101fdb1f063434838d9238a2c6412deab0c 100644 --- a/alib2cli/src/ast/options/TypeOption.h +++ b/alib2cli/src/ast/options/TypeOption.h @@ -13,20 +13,8 @@ public: TypeOption ( std::string type ) : m_type ( std::move ( type ) ) { } - virtual void eval ( SingleStatement & ) const override { - throw exception::CommonException ( "Single statement cannot be parametrized with type." ); - } - - virtual void eval ( ContainerStatement & statement ) const override { - statement.setType ( m_type ); - } - - virtual void eval ( ContainerFileStatement & statement ) const override { - statement.setType ( m_type ); - } - - virtual void eval ( FileStatement & statement ) const override { - statement.setType ( m_type ); + const std::string & getType ( ) const { + return m_type; } }; diff --git a/alib2cli/src/ast/statements/ContainerFileStatement.cpp b/alib2cli/src/ast/statements/ContainerFileStatement.cpp index ffc54259ae67a2886ac4d2e6402550ad3223bfdf..601899fbc9b2a7655e7a4c05334c04a7cd0787b3 100644 --- a/alib2cli/src/ast/statements/ContainerFileStatement.cpp +++ b/alib2cli/src/ast/statements/ContainerFileStatement.cpp @@ -6,18 +6,11 @@ namespace cli { -ContainerFileStatement::ContainerFileStatement ( std::string container, ext::vector < std::unique_ptr < Option > > options, std::unique_ptr < Arg > file ) : m_file ( std::move ( file ) ), m_container ( std::move ( container ) ), m_options ( std::move ( options ) ) { - for ( const std::unique_ptr < Option > & option : m_options ) { - option->eval ( * this ); - } +ContainerFileStatement::ContainerFileStatement ( std::string container, std::unique_ptr < TypeOption > type, std::unique_ptr < Arg > file ) : m_file ( std::move ( file ) ), m_container ( std::move ( container ) ), m_type ( std::move ( type ) ) { } std::shared_ptr < abstraction::OperationAbstraction > ContainerFileStatement::translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const { - return abstraction::Registry::getContainerAbstraction ( m_container, m_type, m_file->eval ( environment ) ); -} - -void ContainerFileStatement::setType ( std::string type ) { - m_type = std::move ( type ); + return abstraction::Registry::getContainerAbstraction ( m_container, m_type->getType ( ), m_file->eval ( environment ) ); } } /* namespace cli */ diff --git a/alib2cli/src/ast/statements/ContainerFileStatement.h b/alib2cli/src/ast/statements/ContainerFileStatement.h index e2e2d88c31ad2b79c581676b7a11a45bf3483d3f..d216cf844dd1be5fee6da66f2879a3cfc6bb79cf 100644 --- a/alib2cli/src/ast/statements/ContainerFileStatement.h +++ b/alib2cli/src/ast/statements/ContainerFileStatement.h @@ -2,22 +2,19 @@ #define _CLI_CONTAINER_FILE_STATEMENT_H_ #include <ast/Statement.h> +#include <ast/options/TypeOption.h> namespace cli { class ContainerFileStatement final : public Statement { std::unique_ptr < cli::Arg > m_file; std::string m_container; - ext::vector < std::unique_ptr < Option > > m_options; - - std::string m_type; + std::unique_ptr < TypeOption > m_type; public: - ContainerFileStatement ( std::string container, ext::vector < std::unique_ptr < Option > > options, std::unique_ptr < Arg > file ); + ContainerFileStatement ( std::string container, std::unique_ptr < TypeOption > type, std::unique_ptr < Arg > file ); virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override; - - void setType ( std::string type ); }; } /* namespace cli */ diff --git a/alib2cli/src/ast/statements/ContainerStatement.cpp b/alib2cli/src/ast/statements/ContainerStatement.cpp index 9751550f2afe283cc0d186f9daf9d404a13ec7cd..55be167c4179b03bc2a98e0570e6faac3ce96744 100644 --- a/alib2cli/src/ast/statements/ContainerStatement.cpp +++ b/alib2cli/src/ast/statements/ContainerStatement.cpp @@ -8,10 +8,7 @@ namespace cli { -ContainerStatement::ContainerStatement ( std::string container, ext::vector < std::unique_ptr < Param > > params, ext::vector < std::unique_ptr < Option > > options ) : m_container ( std::move ( container ) ), m_params ( std::move ( params ) ), m_options ( std::move ( options ) ) { - for ( const std::unique_ptr < Option > & option : m_options ) { - option->eval ( * this ); - } +ContainerStatement::ContainerStatement ( std::string container, ext::vector < std::unique_ptr < Param > > params, std::unique_ptr < TypeOption > type ) : m_container ( std::move ( container ) ), m_params ( std::move ( params ) ), m_type ( std::move ( type ) ) { } std::shared_ptr < abstraction::OperationAbstraction > ContainerStatement::translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const { @@ -25,7 +22,7 @@ std::shared_ptr < abstraction::OperationAbstraction > ContainerStatement::transl moves.push_back ( param->getMove ( ) ); } - std::shared_ptr < abstraction::OperationAbstraction > algo = abstraction::Registry::getContainerAbstraction ( m_container, m_type ); + std::shared_ptr < abstraction::OperationAbstraction > algo = abstraction::Registry::getContainerAbstraction ( m_container, m_type->getType ( ) ); unsigned i = 0; ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > casted_params; @@ -52,8 +49,4 @@ std::shared_ptr < abstraction::OperationAbstraction > ContainerStatement::transl return algo; } -void ContainerStatement::setType ( std::string type ) { - m_type = std::move ( type ); -} - } /* namespace cli */ diff --git a/alib2cli/src/ast/statements/ContainerStatement.h b/alib2cli/src/ast/statements/ContainerStatement.h index 35b97849d36173a4456d16d65440ec323258b344..efbcd246f047976e185b8422f39f018048d8bbcb 100644 --- a/alib2cli/src/ast/statements/ContainerStatement.h +++ b/alib2cli/src/ast/statements/ContainerStatement.h @@ -2,22 +2,19 @@ #define _CLI_CONTAINER_STATEMENT_H_ #include <ast/Statement.h> +#include <ast/options/TypeOption.h> namespace cli { class ContainerStatement final : public Statement { std::string m_container; ext::vector < std::unique_ptr < Param > > m_params; - ext::vector < std::unique_ptr < Option > > m_options; - - std::string m_type; + std::unique_ptr < TypeOption > m_type; public: - ContainerStatement ( std::string container, ext::vector < std::unique_ptr < Param > > params, ext::vector < std::unique_ptr < Option > > options ); + ContainerStatement ( std::string container, ext::vector < std::unique_ptr < Param > > params, std::unique_ptr < TypeOption > type ); virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override; - - void setType ( std::string type ); }; } /* namespace cli */ diff --git a/alib2cli/src/ast/statements/FileStatement.cpp b/alib2cli/src/ast/statements/FileStatement.cpp index 9b8768ab8d0ae4c015159ca5b3b4336d8f8a4e11..98a0ad940d18370dcebd53977bac4e8edcd782a0 100644 --- a/alib2cli/src/ast/statements/FileStatement.cpp +++ b/alib2cli/src/ast/statements/FileStatement.cpp @@ -6,24 +6,19 @@ namespace cli { -FileStatement::FileStatement ( ext::vector < std::unique_ptr < Option > > options, std::unique_ptr < Arg > file ) : m_file ( std::move ( file ) ), m_options ( std::move ( options ) ) { - for ( const std::unique_ptr < Option > & option : m_options ) { - option->eval ( * this ); - } +FileStatement::FileStatement ( std::unique_ptr < TypeOption > type, std::unique_ptr < Arg > file ) : m_file ( std::move ( file ) ), m_type ( std::move ( type ) ) { } std::shared_ptr < abstraction::OperationAbstraction > FileStatement::translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const { ext::deque < sax::Token > tokens = sax::FromXMLParserHelper::parseInput ( m_file->eval ( environment ) ); - std::string type = m_type; + std::string type = ""; + if ( m_type ) + type = m_type->getType ( ); if ( type == "" ) type = tokens [ 0 ].getData ( ); return abstraction::Registry::getXmlParserAbstraction ( type, tokens ); } -void FileStatement::setType ( std::string type ) { - m_type = std::move ( type ); -} - } /* namespace cli */ diff --git a/alib2cli/src/ast/statements/FileStatement.h b/alib2cli/src/ast/statements/FileStatement.h index cc3828577edd7c6c3623e69cafd125b786ebc7b1..41c47fc8b12a392ceb1b21b6c646b97e6ec87322 100644 --- a/alib2cli/src/ast/statements/FileStatement.h +++ b/alib2cli/src/ast/statements/FileStatement.h @@ -2,21 +2,18 @@ #define _CLI_FILE_STATEMENT_H_ #include <ast/Statement.h> +#include <ast/options/TypeOption.h> namespace cli { class FileStatement final : public Statement { std::unique_ptr < cli::Arg > m_file; - ext::vector < std::unique_ptr < Option > > m_options; - - std::string m_type; + std::unique_ptr < TypeOption > m_type; public: - FileStatement ( ext::vector < std::unique_ptr < Option > > options, std::unique_ptr < Arg > file ); + FileStatement ( std::unique_ptr < TypeOption > type, std::unique_ptr < Arg > file ); virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override; - - void setType ( std::string type ); }; } /* namespace cli */ diff --git a/alib2cli/src/ast/statements/SingleStatement.cpp b/alib2cli/src/ast/statements/SingleStatement.cpp index 832b24924febac570ba48eea349816425e44f645..3b35b1afe2952e9a5378673ab175f9bfcb6e0399 100644 --- a/alib2cli/src/ast/statements/SingleStatement.cpp +++ b/alib2cli/src/ast/statements/SingleStatement.cpp @@ -1,15 +1,12 @@ #include <ast/statements/SingleStatement.h> -#include <ast/Option.h> #include <ast/Param.h> #include <ast/Arg.h> #include <abstraction/common/AlgorithmHelper.h> +#include <abstraction/common/AlgorithmCategories.hpp> namespace cli { -SingleStatement::SingleStatement ( std::unique_ptr < Arg > name, ext::vector < std::unique_ptr < Param > > params, ext::vector < std::unique_ptr < Option > > options ) : m_name ( std::move ( name ) ), m_params ( std::move ( params ) ), m_options ( std::move ( options ) ), m_category ( abstraction::AlgorithmCategories::AlgorithmCategory::NONE ) { - for ( const std::unique_ptr < Option > & option : m_options ) { - option->eval ( * this ); - } +SingleStatement::SingleStatement ( std::unique_ptr < Arg > name, ext::vector < std::unique_ptr < Param > > params, std::unique_ptr < CategoryOption > category ) : m_name ( std::move ( name ) ), m_params ( std::move ( params ) ), m_category ( std::move ( category ) ) { } std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const { @@ -24,12 +21,11 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate } std::string name = m_name->eval ( environment ); + abstraction::AlgorithmCategories::AlgorithmCategory category = abstraction::AlgorithmCategories::AlgorithmCategory::NONE; + if ( m_category ) + category = m_category->getCategory ( ); - return abstraction::AlgorithmHelper::eval ( name, params, moves, m_category ); -} - -void SingleStatement::setCategory ( abstraction::AlgorithmCategories::AlgorithmCategory category ) { - m_category = category; + return abstraction::AlgorithmHelper::eval ( name, params, moves, category ); } } /* namespace cli */ diff --git a/alib2cli/src/ast/statements/SingleStatement.h b/alib2cli/src/ast/statements/SingleStatement.h index 87ab9f9213ead62579a1fa26d0b2b153e204efc1..40bd08980fa09d4f29a9cc34ac950ff326d497cc 100644 --- a/alib2cli/src/ast/statements/SingleStatement.h +++ b/alib2cli/src/ast/statements/SingleStatement.h @@ -5,23 +5,19 @@ #include <abstraction/Registry.h> #include <exception/CommonException.h> #include <iostream> -#include <abstraction/common/AlgorithmCategories.hpp> +#include <ast/options/CategoryOption.h> namespace cli { class SingleStatement final : public Statement { std::unique_ptr < cli::Arg > m_name; ext::vector < std::unique_ptr < Param > > m_params; - ext::vector < std::unique_ptr < Option > > m_options; - - abstraction::AlgorithmCategories::AlgorithmCategory m_category; + std::unique_ptr < CategoryOption > m_category; public: - SingleStatement ( std::unique_ptr < cli::Arg > name, ext::vector < std::unique_ptr < Param > > params, ext::vector < std::unique_ptr < Option > > options ); + SingleStatement ( std::unique_ptr < cli::Arg > name, ext::vector < std::unique_ptr < Param > > params, std::unique_ptr < CategoryOption > options ); virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override; - - void setCategory ( abstraction::AlgorithmCategories::AlgorithmCategory category ); }; } /* namespace cli */ diff --git a/alib2cli/src/command/HelpCommand.h b/alib2cli/src/command/HelpCommand.h index bd03d53d77e820247fd2b9531e4479f79a990405..491cf8026cfce56eac69ed28a12e620ae272ea24 100644 --- a/alib2cli/src/command/HelpCommand.h +++ b/alib2cli/src/command/HelpCommand.h @@ -26,41 +26,38 @@ public: std::cout << "statement_list:" << std::endl; std::cout << "statement ( | statement )* - at least one statement followed by a pipe separated sequence of other statements" << std::endl; std::cout << "" << std::endl; + std::cout << "arg:" << std::endl; + std::cout << "value - immediate string value" << std::endl; + std::cout << "#value - string value from environmet variable" << std::endl; + std::cout << "" << std::endl; std::cout << "param:" << std::endl; std::cout << "[^] - - a value from the previous result (PreviousResultParam)" << std::endl; std::cout << "[^] <( statement_list ) - a statement list serving as a param (StatementParam)" << std::endl; - std::cout << "[^] ( type ) param - a casted parameter, type is an immediate value (CastParam)" << std::endl; - std::cout << "[^] ( #type ) param - a casted parameter, type identified by an environment variable (CastParam)" << std::endl; + std::cout << "[^] ( arg ) param - a casted parameter, type is given by arg value (CastParam)" << std::endl; std::cout << "" << std::endl; - std::cout << "identifier - a string param - the value is a immediate string (ImmediateParam)" << std::endl; - std::cout << "number - a number param - the value is a immediate integer (ImmediateParam)" << std::endl; - std::cout << "#identifier - a string param - identified by an environment variable (ValueParam)" << std::endl; - std::cout << "[^] $identifier - a value from a variable, identifier is an immediate value (VariableParam)" << std::endl; - std::cout << "[^] $#identifier - a value from a variable, identified by an environment variable (VariableParam)" << std::endl; + std::cout << "identifier - a string param - the value is a immediate string (ImmediateParam)" << std::endl; + std::cout << "number - a number param - the value is a immediate integer (ImmediateParam)" << std::endl; + std::cout << "#identifier - a string param - identified by an environment variable (ValueParam)" << std::endl; + std::cout << "[^] $arg - a value from a variable, name is given by arg value (VariableParam)" << std::endl; std::cout << "" << std::endl; - std::cout << "<identifier - a value from a xml file, identifier is an immediate value (FileParam)" << std::endl; - std::cout << "<#identifier - a value from a xml file, identified by an environment variable (FileParam)" << std::endl; + std::cout << "<arg - a value from a xml file, filename is given by arg value (FileParam)" << std::endl; std::cout << "" << std::endl; std::cout << "statement:" << std::endl; std::cout << "name ( param )* output_spec - a statement with params, name is an immediate value (SingleStatement)" << std::endl; - std::cout << "( type ) [^] statement - the result of a statement is casted, type is an immediate value (CastedStatement)" << std::endl; - std::cout << "( #type ) [^] statement - the result of a statement is casted, type indentified by an environment variable (CastedStatement)" << std::endl; - std::cout << "{ :type param ( param ) * } - creates a set of type given by param with values from individual statements" << std::endl; + std::cout << "( type ) [^] statement - the result of a statement is casted, type is given by value (CastedStatement)" << std::endl; + std::cout << "{ :type ( statement ) * } - creates a set of type given by arg value with content values from individual statements" << std::endl; std::cout << "" << std::endl; std::cout << "#identifier - an immediate value from an environment (ValueStatement)" << std::endl; std::cout << "$identifier - a value from a variable, identifier is an immediate value (VariableStatement)" << std::endl; std::cout << "$#identifier - a value from a variable, identified by an environment variable (VariableStatement)" << std::endl; std::cout << "" << std::endl; - std::cout << "<identifier - a value from a xml file, identifier is immediate value (FileStatement)" << std::endl; - std::cout << "<#identifier - a value from a xml file, identified by an environment variable (FileStatement)" << std::endl; + std::cout << "< [:type] arg - a value from a xml file, identifier is given by arg value, type of the value can be hinted with optional parameter (FileStatement)" << std::endl; std::cout << "" << std::endl; std::cout << "output_spec:" << std::endl; - std::cout << ">identifier - a value to a xml file, identifier is an immediate value (ResultFileStatement)" << std::endl; - std::cout << ">#identifier - a value to a xml file, identified by an environment variable (ResultFileStatement)" << std::endl; - std::cout << ">$identifier - a value to a variable, identifier is an immediate value (ResultVariableStatement)" << std::endl; - std::cout << ">$#identifier - a value to a variable, identified by an environment variable (ResultVariableStatement)" << std::endl; - std::cout << "> - a value is discarded" << std::endl; - std::cout << " - an empty output specifier prints the result to the stdout (ResultPrintStatement)" << std::endl; + std::cout << ">arg - a value to a xml file, identifier is given by arg value (ResultFileStatement)" << std::endl; + std::cout << ">$arg - a value to a variable, identifier is given by arg value (ResultVariableStatement)" << std::endl; + std::cout << "> - a value is discarded" << std::endl; + std::cout << " - an empty output specifier prints the result to the stdout (ResultPrintStatement)" << std::endl; } else if ( command == "" ) { std::cout << "Simple help for the query language" << std::endl; std::cout << "" << std::endl; diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp index b153b061ca57e32a20426650de21568e77f02269..e2be02264aa300b8e2b89169da7caa9976b6b2f0 100644 --- a/alib2cli/src/parser/Parser.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -32,17 +32,14 @@ #include <command/CastsIntrospectionCommand.h> #include <command/SetCommand.h> -#include <ast/options/HL3Option.h> -#include <ast/options/TypeOption.h> -#include <ast/options/CategoryOption.h> - #include <primitive/Integer.h> #include <primitive/String.h> namespace cli { -std::unique_ptr < Option > Parser::category_option ( ) { - if ( check_nonreserved_kw ( "default", "test", "efficient", "student" ) ) { +std::unique_ptr < CategoryOption > Parser::category_option ( ) { + if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { + match ( cli::Lexer::TokenType::COLON_SIGN ); std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < CategoryOption > ( value ); @@ -51,9 +48,9 @@ std::unique_ptr < Option > Parser::category_option ( ) { } } -std::unique_ptr < Option > Parser::type_option ( ) { - if ( check_nonreserved_kw ( "type" ) ) { - match_nonreserved_kw ( "type" ); +std::unique_ptr < TypeOption > Parser::type_option ( ) { + if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { + match ( cli::Lexer::TokenType::COLON_SIGN ); std::string value = getTokenValue ( ); match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < TypeOption > ( std::move ( value ) ); @@ -62,15 +59,6 @@ std::unique_ptr < Option > Parser::type_option ( ) { } } -std::unique_ptr < Option > Parser::option ( ) { - if ( check_nonreserved_kw ( "hl3" ) ) { - match_nonreserved_kw ( "hl3" ); - return std::make_unique < HL3Option > ( ); - } else { - return nullptr; - } -} - std::unique_ptr < Arg > Parser::arg ( ) { if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) { match ( cli::Lexer::TokenType::HASH_SIGN ); @@ -185,34 +173,15 @@ std::unique_ptr < Param > Parser::value_param ( ) { std::shared_ptr < Statement > Parser::in_redirect_statement ( ) { if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) { match ( cli::Lexer::TokenType::LEFT_BRACE ); - ext::vector < std::unique_ptr < Option > > options; - while ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { - match ( cli::Lexer::TokenType::COLON_SIGN ); - std::unique_ptr < Option > res = type_option ( ); - if ( ! res ) - res = option ( ); - if ( ! res ) - throw exception::CommonException ( "Option not recognised" ); - options.emplace_back ( std::move ( res ) ); - } - + std::unique_ptr < TypeOption > type = type_option ( ); match ( cli::Lexer::TokenType::RIGHT_BRACE ); std::unique_ptr < Arg > file = arg ( ); - return std::make_shared < ContainerFileStatement > ( "Set", std::move ( options ), std::move ( file ) ); + return std::make_shared < ContainerFileStatement > ( "Set", std::move ( type ), std::move ( file ) ); } else { ext::vector < std::unique_ptr < Option > > options; - while ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { - match ( cli::Lexer::TokenType::COLON_SIGN ); - std::unique_ptr < Option > res = type_option ( ); - if ( ! res ) - res = option ( ); - if ( ! res ) - throw exception::CommonException ( "Option not recognised" ); - options.emplace_back ( std::move ( res ) ); - } - + std::unique_ptr < TypeOption > type = type_option ( ); std::unique_ptr < Arg > file = arg ( ); - return std::make_shared < FileStatement > ( std::move ( options ), std::move ( file ) ); + return std::make_shared < FileStatement > ( std::move ( type ), std::move ( file ) ); } } @@ -233,41 +202,23 @@ std::shared_ptr < Statement > Parser::single_statement ( ) { return std::make_shared < CastStatement > ( std::move ( type ), casted_statement, move ); } else if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) { std::unique_ptr < Arg > name = std::make_unique < ImmediateArg > ( matchIdentifier ( ) ); - ext::vector < std::unique_ptr < Option > > options; - while ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { - match ( cli::Lexer::TokenType::COLON_SIGN ); - std::unique_ptr < Option > res = category_option ( ); - if ( ! res ) - res = option ( ); - if ( ! res ) - throw exception::CommonException ( "Option not recognised" ); - options.emplace_back ( std::move ( res ) ); - } + std::unique_ptr < CategoryOption > category = category_option ( ); ext::vector < std::unique_ptr < Param > > params; while ( ! check ( cli::Lexer::TokenType::OUT_REDIRECT ) && ! check ( cli::Lexer::TokenType::PIPE_SIGN ) && ! check ( cli::Lexer::TokenType::END ) && ! check ( cli::Lexer::TokenType::RIGHT_PAREN ) ) { params.emplace_back ( param ( ) ); } - return std::make_shared < SingleStatement > ( std::move ( name ), std::move ( params ), std::move ( options ) ); + return std::make_shared < SingleStatement > ( std::move ( name ), std::move ( params ), std::move ( category ) ); } else if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) { match ( cli::Lexer::TokenType::LEFT_BRACE ); - ext::vector < std::unique_ptr < Option > > options; - while ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) { - match ( cli::Lexer::TokenType::COLON_SIGN ); - std::unique_ptr < Option > res = type_option ( ); - if ( ! res ) - res = option ( ); - if ( ! res ) - throw exception::CommonException ( "Option not recognised" ); - options.emplace_back ( std::move ( res ) ); - } + std::unique_ptr < TypeOption > type = type_option ( ); ext::vector < std::unique_ptr < Param > > params; while ( ! check ( cli::Lexer::TokenType::RIGHT_BRACE ) ) { params.emplace_back ( param ( ) ); } - std::shared_ptr < Statement > res = std::make_shared < ContainerStatement > ( "Set", std::move ( params ), std::move ( options ) ); + std::shared_ptr < Statement > res = std::make_shared < ContainerStatement > ( "Set", std::move ( params ), std::move ( type ) ); match ( cli::Lexer::TokenType::RIGHT_BRACE ); return res; } else if ( check ( cli::Lexer::TokenType::HASH_SIGN ) ) { diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h index 4057552d7d2adc7df67d8400759ff18b5eb491d8..483ea520a035a3544286db8204345ee6e25fc2ff 100644 --- a/alib2cli/src/parser/Parser.h +++ b/alib2cli/src/parser/Parser.h @@ -6,6 +6,9 @@ #include <ast/Option.h> #include <ast/Arg.h> +#include <ast/options/TypeOption.h> +#include <ast/options/CategoryOption.h> + #include <command/Command.h> #include <ast/statements/StatementList.h> @@ -80,9 +83,8 @@ public: return m_current.m_value; } - std::unique_ptr < Option > category_option ( ); - std::unique_ptr < Option > type_option ( ); - std::unique_ptr < Option > option ( ); + std::unique_ptr < CategoryOption > category_option ( ); + std::unique_ptr < TypeOption > type_option ( ); std::unique_ptr < Arg > arg ( ); diff --git a/alib2cli/test-src/cli/CliTest.cpp b/alib2cli/test-src/cli/CliTest.cpp index 7aac73590953182538740527cceee1595a283656..dad46d5e42c13fae5f0bab07a564a4fd07fc95c6 100644 --- a/alib2cli/test-src/cli/CliTest.cpp +++ b/alib2cli/test-src/cli/CliTest.cpp @@ -96,7 +96,7 @@ void CliTest::testCreateUnique ( ) { parser = cli::Parser ( cli::Lexer ( "execute One | Add <( Add (int) <#2 <(One) ) - | Neg (double) - | Divide (double) - <(One | (double) Add <(One) - )" ) ); parser.parse ( )->run ( environment ); - parser = cli::Parser ( cli::Lexer ( "execute <:type int #2" ) ); + parser = cli::Parser ( cli::Lexer ( "execute <:int #2" ) ); parser.parse ( )->run ( environment ); parser = cli::Parser ( cli::Lexer ( "execute One > $res" ) ); @@ -255,7 +255,7 @@ void CliTest::testSetConstruction ( ) { abstraction::AlgorithmRegistry::registerAlgorithm < Print > ( Print::print, abstraction::AlgorithmCategories::AlgorithmCategory::DEFAULT, false, false, std::array < std::string, 1 > ( ) ); cli::Environment environment; - cli::Parser parser ( cli::Lexer ( "execute { :type int 1 2 3 } > $set" ) ); + cli::Parser parser ( cli::Lexer ( "execute { :int 1 2 3 } > $set" ) ); parser.parse ( )->run ( environment ); std::cout << environment.getVariable ( "set" )->getReturnType ( ) << std::endl; parser = cli::Parser ( cli::Lexer ( "execute $set | Print -" ) ); @@ -264,7 +264,7 @@ void CliTest::testSetConstruction ( ) { parser = cli::Parser ( cli::Lexer ( "execute $set >local/yyy.xml" ) ); parser.parse ( )->run ( environment ); - parser = cli::Parser ( cli::Lexer ( "execute <{ :type int }local/yyy.xml > $set2" ) ); + parser = cli::Parser ( cli::Lexer ( "execute <{ :int }local/yyy.xml > $set2" ) ); parser.parse ( )->run ( environment ); std::cout << environment.getVariable ( "set2" )->getReturnType ( ) << std::endl; parser = cli::Parser ( cli::Lexer ( "execute $set2 | Print -" ) );