17 return std::move(
ParseHelper(filename,
"",
true).result);
24 return std::move(
ParseHelper(filename, file).result);
32 return std::move(
ParseHelper(filename, data,
false).result);
41 ParseHelper::ParseHelper(
42 const std::string &filename,
43 const std::string &data,
45 ) : filename(filename) {
48 if (!construct())
return;
52 fptr = fopen(filename.c_str(),
"r");
54 std::ostringstream sb;
55 sb <<
"Failed to open input file " << filename <<
": " 74 ParseHelper::ParseHelper(
75 const std::string &filename,
77 ) : filename(filename) {
80 if (!construct())
return;
93 bool ParseHelper::construct() {
96 std::ostringstream sb;
97 sb <<
"Failed to construct scanner: " << strerror(retcode);
108 void ParseHelper::parse() {
111 std::ostringstream sb;
112 sb <<
"Out of memory while parsing " <<
filename;
115 }
else if (retcode) {
116 std::ostringstream sb;
117 sb <<
"Failed to parse " <<
filename;
123 throw std::runtime_error(
"internal error: no parse errors returned, but AST is incomplete. AST was dumped.");
Parser, generated by Bison.
void * buf
Flex data buffer, if data was specified.
int cqasm_v1lex_destroy(yyscan_t yyscanner)
void push_error(const std::string &error)
Pushes an error.
Toplevel namespace with entry points for the new API.
YY_BUFFER_STATE cqasm_v1_scan_string(yyconst char *yy_str, yyscan_t yyscanner)
Setup the input buffer state to scan a string.
virtual ~ParseHelper()
Destroys the parse helper.
std::vector< std::string > errors
List of accumulated errors.
Internal helper class for parsing cQASM files.
Contains helper classes and objects for the lexer and parser generated by flex/bison, as well as the entry points for invoking the parser directly, in case you don't need semantic analysis.
void cqasm_v1set_in(FILE *_in_str, yyscan_t yyscanner)
Set the input stream.
Namespace for the "new" cQASM 1.x API.
void cqasm_v1_delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner)
Destroy the buffer.
ast::One< ast::Root > root
Root node of the AST, if analysis was sufficiently successful.
std::string filename
Name of the file being parsed.
ParseResult result
The parse result.
Parse result information.
void * scanner
Flex reentrant scanner data.
ParseResult parse_string(const std::string &data, const std::string &filename)
Parse the given string.
int cqasm_v1lex_init(yyscan_t *scanner)
ParseResult parse_file(const std::string &filename)
Parse the given file.
int cqasm_v1parse(yyscan_t scanner, cqasm::v1::parser::ParseHelper &helper)