-
Notifications
You must be signed in to change notification settings - Fork 47
Ability to parse a "blob" (sequence of bytes) which length is defined by a previous token #68
Comments
I would add such constraint on the visitor side... Since Hoa/Compiler does not allow executable code in grammar (unlike JavaCC for example) you will have to define and check such constraints when traversing your AST. |
I'm intrested too. Many files provided by bank are based on that kind of stuff. The purpose here is to have a way to describe that kind of stuff without devlopping a lot of stuff. |
@jubianchi You mean some post-processing (from the Compiler POV) that takes AST as an input and return another "fixed" AST? |
Hello, Unfortunately, this is not possible with such parsers. You might want to either look for a parser generator (like nom), or add this constraint on a visitor, but this is not ideal at all, and it covers a few use cases. |
Hywan, well perhaps it could evolve in something différent or be another lib based on compiler. |
I mean, a visitor which will validate an AST : it takes an AST as an input, validates it and returns the exact same AST if every constraint is OK. |
@Grummfy We can create a parser generator, and add it to |
Thank you for the answer. :) I'm closing the issue since it's out of scope of this library. |
Apply fixes from StyleCI
For example
5 abcde
would be parsed into
with the constraint that the length of the 2nd string token "abcde" is equal to the value of the first number token 5.
Here are 3 examples that would need this feature (maybe that using the Compiler is not the right tool for the job, in which case this issue can be closed) :
1️⃣ parsing the response of a IMAP FETCH command
In this example, the size of the next data token is included not far before the data to parse.
2️⃣ Creating an AST from a PDF file:
This one is a bit more tricky since the size of the data stream (42 bytes) is contained in a the previous "Dictionary Node" (from an AST Point-Of-View), thus requiring knowledge of previous nodes already emited.
3️⃣ Other protocols uses this as well:
Content-Length
header (HTTP), same as 2️⃣payload len
in a websocket frame, though this one is even more challenging because it would in addition require being able to read a streamed inputThe text was updated successfully, but these errors were encountered: