Updated README.

This commit is contained in:
yhirose 2015-06-14 08:02:59 -04:00
parent 652e25a10b
commit b0f34248ab
2 changed files with 38 additions and 20 deletions

View File

@ -198,9 +198,11 @@ It also supports named capture with the `$name<` ... `>` operator.
peglib::match m; peglib::match m;
auto ret = peglib::peg_match( auto ret = peglib::peg_match(
" ROOT <- _ ('[' $test< TAG_NAME > ']' _)* " R"(
" TAG_NAME <- (!']' .)+ " ROOT <- _ ('[' $test< TAG_NAME > ']' _)*
" _ <- [ \t]* ", TAG_NAME <- (!']' .)+
_ <- [ \t]*
)",
" [tag1] [tag:2] [tag-3] ", " [tag1] [tag:2] [tag-3] ",
m); m);
@ -290,11 +292,6 @@ The following are available operators:
| cap | Capture character | | cap | Capture character |
| usr | User defiend parser | | usr | User defiend parser |
Predicate control
-----------------
* TODO
Adjust definitions Adjust definitions
------------------ ------------------
@ -344,7 +341,7 @@ Tested Compilers
TODO TODO
---- ----
* Optimization of grammars * Predicate control
* Unicode support * Unicode support
License License

View File

@ -21,19 +21,40 @@ struct Value
std::function<Value (std::shared_ptr<Environment> env)> eval; std::function<Value (std::shared_ptr<Environment> env)> eval;
}; };
explicit Value() : type(Undefined) {} Value() : type(Undefined) {
//std::cout << "Val::def ctor: " << std::endl;
}
Value(const Value& rhs) : type(rhs.type), v(rhs.v) {
//std::cout << "Val::copy ctor: " << *this << std::endl;
}
Value(Value&& rhs) : type(rhs.type), v(rhs.v) {
//std::cout << "Val::move ctor: " << *this << std::endl;
}
Value& operator=(const Value& rhs) {
if (this != &rhs) {
type = rhs.type;
v = rhs.v;
//std::cout << "Val::copy=: " << *this << std::endl;
}
return *this;
}
Value& operator=(Value&& rhs) {
type = rhs.type;
v = rhs.v;
//std::cout << "Val::move=: " << *this << std::endl;
return *this;
}
explicit Value(bool b) : type(Bool), v(b) {} explicit Value(bool b) : type(Bool), v(b) {}
explicit Value(long l) : type(Long), v(l) {} explicit Value(long l) : type(Long), v(l) {}
explicit Value(std::string&& s) : type(String), v(s) {} explicit Value(std::string&& s) : type(String), v(s) {}
explicit Value(ArrayValue&& a) : type(Array), v(a) {} explicit Value(ArrayValue&& a) : type(Array), v(a) {}
explicit Value(FunctionValue&& f) : type(Function), v(f) {} explicit Value(FunctionValue&& f) : type(Function), v(f) {}
Value(const Value&) = default;
Value(Value&& rhs) : type(rhs.type), v(rhs.v) {}
Value& operator=(const Value&) = default;
Value& operator=(Value&& rhs) { type = rhs.type; v = rhs.v; return *this; }
bool to_bool() const { bool to_bool() const {
switch (type) { switch (type) {
case Bool: return v.get<bool>(); case Bool: return v.get<bool>();
@ -191,7 +212,7 @@ struct Environment
return outer_ && outer_->has(s); return outer_ && outer_->has(s);
} }
Value get(const std::string& s) const { const Value& get(const std::string& s) const {
if (dic_.find(s) != dic_.end()) { if (dic_.find(s) != dic_.end()) {
return dic_.at(s).val; return dic_.at(s).val;
} }
@ -203,13 +224,13 @@ struct Environment
} }
void assign(const std::string& s, const Value& val) { void assign(const std::string& s, const Value& val) {
assert(has(s));
if (dic_.find(s) != dic_.end()) { if (dic_.find(s) != dic_.end()) {
auto& sym = dic_[s]; auto& sym = dic_[s];
if (!sym.mut) { if (!sym.mut) {
std::string msg = "immutable variable '" + s + "'..."; std::string msg = "immutable variable '" + s + "'...";
throw std::runtime_error(msg); throw std::runtime_error(msg);
} }
//std::cout << "Env::assgin: " << s << std::endl;
sym.val = val; sym.val = val;
return; return;
} }
@ -222,7 +243,7 @@ struct Environment
} }
void initialize(const std::string& s, const Value& val, bool mut) { void initialize(const std::string& s, const Value& val, bool mut) {
assert(!has(s)); //std::cout << "Env::initialize: " << s << std::endl;
dic_[s] = Symbol{val, mut}; dic_[s] = Symbol{val, mut};
} }