Thanks nigel,

that is a good description of how i also understood things to be.

And yes, i need what you call stream functionality.

So the question remains, how do i get Parslet to parse only a part of a file ?

Tosrten

Nigel Thorne <mailto:[email protected]>
9. toukokuuta 2014 11.51
Oh I see.

It sounds like you want to parse your input as a stream instead of as a file. If not, then the answer is.. yes you parse the whole document at once. It isn't until the whole file has been matched against your grammar that you know the whole document is valid. I have not yet needed to write a parser with Parslet to process a stream. It would only be valuable for very large files.

By default a Parslet parser parses a whole document at a time into your parse tree. Parsing converts a text document into data structure that represents the meaning of the file. Once your data is in a tree structure you then traverse that tree in some way to "interpret" or "transform" the data into "behaviour" or some other data structure.

Does this make sense?

Cheers
Nigel







---
"Man, I'm going to have so many chickens when this lot hatch!"



Torsten Ruger <mailto:[email protected]>
9. toukokuuta 2014 11.09
Hi Nigel,

thank you, but that is not what i was asking. Maybe i was unclear.

In your example, let's say i do have lines. I understand your :doc, and how to parse many lines _at once_

But i want to parse one line at a time. Parse, do my processing, parse more, more processing until end of file.

I know how to loop through files. But obviously i can't split my input into files, as that involves parsing it.

Torsten

Nigel Thorne <mailto:[email protected]>
9. toukokuuta 2014 2.51

If you are asking "how do I parse a file that contains some structure that is repeating?" Then ... You just need a rule that says that.. For example :

rule(:line){ ... something ... }
rule(:doc){ line.repeat }

If you want to know how to parse several files... You just need a loop through the filenames, opening each file, and ask the parser to parse it... Then parse the next one.

Does this make sense?

Torsten Ruger <mailto:[email protected]>
8. toukokuuta 2014 22.44
Moi,

as i am relatively new, i feel i am missing the obvious. Sorry for the
inconvenience if that is so.

I want to parse a file in bits as it were. So when i call parse (or
whatever) i want it to return the expression, which i then transform and
process.
Then i want to parse more of the same file and repeat.

Seems quite a simple thing, but i can't find any info on it.

I would give my grammar as example, but feel that the issue is the same
for the simples things, ie numbers.So
1
2
3
could be my file and the rule would be match digit.

Thanks for any help,

AND THANKS FOR PARSLET

Torsten

Reply via email to