[antlr-interest] Reading from sys.stdin with ANTLR-Python (for an REPL)

Aaron Lebo aaron.m.lebo at gmail.com
Sun Feb 17 21:52:34 PST 2008


Hi. I'm obviously using the Python runtime of ANTLR.

Reading from a file and parsing it is trivial. The code looks a bit like:

import antlr3
import LangLexer
import LangParser

input = antlr3.ANTLRFileStream('filename...')
lexer = LangLexer.LangLexer(input)
tokens = antlr3.CommonTokenStream(lexer)
parser = LangParser.LangParser(tokens)

So I'm having no issue with that. What I am wanting to do is an REPL and I
need to interactively parse the data coming from sys.stdin. The problem is
that all of the 'Stream' classes from the antlr3 package read all input on
creation, so passing sys.stdin or sys.stdin.read() causes the REPL to hang,
as something like antlr3.ANTLRInputStream(sys.stdin) reads infinitely.

Am I making sense? What solution is there?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080217/c7673723/attachment.html 


More information about the antlr-interest mailing list