diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-03 14:59:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-03 14:59:53 -0500 |
| commit | add95b14f74e6dbe04a6efe98ff0f20424930b73 (patch) | |
| tree | 13ce413ee4190a4c8f8743c7740aaa8d04353f14 /willow/tools/willowc/include/parser.hpp | |
| parent | c5b2905c5a64433f8519531a77d3acc42d881f17 (diff) | |
| download | compiler-dev/stefan.tar.gz | |
[willow]: initial frontend work, unit tests (#8)dev/stefan
Diffstat (limited to 'willow/tools/willowc/include/parser.hpp')
| -rw-r--r-- | willow/tools/willowc/include/parser.hpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/willow/tools/willowc/include/parser.hpp b/willow/tools/willowc/include/parser.hpp new file mode 100644 index 0000000..825dfdd --- /dev/null +++ b/willow/tools/willowc/include/parser.hpp @@ -0,0 +1,33 @@ +#ifndef WILLOWC_INCLUDE_PARSER_HPP +#define WILLOWC_INCLUDE_PARSER_HPP + +#include <tokenizer.hpp> +#include <ast.hpp> + +#include <optional> +#include <memory> +#include <vector> + +namespace willowc { + +class Parser { + std::string_view buf; + + std::vector<TokenKind> kinds; + std::vector<std::size_t> starts; + Tokenizer tokenizer; + + std::size_t pos; + +public: + Parser(std::string_view buf) : buf(buf), tokenizer(buf) {} + + std::optional<std::unique_ptr<ModuleAST>> parse(); + + TokenKind kind() const { return kinds[pos]; } + std::size_t start() const { return starts[pos]; } +}; + +} // namespace willowc + +#endif // WILLOWC_INCLUDE_PARSER_HPP |