7 #warning "This file should not be included directly"
11 #include "diagnostics/Diagnostics.h"
12 #include "diagnostics/Location.h"
13 #include "diagnostics/SourceManager.h"
14 #include "joos1w.parser.tab.h"
15 #include "parsetree/ParseTree.h"
16 #include "utils/BumpAllocator.h"
20 class Joos1WLexer :
public yyFlexLexer {
21 using Node = parsetree::
Node;
22 using Operator = parsetree::
Operator;
23 using Literal = parsetree::
Literal;
25 using Modifier = parsetree::
Modifier;
27 friend class Joos1WParser;
32 : file{file}, yycolumn{1}, diag{diag}, alloc{alloc}, messages{alloc} {}
38 int bison_lex(YYSTYPE* lvalp, YYLTYPE* llocp);
43 template <
typename... Args>
44 Node* make_node(YYLTYPE& loc, Node::Type type, Args&&... args) {
45 void* bytes = alloc.allocate_bytes(
sizeof(Node));
47 Node(make_range(loc), alloc, type, std::forward<Args>(args)...);
52 Node* make_leaf(YYLTYPE& loc, Node::Type type) {
53 void* bytes = alloc.allocate_bytes(
sizeof(Node));
54 return new(bytes) Node
(make_range(loc)
, type
);
57 Node* make_poison(YYLTYPE& loc);
59 Node* make_operator(YYLTYPE& loc, Operator::Type type);
61 Node* make_literal(YYLTYPE& loc, Literal::Type type,
char const* value);
63 Node* make_identifier(YYLTYPE& loc,
char const* name);
65 Node* make_modifier(YYLTYPE& loc, Modifier::Type type);
67 Node* make_basic_type(YYLTYPE& loc, BasicType::Type type);
73 inline void report_parser_error(YYLTYPE& loc,
char const* msg,
74 std::initializer_list<YYLTYPE> ranges = {}) {
76 auto os = diag->ReportError(make_range(loc));
78 size_t length = std::min(1024UL, strlen(msg) + 1);
79 char* ptr =
reinterpret_cast<
char*>(alloc.allocate(length));
80 strncpy(ptr, msg, length);
81 messages.push_back(ptr);
82 os << std::string_view{ptr};
83 for(
auto const& range : ranges) os << make_range(range);
103 BumpAllocator& alloc;
104 std::pmr::vector<
const char*> messages;