Exemplo n.º 1
0
        void UnhandledException(Exception ex)
        {
            int       iPos = GetTextPosition(InputPosition);
            SourcePos pos  = _sourceFile.IndexToLine(iPos);

            ErrorSink.Write(Severity.Critical, pos, "Bug: unhandled exception in parser - " + ex.ExceptionMessageAndType());
        }
Exemplo n.º 2
0
        public sealed override void Advance()
        {
            if (_current.HasValue)
            {
                _sourcePos = _calculatePos(_current.GetValueOrDefault(), _sourcePos);
            }
            if (_bufPos < _bufSize - 1)
            {
                // we are re-reading previously buffered input
                _bufPos++;
                _current = Maybe.Just(Buffer[_bufPos]);
                return;
            }
            _bufPos = _bufSize;  // just to be sure
            if (!IsBuffering)
            {
                // we're at the end of the buffer,
                // and we're not currently writing to the buffer,
                // so the buffer can be discarded
                _bufPos = _bufSize = 0;
                BufferPool <TToken> .Release(Buffer);

                _buffer = null;
            }
            else if (_current.HasValue)
            {
                // don't forget the old value
                PushBuf(_current.GetValueOrDefault());
            }

            _current = AdvanceInput();
        }
Exemplo n.º 3
0
        protected void Error(int inputPosition, string message, params object[] args)
        {
            int       iPos = GetTextPosition(inputPosition);
            SourcePos pos  = _sourceFile.IndexToLine(iPos);

            _messages.Write(_Error, pos, message, args);
        }
Exemplo n.º 4
0
        public SourcePos end;   // Position just after the token

        public Token(SourcePos start, SourcePos end, TokenType type, String value)
        {
            this.start = start;
            this.end   = end;
            this.type  = type;
            this.value = value;
        }
Exemplo n.º 5
0
        protected override void Error(int li, string message)
        {
            int       iPos = GetTextPosition(InputPosition + li);
            SourcePos pos  = _sourceFile.IndexToLine(iPos);

            _messages.Write(_Error, pos, message);
        }
Exemplo n.º 6
0
        protected override void Error(int lookaheadIndex, string message, params object[] args)
        {
            int       iPos = GetTextPosition(InputPosition + lookaheadIndex);
            SourcePos pos  = _sourceFile.IndexToLine(iPos);

            CurrentSink(true).Write(Severity.Error, pos, message, args);
        }
Exemplo n.º 7
0
 protected void ReportError(SourcePos pos, string message)
 {
     if (!isError)
     {
         file.ReportError(new SourceError(pos, message));
     }
     isError = true;
 }
Exemplo n.º 8
0
 public override void Write(IStarboundStream stream)
 {
     stream.WriteVLQ((ulong)Position.Count);
     Position.ForEach(p => p.WriteTo(stream));
     stream.WriteUInt8((byte)Layer);
     SourcePos.WriteTo(stream);
     TileDamage.WriteTo(stream);
 }
Exemplo n.º 9
0
 protected void ConsumeAndReportError(SourcePos pos, string message)
 {
     if (isError)
     {
         Consume();
         isError = true;
     }
     ReportError(pos, message);
 }
Exemplo n.º 10
0
 public sealed override void Advance()
 {
     if (_current.HasValue)
     {
         _sourcePos = _calculatePos(_current.GetValueOrDefault(), _sourcePos);
     }
     _pos++;
     SetCurrent();
 }
Exemplo n.º 11
0
        public void ModelMapperPosfix()
        {
            var source = new SourcePos
            {
                ValueData  = 999,
                Value2Data = 6666
            };
            var dest = mapper.Map <DestPos>(source);

            Assert.AreEqual(dest.Value, source.ValueData);
            Assert.AreEqual(dest.Value2, source.Value2Data);
        }
