diff options
author | dos-reis <gdr@axiomatics.org> | 2014-11-29 19:21:28 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2014-11-29 19:21:28 +0000 |
commit | 11fd57def249cbc6f4aee8dfaac5e7f346f483c0 (patch) | |
tree | 7185e026223f007c21ee41f22959250f38d6ce53 /src/boot | |
parent | e9d8e2490f4dff922c0d86f29f31227655cc0633 (diff) | |
download | open-axiom-11fd57def249cbc6f4aee8dfaac5e7f346f483c0.tar.gz |
Move code from bemol.cc to library.
Diffstat (limited to 'src/boot')
-rw-r--r-- | src/boot/bemol.cc | 60 |
1 files changed, 10 insertions, 50 deletions
diff --git a/src/boot/bemol.cc b/src/boot/bemol.cc index 34870e13..b36b174d 100644 --- a/src/boot/bemol.cc +++ b/src/boot/bemol.cc @@ -35,7 +35,7 @@ // --% Description: #include <open-axiom/diagnostics> -#include <open-axiom/token> +#include <open-axiom/InputFragment> #include <iostream> #include <fstream> #include <vector> @@ -50,59 +50,11 @@ using namespace OpenAxiom; // -- Reading input source files -- // -// A physical line is just raw text, with coupled with location -// information such as line and indentation column. -struct Line : std::string { - LineNumber number; - ColumnIndex indent; - Line() : number(), indent() { } - - std::string sub_string(ColumnIndex s, ColumnIndex e) const { - return substr(s, e - s); - } -}; - -// A program fragment is a logical line, composed of possibly -// several physical lines subject to the off-side rule. As a -// special case, a line ending with the underbar character -// continues to the next next with disregard to the off-side rule. -struct Fragment : std::vector<Line> { - explicit operator bool() const { return not empty(); } - bool line_continuation() const { - return not empty() and back().back() == '_'; - } - ColumnIndex last_indent() const { - return empty() ? 0 : back().indent; - } - using std::vector<Line>::operator[]; - const Line& operator()(const OpenAxiom::FragmentCursor& pos) const { - return (*this)[pos.line]; - } - uint8_t operator[](const OpenAxiom::FragmentCursor& pos) const { - return (*this)[pos.line][pos.column]; - } - uint8_t advance(OpenAxiom::FragmentCursor& pos) const { - return (*this)[pos.line][pos.column++]; - } - - bool covering(const OpenAxiom::FragmentCursor& pos) const { - return pos.column < (*this)[pos.line].size(); - } -}; - -// Formatting program fragments. -static std::ostream& -operator<<(std::ostream& os, const Fragment& f) { - std::copy(f.begin(), f.end(), - std::ostream_iterator<std::string>(std::cout, "\n")); - return os; -} - - // A source input transform a character stream into a program fragment // stream, delivering a fragment one at a time. struct SourceInput { SourceInput(std::istream& is) : input(is) { } + // Return the next program fragment from this input source. Fragment get(); private: @@ -235,6 +187,14 @@ using TokenSequence = OpenAxiom::TokenStream<BemolToken>; // -- +namespace { + struct Parser { + TokenSequence* tokens; + }; +} + +// -- + static void translate_source_file(SourceInput& src, std::ostream& out, const char* path) { while (auto f = src.get()) { |