This repository was archived by the owner on Oct 12, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ add_library(frontend STATIC
1212 ${CMAKE_SOURCE_DIR } /src/frontend/token.cpp
1313 ${CMAKE_SOURCE_DIR } /src/frontend/lexer.cpp
1414 ${CMAKE_SOURCE_DIR } /src/frontend/ast.cpp
15+ ${CMAKE_SOURCE_DIR } /src/frontend/program.cpp
1516 ${CMAKE_SOURCE_DIR } /src/frontend/parser.cpp
1617)
1718
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ namespace frontend {
9898 friend std::ostream &operator <<(std::ostream &outputStream, const DefinitionAstNode &node);
9999 };
100100
101+ // NOTE: Owning and move-only, not copyable.
101102 struct AstNode {
102103 using NodeVariant = std::variant<Expression, DefinitionAstNode>;
103104
@@ -107,10 +108,4 @@ namespace frontend {
107108
108109 friend std::ostream &operator <<(std::ostream &outputStream, const AstNode &node);
109110 };
110-
111- struct Program {
112- std::vector<AstNode> nodes;
113-
114- friend std::ostream &operator <<(std::ostream &outputStream, const Program &program);
115- };
116111}
Original file line number Diff line number Diff line change 11#pragma once
22
33#include < string>
4+ #include < iostream>
45
56namespace frontend {
67 struct Location {
Original file line number Diff line number Diff line change 33#include < lbd/options.h>
44#include < lbd/frontend/ast.h>
55#include < lbd/frontend/token.h>
6+ #include < lbd/frontend/program.h>
67#include < lbd/interpreter/type.h>
78#include < vector>
89
910namespace frontend {
1011 struct Parser {
12+ // TODO: Make this private
1113 Program program;
1214
1315 explicit Parser (const std::vector<token::Token> &tokens, context::Options options_ = {});
@@ -22,7 +24,8 @@ namespace frontend {
2224
2325 static IdentifierAstNode consumeIdentifier (const std::vector<token::Token> &tokens, size_t &index);
2426
25- static interpreter::type::PrimitiveType consumePrimitiveTypeName (const std::vector<token::Token> &tokens, size_t &index);
27+ static interpreter::type::PrimitiveType consumePrimitiveTypeName (
28+ const std::vector<token::Token> &tokens, size_t &index);
2629
2730 static interpreter::type::Type parseType (const std::vector<token::Token> &tokens, size_t &index);
2831
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < lbd/frontend/ast.h>
4+ #include < vector>
5+
6+ namespace frontend {
7+ struct Program {
8+ std::vector<AstNode> astNodes;
9+
10+ friend std::ostream &operator <<(std::ostream &outputStream, const Program &program);
11+ };
12+ }
Original file line number Diff line number Diff line change 22
33#include < optional>
44#include < lbd/frontend/location.h>
5- #include < lbd/utils/term .h>
5+ #include < lbd/utils/terminal .h>
66#include < lbd/exceptions.h>
77
88namespace logs {
Original file line number Diff line number Diff line change 11#pragma once
22
3- #include " logs.h"
3+ #include < lbd/ logs.h>
44
55namespace context {
66 struct Options {
File renamed without changes.
Original file line number Diff line number Diff line change @@ -109,11 +109,4 @@ namespace frontend {
109109 node.print (outputStream, 0 );
110110 return outputStream;
111111 }
112-
113- std::ostream &operator <<(std::ostream &outputStream, const Program &program) {
114- for (const AstNode &node: program.nodes ) {
115- outputStream << node;
116- }
117- return outputStream;
118- }
119112}
Original file line number Diff line number Diff line change @@ -159,8 +159,8 @@ namespace frontend {
159159 optionsValue.logger .debug (token);
160160 }
161161 }
162- for (Parser parser (tokens, optionsValue); auto &node : parser.program .nodes ) {
163- nodes.emplace_back (std::move (node ));
162+ for (Parser parser (tokens, optionsValue); auto &astNode : parser.program .astNodes ) {
163+ nodes.emplace_back (std::move (astNode ));
164164 }
165165 }
166166
You can’t perform that action at this time.
0 commit comments