Ejemplo n.º 1
0
 // ReSharper disable once UnusedParameter.Local
 private void ValidateToken(TokenId t, string errorMessage)
 {
     if (_token.id != t)
     {
         throw ParseException.Create(_token.pos, errorMessage);
     }
 }
Ejemplo n.º 2
0
        private void ReadMultilineComment()
        {
            _reader.Pos += 2;

            while (true)
            {
                switch (_reader.Char)
                {
                case CharReader.EOF:
                    _errorReporter.UnterminatedComment(_tokenRange.StartLocation, _source.Substring(_tokenStart, _reader.Pos - _tokenStart));
                    _tokenId = TokenId.Eof;
                    return;

                case '*':
                    if (_reader.Peek() == '/')
                    {
                        _reader.Pos++;
                        return;
                    }
                    _reader.Pos++;
                    break;

                default:
                    _reader.Pos++;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public void Reconocer(Context context)
        {
            try
            {
                int caracter = (int)this.cadena[indice];

                if ((caracter > 96 && caracter < 123) || (caracter > 47 && caracter < 58))
                {
                    lexema += this.cadena[indice];
                    Estado_1 e1 = new Estado_1(indice + 1, cadena, lexema);
                    e1.Reconocer(context);
                }
                else
                {
                    Token t = new TokenId(lexema);

                    Estatico.t.Text += t.mostrarToken();

                    lexema = "";
                    Estado_0 e0 = new Estado_0(indice, cadena, lexema);
                    e0.Reconocer(context);
                }
            }
            catch (Exception e)
            {
                Token t = new TokenId(lexema);

                Estatico.t.Text += t.mostrarToken();
            }
        }
Ejemplo n.º 4
0
 public BinaryExpression(TokenId op, ExpressionNode left, ExpressionNode right)
     : base(left.RelatedToken)
 {
     _op = op;
     _left = left;
     _right = right;
 }
Ejemplo n.º 5
0
 /// <summary>Whether the specified token identifier is a numeric literal.</summary>
 /// <param name="id">Token to check.</param>
 /// <returns>true if it's a numeric literal; false otherwise.</returns>
 internal static bool IsNumeric(TokenId id)
 {
     return
         (id == TokenId.IntegerLiteral || id == TokenId.DecimalLiteral ||
          id == TokenId.DoubleLiteral || id == TokenId.Int64Literal ||
          id == TokenId.SingleLiteral);
 }
Ejemplo n.º 6
0
        IParseElement[] GetSequence(int start, int end)
        {
            List <IParseElement> elements = new List <IParseElement>();

            uint inGroup = 0;

            for (int i = start; i <= end; i++)
            {
                TokenId id = tokens[i].TokenId;

                // First check groups.
                for (int j = 0; j < groupInfo.Length; j++)
                {
                    if (groupInfo[j].StartToken == id)
                    {
                        inGroup++;
                    }
                    if (groupInfo[j].EndToken == id)
                    {
                        inGroup--;
                    }
                }

                if (inGroup == 0)
                {
                    elements.Add(Parse(start, i));
                    start = i + 1;
                }
            }

            return(elements.ToArray());
        }
Ejemplo n.º 7
0
 public static void Validate(this Token token, TokenId t, Exception exc)
 {
     if (!token.Is(t))
     {
         throw exc;
     }
 }
Ejemplo n.º 8
0
 public static void Validate(this Token token, TokenId t, string errorMessage)
 {
     if (!token.Is(t))
     {
         throw Error.GenericSyntaxError(token, errorMessage);
     }
 }
Ejemplo n.º 9
0
 // ReSharper disable once UnusedParameter.Local
 private void ValidateToken(TokenId t)
 {
     if (_token.id != t)
     {
         throw ParseException.Create(_token.pos, ErrorMessages.SyntaxError);
     }
 }
Ejemplo n.º 10
0
 public Token(TokenId id, string text, int line, int col)
 {
     Id   = id;
     Text = text;
     Line = line;
     Col  = col;
 }
Ejemplo n.º 11
0
 public BinaryExpression(TokenId op, ExpressionNode left, ExpressionNode right)
     : base(left.RelatedToken)
 {
     _op    = op;
     _left  = left;
     _right = right;
 }
Ejemplo n.º 12
0
 public MemberAccessExpression(ExpressionNode left, ExpressionNode right, TokenId qualifierKind, bool isMember)
     : base(left.RelatedToken)
 {
     _left     = left;
     _right    = right;
     _isMember = isMember;
 }
Ejemplo n.º 13
0
 public Token(string text, TokenId tokenId, int pos, SourceRange range)
 {
     _text    = text;
     _tokenId = tokenId;
     _pos     = pos;
     _range   = range;
 }
Ejemplo n.º 14
0
        private Token Symbol(TokenId symbol, int len)
        {
            var t = new Token(symbol, Line, Col - (len - 1));

            Col += len;
            return(t);
        }
Ejemplo n.º 15
0
        private object EvalDoubleOperator(TokenId op, object value)
        {
            if (value is decimal)
            {
                return(EvalDecimalOperator(op, (decimal)value));
            }

            double v = Convert.ToDouble(value);

            switch (op)
            {
            case TokenId.Plus:
                return(v);

            case TokenId.Minus:
                return(-v);

            case TokenId.PlusPlus:
                return(++v);

            case TokenId.MinusMinus:
                return(--v);

            default:
                throw new ParseException(string.Format("Unary not support, tokenId: '{0}', value: {1} at line: {2} column:{3}", RelatedToken.TokenId, value, RelatedToken.StartLocation.LineIndex + 1, RelatedToken.StartLocation.CharacterIndex + 1));
            }
        }
Ejemplo n.º 16
0
 public Token(string text, TokenId tokenId, int pos, SourceRange range)
 {
     _text = text;
     _tokenId = tokenId;
     _pos = pos;
     _range = range;
 }
Ejemplo n.º 17
0
 public Token(TokenId id, int line, int col)
 {
     Id   = id;
     Text = string.Empty;
     Line = line;
     Col  = col;
 }
Ejemplo n.º 18
0
        private object Evaluate(TokenId op, object lValue)
        {
            object result = null;

            if (lValue == null)
            {
                result = false;
            }
            else if (Util.IsInteger(lValue))
            {
                result = EvalIntOperator(op, lValue);
            }
            else if (Util.IsNumber(lValue))
            {
                result = EvalDoubleOperator(op, lValue);
            }
            else if (lValue is bool)
            {
                result = EvalBooleanOperator(op, lValue);
            }
            else
            {
                throw new ParseException(string.Format("UnaryNotSupport '{0}' not exists at line: {1} column:{2}", RelatedToken.Data, RelatedToken.StartLocation.LineIndex + 1, RelatedToken.StartLocation.CharacterIndex + 1));
            }

            return(result);
        }
Ejemplo n.º 19
0
 internal void Reset()
 {
     tokenId  = TokenId.None;
     argument = 0;
     whole.Reset();
     wholePosition.Reset();
 }
Ejemplo n.º 20
0
 public TokenId MakeEmptyToken(TokenId tokenId)
 {
     token.tokenId = tokenId;
     state         = 5;
     tokenValid    = true;
     return(tokenId);
 }
Ejemplo n.º 21
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (OwnerAddress.Length != 0)
            {
                hash ^= OwnerAddress.GetHashCode();
            }
            if (ExchangeId != 0L)
            {
                hash ^= ExchangeId.GetHashCode();
            }
            if (TokenId.Length != 0)
            {
                hash ^= TokenId.GetHashCode();
            }
            if (Quant != 0L)
            {
                hash ^= Quant.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Ejemplo n.º 22
0
 public Token(TokenId tokenId, string data, int lineIndex, int characterIndex, int length)
 {
     _tokenId = tokenId;
     _data = data;
     _startLocation = new Location(lineIndex, characterIndex);
     _endLocation = new Location(lineIndex, characterIndex + length);
 }
Ejemplo n.º 23
0
 public Token(TokenId tokenId, string data, Location startLocation, Location endLocation)
 {
     _tokenId = tokenId;
     _data = data;
     _startLocation = startLocation;
     _endLocation = endLocation;
 }
Ejemplo n.º 24
0
        private object Evaluate(TokenId op, object lValue, object rValue)
        {
            object result = null;

            if (Util.IsInteger(lValue) && Util.IsInteger(rValue))
            {
                result = EvalIntOperator(op, lValue, rValue);
            }
            else if (Util.IsNumber(lValue) && Util.IsNumber(rValue))
            {
                result = EvalDoubleOperator(op, lValue, rValue);
            }
            else if (lValue is DateTime && rValue is DateTime)
            {
                result = EvalDateTimeOperator(op, (DateTime)lValue, (DateTime)rValue);
            }
            else if (lValue is bool && rValue is bool)
            {
                result = EvalBooleanOperator(op, lValue, rValue);
            }
            else if (Util.IsString(lValue) || Util.IsString(rValue))
            {
                result = EvalStringOperator(op, lValue, rValue);
            }
            else
            {
                throw new ParseException("BinaryNotSupport '{0}' between type of '{1}' and '{2}'", op.ToString(), lValue.GetType().Name, rValue.GetType().Name);
            }

            return(result);
        }
Ejemplo n.º 25
0
        public static string Text(this TokenId value, bool as_symbol = true)
        {
            var result = "";

            switch (value)
            {
            case TokenId._EOT_:               result = "_EOT_"; break;

            case TokenId._ERROR_:             result = "_ERROR_"; break;

            case TokenId.NAME:                result = (as_symbol) ? "#" : "[A-Za-z]+"; break;

            case TokenId.INT:                 result = "([+-]?[1-9][0-9]*|0)"; break;

            case TokenId.BRACKET_OPEN:        result = "["; break;

            case TokenId.BRACKET_CLOSE:       result = "]"; break;

            case TokenId.PARENTESES_OPEN:     result = "("; break;

            case TokenId.PARENTESES_CLOSE:    result = ")"; break;

            case TokenId.PWR:                 result = "^"; break;

            case TokenId.DIV:                 result = "/"; break;

            default: result = $"{value}"; break;
            }
            return(result);
        }
Ejemplo n.º 26
0
 public Token(string idText, int line, int col)
 {
     Id   = TokenId.Id;
     Text = idText;
     Line = line;
     Col  = col;
 }
Ejemplo n.º 27
0
        private object EvalIntOperator(TokenId op, object value)
        {
            long result = Convert.ToInt64(value);

            switch (op)
            {
            case TokenId.Plus:
                break;

            case TokenId.Minus:
                result = -result;
                break;

            case TokenId.PlusPlus:
                ++result;
                break;

            case TokenId.MinusMinus:
                --result;
                break;

            default:
                throw new ParseException(string.Format("Unary not support, tokenId: '{0}', value: {1} at line: {2} column:{3}", RelatedToken.TokenId, value, RelatedToken.StartLocation.LineIndex + 1, RelatedToken.StartLocation.CharacterIndex + 1));
            }

            if (result >= Int32.MinValue && result <= Int32.MaxValue)
            {
                return((int)result);
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 28
0
 public Token(string idText)
 {
     Id   = TokenId.Id;
     Text = idText;
     Line = 0;
     Col  = 0;
 }
Ejemplo n.º 29
0
 internal void ValidateToken(TokenId t)
 {
     if (this.token.Id != t)
     {
         throw ParseError(Strings.RequestQueryParser_SyntaxError(this.textPos));
     }
 }
Ejemplo n.º 30
0
 public Token(TokenId tokenId, string data, Location startLocation, Location endLocation)
 {
     _tokenId       = tokenId;
     _data          = data;
     _startLocation = startLocation;
     _endLocation   = endLocation;
 }
Ejemplo n.º 31
0
 public void ValidateToken(TokenId t, string errorMessage)
 {
     if (CurrentToken.Id != t)
     {
         throw ParseError(errorMessage);
     }
 }
Ejemplo n.º 32
0
 public void ValidateToken(TokenId t)
 {
     if (CurrentToken.Id != t)
     {
         throw ParseError(Res.SyntaxError);
     }
 }
Ejemplo n.º 33
0
 public MemberAccessExpression(ExpressionNode left, ExpressionNode right, TokenId qualifierKind, bool isMember)
     : base(left.RelatedToken)
 {
     _left = left;
     _right = right;
     _isMember = isMember;
 }
Ejemplo n.º 34
0
        public IEnumerable <ITagSpan <LexTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            foreach (SnapshotSpan curSpan in spans)
            {
                if (curSpan.Snapshot != _lineCacheSnapshot)
                {
                    yield break;
                }

                ITextSnapshotLine line = curSpan.Start.GetContainingLine();

                _lexer.HaveLine(line.GetText(), _lineStartState[line.LineNumber]);
                int location = line.Start;

                while (location < line.End)
                {
                    int     length;
                    TokenId token = _lexer.Token(out length);

                    if (token != TokenId.Ignore)
                    {
                        var tokenSpan = new SnapshotSpan(curSpan.Snapshot, new Span(location, length));
                        if (tokenSpan.OverlapsWith(curSpan))
                        {
                            yield return(new TagSpan <LexTag>(tokenSpan, new LexTag(token)));
                        }
                    }

                    location += length;
                }
            }
        }
Ejemplo n.º 35
0
 public Token(string text)
 {
     Id   = TokenId.Id;
     Text = text;
     Line = -1;
     Col  = -1;
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Initializes an instance of the Token class.
 /// </summary>
 /// <param name="obj">The object.</param>
 /// <param name="col">The column.</param>
 /// <param name="line">The line.</param>
 /// <param name="pos">The position.</param>
 /// <param name="type">The type.</param>
 public Token(dynamic obj, int col, int line, int pos, TokenId type)
 {
     Object = obj;
     Column = col;
     Line = line;
     Position = pos;
     Type = type;
 }
Ejemplo n.º 37
0
        private bool Match(TokenId tokenID)
        {
            if (_token.Id == tokenID)
            {
                NextToken();
                return true;
            }

            _errorReporter.TokenExpected(_token.Range, _token.Text, tokenID);
            return false;
        }
Ejemplo n.º 38
0
        private object EvalBooleanOperator(TokenId op, object lValue)
        {
            bool v = Util.ToBool(lValue);

            switch (op)
            {
                case TokenId.Not: return !v;
            }

            throw new ParseException(string.Format("Unary not support, tokenId: '{0}', value: {1} at line: {2} column:{3}", RelatedToken.TokenId, lValue, RelatedToken.StartLocation.LineIndex + 1, RelatedToken.StartLocation.CharacterIndex + 1));
        }
Ejemplo n.º 39
0
 private object EvalDecimalOperator(TokenId op, decimal value)
 {
     switch (op)
     {
         case TokenId.Plus:
             return value;
         case TokenId.Minus:
             return -value;
         case TokenId.PlusPlus:
             return ++value;
         case TokenId.MinusMinus:
             return --value;
         default:
             throw new ParseException(string.Format("Unary not support, tokenId: '{0}', value: {1} at line: {2} column:{3}", RelatedToken.TokenId, value, RelatedToken.StartLocation.LineIndex + 1, RelatedToken.StartLocation.CharacterIndex + 1));
     }
 }
Ejemplo n.º 40
0
 private TokenInfo(TokenId tokenId, string text, bool isKeyword, bool isQueryKeyword, UnaryOperator unOp, BinaryOperator binOp)
 {
     _tokenId = tokenId;
     _text = text;
     _isKeyword = isKeyword;
     _isQueryKeyword = isQueryKeyword;
     _unaryOperator = unOp;
     _binaryOperator = binOp;
 }
Ejemplo n.º 41
0
 private void ValidateToken(TokenId t)
 {
     if (this._token.Id != t)
         throw this.ParseError("Syntax error", new object[0]);
 }
Ejemplo n.º 42
0
 private void ValidateToken(TokenId t, string errorMessage)
 {
     if (this._token.Id != t)
         throw this.ParseError(errorMessage, new object[0]);
 }
Ejemplo n.º 43
0
 void IErrorReporter.TokenExpected(SourceRange sourceRange, string foundTokenText, TokenId expected)
 {
     string message = String.Format(CultureInfo.CurrentCulture, Resources.TokenExpected, foundTokenText, TokenInfo.FromTokenId(expected).Text);
     HandleError(sourceRange, ErrorId.TokenExpected, message);
 }
Ejemplo n.º 44
0
 private void ValidateToken(TokenId t, string errorMessage)
 {
     if (token.id != t) throw ParseError(errorMessage);
 }
Ejemplo n.º 45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Token"/> class with the specified ID and extension data.
 /// </summary>
 /// <remarks>
 /// <para>This constructor is typically used for authentication requests which specified a <see cref="Token"/>
 /// as the credentials.</para>
 /// </remarks>
 /// <param name="id">The unique ID of the token.</param>
 /// <param name="extensionData">The extension data.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="extensionData"/> is <see langword="null"/>.</exception>
 public Token(TokenId id, ImmutableDictionary<string, JToken> extensionData)
     : base(extensionData)
 {
     _id = id;
 }
Ejemplo n.º 46
0
		void ValidateToken(TokenId t)
		{
			if (_token.id != t)
				throw CreateParseException(_token.pos, ErrorMessages.SyntaxError);
		}
Ejemplo n.º 47
0
 public Token(TokenId tokenId)
 {
     _tokenId = tokenId;
     _startLocation = new Location(-1, -1);
     _endLocation = new Location(-1, -1);
 }
Ejemplo n.º 48
0
 /// <summary>Validates the current token is of the specified kind.</summary>
 /// <param name="t">Expected token kind.</param>
 internal void ValidateToken(TokenId t)
 {
     if (this.token.Id != t)
     {
         throw ParseError(Strings.RequestQueryParser_SyntaxError(this.textPos));
     }
 }
Ejemplo n.º 49
0
 void ValidateToken(TokenId t)
 {
     if (token.id != t) throw ParseError(ErrorMessages.SyntaxError);
 }
Ejemplo n.º 50
0
 /// <summary>Whether the specified token identifier is a numeric literal.</summary>
 /// <param name="id">Token to check.</param>
 /// <returns>true if it's a numeric literal; false otherwise.</returns>
 internal static bool IsNumeric(TokenId id)
 {
     return 
         id == TokenId.IntegerLiteral || id == TokenId.DecimalLiteral ||
         id == TokenId.DoubleLiteral || id == TokenId.Int64Literal ||
         id == TokenId.SingleLiteral;
 }
Ejemplo n.º 51
0
 void ValidateToken(TokenId t)
 {
     if (_token.id != t)
     {
         throw ParseError(SRResources.SyntaxError);
     }
 }
 static TokenId GetAliasedTokenId(TokenId t, string alias)
 {
     TokenId id;
     return t == TokenId.Identifier && _predefinedAliases.TryGetValue(alias, out id) ? id : t;
 }
Ejemplo n.º 53
0
 public static TokenInfo FromTokenId(TokenId tokenId)
 {
     return _infosById[tokenId];
 }
Ejemplo n.º 54
0
 public Token(TokenId tokenId, int lineIndex, int characterIndex)
 {
     _tokenId = tokenId;
     _startLocation = new Location(lineIndex, characterIndex);
     _endLocation = new Location(lineIndex, characterIndex + 1);
 }
Ejemplo n.º 55
0
        private static void Add(TokenId tokenId, string text, bool isKeyword, bool isQueryKeyword, UnaryOperator unOp, BinaryOperator binOp)
        {
            TokenInfo info = new TokenInfo(tokenId, text, isKeyword, isQueryKeyword, unOp, binOp);

            _infosById.Add(tokenId, info);

            if (text != null)
                _infosByText.Add(text, info);
        }
Ejemplo n.º 56
0
		void ValidateToken(TokenId t, string errorMessage)
		{
			if (_token.id != t)
				throw CreateParseException(_token.pos, errorMessage);
		}
Ejemplo n.º 57
0
 private void ValidateToken(TokenId t)
 {
     if (token.id != t) throw ParseError(Res.SyntaxError);
 }
Ejemplo n.º 58
0
 public Token(TokenId tokenId, Location startLocation, Location endLocation)
 {
     _tokenId = tokenId;
     _startLocation = startLocation;
     _endLocation = endLocation;
 }
Ejemplo n.º 59
0
        public HttpResponseMessage PostAuthenticate([FromBody] AuthenticationRequest authenticationRequest)
        {
            MediaTypeHeaderValue acceptedType = new MediaTypeHeaderValue("application/json");
            MediaTypeHeaderValue contentType = Request.Content.Headers.ContentType;
            if (!HttpApiCall.IsAcceptable(acceptedType, contentType))
                return new HttpResponseMessage(HttpStatusCode.BadRequest);

            ValidateRequest(Request);

            if (authenticationRequest == null)
                return new HttpResponseMessage(HttpStatusCode.BadRequest);

            AuthenticationData authenticationData = authenticationRequest.AuthenticationData;
            if (authenticationData == null)
                return new HttpResponseMessage(HttpStatusCode.BadRequest);

            if (authenticationData.TenantName != null
                && !string.Equals(authenticationData.TenantName, _tenantName, StringComparison.OrdinalIgnoreCase))
                return new HttpResponseMessage(HttpStatusCode.Unauthorized);

            if (authenticationData.TenantId != null
                && authenticationData.TenantId != new ProjectId(_tenantId))
            {
                return new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }

            if (authenticationData.Token != null)
                throw new NotImplementedException();

            PasswordCredentials passwordCredentials = authenticationData.PasswordCredentials;
            if (passwordCredentials == null)
                return new HttpResponseMessage(HttpStatusCode.BadRequest);

            if (!string.Equals(passwordCredentials.Username, _username, StringComparison.OrdinalIgnoreCase)
                || !string.Equals(passwordCredentials.Password, _password, StringComparison.Ordinal))
            {
                return new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }

            bool hasTenant = authenticationData.TenantId != null || authenticationData.TenantName != null;

            string responseBody;
            if (hasTenant)
                responseBody = IdentityServiceResources.AuthenticateResponseTemplate;
            else
                responseBody = IdentityServiceResources.AuthenticateWithoutTenantResponseTemplate;

            lock (_lock)
            {
                var parameters = new Dictionary<string, string>();

                // expire the token 5 minutes early
                if (!_tokenExpires.HasValue || _tokenExpires < DateTimeOffset.Now - TimeSpan.FromMinutes(5))
                {
                    // generate a new token
                    _tokenCreated = DateTimeOffset.Now;
                    _tokenExpires = _tokenCreated + TimeSpan.FromHours(24);
                    _tokenId = new TokenId(Guid.NewGuid().ToString());
                }

                parameters["issued_at"] = JsonConvert.SerializeObject(_tokenCreated.Value);
                parameters["expires"] = JsonConvert.SerializeObject(_tokenExpires.Value);
                parameters["tokenId"] = JsonConvert.SerializeObject(_tokenId);
                parameters["tenantId"] = JsonConvert.SerializeObject(_tenantId);
                parameters["tenantName"] = JsonConvert.SerializeObject(_tenantName);
                parameters["username"] = JsonConvert.SerializeObject(_username);
                parameters["userId"] = JsonConvert.SerializeObject(_userId);
                parameters["userFullName"] = JsonConvert.SerializeObject(_userFullName);

                foreach (var pair in parameters)
                    responseBody = responseBody.Replace("{" + pair.Key + "}", JsonConvert.DeserializeObject<string>(pair.Value));
            }

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            result.Content = new StringContent(responseBody, Encoding.UTF8, "application/json");
            return result;
        }
 /// <summary>Validates the current token is of the specified kind.</summary>
 /// <param name="t">Expected token kind.</param>
 private void ValidateToken(TokenId t)
 {
     if (this.CurrentToken.Id != t)
     {
         throw ParseError(Strings.RequestQueryParser_SyntaxError(this.CurrentToken.Position));
     }
 }