From: Stephen Dolan Date: Sat, 22 Sep 2012 13:03:46 +0000 (+0100) Subject: Allow underscores in IDENT tokens. Fixes #3. X-Git-Tag: jq-1.1~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2643cc0d564033c49bffbd0de9a8e797281e73f;p=jq Allow underscores in IDENT tokens. Fixes #3. 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). --- diff --git a/lexer.l b/lexer.l index e604ada..fe0049a 100644 --- a/lexer.l +++ b/lexer.l @@ -107,7 +107,7 @@ } -[[: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]+ {} diff --git a/testdata b/testdata index 8a28997..307eaa6 100644 --- 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