示例#1
0
        IToken ITokenFactory.Create(Tuple <ITokenSource, ICharStream> source, int type, string text, int channel, int start, int stop, int line, int charPositionInLine)
        {
            CPPToken t = new CPPToken(source, type, channel, start, stop);

            t.Line = line;
            // t.  setCharPositionInLine(charPositionInLine);
            var input = source.Item2;

            t.Text     = input.GetText(Interval.Of(start, stop));
            t.filename = stack.Peek();
            return(t);
        }
示例#2
0
        public override void SyntaxError(TextWriter output,
                                         IRecognizer recognizer,
                                         IToken offendingSymbol,
                                         int line,
                                         int charPositionInLine,
                                         string msg, RecognitionException e)
        {
            CPPToken token = (CPPToken)offendingSymbol;

            System.Console.Error.WriteLine(token.filename +
                                           " line " + line + ":" + charPositionInLine + " at " +
                                           token.Text + ": " + msg);
        }
示例#3
0
        public int getLineFromCharIndex(int ci)
        {
            int ti = getTokenIndexFromCharIndex(ci);

            if (ti == -1)
            {
                return(-1);
            }
            var      tt = tokens[ti];
            CPPToken t  = tt as CPPToken;
            int      iv = intervalFor(t.lineIntervals, ci); // gives line num from 0

            return(iv + t.Line);                            // add starting line number of entire preprocessed token
        }