Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ScriptParser Class Reference

#include <ored/scripting/scriptparser.hpp>

+ Collaboration diagram for ScriptParser:

Public Member Functions

 ScriptParser (const std::string &script)
 
bool success () const
 
ASTNodePtr ast () const
 
const ParserErrorerror () const
 

Private Attributes

bool success_
 
ASTNodePtr ast_
 
ParserError parserError_
 

Detailed Description

Definition at line 47 of file scriptparser.hpp.

Constructor & Destructor Documentation

◆ ScriptParser()

ScriptParser ( const std::string &  script)

Definition at line 48 of file scriptparser.cpp.

48 {
49 ScriptGrammarIterator first(script.begin()), iter = first, last(script.end());
50 ScriptGrammar grammar(first);
51 success_ = qi::phrase_parse(iter, last, grammar, boost::spirit::qi::space);
52 if (!success_ || iter != last) {
53 success_ = false;
55 LocationInfo(boost::spirit::get_line(iter), boost::spirit::get_column(first, iter),
56 boost::spirit::get_line(iter), boost::spirit::get_column(first, iter));
57 parserError_.remainingInput = std::string(iter, last);
58 if (grammar.hasError) {
60 parserError_.expectedWhere = LocationInfo(
61 boost::spirit::get_line(grammar.errorPos), boost::spirit::get_column(first, grammar.errorPos),
62 boost::spirit::get_line(grammar.errorPos), boost::spirit::get_column(first, grammar.errorPos));
63 parserError_.scriptContext = std::string(grammar.errorBegin, grammar.errorEnd);
64 parserError_.errorPos = std::distance(grammar.errorBegin, grammar.errorPos);
65 auto currentLine = boost::spirit::get_current_line(grammar.errorBegin, grammar.errorPos, grammar.errorEnd);
66 parserError_.scriptCurrentLine = std::string(currentLine.begin(), currentLine.end());
67 }
68 } else {
69 QL_REQUIRE(grammar.evalStack.size() == 1,
70 "ScriptParser: unexpected eval stack size (" << grammar.evalStack.size() << "), should be 1");
71 ast_ = grammar.evalStack.top();
72 QL_REQUIRE(ast_, "ScriptParser: ast is null");
73 }
74}
std::string script
boost::spirit::line_pos_iterator< std::string::const_iterator > ScriptGrammarIterator
Definition: grammar.hpp:46
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
LocationInfo stoppedParsingAt
LocationInfo expectedWhere
std::string remainingInput
std::string scriptCurrentLine
+ Here is the call graph for this function:

Member Function Documentation

◆ success()

bool success ( ) const

Definition at line 51 of file scriptparser.hpp.

51{ return success_; }
+ Here is the caller graph for this function:

◆ ast()

ASTNodePtr ast ( ) const

Definition at line 53 of file scriptparser.hpp.

53{ return ast_; }
+ Here is the caller graph for this function:

◆ error()

const ParserError & error ( ) const

Definition at line 55 of file scriptparser.hpp.

55{ return parserError_; }
+ Here is the caller graph for this function:

Member Data Documentation

◆ success_

bool success_
private

Definition at line 58 of file scriptparser.hpp.

◆ ast_

ASTNodePtr ast_
private

Definition at line 59 of file scriptparser.hpp.

◆ parserError_

ParserError parserError_
private

Definition at line 60 of file scriptparser.hpp.