[augeas-devel] augeas: master - Language: allow '_' as an identifier that is never bound
David Lutterkort
lutter at fedoraproject.org
Sun Jan 17 22:23:56 UTC 2010
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=3c9c9da314aac8d422f80bc7be1655079064cbbc
Commit: 3c9c9da314aac8d422f80bc7be1655079064cbbc
Parent: 911e52f8f851e483dc03d8d75be7bed3ac667a75
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Fri Jan 15 16:51:14 2010 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Fri Jan 15 17:01:59 2010 -0800
Language: allow '_' as an identifier that is never bound
The expression
let _ = something
will evaluate something and then immediately forget it
* src/lexer.l (LID): allow leading underscore
* src/syntax.c (bind, bind_type): do not bind '_'
---
src/lexer.l | 2 +-
src/syntax.c | 16 +++++++++++++---
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/lexer.l b/src/lexer.l
index 66637e1..3e29d15 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -69,7 +69,7 @@ static char *regexp_literal(const char *s, int len) {
DIGIT [0-9]
UID [A-Z][A-Za-z0-9_]*
-LID [a-z][A-Za-z0-9_]*
+LID [a-z_][A-Za-z0-9_]*
LETREC let[ \t]+rec
WS [ \t\n]
QID {UID}\.{LID}
diff --git a/src/syntax.c b/src/syntax.c
index 0e2f9b7..d4e3282 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -65,6 +65,9 @@ static const char *const type_names[] = {
"transform", "function", NULL
};
+/* The anonymous identifier which we will never bind */
+static const char const anon_ident[] = "_";
+
static void print_value(FILE *out, struct value *v);
/* The evaluation context with all loaded modules and the bindings for the
@@ -572,6 +575,9 @@ static struct type *ctx_lookup_type(struct info *info,
static struct binding *bind_type(struct binding **bnds,
const char *name, struct type *type) {
struct binding *binding;
+
+ if (STREQ(name, anon_ident))
+ return NULL;
make_ref(binding);
make_ref(binding->ident);
binding->ident->str = strdup(name);
@@ -601,11 +607,15 @@ static void unbind_param(struct binding **bnds, ATTRIBUTE_UNUSED struct param *p
unref(b, binding);
}
-/* Takes ownership of TYPE and VALUE */
+/* Takes ownership of VALUE */
static void bind(struct binding **bnds,
const char *name, struct type *type, struct value *value) {
- struct binding *b = bind_type(bnds, name, type);
- b->value = ref(value);
+ struct binding *b = NULL;
+
+ if (STRNEQ(name, anon_ident)) {
+ b = bind_type(bnds, name, type);
+ b->value = ref(value);
+ }
}
/*
More information about the augeas-devel
mailing list