From a2643cc0d564033c49bffbd0de9a8e797281e73f Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Sat, 22 Sep 2012 14:03:46 +0100 Subject: [PATCH] Allow underscores in IDENT tokens. Fixes #3. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 2 +- testdata | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 -- 2.49.0