]> granicus.if.org Git - jq/commitdiff
Allow underscores in IDENT tokens. Fixes #3.
authorStephen Dolan <mu@netsoc.tcd.ie>
Sat, 22 Sep 2012 13:03:46 +0000 (14:03 +0100)
committerStephen Dolan <mu@netsoc.tcd.ie>
Sat, 22 Sep 2012 13:03:46 +0000 (14:03 +0100)
IDENT syntax now includes ASCII letters and underscores, so
'.foo_bar' now works. Non-ASCII letters won't work in IDENT
tokens (it's impossible to tell which non-ascii characters are
"letters" without full unicode tables), so '.donnĂ©es' is still
a syntax error (the workaround is '.["donnĂ©es"]', since you can
put anything you like in a string).

lexer.l
testdata

diff --git a/lexer.l b/lexer.l
index e604adabe1215f271bd6e06eda759856e62101aa..fe0049a9b658c4a10b6ed7104d2920b32b5bd2d0 100644 (file)
--- a/lexer.l
+++ b/lexer.l
 }
   
 
-[[:alnum:]]+  { yylval->literal = jv_string(yytext); return IDENT;}
+[a-zA-Z_][a-zA-Z_0-9]*  { yylval->literal = jv_string(yytext); return IDENT;}
 
 [ \n\t]+  {}
 
index 8a28997343de773025b17d94b207891f3843b150..307eaa6263cba25827165f1cced2925a793274e7 100644 (file)
--- a/testdata
+++ b/testdata
@@ -61,6 +61,10 @@ null
 {"foo": {"bar": 42}, "bar": "badvalue"}
 42
 
+.foo_bar
+{"foo_bar": 2}
+2
+
 .["foo"].bar
 {"foo": {"bar": 42}, "bar": "badvalue"}
 42