Exemplo n.º 12
0
        protected sealed override void Rewind(Positioned <int> bookmark)
        {
            if (_bufPos == _bufSize && _current.HasValue)
            {
                // we were writing to the buffer before the rewind,
                // so don't forget to store the last value
                PushBuf(_current.GetValueOrDefault());
            }
            _bufPos  = bookmark.Value;
            _current = _bufPos >= _bufSize
                ? Maybe.Nothing <TToken>()
                : Maybe.Just(Buffer[_bufPos]);

            _sourcePos = bookmark.Pos;
        }
Exemplo n.º 13
0
        private static string Process(MacroProcessor MP, string codeStr, int lineZero)
        {
            VList <LNode> output = VList <LNode> .Empty;
            var           msgs   = new MessageHolder();

            using (MessageSink.PushCurrent(msgs))
            {
                var code = EcsLanguageService.Value.Parse(codeStr, msgs);
                if (!msgs.List.Any(m => m.Severity >= Severity.Error))
                {
                    output = MP.ProcessSynchronously(LNode.List(code));
                }
            }
            foreach (var m in msgs.List)
            {
                // Goal: add lineNo to line number of error message to get correct line number
                object    loc = MessageSink.LocationOf(m.Context);
                SourcePos pos = default(SourcePos);
                if (loc is SourceRange)
                {
                    pos = ((SourceRange)loc).Start;
                }
                else if (loc is SourcePos)
                {
                    pos = ((SourcePos)loc);
                }
                else
                {
                    pos = new SourcePos("Unknown", 0, 0);
                }
                pos = new SourcePos(pos.FileName, pos.Line + lineZero, pos.PosInLine);

                MessageSink.Current.Write(m.Severity, pos, m.Format, m.Args);
            }
            if (msgs.List.Any(m => m.Severity >= Severity.Error))
            {
                return(null);
            }
            else
            {
                return(EcsLanguageService.Value.Print(output, null, null, "  ", "\n"));
            }
        }
Exemplo n.º 14
0
        public new virtual void Error(int lookaheadIndex, string format, params object[] args)
        {
            int       index = InputPosition + lookaheadIndex;
            SourcePos pos;

            if (SourceFile == null)
            {
                pos = new SourcePos(FileName, LineNumber, index - LineStartAt + 1);
            }
            else
            {
                pos = SourceFile.IndexToLine(index);
            }

            if (ErrorSink != null)
            {
                if (args != null)
                {
                    ErrorSink.Write(Severity.Error, pos, format, args);
                }
                else
                {
                    ErrorSink.Write(Severity.Error, pos, format);
                }
            }
            else
            {
                string msg;
                if (args != null)
                {
                    msg = Localize.From(format, args);
                }
                else
                {
                    msg = Localize.From(format);
                }
                throw new FormatException(pos + ": " + msg);
            }
        }
Exemplo n.º 15
0
        public sealed override void Advance()
        {
            if (_current.HasValue)
            {
                _sourcePos = _calculatePos(_current.GetValueOrDefault(), _sourcePos);
            }
            if (_bufPos < _bufSize)
            {
                // we are re-reading previously buffered input
                _bufPos++;
                if (_bufPos < _bufSize)
                {
                    _current = Maybe.Just(Buffer[_bufPos]);
                    return;
                }
            }
            else if (!IsBuffering)
            {
                if (_buffer != null)
                {
                    // an explanatory Haiku:
                    //
                    // At end of buffer,
                    // not right now writing to it.
                    // Buffer: discarded.
                    _bufPos = _bufSize = 0;
                    ArrayPool <TToken> .Shared.Return(_buffer);

                    _buffer = null;
                }
            }
            else if (_current.HasValue)
            {
                // don't forget the old value
                PushBuf(_current.GetValueOrDefault());
            }

            _current = AdvanceInput();
        }
Exemplo n.º 16
0
        public Token Lex()
        {
            while (true)
            {
                // Reset token
                tokenStart = GetPosition();
                tokenValue = "";
                skipToken  = false;

                // Handle EOF
                if (EOF)
                {
                    return(MakeToken(Token.EOF));
                }

                // Advance to next character
                Consume();

                // Lex a single token
                var type = LexOne();
                if (type != null)
                {
                    return(MakeToken(type));
                }
                if (skipToken)
                {
                    continue;
                }

                // Handle error
                if (!isError)
                {
                    errorStart = tokenStart;
                }
                isError     = true;
                errorValue += tokenValue;
            }
        }
