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

file reading syntax gradual change

parent 48e1dcac
No related branches found
No related tags found
No related merge requests found
......@@ -139,12 +139,12 @@ int main ( int argc, char * argv[] ) {
if ( collection.isSet ( )
&& ( operation.getValue ( ) == "set" || operation.getValue ( ) == "add" || operation.getValue ( ) == "remove" )
&& ( automatonInput.isSet ( ) || grammarInput.isSet ( ) || regexpInput.isSet ( ) || stringInput.isSet ( ) ) ) {
parser = cli::Parser ( cli::Lexer ( "execute < { :Object } #collection > $argument" ) );
parser = cli::Parser ( cli::Lexer ( "execute < :set @Object #collection > $argument" ) );
parser.parse ( )->run ( environment );
}
if ( collection.isSet ( )
&& ( operation.getValue ( ) == "add" || operation.getValue ( ) == "remove" ) && ( treeInput.isSet ( ) ) ) {
parser = cli::Parser ( cli::Lexer ( "execute < { :ranked_symbol } #collection > $argument" ) );
parser = cli::Parser ( cli::Lexer ( "execute < :set @ranked_symbol #collection > $argument" ) );
parser.parse ( )->run ( environment );
}
 
......
......@@ -163,7 +163,7 @@ int main ( int argc, char * argv[] ) {
input = nonlinearVariablesInput.getValue ( );
 
environment.setBinding ( "inputNonlinearVariables", input );
cli::Parser parser ( cli::Lexer ( "execute <{:ranked_symbol} #inputNonlinearVariables > $nonlinearVariables" ) );
cli::Parser parser ( cli::Lexer ( "execute <:set @ranked_symbol #inputNonlinearVariables > $nonlinearVariables" ) );
parser.parse ( )->run ( environment );
}
 
......
#include <ast/statements/ContainerFileStatement.h>
#include <ast/Statement.h>
#include <ast/Option.h>
#include <ast/Arg.h>
#include <registry/XmlRegistry.h>
#include <abstraction/ImmediateValueAbstraction.hpp>
namespace cli {
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 {
std::shared_ptr < abstraction::UnaryOperationAbstraction < ext::deque < sax::Token >, const std::string & > > tokens = abstraction::XmlRegistry::fileToTokensAbstraction ( m_file->eval ( environment ));
tokens->eval ( );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::XmlRegistry::getXmlContainerParserAbstraction ( m_container, m_type->getType ( ) );
res->attachInput ( tokens, 0, true );
res->eval ( );
return res;
}
} /* namespace cli */
#ifndef _CLI_CONTAINER_FILE_STATEMENT_H_
#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;
std::unique_ptr < TypeOption > m_type;
public:
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;
virtual bool getImplicitMove ( ) const override {
return true;
}
};
} /* namespace cli */
#endif /* _CLI_CONTAINER_FILE_STATEMENT_H_ */
......@@ -4,10 +4,11 @@
#include <ast/Arg.h>
 
#include <common/XmlParserHelper.h>
#include <registry/XmlRegistry.h>
 
