39 return d_get_number_of_children(
node);
55 return std::string(
node->start_loc.s,
node->end -
node->start_loc.s);
62 std::stringstream result;
72 return node->start_loc.col;
77 return node->start_loc.line;
82 return std::string(
node->start_loc.pathname);
96 std::stringstream result;
99 result <<
'"' << node.
string() <<
'"';
120 std::ostringstream out;
121 out <<
"parser_table::symbol_name: index " << i <<
" out of bounds!";
122 throw std::runtime_error(out.str());
124 const char* name =
m_table.symbols[i].name;
129 return std::string(name);
140 return m_table.symbols[i].start_symbol;
146 return m_table.symbols[i].kind == D_SYMBOL_NTERM;
164 std::clog <<
"--------------------" << std::endl;
165 std::clog <<
"- symbol table -" << std::endl;
166 std::clog <<
"--------------------" << std::endl;
169 std::clog << std::setw(3) << i <<
" " <<
symbol_name(i) << std::endl;
171 std::clog <<
"--------------------" << std::endl;
178 m_parser = new_D_Parser(&tables, 0);
182 m_parser->dont_use_greediness_for_disambiguation = 1;
183 m_parser->dont_use_height_for_disambiguation = 1;
186 m_parser->ambiguity_fn = ambiguity_fn;
190 m_parser->syntax_error_fn = syntax_error_fn;
213 m_parser->partial_parses = partial_parses ? 1 : 0;
214 D_ParseNode* result = dparse(
m_parser,
const_cast<char*
>(text.c_str()),
static_cast<int>(text.size()));
215 if (!result ||
m_parser->syntax_errors)
217 if (result !=
nullptr) {
232 return std::string(count,
' ');
237 std::string result = s.substr(0, max_size);
240 std::string::size_type pos = result.find(
'\n');
241 if (pos != std::string::npos)
243 result = result.substr(0, pos);
254 std::string prefix =
indent(2 * level);
255 std::cout << prefix <<
"--- " << symbol <<
" \"" <<
truncate(node.
string()) <<
"\"" << std::endl;
277std::string
add_context(
const d_loc_t* loc,
const std::string& message)
280 s <<
"Line " << loc->line <<
", column " << loc->col <<
": "
281 << message << std::endl;
282 char* beg = loc->s - loc->col;
284 while (*end !=
'\0' && *end !=
'\n' && *end !=
'\r')
288 std::string line(beg, end);
289 s <<
" " << line << std::endl;
290 for (
int i = 0; i < loc->col + 2; ++i)
301 for (
int i = 0; i < n; i++)
316 for (
int i = 0; i < n; ++i)
332D_ParseNode*
ambiguity_fn(
struct D_Parser * ,
int n,
struct D_ParseNode **v)
339 D_ParseNode* result =
nullptr;
340 for (
int i = 0; i < n; i++)
363 D_ParseNode* result =
nullptr;
364 for (
int i = 0; i < n; i++)
390 D_ParseNode* result =
nullptr;
391 for (
int i = 0; i < n; i++)
417 for (
int i = 0; i < n; i++)
430 for (
int i = 0; i < n; ++i)
444 SNode *s = ((Parser*)ap)->snode_hash.last_all;
445 ZNode *z = s !=
nullptr ? s->zns.v[0] :
nullptr;
446 while (z !=
nullptr && z->pn->parse_node.start_loc.s == z->pn->parse_node.end)
448 z = (z->sns.v && z->sns.v[0]->zns.v) ? z->sns.v[0]->zns.v[0] :
nullptr;
450 if (z && z->pn->parse_node.start_loc.s != z->pn->parse_node.end)
452 after = std::string(z->pn->parse_node.start_loc.s, z->pn->parse_node.end);
455 std::string message =
"syntax error";
458 message = message +
" after '" + after +
"'";
471 if (ap->loc.s ==
nullptr)
478 Parser* p = (Parser*)ap;
479 if (p->pnode_hash.all && p->pnode_hash.all->latest)
482 D_Symbol &s = p->t->symbols[n.
symbol()];
483 if (s.kind == D_SYMBOL_INTERNAL)
486 int parentsym = n.
symbol() - 1;
487 while (p->t->symbols[parentsym].kind == D_SYMBOL_INTERNAL)
489 s = p->t->symbols[parentsym];
494 case D_SYMBOL_STRING:
499 << (std::isalpha(n.
string()[0], loc) ?
"keyword " :
"")
500 <<
"'" << n.
string() <<
"'" << std::endl;
Standard exception class for reporting runtime errors.
D_ParserTables parser_tables_mcrl2
D_ParserTables parser_tables_mcrl2
struct D_ParseNode *(* D_AmbiguityFn)(struct D_Parser *, int n, struct D_ParseNode **v)
void(* D_SyntaxErrorFn)(struct D_Parser *)
add your file description here.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
std::string add_context(const d_loc_t *loc, const std::string &message)
static void log_location(struct D_Parser *ap)
void syntax_error_fn(struct D_Parser *ap)
Custom syntax error function that prints both the line number and the column.
bool is_all_of_type(D_ParseNode *nodes[], int n, const char *type, const core::parser_table &table)
void increment_dparser_error_message_count()
void set_dparser_max_error_message_count(std::size_t n)
struct D_ParseNode * ambiguity_fn(struct D_Parser *, int, struct D_ParseNode **)
Function for resolving ambiguities in the '_ -> _ <> _' operator for process expressions.
void print_chosen_node(D_ParseNode *node, const core::parser_table &table)
void reset_dparser_error_message_count()
std::size_t get_dparser_max_error_message_count()
void print_ambiguous_nodes(D_ParseNode *nodes[], int n, const char *type, const core::parser_table &table)
std::size_t get_dparser_error_message_count()
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
parse_node child(int i) const
std::string pathname() const
parse_node find_in_tree(int symbol) const
std::string add_context(const std::string &message) const
std::string string() const
Wrapper for D_ParserTables.
std::string symbol_name(unsigned int i) const
std::string tree(const core::parse_node &node) const
bool is_term_symbol(unsigned int i) const
int start_symbol(unsigned int i) const
unsigned int start_symbol_index(const std::string &name) const
unsigned int symbol_count() const
Wrapper for D_Parser and its corresponding D_ParserTables.
parse_node parse(const std::string &text, unsigned int start_symbol_index=0, bool partial_parses=false)
Parses a string. N.B. The user is responsible for destruction of the returned value by calling destro...
const parser_table & symbol_table() const
void announce(D_ParseNode &node_ref)
Callback function for nodes in the parse tree.
parser(D_ParserTables &tables, D_AmbiguityFn ambiguity_fn=nullptr, D_SyntaxErrorFn syntax_error_fn=nullptr, std::size_t max_error_message_count=1)
void custom_parse_error(const std::string &message) const
void print_symbol_table() const
std::string indent(unsigned int count) const
std::string truncate(const std::string &s, unsigned int max_size=20) const
void print_tree(const parse_node &node, unsigned int level=0) const
unsigned int start_symbol_index(const std::string &name) const
void destroy_parse_node(const parse_node &node)