Exemplo n.º 17
0
 internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out SourcePos result)
 {
     result = state.ComputeSourcePos();
     return(true);
 }
Exemplo n.º 18
0
Arquivo: Value.cs Projeto: cakoose/cks
 public Value(SourcePos SourcePos)
     : base(SourcePos)
 {
 }
Exemplo n.º 19
0
 public void AddStacktraceElement(string funcall, SourcePos pos)
 {
     stacktrace.AddElement(funcall, pos);
 }
Exemplo n.º 20
0
 public ControlErrorException(Value type, Value msg, SourcePos pos, Stacktrace stacktrace) : base(pos)
 {
     this.type       = type;
     this.msg        = msg;
     this.stacktrace = stacktrace;
 }
Exemplo n.º 21
0
 public ControlErrorException(Value type, string msg, SourcePos pos, Stacktrace stacktrace) : base(pos)
 {
     this.type       = type;
     this.msg        = new ValueString(msg);
     this.stacktrace = stacktrace;
 }
Exemplo n.º 22
0
 public ControlErrorException(Value type, string message, SourcePos pos) : base(pos)
 {
     this.type  = type;
     msg        = new ValueString(message);
     stacktrace = new Stacktrace();
 }
Exemplo n.º 23
0
 protected sealed override void Rewind(Positioned <int> bookmark)
 {
     _pos = bookmark.Value;
     SetCurrent();
     _sourcePos = bookmark.Pos;
 }
Exemplo n.º 24
0
 public ControlDivideByZeroException(string msg, SourcePos pos, Stacktrace stacktrace)
     : base(new ValueString("ERROR"), msg, pos, stacktrace)
 {
 }
Exemplo n.º 25
0
 public ValueControlReturn(Value value, SourcePos pos)
 {
     this.value = value;
     this.pos   = pos;
 }
Exemplo n.º 26
0
 public Token(string value, TokenType type, SourcePos pos)
 {
     this.value = value;
     this.type  = type;
     this.pos   = pos;
 }
Exemplo n.º 27
0
 public LexerSourceFile(CharSource source, SourcePos startingPos = null) : base(source, startingPos)
 {
 }
Exemplo n.º 28
0
        /// <summary>This method is called to format and handle errors that occur
        /// during lexing. The default implementation sends errors to <see cref="ErrorSink"/>,
        /// which, by default, throws a <see cref="FormatException"/>.</summary>
        /// <param name="lookaheadIndex">Index where the error occurred, relative to
        /// the current InputPosition (i.e. InputPosition + lookaheadIndex is the
        /// position of the error).</param>
        /// <param name="format">An error description with argument placeholders.</param>
        /// <param name="args">Arguments to insert into the error message.</param>
        protected virtual void Error(int lookaheadIndex, string format, params object[] args)
        {
            SourcePos pos = IndexToLine(InputPosition + lookaheadIndex);

            ErrorSink.Write(Severity.Error, pos, format, args);
        }
Exemplo n.º 29
0
 /// <summary>
 /// Adds a new item to the <see cref="MemoryMap"/>.
 /// </summary>
 /// <param name="position">The memory address to add the item at.</param>
 /// <param name="sourcePosition">The <see cref="SourcePos"/> source position at which this occurs.</param>
 /// <param name="value">The <see cref="object"/> value to add to memory.</param>
 public void AddMemory(int position, SourcePos sourcePosition, object value)
 {
     Memory.Add(position, value);
     SourcePositions.Add(position, sourcePosition);
 }
Exemplo n.º 30
0
 public ValueControlBreak(SourcePos pos)
 {
     this.pos = pos;
 }
Exemplo n.º 31
0
 public ControlDivideByZeroException(string message, SourcePos pos)
     : base(new ValueString("ERROR"), message, pos)
 {
 }