private void Block() { while (!Tokens.Check(RIGHT_BRACE) && !Tokens.IsAtEnd()) { Declaration(); } Tokens.Consume(RIGHT_BRACE, "Expect '}' after block."); return; }
/// <summary> /// Recupera os dados do usuário pelo token informado. /// </summary> /// <param name="token"></param> /// <param name="userIsOnline"></param> /// <returns></returns> public Security.IUser GetUserByToken(string token, bool userIsOnline) { var result = Tokens.Check(token); if (result == null || !result.Success) { return(null); } return(GetUserByKey(result.UserId.ToString(), true)); }
/// <summary> /// classDecl → "class" IDENTIFIER ( "<" IDENTIFIER )? /// "{" function* "}" ; /// </summary> private void ClassDeclaration() { Token className = Tokens.Consume(IDENTIFIER, "Expect class name."); int nameConstant = MakeStringConstant(className.Lexeme); // no fixup needed DeclareVariable(className); // The class name binds the class object type to a variable of the same name. // todo? make the class declaration an expression, require explicit binding of class to variable (like var Pie = new Pie()); 27.2 EmitOpcode(className.Line, OP_CLASS); EmitConstantIndex(className.Line, nameConstant, _FixupStrings); DefineVariable(className.Line, MakeBitStrConstant(className.Lexeme)); _CurrentClass = new LoxCompilerClass(className, _CurrentClass); // superclass: if (Tokens.Match(LESS)) { Tokens.Consume(IDENTIFIER, "Expect superclass name."); if (Tokens.Previous().Lexeme == className.Lexeme) { throw new CompilerException(Tokens.Previous(), "A class cannot inherit from itself."); } NamedVariable(Tokens.Previous(), false); // push super class onto stack BeginScope(); AddLocal(MakeSyntheticToken(SUPER, "super", LineOfLastToken)); DefineVariable(LineOfLastToken, 0); NamedVariable(className); // push class onto stack EmitOpcode(className.Line, OP_INHERIT); _CurrentClass.HasSuperClass = true; } NamedVariable(className); // push class onto stack // body: Tokens.Consume(LEFT_BRACE, "Expect '{' before class body."); while (!Tokens.Check(RIGHT_BRACE) && !Tokens.IsAtEnd()) { // lox doesn't have field declarations, so anything before the brace that ends the class body must be a method. // initializer is a special method MethodDeclaration("method", ELoxFunctionType.TYPE_METHOD); } Tokens.Consume(RIGHT_BRACE, "Expect '}' after class body."); EmitOpcode(LineOfLastToken, OP_POP); // pop class from stack if (_CurrentClass.HasSuperClass) { EndScope(); } _CurrentClass = _CurrentClass.Enclosing; return; }
/// <summary> /// Recupera os dados do usuário pelo token informado. /// </summary> /// <param name="token"></param> /// <param name="userIsOnline"></param> /// <returns></returns> public IUser GetUserByToken(string token, bool userIsOnline) { if (!Net.ServicesConfiguration.Current.Contains(UserProviderServiceClientConfigurationName)) { return(null); } // Verifica se o token é válido var result = Tokens.Check(token); if (result == null || !result.Success) { return(null); } // Recupera os dados do usuário com base no token informado var user = UserProviderClient.GetUserByToken(token, userIsOnline); return(user == null ? null : new Wrappers.UserWrapper(user)); }
/// <summary> /// arguments → expression ( "," expression )* ; /// /// Requires one or more argument expressions, followed by zero or more expressions each preceded by a comma. /// To handle zero-argument calls, the call rule itself considers the entire arguments production optional. /// </summary> private void FinishCall(EGearsOpCode opCode) { int argumentCount = 0; if (!Tokens.Check(RIGHT_PAREN)) { do { if (argumentCount >= MAX_PARAMS) { throw new CompilerException(Tokens.Peek(), $"Cannot have more than {MAX_PARAMS} arguments."); } Expression(); argumentCount += 1; } while (Tokens.Match(COMMA)); } Tokens.Consume(RIGHT_PAREN, "Expect ')' ending call operator parens (following any arguments)."); EmitOpcode(LineOfLastToken, opCode); EmitData(LineOfLastToken, (byte)argumentCount); }
private void FunctionBody() { BeginScope(); Tokens.Consume(LEFT_PAREN, $"Expect '(' after function name."); // parameter list: if (!Tokens.Check(RIGHT_PAREN)) { do { int paramConstant = ParseVariable("Expect parameter name."); DefineVariable(LineOfLastToken, paramConstant); if (++Arity >= MAX_PARAMS) { throw new CompilerException(Tokens.Peek(), $"Cannot have more than {MAX_PARAMS} parameters."); } } while (Tokens.Match(COMMA)); } Tokens.Consume(RIGHT_PAREN, "Expect ')' after parameters."); // body: Tokens.Consume(LEFT_BRACE, "Expect '{' before function body."); Block(); // no need for end scope, as functions are each compiled by their own compiler object. }
/// <summary> /// Verifica se um token está ou não válido /// </summary> /// <param name="userName"></param> /// <param name="token">token</param> /// <returns>Objeto com o resultado da consulta</returns> public Security.TokenConsultResult Check(string userName, string token) { return(Tokens.Check(token)); }
/// <summary> /// Verifica se o token é válido. /// </summary> /// <param name="token">Token.</param> /// <returns>True caso seja válido.</returns> public TokenConsultResult Check(string token) { return(Tokens.Check(token)); }