diff options
author | David Robillard <d@drobilla.net> | 2010-12-05 01:45:37 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-05 01:45:37 +0000 |
commit | 19ec222ce04979ccd4125ecb6c95a86302ba937c (patch) | |
tree | e89be99e27f774e405e8ed7dd1058b9a837cf53f /src/parse.cpp | |
parent | 931652d4f065c06d9061166c961ff9af6750267e (diff) | |
download | resp-19ec222ce04979ccd4125ecb6c95a86302ba937c.tar.gz resp-19ec222ce04979ccd4125ecb6c95a86302ba937c.tar.bz2 resp-19ec222ce04979ccd4125ecb6c95a86302ba937c.zip |
Simplify parser.
git-svn-id: http://svn.drobilla.net/resp/resp@300 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/parse.cpp')
-rw-r--r-- | src/parse.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/parse.cpp b/src/parse.cpp index e26ef1f..21a9963 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -40,7 +40,7 @@ PEnv::parse(const AST* exp) THROW_IF(tup->empty(), exp->loc, "Call to empty list"); const ALexeme* form = tup->head()->to_lexeme(); if (form) { - const PEnv::Handler* h = handler(true, form->cppstr); + const PEnv::Handler* h = handler(form->cppstr); if (h) return h->func(*this, exp, h->arg); // Parse special form @@ -61,10 +61,10 @@ PEnv::parse(const AST* exp) return new ALiteral<float>(T_FLOAT, strtod(s.c_str(), NULL), exp->loc); } else if (lex->cppstr[0] == '\"') { return new AString(exp->loc, lex->cppstr.substr(1, lex->cppstr.length() - 2)); - } else { - const PEnv::Handler* h = handler(false, lex->cppstr); - if (h) - return h->func(*this, exp, h->arg); + } else if (lex->cppstr == "#t") { + return new ALiteral<bool>(T_BOOL, true, exp->loc); + } else if (lex->cppstr == "#f") { + return new ALiteral<bool>(T_BOOL, false, exp->loc); } return sym(lex->cppstr, exp->loc); } @@ -160,28 +160,22 @@ void initLang(PEnv& penv, TEnv& tenv) { // Types - tenv.def(penv.sym("Nothing"), new AType(penv.sym("Nothing"), AType::PRIM)); tenv.def(penv.sym("Bool"), new AType(penv.sym("Bool"), AType::PRIM)); - tenv.def(penv.sym("Int"), new AType(penv.sym("Int"), AType::PRIM)); tenv.def(penv.sym("Float"), new AType(penv.sym("Float"), AType::PRIM)); - tenv.def(penv.sym("String"), new AType(penv.sym("String"), AType::PRIM)); + tenv.def(penv.sym("Int"), new AType(penv.sym("Int"), AType::PRIM)); tenv.def(penv.sym("Lexeme"), new AType(penv.sym("Lexeme"), AType::PRIM)); + tenv.def(penv.sym("Nothing"), new AType(penv.sym("Nothing"), AType::PRIM)); tenv.def(penv.sym("Quote"), new AType(penv.sym("Quote"), AType::PRIM)); + tenv.def(penv.sym("String"), new AType(penv.sym("String"), AType::PRIM)); - // Literals - static bool trueVal = true; - static bool falseVal = false; - penv.reg(false, "#t", PEnv::Handler(parseBool, &trueVal)); - penv.reg(false, "#f", PEnv::Handler(parseBool, &falseVal)); - // Special forms - penv.reg(true, "fn", PEnv::Handler(parseFn)); - penv.reg(true, "quote", PEnv::Handler(parseQuote)); - penv.reg(true, "if", PEnv::Handler(parseCall)); - penv.reg(true, ".", PEnv::Handler(parseCall)); - penv.reg(true, "def", PEnv::Handler(parseDef)); - penv.reg(true, "def-type", PEnv::Handler(parseCall)); - penv.reg(true, "match", PEnv::Handler(parseCall)); + penv.reg(".", PEnv::Handler(parseCall)); + penv.reg("def", PEnv::Handler(parseDef)); + penv.reg("def-type", PEnv::Handler(parseCall)); + penv.reg("fn", PEnv::Handler(parseFn)); + penv.reg("if", PEnv::Handler(parseCall)); + penv.reg("match", PEnv::Handler(parseCall)); + penv.reg("quote", PEnv::Handler(parseQuote)); // Numeric primitives penv.primitives.insert("+"); @@ -199,5 +193,5 @@ initLang(PEnv& penv, TEnv& tenv) penv.primitives.insert("<"); penv.primitives.insert("<="); FOREACH (PEnv::Primitives::const_iterator, i, penv.primitives) - penv.reg(true, *i, PEnv::Handler(parseCall)); + penv.reg(*i, PEnv::Handler(parseCall)); } |