Beispiel #1
0
        private void ReportFormattedError(Error error, params object[] args)
        {
            BufferPosition position = _text.Position;

            position.Line -= 1;
            ReportError(error, position, args);
        }
Beispiel #2
0
 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;
 }
Beispiel #3
0
        private void ReportError(Error error)
        {
            BufferPosition position = _text.Position;

            position.Line -= 1;
            ReportError(error, position);
        }
Beispiel #4
0
 private void ReportError(Error error, BufferPosition position, params object[] args)
 {
     if (OnError != null)
     {
         OnError(this, new FileErrorEventArgs(error, _lineMap.Map(position), args));
     }
 }
Beispiel #5
0
 private void ReportError(Error error, BufferPosition position, params object[] args)
 {
     if (OnError != null)
     {
         OnError(this, new ErrorEventArgs(error, position, args));
     }
 }
Beispiel #6
0
        private BufferPosition TakePosition()
        {
            _lastLine = _text.Line;
            BufferPosition position = _position;

            ClearPosition();
            return(position);
        }
Beispiel #7
0
 /// <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);
 }
Beispiel #8
0
        /// <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));
        }
Beispiel #9
0
 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;
 }
Beispiel #11
0
 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;
 }
Beispiel #13
0
 internal BooleanToken(bool value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Boolean, sourcePath, position)
 {
     _value = value;
 }
Beispiel #14
0
 public FilePosition(BufferPosition position, string fileName)
 {
     _position = position;
     _fileName = fileName;
 }
Beispiel #15
0
        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));
        }
Beispiel #16
0
 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;
 }
Beispiel #18
0
 internal DecimalToken(decimal value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Decimal, sourcePath, position)
 {
     _value = value;
 }
Beispiel #19
0
 internal Token(TokenType type, string sourcePath, BufferPosition position) {
     _type = type;
     _sourcePath = sourcePath;
     _position = position;
 }
Beispiel #20
0
 private void StartToken()
 {
     _position = _text.Position;
 }
Beispiel #21
0
 private void ClearPosition()
 {
     _position = new BufferPosition();
 }
Beispiel #22
0
 public ErrorEventArgs(Error error, BufferPosition position, params object[] args)
 {
     _error    = error;
     _position = position;
     _args     = args;
 }
Beispiel #23
0
 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;
 }
Beispiel #25
0
 public int CompareTo(BufferPosition pos)
 {
     if (this < pos) {
         return -1;
     }
     else if (this == pos) {
         return 0;
     }
     else {
         return 1;
     }
 }
Beispiel #26
0
 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));
     }
 }
Beispiel #30
0
 internal NullToken(string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Null, sourcePath, position) {
 }
Beispiel #31
0
 internal ULongToken(ulong value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.ULong, sourcePath, position)
 {
     _value = value;
 }
Beispiel #32
0
 internal FloatToken(float value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Float, sourcePath, position) {
     _value = value;
 }
Beispiel #33
0
 public PreprocessorStringToken(string value, BufferPosition position)
     : base(PreprocessorTokenType.String, position)
 {
     _value = value;
 }
Beispiel #34
0
 internal IdentifierToken(Name identifier, bool atPrefixed, string sourcePath, BufferPosition position)
     : base(TokenType.Identifier, sourcePath, position) {
     _symbol = identifier;
     _atPrefixed = atPrefixed;
 }
Beispiel #35
0
 private void ClearPosition() {
     _position = new BufferPosition();
 }
Beispiel #36
0
 public ErrorEventArgs(Error error, BufferPosition position, params object[] args)
 {
     _error = error;
     _position = position;
     _args = args;
 }
Beispiel #37
0
 private void StartToken() {
     _position = _text.Position;
 }
 private PreprocessorToken NewPPToken(PreprocessorTokenType type, BufferPosition position)
 {
     return new PreprocessorToken(type, position);
 }
Beispiel #39
0
 internal CommentToken(CommentTokenType type, string comment, string sourcePath, BufferPosition position)
     : base(TokenType.Comment, sourcePath, position) {
     _commentType = type;
     _comment = comment;
 }
Beispiel #40
0
 public FilePosition(BufferPosition position, string fileName)
 {
     _position = position;
     _fileName = fileName;
 }
Beispiel #41
0
 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;
 }
Beispiel #43
0
 internal LiteralToken(LiteralTokenType literalType, string sourcePath, BufferPosition position)
     : base(TokenType.Literal, sourcePath, position)
 {
     _literalType = literalType;
 }