Closed iainelder closed 7 months ago
I don't know where @erezsh got that from, Lark has never supported passing in a file object (or any IOStream) to .parse
. This is also quite hard to add since we are using re
, which can't deal with those objects directly, I can try to add support for it.
Ofcourse, if the file is smaller than a few MB, just loading it into memory is the better choice for speed.
@erezsh showed that Lark's parse method takes a file argument so that Lark can read the file as it needs to.
I don't think that I did.
@erezsh showed that Lark's parse method takes a file argument so that Lark can read the file as it needs to.
I don't think that I did.
You did, the quote is exactly what you wrote.
@iainelder My bad, I was wrong, and I apologize for misleading you. You should read the file yourself, and provide it to Lark as a string.
If you need to parse a very large file, there might be a way to do so incrementally, but a solution isn't yet written or tested. See #1211 .
If the file is smaller than a few MB, just loading it into memory is the better choice for speed.
My data is small enough that I can work like this.
Thanks for clarifying. The documentation does show that parse
expects a string, but that issue ranks high on Google :-)
Describe the bug
I want Lark to read the file for me so that I don't have to read the whole file into memory first.
In #488 @erezsh showed that Lark's
parse
method takes a file argument so that Lark can read the file as it needs to.I use this complete example to try to reproduce it. I'm not ready to use a transformer yet, so I omit that part.
I expect the result to be a tree with tokens for
1
,22
, and333
.Instead I get the following error:
Despite that example code, it looks like Lark really expects a string, which has a
len
method.How do I get Lark to read the file for me?