private void ReportFormattedError(Error error, params object[] args) { BufferPosition position = _text.Position; position.Line -= 1; ReportError(error, position, args); }
private void ReportError(Error error, Token token, params object[] args) { BufferPosition newPosition = token.Position; if (OnError != null && lastErrorPosition != newPosition) { OnError(this, new ErrorEventArgs(error, newPosition, args)); } lastErrorPosition = newPosition; }
private void ReportError(Error error) { BufferPosition position = _text.Position; position.Line -= 1; ReportError(error, position); }
private void ReportError(Error error, BufferPosition position, params object[] args) { if (OnError != null) { OnError(this, new FileErrorEventArgs(error, _lineMap.Map(position), args)); } }
private void ReportError(Error error, BufferPosition position, params object[] args) { if (OnError != null) { OnError(this, new ErrorEventArgs(error, position, args)); } }
private BufferPosition TakePosition() { _lastLine = _text.Line; BufferPosition position = _position; ClearPosition(); return(position); }
/// <summary> /// Map a buffer position to a position in a file. /// </summary> public FilePosition Map(BufferPosition from) { MapEntry entry = FindEntry(from.Line); return new FilePosition( new BufferPosition( entry.to + (from.Line - entry.from), from.Column + 1, from.Offset), entry.fileName); }
/// <summary> /// Map a buffer position to a position in a file. /// </summary> public FilePosition Map(BufferPosition from) { MapEntry entry = FindEntry(from.Line); return(new FilePosition( new BufferPosition( entry.to + (from.Line - entry.from), from.Column + 1, from.Offset), entry.fileName)); }
public int CompareTo(BufferPosition pos) { if (this < pos) { return(-1); } else if (this == pos) { return(0); } else { return(1); } }
public PreprocessorIntToken(int value, BufferPosition position) : base(PreprocessorTokenType.Int, position) { _value = value; }
internal IntToken(int value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Int, sourcePath, position) { _value = value; }
public PreprocessorIntToken(int value, BufferPosition position) : base(PreprocessorTokenType.Int, position) { _value = value; }
internal BooleanToken(bool value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Boolean, sourcePath, position) { _value = value; }
public FilePosition(BufferPosition position, string fileName) { _position = position; _fileName = fileName; }
public PreprocessorToken NextToken(TextBuffer text) { _text = text; SkipWhiteSpace(); BufferPosition position = text.Position; char ch = PeekChar(); if (ch == '\0' || IsLineSeparator(ch)) { return(NewPPToken(PreprocessorTokenType.EndOfLine, position)); } ch = NextChar(); switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { int intValue = (ch - '0'); while (IsDigit(PeekChar())) { int value10 = intValue * 10; if (value10 < intValue) { ReportError(LexError.NumericConstantOverflow); } else { intValue = value10 + (NextChar() - '0'); } } return(new PreprocessorIntToken(intValue, position)); } case '=': if (PeekChar() == '=') { NextChar(); return(NewPPToken(PreprocessorTokenType.EqualEqual, position)); } break; case '!': if (PeekChar() == '=') { NextChar(); return(NewPPToken(PreprocessorTokenType.NotEqual, position)); } else { return(NewPPToken(PreprocessorTokenType.Not, position)); } case '&': if (PeekChar() == '&') { NextChar(); return(NewPPToken(PreprocessorTokenType.And, position)); } break; case '|': if (PeekChar() == '|') { NextChar(); return(NewPPToken(PreprocessorTokenType.Or, position)); } break; case '(': return(NewPPToken(PreprocessorTokenType.OpenParen, position)); case ')': return(NewPPToken(PreprocessorTokenType.CloseParen, position)); case '"': _value.Length = 0; while ((ch = PeekChar()) != '"') { if (EOF) { ReportError(LexError.UnexpectedEndOfFileString); break; } else if (IsLineSeparator(ch)) { ReportError(LexError.WhiteSpaceInConstant); break; } _value.Append(ch); NextChar(); } NextChar(); return(new PreprocessorStringToken(_value.ToString(), position)); case '/': if (PeekChar() == '/') { IgnoreRestOfLine(); return(NewPPToken(PreprocessorTokenType.EndOfLine, position)); } break; default: if (IsLineSeparator(ch)) { return(NewPPToken(PreprocessorTokenType.EndOfLine, position)); } if (!IsIdentifierChar(ch)) { break; } _value.Length = 0; _value.Append(ch); while (IsIdentifierChar(PeekChar())) { _value.Append(NextChar()); } Name id = _nameTable.Add(_value); PreprocessorTokenType type = _keywords.IsKeyword(id); if (type != PreprocessorTokenType.Invalid) { return(NewPPToken(type, position)); } else { return(new PreprocessorIdentifierToken(id, position)); } } return(NewPPToken(PreprocessorTokenType.Unknown, position)); }
private void ReportError(Error error, BufferPosition position, params object[] args) { if (OnError != null) { OnError(this, new FileErrorEventArgs(error, _lineMap.Map(position), args)); } }
public PreprocessorIdentifierToken(Name value, BufferPosition position) : base(PreprocessorTokenType.Identifier, position) { _value = value; }
internal DecimalToken(decimal value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Decimal, sourcePath, position) { _value = value; }
internal Token(TokenType type, string sourcePath, BufferPosition position) { _type = type; _sourcePath = sourcePath; _position = position; }
private void StartToken() { _position = _text.Position; }
private void ClearPosition() { _position = new BufferPosition(); }
public ErrorEventArgs(Error error, BufferPosition position, params object[] args) { _error = error; _position = position; _args = args; }
internal CharToken(char value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Char, sourcePath, position) { _value = value; }
public PreprocessorStringToken(string value, BufferPosition position) : base(PreprocessorTokenType.String, position) { _value = value; }
public int CompareTo(BufferPosition pos) { if (this < pos) { return -1; } else if (this == pos) { return 0; } else { return 1; } }
private PreprocessorToken NewPPToken(PreprocessorTokenType type, BufferPosition position) { return(new PreprocessorToken(type, position)); }
public PreprocessorIdentifierToken(Name value, BufferPosition position) : base(PreprocessorTokenType.Identifier, position) { _value = value; }
public PreprocessorToken(PreprocessorTokenType type, BufferPosition position) { _type = type; _position = position; }
private void ReportError(Error error, BufferPosition position, params object[] args) { if (OnError != null) { OnError(this, new ErrorEventArgs(error, position, args)); } }
internal NullToken(string sourcePath, BufferPosition position) : base(LiteralTokenType.Null, sourcePath, position) { }
internal ULongToken(ulong value, string sourcePath, BufferPosition position) : base(LiteralTokenType.ULong, sourcePath, position) { _value = value; }
internal FloatToken(float value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Float, sourcePath, position) { _value = value; }
public PreprocessorStringToken(string value, BufferPosition position) : base(PreprocessorTokenType.String, position) { _value = value; }
internal IdentifierToken(Name identifier, bool atPrefixed, string sourcePath, BufferPosition position) : base(TokenType.Identifier, sourcePath, position) { _symbol = identifier; _atPrefixed = atPrefixed; }
private void ClearPosition() { _position = new BufferPosition(); }
public ErrorEventArgs(Error error, BufferPosition position, params object[] args) { _error = error; _position = position; _args = args; }
private void StartToken() { _position = _text.Position; }
private PreprocessorToken NewPPToken(PreprocessorTokenType type, BufferPosition position) { return new PreprocessorToken(type, position); }
internal CommentToken(CommentTokenType type, string comment, string sourcePath, BufferPosition position) : base(TokenType.Comment, sourcePath, position) { _commentType = type; _comment = comment; }
public FilePosition(BufferPosition position, string fileName) { _position = position; _fileName = fileName; }
internal DoubleToken(double value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Double, sourcePath, position) { _value = value; }
public PreprocessorToken(PreprocessorTokenType type, BufferPosition position) { _type = type; _position = position; }
internal LiteralToken(LiteralTokenType literalType, string sourcePath, BufferPosition position) : base(TokenType.Literal, sourcePath, position) { _literalType = literalType; }