From 4e201e6a70e60d24b22ce62109b5af3d90c0a27e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 10 Sep 2020 03:41:03 -0700 Subject: Added dashes to identifiers --- bpeg.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'bpeg.c') diff --git a/bpeg.c b/bpeg.c index 37018d1..b9b4232 100644 --- a/bpeg.c +++ b/bpeg.c @@ -702,14 +702,10 @@ static vm_op_t *compile_bpeg(const char *source, const char *str) visualize(source, str, "Ref"); --str; const char *refname = str; - size_t len = 1; - for (++str; isalnum(*str); ++str) { - ++len; - visualize(source, str, NULL); - } + str = after_name(str); op->op = VM_REF; - //debug("Ref: %s\n", refname); - op->args.s = strndup(refname, len); + op->len = (size_t)(str - refname); + op->args.s = strndup(refname, op->len); break; } else { visualize(source, str, "Finished"); @@ -828,10 +824,10 @@ static void load_defs(void) load_def("esc", "\\e"); load_def("e", "\\e"); load_def("tab", "\\t"); load_def("t", "\\t"); load_def("nl", "\\n"); load_def("lf", "\\n"); load_def("n", "\\n"); - load_def("cBlockComment", "'/*' &&'*/'"); - load_def("cLineComment", "'//' &$"); - load_def("cComment", "cLineComment / cBlockComment"); - load_def("hashComment", "`# &$"); + load_def("c-block-comment", "'/*' &&'*/'"); + load_def("c-line-comment", "'//' &$"); + load_def("c-comment", "c-line-comment / c-block-comment"); + load_def("hash-comment", "`# &$"); load_def("comment", "!(/)"); // undefined by default load_def("WS", "` /\\t/\\n/\\r/comment"); load_def("ws", "` /\\t"); @@ -1062,8 +1058,7 @@ static vm_op_t *load_grammar(const char *grammar) name = strndup(name, 1); defs += 1; } else { - check(isalpha(*name), "Definition must begin with a name"); - while (isalnum(*defs)) ++defs; + defs = after_name(defs); name = strndup(name, (size_t)(defs-name)); } defs = after_spaces(defs); -- cgit v1.2.3