diff options
author | David Robillard <d@drobilla.net> | 2009-03-07 03:25:15 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-07 03:25:15 +0000 |
commit | 59e358c5edd79d7dcafcef95a978fb36959d1da6 (patch) | |
tree | 37ddd9ad52afe99cbe0a64f3f865517ef19e9979 /tuplr.cpp | |
parent | 240b9f437bf87e98ca2c4ad8f242e86fca7f24e5 (diff) | |
download | resp-59e358c5edd79d7dcafcef95a978fb36959d1da6.tar.gz resp-59e358c5edd79d7dcafcef95a978fb36959d1da6.tar.bz2 resp-59e358c5edd79d7dcafcef95a978fb36959d1da6.zip |
Block comments.
Wrap up cursor moving logic into a separate function so it's less crufty.
git-svn-id: http://svn.drobilla.net/resp/tuplr@71 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.cpp')
-rw-r--r-- | tuplr.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -36,30 +36,38 @@ std::ostream& out = std::cout; * S-Expression Lexer :: text -> S-Expressions (SExp) * ***************************************************************************/ +inline int +readChar(Cursor& cur, istream& in) +{ + int ch = in.get(); + switch (ch) { + case '\n': ++cur.line; cur.col = 0; break; + default: ++cur.col; + } + return ch; +} + SExp -readExpression(Cursor& cur, std::istream& in) +readExpression(Cursor& cur, istream& in) { #define PUSH(s, t) { if (t != "") { s.top().list.push_back(SExp(loc, t)); t = ""; } } #define YIELD(s, t) { if (s.empty()) { return SExp(loc, t); } else PUSH(s, t) } stack<SExp> stk; string tok; Cursor loc; // start of tok - while (char ch = in.get()) { - ++cur.col; - switch (ch) { + while (int c = readChar(cur, in)) { + switch (c) { case EOF: if (!stk.empty()) throw Error("unexpected end of file", cur); return SExp(cur); case ';': - while ((ch = in.get()) != '\n') {} - case '\n': - ++cur.line; cur.col = 0; - case ' ': case '\t': + while ((c = readChar(cur, in)) != '\n') {} + case '\n': case ' ': case '\t': if (tok != "") YIELD(stk, tok); break; case '"': loc = cur; - do { tok.push_back(ch); ++cur.col; } while ((ch = in.get()) != '"'); + do { tok.push_back(c); } while ((c = readChar(cur, in)) != '"'); YIELD(stk, tok + '"'); break; case '(': @@ -79,9 +87,14 @@ readExpression(Cursor& cur, std::istream& in) stk.top().list.push_back(l); } break; + case '#': + if (in.peek() == '|') { + while (!(readChar(cur, in) == '|' && readChar(cur, in) == '#')) {} + break; + } default: if (tok == "") loc = cur; - tok += ch; + tok += c; } } switch (stk.size()) { |