From d1f38c9f27ff1a0208884058d3c8450650703ee9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 4 Jul 2009 06:12:50 +0000 Subject: Parse AString. git-svn-id: http://svn.drobilla.net/resp/tuplr@186 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/constrain.cpp | 6 ++++++ src/parse.cpp | 1 + src/tuplr.hpp | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/constrain.cpp b/src/constrain.cpp index f9a0e11..7db25fa 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -22,6 +22,12 @@ #include #include "tuplr.hpp" +void +AString::constrain(TEnv& tenv, Constraints& c) const +{ + c.push_back(Constraint(tenv.var(this), tenv.named("String"), loc)); +} + void ASymbol::constrain(TEnv& tenv, Constraints& c) const { diff --git a/src/parse.cpp b/src/parse.cpp index d36a92a..9d26652 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -106,6 +106,7 @@ initLang(PEnv& penv, TEnv& tenv) tenv.def(penv.sym("Bool"), make_pair((AST*)0, new AType(penv.sym("Bool")))); tenv.def(penv.sym("Int"), make_pair((AST*)0, new AType(penv.sym("Int")))); tenv.def(penv.sym("Float"), make_pair((AST*)0, new AType(penv.sym("Float")))); + tenv.def(penv.sym("String"), make_pair((AST*)0, new AType(penv.sym("String")))); // Literals static bool trueVal = true; diff --git a/src/tuplr.hpp b/src/tuplr.hpp index da8eea5..1e64da1 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -237,7 +237,7 @@ struct ALiteral : public AST { struct AString : public AST, public std::string { AString(Cursor c, const string& s) : AST(c), std::string(s) {} bool operator==(const AST& rhs) const { return this == &rhs; } - void constrain(TEnv& tenv, Constraints& c) const {} + void constrain(TEnv& tenv, Constraints& c) const; CValue compile(CEnv& cenv) { return NULL; } }; @@ -535,6 +535,8 @@ struct PEnv : private map { return new ALiteral(strtol(s.c_str(), NULL, 10), exp->loc); else return new ALiteral(strtod(s.c_str(), NULL), exp->loc); + } else if ((*str)[0] == '\"') { + return new AString(exp->loc, str->substr(1, str->length() - 2)); } else { const PEnv::Handler* h = handler(false, *str); if (h) -- cgit v1.2.1