libqasm
library for handling cQASM files
cqasm-v1-parse-helper.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include "cqasm-annotations.hpp"
10 #include "cqasm-v1-ast.hpp"
11 #include <cstdio>
12 
13 namespace cqasm {
14 namespace v1 {
15 
19 namespace parser {
20 
21 // SourceLocation used to live in this namespace, before the v1/v2 namespaces
22 // were a thing. Make sure it exists here for compatibility.
24 
28 class ParseResult {
29 public:
30 
37 
42  std::vector<std::string> errors;
43 
44 };
45 
49 ParseResult parse_file(const std::string &filename);
50 
54 ParseResult parse_file(FILE *file, const std::string &filename = "<unknown>");
55 
60 ParseResult parse_string(const std::string &data, const std::string &filename="<unknown>");
61 
65 class ParseHelper {
66 public:
67 
71  FILE *fptr = nullptr;
72 
76  void *buf = nullptr;
77 
81  void *scanner = nullptr;
82 
86  std::string filename;
87 
92 
93 private:
94  friend ParseResult parse_file(const std::string &filename);
95  friend ParseResult parse_file(FILE *file, const std::string &filename);
96  friend ParseResult parse_string(const std::string &data, const std::string &filename);
97 
104  ParseHelper(const std::string &filename, const std::string &data, bool use_file);
105 
110  ParseHelper(const std::string &filename, FILE *fptr);
111 
115  bool construct();
116 
120  void parse();
121 
122 public:
123 
127  virtual ~ParseHelper();
128 
132  void push_error(const std::string &error);
133 
134 };
135 
136 } // namespace parser
137 } // namespace v1
138 } // namespace cqasm
Defines the types for the cQASM abstract syntax tree, based on the classes from cqasm::tree.
Contains annotation objects used within the trees by libqasm.
Toplevel namespace with entry points for the new API.
Source location annotation object, containing source file line numbers etc.
std::vector< std::string > errors
List of accumulated errors.
Internal helper class for parsing cQASM files.
cqasm::tree::One< T > One
Namespace for the "new" cQASM 1.x API.
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.
ParseResult parse_string(const std::string &data, const std::string &filename)
Parse the given string.
ParseResult parse_file(const std::string &filename)
Parse the given file.
annotations::SourceLocation SourceLocation