StringOf() public static method

public static StringOf ( Token tokens ) : string
tokens Token
return string
Exemplo n.º 1
0
        private void Expect(TokenType[] types, bool identifierAllowed = true)
        {
            var next = _scanner.PeekToken();

            if (next == null)
            {
                throw new EvaluatorException(_scanner.Column,
                                             string.Format("Unexpected end of input, instead of token(s): {0}{1}.", identifierAllowed ? "'IDENT', " : "", Token.StringOf(types)));
            }
            if ((identifierAllowed && next.Type == TokenType.Identifier) ||
                types.Contains(next.Type))
            {
                Consume();
            }
            else
            {
                throw new EvaluatorException(_scanner.Column,
                                             string.Format("Syntax error, expected token(s): {0}{1}; but found '{2}'.", identifierAllowed ? "'IDENT', " : "", Token.StringOf(types), Token.StringOf(next)));
            }
        }
Exemplo n.º 2
0
        private void Expect(TokenType type)
        {
            var next = _scanner.PeekToken();

            if (next == null)
            {
                throw new EvaluatorException(_scanner.Column,
                                             string.Format("Unexpected end of input, instead of token(s): 'LITERAL', '{0}'.", Token.StringOf(type)));
            }
            if (next.Type == type)
            {
                Consume();
            }
            else
            {
                throw new EvaluatorException(_scanner.Column,
                                             string.Format("Syntax error, expected token(s) 'LITERAL', '{0}'; but found '{1}'.", Token.StringOf(type), Token.StringOf(next)));
            }
        }
Exemplo n.º 3
0
 private void Ensure(TokenType[] types, bool identifierAllowed = true)
 {
     if (_current == null)
     {
         throw new EvaluatorException(_scanner.Column,
                                      string.Format("Unexpected end of input, instead of token(s): {0}{1}.", identifierAllowed ? "'IDENT', " : "", Token.StringOf(types)));
     }
     if (!((identifierAllowed && _current.Type == TokenType.Identifier) ||
           types.Contains(_current.Type)))
     {
         throw new EvaluatorException(_scanner.Column,
                                      string.Format("Syntax error, expected token(s): 'IDENT', {0}; but found '{1}'.", Token.StringOf(types), Token.StringOf(_current)));
     }
 }