Exemple #1
0
        //readonly object LEXLOCK = new object();

        internal IToken[] Lex(string line, ref TokenLine state, DoubleLinkedList <TokenLine> mlines)
        {
            if (line == null)
            {
                return(null);
            }
            //lock(LEXLOCK)
            {
                IToken[] tokens = null;

                TokenLine currentline = null, prevline = state;

                Stack ls = null;
                if (prevline == null) //first line
                {
                    ls = null;
                    if (mlines.First != null)
                    {
                        currentline = mlines.First.Data;
                    }
                }
                else
                {
                    //see if we have a line already
                    if (prevline != mlines.Last.Data)
                    {
                        DoubleLinkedList <TokenLine> .IPosition pos = mlines.PositionOf(prevline);

                        Debug.Assert(pos != null);

                        pos = pos.Next;

                        if (pos != null)
                        {
                            currentline = pos.Data;
                        }
                    }

                    if (prevline.state != null)
                    {
                        ls = prevline.state;
                    }
                    else
                    {
                        ls = null;
                    }
                }

                tokens = Lex(line, ref ls);

                if (currentline != null)
                {
                    state = currentline;
                    currentline.Tokens = tokens;
                    currentline.state  = ls;
                }

                return(tokens);
            }
        }
Exemple #2
0
            public bool MoveNext()
            {
START:          // fix to prevent recursion stack overflow, one could probably use for or while too, thanks to ahz
                if (tl == null)
                {
                    return(false);
                }
                tokenpos++;
                if (tl.Tokens == null || tl.Tokens.Length == tokenpos)
                {
                    if (currentline.Next == null)
                    {
                        return(false);
                    }
                    line++;
                    tokenpos    = -1;
                    currentline = currentline.Next;
                    tl          = currentline.Data;
                    if (tl == null)
                    {
                        return(false);
                    }
                    goto START;
                }
                IToken t = tl.Tokens[tokenpos];

                if (!IsValid(t))
                {
                    goto START;
                }

                if (updatelocations)
                {
                    //this is from the lexer, will allways have Location not range
                    Location loc = t.Location;

                    //check existing error state and clear the line
                    if (loc.Error || loc.Warning)// || loc.Paired)
                    {
                        if (lang.cb != null)
                        {
                            lang.cb.Invoke(loc);
                        }
                    }

                    //reset error/warning state
                    loc.Error = loc.Warning = false;

                    loc.filename   = filename;
                    loc.LineNumber = line;
                    //loc.Paired = false;
                }

                current = t;
                return(true);
            }
Exemple #3
0
 public void Reset()
 {
     line        = 1;
     currentline = lines.First;
     tokenpos    = -1;
     if (currentline != null)
     {
         tl = currentline.Data;
     }
 }