[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-recutils] Bug in seletion expr when field name contains a hyphe
From: |
Jose E. Marchesi |
Subject: |
Re: [bug-recutils] Bug in seletion expr when field name contains a hyphen |
Date: |
Sun, 23 Jun 2013 14:32:29 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Hi John.
There is indeed an inconsistency:
rec.h: #define REC_FNAME_RE "[a-zA-Z%][a-zA-Z0-9_-]*"
rec-sex-lex.l: FIELD_NAME {LETTER}[a-zA-Z0-9_]+
Documentation:
@cindex field name
A @dfn{field name} is a sequence of alphanumeric characters plus
dashes (@code{-}) and underscores (@code{_}), starting with a letter
or the character @code{%}. The regular expression denoting a field
name is:
@example
[a-zA-Z%][a-zA-Z0-9_-]+
@end example
A possible solution would be to instruct the SEX lexer to allow hyphens
in field names before the operator "-" (see patch below) but that could
lead to some confusing situations. The other alternative would be to
forbit hyphens in field names. What do you think?
diff --git a/src/rec-sex-lex.l b/src/rec-sex-lex.l
index 6535d86..30a665c 100644
--- a/src/rec-sex-lex.l
+++ b/src/rec-sex-lex.l
@@ -69,7 +69,7 @@ NEWLINE \n
BLANK [ \t\n]
DIGIT [0-9]
LETTER [a-zA-Z]
-FIELD_NAME {LETTER}[a-zA-Z0-9_]+
+FIELD_NAME {LETTER}[a-zA-Z0-9_-]+
STRING '([^']|\\(.|\n))*'|\"([^"]|\\(.|\n))*\"
/* Please do not touch this comment' */
@@ -104,6 +104,29 @@ STRING '([^']|\\(.|\n))*'|\"([^"]|\\(.|\n))*\"
return REC_SEX_TOK_INT;
}
+{FIELD_NAME}(\.{FIELD_NAME})?(\[[0-9]+\])? {
+ int res;
+ char *match;
+ char *name, *subname;
+ int index = -1;
+
+ match = strdup (yytext);
+ rec_sex_lex_extract_index (match, &index);
+ name = rec_sex_lex_extract_name (match);
+ subname = rec_sex_lex_extract_subname (match);
+
+ /* Create a name node. */
+ yylval->node = rec_sex_ast_node_new ();
+ rec_sex_ast_node_set_name (yylval->node, name, subname);
+ rec_sex_ast_node_set_index (yylval->node, index);
+ res = REC_SEX_TOK_NAM;
+
+ free (name);
+ free (match);
+
+ return res;
+}
+
"+" { return REC_SEX_TOK_ADD; }
"-" { return REC_SEX_TOK_SUB; }
"/" { return REC_SEX_TOK_DIV; }
@@ -130,28 +153,6 @@ STRING '([^']|\\(.|\n))*'|\"([^"]|\\(.|\n))*\"
":" { return REC_SEX_TOK_COLON; }
"&" { return REC_SEX_TOK_AMP; }
-{FIELD_NAME}(\.{FIELD_NAME})?(\[[0-9]+\])? {
- int res;
- char *match;
- char *name, *subname;
- int index = -1;
-
- match = strdup (yytext);
- rec_sex_lex_extract_index (match, &index);
- name = rec_sex_lex_extract_name (match);
- subname = rec_sex_lex_extract_subname (match);
-
- /* Create a name node. */
- yylval->node = rec_sex_ast_node_new ();
- rec_sex_ast_node_set_name (yylval->node, name, subname);
- rec_sex_ast_node_set_index (yylval->node, index);
- res = REC_SEX_TOK_NAM;
-
- free (name);
- free (match);
-
- return res;
-}
{STRING} {
/*