[antlr-interest] can't start lexer after beginning of input (CharStream.setLine())

Doucette, Charles cdoucette at vaultus.com
Wed Sep 24 09:29:15 PDT 2008


Apparently, I am supposed to call seek(index) and that will update line and charPositionInLine.

Chuck

________________________________
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Doucette, Charles
Sent: Wednesday, September 24, 2008 12:12 PM
To: Antlr
Subject: [antlr-interest] can't start lexer after beginning of input (CharStream.setLine())

I am attempting to automate auto-completion.

I thought rather than trying to write my own lexer, I should use the one I already wrote.

I am implementing a completion method which is given the contents of a buffer and the offset within that buffer where the cursor is when you attempt to invoke completion.

I use DefaultLineTracker to determine which line number and the target offset within that line.

I want to determine the list of tokens on that line which preceed the point of completion.

Here is most of the code of my lexify method:

      ANTLRStringStream strStream = new ANTLRStringStream(contents);
      strStream.setLine(line);
      int posInLine = 0;
      strStream.setCharPositionInLine(posInLine);
      Lexer lexer = new vscriptLexer(strStream);
      while (posInLine <= targetPosInLine) {
         Token token = lexer.nextToken();
         tokenList.add(token);
         posInLine = lexer.getCharPositionInLine();
      }
      tokens = tokenList.toArray(tokens);
      return tokens;

When I run it, the first token returned is the first token in the file - rather than the token on the line number that I set the input to.

Is it possible to do what I am trying to do?
If so, am I going about it the correct way?

Thanks,
Chuck

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080924/4c40f598/attachment.html 


More information about the antlr-interest mailing list