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

View File

@ -17,23 +17,44 @@ struct Value
std::string name;
bool mut;
};
std::vector<Parameter> params;
std::vector<Parameter> params;
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(long l) : type(Long), v(l) {}
explicit Value(std::string&& s) : type(String), v(s) {}
explicit Value(ArrayValue&& a) : type(Array), v(a) {}
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 {
switch (type) {
case Bool: return v.get<bool>();
@ -191,7 +212,7 @@ struct Environment
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()) {
return dic_.at(s).val;
}
@ -203,13 +224,13 @@ struct Environment
}
void assign(const std::string& s, const Value& val) {
assert(has(s));
if (dic_.find(s) != dic_.end()) {
auto& sym = dic_[s];
if (!sym.mut) {
std::string msg = "immutable variable '" + s + "'...";
throw std::runtime_error(msg);
}
//std::cout << "Env::assgin: " << s << std::endl;
sym.val = val;
return;
}
@ -222,7 +243,7 @@ struct Environment
}
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};
}