From e82d62219c661a2594286e0f867354864514bd87 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Sun, 15 Jan 2017 23:47:28 -0800 Subject: Use library parser for bemol. --- src/syntax/Parser.cxx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/syntax/Parser.cxx') diff --git a/src/syntax/Parser.cxx b/src/syntax/Parser.cxx index e8759d2b..d78d3157 100644 --- a/src/syntax/Parser.cxx +++ b/src/syntax/Parser.cxx @@ -49,6 +49,46 @@ namespace { using TokenSequence = TokenStream; + struct ParsingContext { + explicit ParsingContext(TokenSequence& ts) + : tokens{ ts }, position{ } + { } + + bool exhausted() const { + return position >= tokens.size(); + } + + const Token* current_token() const { + if (exhausted()) + return nullptr; + return &tokens[position]; + } + + void advance() { ++position; } + + private: + TokenSequence& tokens; + TokenSequence::size_type position; + }; + + const Token* next_token(ParsingContext& ctx) { + while (auto t = ctx.current_token()) { + switch (t->category) { + case TokenCategory::Whitespace: + break; + + case TokenCategory::Comment: + if (t->value == TokenValue::Wisecrack) + break; + + default: + return t; + } + ctx.advance(); + } + return nullptr; + } + // Simple wrapper around standard file streams, along with the pathname // to the file. template @@ -75,6 +115,9 @@ namespace { // FIXME: This is just a stub to get a native parsing entry point // into the bootsys and interpsys images. void transpile_boot_to_lisp(InputFile& in, OutputFile& out) { + out.stream << "## Input: " << in.path << '\n' + << "## Output: " << out.path << '\n'; + SourceInput src { in.stream }; while (auto f = src.get()) { out.stream << "================================================\n"; -- cgit v1.2.3