public void SetSource(IList <string> source)
 {
     this.buffer = ScanBuff.GetBuffer(source);
     this.code   = '\n'; // to initialize yyline, yycol and lineStart
     this.lNum   = 0;
     GetCode();
 }
 void RestoreBuffCtx(BufferContext value)
 {
     this.buffer = value.buffSv;
     this.code   = value.chrSv;
     this.cCol   = value.cColSv;
     this.lNum   = value.lNumSv;
 }
Esempio n. 3
0
 public void SetSource(TextReader source)
 {
     this.buffer = ScanBuff.GetBuffer(source);
     this.lNum   = 0;
     this.code   = '\n'; // to initialize yyline, yycol and lineStart
     GetCode();
 }
 public void SetSource(Stream source, int fallbackCodePage)
 {
     this.buffer = ScanBuff.GetBuffer(source, fallbackCodePage);
     this.lNum   = 0;
     this.code   = '\n'; // to initialize yyline, yycol and lineStart
     GetCode();
 }
 public void SetSource(string source, int offset)
 {
     this.buffer     = ScanBuff.GetBuffer(source);
     this.buffer.Pos = offset;
     this.lNum       = 0;
     this.code       = '\n'; // to initialize yyline, yycol and lineStart
     GetCode();
 }
Esempio n. 6
0
 public void SetSource(IEnumerator <char> source)
 {
     this.buffer     = ScanBuff.GetBuffer(source);
     this.buffer.Pos = 0;
     this.lNum       = 0;
     this.code       = '\n'; // to initialize yyline, yycol and lineStart
     GetCode();
 }
