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()); }
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(); }
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); }
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; }
protected override void Error(int li, string message) { int iPos = GetTextPosition(InputPosition + li); SourcePos pos = _sourceFile.IndexToLine(iPos); _messages.Write(_Error, pos, message); }
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); }
protected void ReportError(SourcePos pos, string message) { if (!isError) { file.ReportError(new SourceError(pos, message)); } isError = true; }
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); }
protected void ConsumeAndReportError(SourcePos pos, string message) { if (isError) { Consume(); isError = true; } ReportError(pos, message); }
public sealed override void Advance() { if (_current.HasValue) { _sourcePos = _calculatePos(_current.GetValueOrDefault(), _sourcePos); } _pos++; SetCurrent(); }
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); }
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; }
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")); } }
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); } }
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(); }
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; } }
internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out SourcePos result) { result = state.ComputeSourcePos(); return(true); }
public Value(SourcePos SourcePos) : base(SourcePos) { }
public void AddStacktraceElement(string funcall, SourcePos pos) { stacktrace.AddElement(funcall, pos); }
public ControlErrorException(Value type, Value msg, SourcePos pos, Stacktrace stacktrace) : base(pos) { this.type = type; this.msg = msg; this.stacktrace = stacktrace; }
public ControlErrorException(Value type, string msg, SourcePos pos, Stacktrace stacktrace) : base(pos) { this.type = type; this.msg = new ValueString(msg); this.stacktrace = stacktrace; }
public ControlErrorException(Value type, string message, SourcePos pos) : base(pos) { this.type = type; msg = new ValueString(message); stacktrace = new Stacktrace(); }
protected sealed override void Rewind(Positioned <int> bookmark) { _pos = bookmark.Value; SetCurrent(); _sourcePos = bookmark.Pos; }
public ControlDivideByZeroException(string msg, SourcePos pos, Stacktrace stacktrace) : base(new ValueString("ERROR"), msg, pos, stacktrace) { }
public ValueControlReturn(Value value, SourcePos pos) { this.value = value; this.pos = pos; }
public Token(string value, TokenType type, SourcePos pos) { this.value = value; this.type = type; this.pos = pos; }
public LexerSourceFile(CharSource source, SourcePos startingPos = null) : base(source, startingPos) { }
/// <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); }
/// <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); }
public ValueControlBreak(SourcePos pos) { this.pos = pos; }
public ControlDivideByZeroException(string message, SourcePos pos) : base(new ValueString("ERROR"), message, pos) { }