logoalt Hacker News

djoldman11/08/20241 replyview on HN

I love love love ragel.

Won't the code here:

https://github.com/gritzko/librdx/blob/master/JSON.lex

accept "[" as valid json?

   delimiter = OpenObject | CloseObject | OpenArray | CloseArray | Comma | Colon;
   primitive = Number | String | Literal;
   JSON = ws* ( primitive? ( ws* delimiter ws* primitive? )* ) ws*;
   Root = JSON;
(pick zero of everything in JSON except one delimiter...)

I usually begin with the RFCs:

https://datatracker.ietf.org/doc/html/rfc4627#autoid-3

I'm not sure one can implement JSON with ragel... I believe ragel can only handle regular languages and JSON is context free.


Replies

gritzko11/08/2024

That is a lexer, so yes, it accepts almost any sequence of valid tokens. Pure Ragel only parses regular languages, but there are ways.