diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-11 13:57:42 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-11 13:57:42 +0200 |
commit | e6d92a1fb21232ab09886431d39ccb8a95c7c68d (patch) | |
tree | 0d543e1e3c1b22e88f22f02e2dae75ae9eba2db5 /build/bd.cxx | |
parent | fdc21950905d64b2ca1df5a0b2622022beffe922 (diff) |
Initial lexer implementation for buildfiles
Diffstat (limited to 'build/bd.cxx')
-rw-r--r-- | build/bd.cxx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/build/bd.cxx b/build/bd.cxx index c592d64..33ee02f 100644 --- a/build/bd.cxx +++ b/build/bd.cxx @@ -6,6 +6,7 @@ #include <vector> #include <cassert> +#include <fstream> #include <iostream> #include <typeinfo> #include <system_error> @@ -15,6 +16,9 @@ #include <build/process> #include <build/diagnostics> +#include <build/token> +#include <build/lexer> + using namespace std; namespace build @@ -132,6 +136,64 @@ main (int argc, char* argv[]) // tzset (); + // Parse buildfile. + // + path bf ("buildfile"); + + ifstream ifs (bf.string ().c_str ()); + if (!ifs.is_open ()) + { + cerr << "error: unable to open " << bf << " in read mode" << endl; + return 1; + } + + ifs.exceptions (ifstream::failbit | ifstream::badbit); + lexer l (ifs, bf.string ()); + + try + { + for (token t (l.next ());; t = l.next ()) + { + cout << t.line () << ':' << t.column () << ": "; + + switch (t.type ()) + { + case token_type::eos: cout << "<eos>"; break; + case token_type::punctuation: + { + switch (t.punctuation ()) + { + case token_punctuation::newline: cout << "\\n"; break; + case token_punctuation::colon: cout << ':'; break; + case token_punctuation::lcbrace: cout << '{'; break; + case token_punctuation::rcbrace: cout << '}'; break; + } + break; + } + case token_type::name: cout << '\'' << t.name () << '\''; break; + } + + cout << endl; + + if (t.type () == token_type::eos) + break; + } + } + catch (const lexer_error&) + { + return 1; // Diagnostics has already been issued. + } + catch (const std::ios_base::failure&) + { + cerr << "error: failed to read from " << bf << endl; + return 1; + } + + return 0; + + + // Register rules. + // cxx::link cxx_link; rules.emplace (typeid (exe), cxx_link); |