namespace cli {
 
FileStatement::FileStatement ( std::unique_ptr < TypeOption > type, std::unique_ptr < Arg > file ) : m_file ( std::move ( file ) ), m_type ( std::move ( type ) ) {
FileStatement::FileStatement ( std::unique_ptr < Arg > file, std::unique_ptr < Arg > fileType, std::unique_ptr < TypeOption > type, ext::vector < std::unique_ptr < cli::Arg > > templateParams ) : m_file ( std::move ( file ) ), m_fileType ( std::move ( fileType ) ), m_type ( std::move ( type ) ), m_templateParams ( std::move ( templateParams ) ) {
}
 
std::shared_ptr < abstraction::OperationAbstraction > FileStatement::translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const {
......@@ -15,9 +16,20 @@ std::shared_ptr < abstraction::OperationAbstraction > FileStatement::translateAn
if ( m_type )
type = m_type->getType ( );
 
std::string file = m_file->eval ( environment );
if ( type == "set" || type == "Set" ) {
std::shared_ptr < abstraction::UnaryOperationAbstraction < ext::deque < sax::Token >, const std::string & > > tokens = abstraction::XmlRegistry::fileToTokensAbstraction ( m_file->eval ( environment ));
tokens->eval ( );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::XmlRegistry::getXmlContainerParserAbstraction ( "Set", m_templateParams [ 0 ]->eval ( environment ) );
res->attachInput ( tokens, 0, true );
res->eval ( );
return res;
} else {
std::string file = m_file->eval ( environment );
return abstraction::XmlParserHelper::eval ( std::move ( type ), file );
}
 
return abstraction::XmlParserHelper::eval ( std::move ( type ), file );
}
 
} /* namespace cli */
......@@ -8,10 +8,12 @@ namespace cli {
 
class FileStatement final : public Statement {
std::unique_ptr < cli::Arg > m_file;
std::unique_ptr < Arg > m_fileType;
std::unique_ptr < TypeOption > m_type;
ext::vector < std::unique_ptr < cli::Arg > > m_templateParams;
 
public:
FileStatement ( std::unique_ptr < TypeOption > type, std::unique_ptr < Arg > file );
FileStatement ( std::unique_ptr < Arg > file, std::unique_ptr < Arg > fileType, std::unique_ptr < TypeOption > type, ext::vector < std::unique_ptr < cli::Arg > > templateParams );
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override;
 
......
......@@ -9,9 +9,10 @@ namespace cli {
 
class ResultFileStatement final : public Statement {
std::unique_ptr < cli::Arg > m_file;
std::unique_ptr < Arg > m_fileType;
 
public:
ResultFileStatement ( std::unique_ptr < cli::Arg > file ) : m_file ( std::move ( file ) ) {
ResultFileStatement ( std::unique_ptr < cli::Arg > file, std::unique_ptr < Arg > fileType ) : m_file ( std::move ( file ) ), m_fileType ( std::move ( fileType ) ) {
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
......
......@@ -3,7 +3,6 @@
#include <ast/statements/CastStatement.h>
#include <ast/statements/SingleStatement.h>
#include <ast/statements/ContainerStatement.h>
#include <ast/statements/ContainerFileStatement.h>
#include <ast/statements/ResultFileStatement.h>
#include <ast/statements/ResultVariableStatement.h>
#include <ast/statements/ResultPrintStatement.h>
......@@ -94,18 +93,22 @@ std::unique_ptr < Arg > Parser::template_arg ( ) {
}
 
std::shared_ptr < Statement > Parser::in_redirect_file ( ) {
if ( check ( cli::Lexer::TokenType::LEFT_BRACE ) ) {
match ( cli::Lexer::TokenType::LEFT_BRACE );
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 ( type ), std::move ( file ) );
} else {
ext::vector < std::unique_ptr < Option > > options;
std::unique_ptr < TypeOption > type = type_option ( );
std::unique_ptr < Arg > file = arg ( );
return std::make_shared < FileStatement > ( std::move ( type ), std::move ( file ) );
std::unique_ptr < Arg > fileType;
if ( check ( cli::Lexer::TokenType::LEFT_BRACKET ) ) {
match ( cli::Lexer::TokenType::LEFT_BRACKET );
fileType = arg ( );
match ( cli::Lexer::TokenType::RIGHT_BRACKET );
}
std::unique_ptr < TypeOption > type = type_option ( );
ext::vector < std::unique_ptr < cli::Arg > > templateArgs;
while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) {
templateArgs.emplace_back ( template_arg ( ) );
}
std::unique_ptr < Arg > file = arg ( );
return std::make_shared < FileStatement > ( std::move ( file ), std::move ( fileType ), std::move ( type ), std::move ( templateArgs ) );
}
 
std::shared_ptr < Statement > Parser::in_redirect ( ) {
......@@ -221,14 +224,16 @@ std::shared_ptr < StatementList > Parser::statement_list ( ) {
}
 
void Parser::out_redirect_file ( std::shared_ptr < StatementList > & list ) {
std::unique_ptr < Arg > fileType;
if ( check ( cli::Lexer::TokenType::LEFT_BRACKET ) ) {
match ( cli::Lexer::TokenType::LEFT_BRACKET );
std::unique_ptr < Arg > name = arg ( );
fileType = arg ( );
match ( cli::Lexer::TokenType::RIGHT_BRACKET );
}
 
std::unique_ptr < Arg > file = arg ( );
list->append ( std::make_unique < ResultFileStatement > ( std::move ( file ) ) );
list->append ( std::make_unique < ResultFileStatement > ( std::move ( file ), std::move ( fileType ) ) );
}
 
void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) {
......
......@@ -262,7 +262,7 @@ void CliTest::testSetConstruction ( ) {
parser = cli::Parser ( cli::Lexer ( "execute $set >local/yyy.xml" ) );
parser.parse ( )->run ( environment );
 
parser = cli::Parser ( cli::Lexer ( "execute <{ :int }local/yyy.xml > $set2" ) );
parser = cli::Parser ( cli::Lexer ( "execute < :set @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 -" ) );
......
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