Esempio n. 7
0
 public LexSpan(int sl, int sc, int el, int ec, int sp, int ep, ScanBuff bf)
 {
     startLine   = sl;
     startColumn = sc;
     endLine     = el;
     endColumn   = ec;
     startIndex  = sp;
     endIndex    = ep;
     buffer      = bf;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LexSpan"/> class with parameters specifying the start and end location and the <see cref="ScanBuff"/>
 /// that represents the currently active file.
 /// </summary>
 /// <param name="sl">The line number where the token starts.</param>
 /// <param name="sc">The column number of the line where the token starts.</param>
 /// <param name="el">The line number where the token ends.</param>
 /// <param name="ec">The column number of the line where the token ends.</param>
 /// <param name="sp">The index of the active file where the token starts.</param>
 /// <param name="ep">The index of the active file where the token ends.</param>
 /// <param name="bf">The <see cref="ScanBuff"/> that represents the active file.</param>
 public LexSpan(int sl, int sc, int el, int ec, int sp, int ep, ScanBuff bf)
 {
     Contract.Requires (sl >= 0);
     Contract.Requires (sc >= 0);
     Contract.Requires (el >= 0);
     Contract.Requires (ec >= 0);
     Contract.Requires (sp >= 0);
     Contract.Requires (ep >= 0);
     Contract.Requires (bf != null);
     startLine = sl;
     startColumn = sc;
     endLine = el;
     endColumn = ec;
     startIndex = sp;
     endIndex = ep;
     buffer = bf;
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LexSpan"/> class with parameters specifying the start and end location and the <see cref="ScanBuff"/>
 /// that represents the currently active file.
 /// </summary>
 /// <param name="sl">The line number where the token starts.</param>
 /// <param name="sc">The column number of the line where the token starts.</param>
 /// <param name="el">The line number where the token ends.</param>
 /// <param name="ec">The column number of the line where the token ends.</param>
 /// <param name="sp">The index of the active file where the token starts.</param>
 /// <param name="ep">The index of the active file where the token ends.</param>
 /// <param name="bf">The <see cref="ScanBuff"/> that represents the active file.</param>
 public LexSpan(int sl, int sc, int el, int ec, int sp, int ep, ScanBuff bf)
 {
     Contract.Requires(sl >= 0);
     Contract.Requires(sc >= 0);
     Contract.Requires(el >= 0);
     Contract.Requires(ec >= 0);
     Contract.Requires(sp >= 0);
     Contract.Requires(ep >= 0);
     Contract.Requires(bf != null);
     startLine   = sl;
     startColumn = sc;
     endLine     = el;
     endColumn   = ec;
     startIndex  = sp;
     endIndex    = ep;
     buffer      = bf;
 }
        // -----------------------------------------------------
        //   Console Error Reporting Method
        // -----------------------------------------------------

        internal void DumpErrorsInMsbuildFormat(ScanBuff buff, TextWriter wrtr)
        {
            StringBuilder builder = new StringBuilder();
            //
            // Message prefix
            //
            string location = (buff != null ? buff.FileName : "GPPG");

            foreach (Error err in errors)
            {
                builder.Length = 0; // Works for V2.0 even.
                //
                // Origin
                //
                builder.Append(location);
                if (buff != null)
                {
                    builder.Append('(');
                    builder.Append(err.span.startLine);
                    builder.Append(',');
                    builder.Append(err.span.startColumn);
                    builder.Append(')');
                }
                builder.Append(':');
                //
                // Category                builder.Append( ':' );
                //
                builder.Append(err.isWarn ? "warning " : "error ");
                builder.Append(err.code);
                builder.Append(':');
                //
                // Message
                //
                builder.Append(err.message);
                Console.Error.WriteLine(builder.ToString());
            }
        }
Esempio n. 11
0
        // -----------------------------------------------------
        //   Console Error Reporting Method
        // -----------------------------------------------------

        internal void DumpAll(ScanBuff buff, TextWriter wrtr)
        {
            int line = 1;
            int eNum = 0;
            int eLin = 0;
            int nxtC = (int)'\n';
            //
            //  Initialize the error group
            //
            int groupFirst  = 0;
            int currentCol  = 0;
            int currentLine = 0;

            //
            //  Reset the source file buffer to the start
            //
            buff.Pos = 0;
            wrtr.WriteLine("Error Summary --- ");
            //
            //  Initialize the error group
            //
            groupFirst  = 0;
            currentCol  = 0;
            currentLine = 0;
            //
            //  Now, for each error do
            //
            for (eNum = 0; eNum < errors.Count; eNum++)
            {
                eLin = errors[eNum].span.startLine;
                if (eLin > currentLine)
                {
                    //
                    // Spill all the waiting messages
                    //
                    if (currentCol > 0)
                    {
                        wrtr.WriteLine();
                        currentCol = 0;
                    }
                    for (int i = groupFirst; i < eNum; i++)
                    {
                        Error err = errors[i];
                        wrtr.Write((err.isWarn ? "Warning: " : "Error: "));
                        wrtr.Write(err.message);
                        wrtr.WriteLine();
                    }
                    currentLine = eLin;
                    groupFirst  = eNum;
                }
                //
                //  Skip lines up to *but not including* the error line
                //
                while (line < eLin)
                {
                    nxtC = buff.Read();
                    if (nxtC == (int)'\n')
                    {
                        line++;
                    }
                    else if (nxtC == ScanBuff.EndOfFile)
                    {
                        break;
                    }
                }
                //
                //  Emit the error line
                //
                if (line <= eLin)
                {
                    wrtr.Write((char)((eLin / 1000) % 10 + (int)'0'));
                    wrtr.Write((char)((eLin / 100) % 10 + (int)'0'));
                    wrtr.Write((char)((eLin / 10) % 10 + (int)'0'));
                    wrtr.Write((char)((eLin) % 10 + (int)'0'));
                    wrtr.Write(' ');
                    while (line <= eLin)
                    {
                        nxtC = buff.Read();
                        if (nxtC == (int)'\n')
                        {
                            line++;
                        }
                        else if (nxtC == ScanBuff.EndOfFile)
                        {
                            break;
                        }
                        wrtr.Write((char)nxtC);
                    }
                }
                //
                //  Now emit the error message(s)
                //
                if (errors[eNum].span.startColumn >= 0 && errors[eNum].span.startColumn < 75)
                {
                    if (currentCol == 0)
                    {
                        wrtr.Write("-----");
                    }
                    for (int i = currentCol; i < errors[eNum].span.startColumn; i++, currentCol++)
                    {
                        wrtr.Write('-');
                    }
                    for (; currentCol < errors[eNum].span.endColumn && currentCol < 75; currentCol++)
                    {
                        wrtr.Write('^');
                    }
                }
            }
            //
            //  Clean up after last message listing
            //  Spill all the waiting messages
            //
            if (currentCol > 0)
            {
                wrtr.WriteLine();
            }
            for (int i = groupFirst; i < errors.Count; i++)
            {
                Error err = errors[i];
                wrtr.Write((err.isWarn ? "Warning: " : "Error: "));
                wrtr.Write(errors[i].message);
                wrtr.WriteLine();
            }
        }
Esempio n. 12
0
        // -----------------------------------------------------
        //   Error Listfile Reporting Method
        // -----------------------------------------------------

        internal void MakeListing(ScanBuff buff, StreamWriter sWrtr, string name, string version)
        {
            int line = 1;
            int eNum = 0;
            int eLin = 0;

            int nxtC = (int)'\n';
            int groupFirst;
            int currentCol;
            int currentLine;

            //
            //  Errors are sorted by line number
            //
            errors = SortedErrorList();
            //
            //  Reset the source file buffer to the start
            //
            buff.Pos = 0;
            sWrtr.WriteLine();
            ListDivider(sWrtr);
            sWrtr.WriteLine("//  GPLEX error listing for lex source file <"
                            + name + ">");
            ListDivider(sWrtr);
            sWrtr.WriteLine("//  Version:  " + version);
            sWrtr.WriteLine("//  Machine:  " + Environment.MachineName);
            sWrtr.WriteLine("//  DateTime: " + DateTime.Now.ToString());
            sWrtr.WriteLine("//  UserName: "******"// Warning: " : "// Error: ");
                        string msg    = StringUtilities.MakeComment(3, prefix + err.message);
                        if (StringUtilities.MaxWidth(msg) > maxGroupWidth)
                        {
                            maxGroupWidth = StringUtilities.MaxWidth(msg);
                        }
                        sWrtr.Write(msg);
                        sWrtr.WriteLine();
                    }
                    if (groupFirst < eNum)
                    {
                        sWrtr.Write("// ");
                        Spaces(sWrtr, maxGroupWidth - 3);
                        sWrtr.WriteLine();
                    }
                    currentLine = eLin;
                    groupFirst  = eNum;
                }
                //
                //  Emit lines up to *and including* the error line
                //
                while (line <= eLin)
                {
                    nxtC = buff.Read();
                    if (nxtC == (int)'\n')
                    {
                        line++;
                    }
                    else if (nxtC == ScanBuff.EndOfFile)
                    {
                        break;
                    }
                    sWrtr.Write((char)nxtC);
                }
                //
                //  Now emit the error message(s)
                //
                if (errN.span.endColumn > 3 && errN.span.startColumn < 80)
                {
                    if (currentCol == 0)
                    {
                        sWrtr.Write("//");
                        currentCol = 2;
                    }
                    if (errN.span.startColumn > currentCol)
                    {
                        Spaces(sWrtr, errN.span.startColumn - currentCol);
                        currentCol = errN.span.startColumn;
                    }
                    for (; currentCol < errN.span.endColumn && currentCol < 80; currentCol++)
                    {
                        sWrtr.Write('^');
                    }
                }
            }
            //
            //  Clean up after last message listing
            //  Spill all the waiting messages
            //
            int maxEpilogWidth = 0;

            if (currentCol > 0)
            {
                sWrtr.WriteLine();
            }
            for (int i = groupFirst; i < errors.Count; i++)
            {
                Error  err    = errors[i];
                string prefix = (err.isWarn ? "// Warning: " : "// Error: ");
                string msg    = StringUtilities.MakeComment(3, prefix + err.message);
                if (StringUtilities.MaxWidth(msg) > maxEpilogWidth)
                {
                    maxEpilogWidth = StringUtilities.MaxWidth(msg);
                }
                sWrtr.Write(msg);
                sWrtr.WriteLine();
            }
            if (groupFirst < errors.Count)
            {
                sWrtr.Write("// ");
                Spaces(sWrtr, maxEpilogWidth - 3);
                sWrtr.WriteLine();
            }
            //
            //  And dump the tail of the file
            //
            nxtC = buff.Read();
            while (nxtC != ScanBuff.EndOfFile)
            {
                sWrtr.Write((char)nxtC);
                nxtC = buff.Read();
            }
            ListDivider(sWrtr); sWrtr.WriteLine();
            sWrtr.Flush();
            // sWrtr.Close();
        }
Esempio n. 13
0
 public void SetSource(System.IO.Stream source)
 {
     this.buffer = new BuildBuffer(source);
     code = buffer.Read();
 }
Esempio n. 14
0
 public void SetSource(Stream source, int fallbackCodePage)
 {
     this.buffer = ScanBuff.GetBuffer(source, fallbackCodePage);
     this.lNum = 0;
     this.code = '\n'; // to initialize yyline, yycol and lineStart
     GetCode();
 }
Esempio n. 15
0
 public void SetSource(IList<string> source)
 {
     this.buffer = ScanBuff.GetBuffer(source);
     this.code = '\n'; // to initialize yyline, yycol and lineStart
     this.lNum = 0;
     GetCode();
 }
Esempio n. 16
0
 public void SetSource(string source, int offset)
 {
     this.buffer = ScanBuff.GetBuffer(source);
     this.buffer.Pos = offset;
     this.lNum = 0;
     this.code = '\n'; // to initialize yyline, yycol and lineStart
     GetCode();
 }
Esempio n. 17
0
        void RestoreBuffCtx(BufferContext value)
		{
			this.buffer = value.buffSv;
			this.code = value.chrSv;
			this.cCol = value.cColSv;
			this.lNum = value.lNumSv;
        }