// ReSharper disable once UnusedParameter.Local private void ValidateToken(TokenId t, string errorMessage) { if (_token.id != t) { throw ParseException.Create(_token.pos, errorMessage); } }
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; } } }
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(); } }
public BinaryExpression(TokenId op, ExpressionNode left, ExpressionNode right) : base(left.RelatedToken) { _op = op; _left = left; _right = right; }
/// <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); }
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()); }
public static void Validate(this Token token, TokenId t, Exception exc) { if (!token.Is(t)) { throw exc; } }
public static void Validate(this Token token, TokenId t, string errorMessage) { if (!token.Is(t)) { throw Error.GenericSyntaxError(token, errorMessage); } }
// ReSharper disable once UnusedParameter.Local private void ValidateToken(TokenId t) { if (_token.id != t) { throw ParseException.Create(_token.pos, ErrorMessages.SyntaxError); } }
public Token(TokenId id, string text, int line, int col) { Id = id; Text = text; Line = line; Col = col; }
public MemberAccessExpression(ExpressionNode left, ExpressionNode right, TokenId qualifierKind, bool isMember) : base(left.RelatedToken) { _left = left; _right = right; _isMember = isMember; }
public Token(string text, TokenId tokenId, int pos, SourceRange range) { _text = text; _tokenId = tokenId; _pos = pos; _range = range; }
private Token Symbol(TokenId symbol, int len) { var t = new Token(symbol, Line, Col - (len - 1)); Col += len; return(t); }
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)); } }
public Token(TokenId id, int line, int col) { Id = id; Text = string.Empty; Line = line; Col = col; }
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); }
internal void Reset() { tokenId = TokenId.None; argument = 0; whole.Reset(); wholePosition.Reset(); }
public TokenId MakeEmptyToken(TokenId tokenId) { token.tokenId = tokenId; state = 5; tokenValid = true; return(tokenId); }
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); }
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); }
public Token(TokenId tokenId, string data, Location startLocation, Location endLocation) { _tokenId = tokenId; _data = data; _startLocation = startLocation; _endLocation = endLocation; }
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); }
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); }
public Token(string idText, int line, int col) { Id = TokenId.Id; Text = idText; Line = line; Col = col; }
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); } }
public Token(string idText) { Id = TokenId.Id; Text = idText; Line = 0; Col = 0; }
internal void ValidateToken(TokenId t) { if (this.token.Id != t) { throw ParseError(Strings.RequestQueryParser_SyntaxError(this.textPos)); } }
public void ValidateToken(TokenId t, string errorMessage) { if (CurrentToken.Id != t) { throw ParseError(errorMessage); } }
public void ValidateToken(TokenId t) { if (CurrentToken.Id != t) { throw ParseError(Res.SyntaxError); } }
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; } } }
public Token(string text) { Id = TokenId.Id; Text = text; Line = -1; Col = -1; }
/// <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; }
private bool Match(TokenId tokenID) { if (_token.Id == tokenID) { NextToken(); return true; } _errorReporter.TokenExpected(_token.Range, _token.Text, tokenID); return false; }
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)); }
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)); } }
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; }
private void ValidateToken(TokenId t) { if (this._token.Id != t) throw this.ParseError("Syntax error", new object[0]); }
private void ValidateToken(TokenId t, string errorMessage) { if (this._token.Id != t) throw this.ParseError(errorMessage, new object[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); }
private void ValidateToken(TokenId t, string errorMessage) { if (token.id != t) throw ParseError(errorMessage); }
/// <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; }
void ValidateToken(TokenId t) { if (_token.id != t) throw CreateParseException(_token.pos, ErrorMessages.SyntaxError); }
public Token(TokenId tokenId) { _tokenId = tokenId; _startLocation = new Location(-1, -1); _endLocation = new Location(-1, -1); }
/// <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)); } }
void ValidateToken(TokenId t) { if (token.id != t) throw ParseError(ErrorMessages.SyntaxError); }
/// <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; }
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; }
public static TokenInfo FromTokenId(TokenId tokenId) { return _infosById[tokenId]; }
public Token(TokenId tokenId, int lineIndex, int characterIndex) { _tokenId = tokenId; _startLocation = new Location(lineIndex, characterIndex); _endLocation = new Location(lineIndex, characterIndex + 1); }
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); }
void ValidateToken(TokenId t, string errorMessage) { if (_token.id != t) throw CreateParseException(_token.pos, errorMessage); }
private void ValidateToken(TokenId t) { if (token.id != t) throw ParseError(Res.SyntaxError); }
public Token(TokenId tokenId, Location startLocation, Location endLocation) { _tokenId = tokenId; _startLocation = startLocation; _endLocation = endLocation; }
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)); } }