public async Task Deposit(IEnumerable <Token> tokens, CancellationToken cancellationToken) { using (var iterator = tokens.GetEnumerator()) { if (!iterator.MoveNext()) { return; } var token = iterator.Current; var mintRequestId = TokenIdentifier.Parse(token.Id).MintRequestId; var list = new List <Token>() { token }; await repository.Save(token, ExpectedVersion.Initial, cancellationToken); while (iterator.MoveNext()) { token = iterator.Current; await repository.Save(token, ExpectedVersion.Initial, cancellationToken); list.Add(token); } deposited.Add(mintRequestId, list); } }
private void parseLabel() { TokenIdentifier ident = readToken() as TokenIdentifier; readToken(); this.instructions.Add(new Label(ident.Value)); }
public Expr Parse(ParserContext context) { // Ensure current token is parentheses start. context.Stream.EnsureCurrent(TokenType.SymbolParenthesesL); // Peek at the next token. Token peek = context.Stream.Peek(); // Lambda expresion. if (TokenIdentifier.IsType(peek, context) || peek.Type == TokenType.SymbolParenthesesR) { // Delegate to the lambda expression parser. return(new LambdaExprParser().Parse(context)); } // Skip the parentheses start token. context.Stream.Skip(); // Parse the expression. Expr expr = new ExprParser().Parse(context); // Ensure current token is parentheses end. context.Stream.EnsureCurrent(TokenType.SymbolParenthesesR); // Skip the parentheses end token. context.Stream.Skip(); // Return the expression. return(expr); }
public override void Assemble(CodeGenerator cgen, Instruction ins, BytecodeStream str) { if (ins.Operands.Count != 2) { cgen.CreateError("{0} does not take {1} arguments!", ins.Name, ins.Operands.Count); } else if (!(ins.Operands[0] is TokenRegister) || (!(ins.Operands[1] is TokenRegister) && !(ins.Operands[1] is TokenIntLiteral) && !(ins.Operands[1] is TokenIdentifier))) { cgen.CreateError("Unsupported addressing mode for instruction '{0}'", ins.Name); } else { TokenRegister op1 = ins.Operands[0] as TokenRegister; Opcode opcode = Opcode.ADD; if (ins.Operands[1] is TokenRegister) { TokenRegister op2 = ins.Operands[1] as TokenRegister; str.Emit(new QuasarInstruction(opcode, new RegisterOperand(op1.Register), new RegisterOperand(op2.Register))); } else if (ins.Operands[1] is TokenIntLiteral) { TokenIntLiteral op2 = ins.Operands[1] as TokenIntLiteral; Console.WriteLine("Add with " + op1.Register); str.Emit(new QuasarInstruction(opcode, new RegisterOperand(op1.Register), new IntegerOperand((int)op2.Value))); } else if (ins.Operands[1] is TokenIdentifier) { TokenIdentifier ident = ins.Operands[1] as TokenIdentifier; str.Emit(new QuasarInstruction(opcode, new RegisterOperand(op1.Register), new SymbolReferenceOperand(ident.Value))); } } }
public Call ParseStatementLevelFunctionCall(TokenIdentifier functionIdentifier) { var call = ParseFunctionCall(functionIdentifier); if (call == null) { return(null); } else { if (!(Peek() is TokenCloseParen)) { throw new ParseFatalException("Parsing a top level function requires that Peek() at this stage returns a TokenCloseParen. It's currently returning (" + Peek().GetType().Name + "). The next step is to determine whether the next token is a TokenEndLine.", this); } else { var tok = ReadNext(); if (tok is TokenNewLine) { return(call); } else { throw new ParseException("Expected a newline, got " + tok.ToString(), this); } } } }
public Call ParseFunctionCall(TokenIdentifier functionIdentifier) { if (Peek() != functionIdentifier) { throw new ParseFatalException($"The current node ({Peek().ToString()}) is not the same as the required ({functionIdentifier.ToString()}). The parser is about to possibly parse a function call, but it cannot determine the function name.", this); } var next = ReadNext(); if (next is TokenOpenParen) { //good chance it will be a function call //then, the next it's either a close paren or an expression next = ReadNext(); if (next is TokenCloseParen) //a close paren creates a function call without arguments { return(new Call(functionIdentifier.Identifier)); } else { var exprList = ParseExpressionList(true); return(new Call(functionIdentifier.Identifier, exprList)); } } else { return(null); //it's not a function call. What is the parser expecting? Return null and let the caller decide } }
private ActionResult CheckFileNameTemplate(ConversionProfile profile, CheckLevel checkLevel) { if (checkLevel == CheckLevel.Job) { return(new ActionResult()); //Job uses Job.OutputFileTemplate } if (profile.AutoSave.Enabled) { if (string.IsNullOrEmpty(profile.FileNameTemplate)) { _logger.Error("Automatic saving without filename template."); return(new ActionResult(ErrorCode.AutoSave_NoFilenameTemplate)); } } if (TokenIdentifier.ContainsTokens(profile.FileNameTemplate)) { return(new ActionResult()); } if (!_pathUtil.IsValidFilename(profile.FileNameTemplate)) { return(new ActionResult(ErrorCode.FilenameTemplate_IllegalCharacters)); } return(new ActionResult()); }
T DecryptFiveByFive(T item) { var properties = ToDictionary(new ProjectionProxy(item)); var tokenId = properties["id"]; var code = properties["code"]; var hash = properties["hash"]; var salt = TokenIdentifier.Parse(tokenId.Value).MintRequestId.ToByteArray(); using (var tokenCode = tokenSecurity.DecryptFromBase64(code.Value, hash.Value, salt)) { var fiveByFive = SecureStringToGlobalAllocAnsi(tokenCode); try { code.Value = PtrToStringAnsi(fiveByFive); } finally { if (fiveByFive != IntPtr.Zero) { ZeroFreeGlobalAllocAnsi(fiveByFive); } } } return(item); }
public Expr Parse(TokenStream stream) { TokenType nextTokenType = stream.Peek().Type; // Variable declaration expression. if (TokenIdentifier.IsType(nextTokenType)) { return(new VarDeclareExprParser().Parse(stream)); } // Numeric expression. else if (TokenIdentifier.IsNumeric(nextTokenType)) { return(new NumericExprParser().Parse(stream)); } // Identifier expression. else if (nextTokenType == TokenType.Identifier) { return(new IdentifierExprParser().Parse(stream)); } // Parentheses expression. else if (nextTokenType == TokenType.SymbolParenthesesL) { return(new ParenthesesExprParser().Parse(stream)); } // At this point, return null. return(null); }
private ActionResult CheckTargetDirectory(ConversionProfile profile, CheckLevel checkLevel) { if (checkLevel == CheckLevel.Job) return new ActionResult(); //Job uses Job.OutputFilenameTemplate if (!profile.AutoSave.Enabled && string.IsNullOrWhiteSpace(profile.TargetDirectory)) return new ActionResult(); // Valid LastSaveDirectory-Trigger if (profile.AutoSave.Enabled && string.IsNullOrWhiteSpace(profile.TargetDirectory)) return new ActionResult(ErrorCode.TargetDirectory_NotSetForAutoSave); if (TokenIdentifier.ContainsTokens(profile.TargetDirectory)) return new ActionResult(); var pathUtilStatus = _pathUtil.IsValidRootedPathWithResponse(profile.TargetDirectory); switch (pathUtilStatus) { case PathUtilStatus.InvalidRootedPath: return new ActionResult(ErrorCode.TargetDirectory_InvalidRootedPath); case PathUtilStatus.PathTooLongEx: return new ActionResult(ErrorCode.TargetDirectory_TooLong); case PathUtilStatus.NotSupportedEx: return new ActionResult(ErrorCode.TargetDirectory_InvalidRootedPath); case PathUtilStatus.ArgumentEx: return new ActionResult(ErrorCode.TargetDirectory_IllegalCharacters); } return new ActionResult(); }
public FormalArg Parse(TokenStream stream) { // Initialize the type value. string typeValue; // Check if the next token is a type if (TokenIdentifier.IsType(stream.Peek())) { // Capture argument type value. typeValue = stream.Next().Value; } else { // TODO: Better error lol. throw new Exception("Oops you need a type!"); } // Create the argument's type. var type = new Type(typeValue); // Create the formal argument entity. var arg = new FormalArg(type); // Capture the argument's name. var name = stream.Next(TokenType.Identifier).Value; // Assign the argument's name. arg.SetName(name); return(arg); }
public ActionResult Check(ConversionProfile profile, Accounts accounts, CheckLevel checkLevel) { if (!IsEnabled(profile)) { return(new ActionResult()); } var isJobLevelCheck = checkLevel == CheckLevel.Job; var account = accounts.GetDropboxAccount(profile); if (account == null) { return(new ActionResult(ErrorCode.Dropbox_AccountNotSpecified)); } var accessToken = account.AccessToken; if (string.IsNullOrEmpty(accessToken)) { return(new ActionResult(ErrorCode.Dropbox_AccessTokenNotSpecified)); } if (!isJobLevelCheck && TokenIdentifier.ContainsTokens(profile.DropboxSettings.SharedFolder)) { return(new ActionResult()); } if (!ValidName.IsValidDropboxFolder(profile.DropboxSettings.SharedFolder)) { return(new ActionResult(ErrorCode.Dropbox_InvalidFolderName)); } return(new ActionResult()); }
private Qualifier ParseQualifier() { TokenIdentifier identifier = this.GetIdentifier(); Token token = this.m_queue.Peek(); TokenType type = token.Type; if (type != TokenType.Comma) { if (type == TokenType.OpenParens) { this.m_queue.Dequeue(); object obj = this.ParseConstantValue(); this.Consume(TokenType.CloseParens); Flavor flavor = Flavor.None; if (this.PeekAs <TokenColon>() != null) { this.Consume <TokenColon>(); flavor = this.ParseFlavors(); } return(new Qualifier(identifier.Location, identifier.Value, obj, flavor)); } else { if (type != TokenType.CloseBracket) { throw new ParseFailureException(string.Format("Unexpected token while parsing a qualifer: {0}", token.Type.ToString()), token.Location); } } } return(new Qualifier(identifier.Location, identifier.Value, null, Flavor.None)); }
public Attribution ParseAttribution(TokenIdentifier functionIdentifier) { if (Peek() != functionIdentifier) { throw new ParseFatalException($"The current node ({Peek().ToString()}) is not the same as the required ({functionIdentifier.ToString()}). The parser is about to possibly parse an attribution to a variable, but it cannot determine the variable name.", this); } var next = ReadNext(); if (next is TokenAttribution) //good chances it's an attribution { next = ReadNext(); var expr = ParseExpression(false); var tok = Peek(); if (tok is TokenNewLine || tok is TokenEOF) { return(new Attribution(functionIdentifier, expr)); } else { throw new ParseException("Expected a newline or end of file, got " + tok.ToString(), this); } } else { return(null); //it's not an attribution. What is the parser expecting? Return null and let the caller decide } }
public Token NextToken() { Token token = null; if (ptr >= Text.Length) { token = new Token(TokenType.END_OF_STREAM); goto done; } char currentChar = Text[ptr++]; switch (currentChar) { case '+': token = new Token(TokenType.PLUS); break; default: if (char.IsDigit(currentChar)) { string numStr = ""; numStr += currentChar; while (ptr < Text.Length && char.IsDigit(Text[ptr])) { numStr += Text[ptr]; ptr++; } double value = double.Parse(numStr); token = new TokenNumber(value); } else if (char.IsLetter(currentChar) || currentChar == '_') { string ident = ""; ident += currentChar; while (ptr < Text.Length && char.IsDigit(Text[ptr]) || currentChar == '_') { ident += Text[ptr]; ptr++; } token = new TokenIdentifier(ident); } break; } if (token == null) { token = new Token(TokenType.UNKNOWN); } done: return(token); }
private ActionResult CheckAttachmentPageSettings(ConversionProfile profile, CheckLevel checkLevel) { if (!profile.AttachmentPage.Enabled) { return(new ActionResult()); } var isJobLevelCheck = checkLevel == CheckLevel.Job; if (string.IsNullOrEmpty(profile.AttachmentPage.File)) { _logger.Error("No attachment file is specified."); return(new ActionResult(ErrorCode.Attachment_NoFileSpecified)); } if (!isJobLevelCheck && TokenIdentifier.ContainsTokens(profile.AttachmentPage.File)) { return(new ActionResult()); } if (!profile.AttachmentPage.File.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase)) { _logger.Error("The attachment file \"" + profile.CoverPage.File + "\" is no pdf file."); return(new ActionResult(ErrorCode.Attachment_NoPdf)); } var pathUtilStatus = _pathUtil.IsValidRootedPathWithResponse(profile.AttachmentPage.File); switch (pathUtilStatus) { case PathUtilStatus.InvalidRootedPath: return(new ActionResult(ErrorCode.AttachmentPage_InvalidRootedPath)); case PathUtilStatus.PathTooLongEx: return(new ActionResult(ErrorCode.AttachmentPage_TooLong)); case PathUtilStatus.NotSupportedEx: return(new ActionResult(ErrorCode.AttachmentPage_InvalidRootedPath)); case PathUtilStatus.ArgumentEx: return(new ActionResult(ErrorCode.AttachmentPage_IllegalCharacters)); } if (!isJobLevelCheck && profile.AttachmentPage.File.StartsWith(@"\\")) { return(new ActionResult()); } if (!_file.Exists(profile.AttachmentPage.File)) { _logger.Error("The attachment file \"" + profile.AttachmentPage.File + "\" does not exist."); return(new ActionResult(ErrorCode.Attachment_FileDoesNotExist)); } return(new ActionResult()); }
/// <summary> /// Check for valid profile /// </summary> /// <param name="profile"></param> /// <param name="accounts">accounts are not used here, but are required for common ICheckable</param> /// <param name="checkLevel"></param> /// <returns>ActionResult</returns> public ActionResult Check(ConversionProfile profile, Accounts accounts, CheckLevel checkLevel) { if (!IsEnabled(profile)) { return(new ActionResult()); } var isJobLevelCheck = checkLevel == CheckLevel.Job; if (string.IsNullOrWhiteSpace(profile.Scripting.ScriptFile)) { return(new ActionResult(ErrorCode.Script_NoScriptFileSpecified)); } //Skip further check for tokens if (!isJobLevelCheck && TokenIdentifier.ContainsTokens(profile.Scripting.ScriptFile)) { return(new ActionResult()); } var pathUtilStatus = _pathUtil.IsValidRootedPathWithResponse(profile.Scripting.ScriptFile); switch (pathUtilStatus) { case PathUtilStatus.InvalidRootedPath: return(new ActionResult(ErrorCode.Script_InvalidRootedPath)); case PathUtilStatus.PathTooLongEx: return(new ActionResult(ErrorCode.Script_PathTooLong)); case PathUtilStatus.NotSupportedEx: return(new ActionResult(ErrorCode.Script_InvalidRootedPath)); case PathUtilStatus.ArgumentEx: return(new ActionResult(ErrorCode.Script_IllegalCharacters)); } //Skip check for network path if (!isJobLevelCheck && profile.Scripting.ScriptFile.StartsWith(@"\\")) { return(new ActionResult()); } if (!_file.Exists(profile.Scripting.ScriptFile)) { _logger.Error("The script file \"" + profile.Scripting.ScriptFile + "\" does not exist."); return(new ActionResult(ErrorCode.Script_FileDoesNotExist)); } return(new ActionResult()); }
public override void Assemble(CodeGenerator cgen, Instruction ins, BytecodeStream str) { if (ins.Operands.Count != 1) { cgen.CreateError("Instruction {0} does not take {1} operand(s)!", ins.Name, ins.Operands.Count); } else if (ins.Operands[0] is TokenIdentifier) { TokenIdentifier label = ins.Operands[0] as TokenIdentifier; str.Emit(new QuasarInstruction(Opcode.BSR, new SymbolReferenceOperand(label.Value, true))); } }
public override ActionResult Check(ConversionProfile profile, Accounts accounts, CheckLevel checkLevel) { var actionResult = new ActionResult(); if (!IsEnabled(profile)) { return(actionResult); } var isFinal = checkLevel == CheckLevel.Job; var ftpAccount = accounts.GetFtpAccount(profile); if (ftpAccount == null) { Logger.Error($"The specified FTP account with ID '{profile.Ftp.AccountId}' is not configured."); actionResult.Add(ErrorCode.Ftp_NoAccount); return(actionResult); } if (string.IsNullOrEmpty(ftpAccount.Server)) { Logger.Error("No FTP server specified."); actionResult.Add(ErrorCode.Ftp_NoServer); } if (string.IsNullOrEmpty(ftpAccount.UserName)) { Logger.Error("No FTP username specified."); actionResult.Add(ErrorCode.Ftp_NoUser); } if (profile.AutoSave.Enabled && string.IsNullOrEmpty(ftpAccount.Password)) { Logger.Error("Automatic saving without ftp password."); actionResult.Add(ErrorCode.Ftp_AutoSaveWithoutPassword); } if (!isFinal && TokenIdentifier.ContainsTokens(profile.Ftp.Directory)) { return(actionResult); } if (!ValidName.IsValidFtpPath(profile.Ftp.Directory)) { actionResult.Add(ErrorCode.FtpDirectory_InvalidFtpPath); } return(actionResult); }
public Type Parse(TokenStream stream) { // Consume type token. Token type = stream.Next(); // Ensure type value is a type. if (!TokenIdentifier.IsType(type)) { throw new Exception($"Expected a type but got '{type.Type}'"); } // Create the type. return(new Type(type.Value)); }
public Expr Parse(ParserContext context) { // Capture current token type. TokenType currentTokenType = context.Stream.Current.Type; // Pipe operation. if (currentTokenType == TokenType.SymbolColon) { return(new PipeParser().Parse(context)); } // Numeric expression. else if (TokenIdentifier.IsNumeric(currentTokenType)) { return(new NumericExprParser().Parse(context)); } // Identifier expression. else if (currentTokenType == TokenType.Identifier) { return(new IdentifierExprParser().Parse(context)); } // Parentheses expression. else if (currentTokenType == TokenType.SymbolParenthesesL) { return(new ParenthesesExprParser().Parse(context)); } // String expression. else if (currentTokenType == TokenType.LiteralString) { return(new StringExprParser().Parse(context)); } // Boolean expression. else if (TokenIdentifier.IsBoolean(currentTokenType)) { return(new BooleanExprParser().Parse(context)); } // Struct expression. else if (currentTokenType == TokenType.KeywordNew) { return(new StructExprParser().Parse(context)); } // Array expression. else if (currentTokenType == TokenType.SymbolBracketL) { // TODO: Type is hard-coded for debugging purposes, not yet supported auto-type (might need infering?). return(new ArrayExprParser(PrimitiveTypeFactory.Int32()).Parse(context)); } // At this point, return null. return(null); }
private DataType ParseBuiltInTypeOrObjectReference() { TokenIdentifier tokenIdentifier = this.PeekAs <TokenIdentifier>(); if (tokenIdentifier == null || tokenIdentifier.IsKeyword) { return(this.ParseBuiltInType()); } else { ClassName className = this.ParseClassName(); this.Consume(KeywordType.REF); return(new ObjectReference(className)); } }
public Value Parse(ParserContext context) { // Consume the value string. string value = context.Stream.Current.Value; // Attempt to identify value string type. TokenType?type = TokenIdentifier.IdentifyComplex(value); // Ensure type has successfully been identified. if (!type.HasValue) { throw new Exception("Unable to identify literal token type"); } // Create and return the value. return(new Value(Resolvers.PrimitiveType(type.Value), type.Value, value)); }
public Value Parse(TokenStream stream) { // Consume the value string. var value = stream.Next().Value; // Attempt to identify value string type. var type = TokenIdentifier.IdentifyComplex(value); // Ensure type has successfully been identified. if (!type.HasValue) { throw new Exception("Unable to identify literal token type"); } // Create and return the value. return(new Value(Resolvers.TypeFromTokenType(type.Value), type.Value, value)); }
public NumericExpr Parse(TokenStream stream) { // Consume numeric literal token. Token token = stream.Next(); // Ensure captured token is numeric. if (!TokenIdentifier.IsNumeric(token)) { throw new Exception($"Expected token to be classified as numeric, but got '{token.Type}'"); } // Create the numeric expression entity. var numericExpr = new NumericExpr(token.Type, Resolvers.TypeFromToken(token), token.Value); // Return the numeric expression entity. return(numericExpr); }
public Task RemoveFromCirculation(Guid mintRequestId, string correlationId, CancellationToken cancellationToken) { foreach (var circulated in vault.Select(p => p.Value)) { var tokenIds = circulated.ToArray(); foreach (var tokenId in tokenIds) { var id = TokenIdentifier.Parse(tokenId); if (id.MintRequestId == mintRequestId) { circulated.Remove(tokenId); } } } return(CompletedTask); }
public NumericExpr Parse(ParserContext context) { // Consume numeric literal token. Token token = context.Stream.Current; // Skip numeric literal token. context.Stream.Skip(); // Ensure captured token is numeric. if (!TokenIdentifier.IsNumeric(token)) { throw new Exception($"Expected token to be classified as numeric, but got '{token.Type}'"); } // Create the numeric expression entity. NumericExpr numericExpr = new NumericExpr(token.Type, Resolvers.PrimitiveType(token), token.Value); // Return the numeric expression entity. return(numericExpr); }
public BooleanExpr Parse(ParserContext context) { // Consume boolean literal token. Token token = context.Stream.Current; // Skip boolean literal token. context.Stream.Skip(); // Ensure captured token is a boolean. if (!TokenIdentifier.IsBoolean(token.Type)) { throw new Exception($"Expected token type to be boolean, but got '{token.Type}'"); } // Create the boolean expression entity. BooleanExpr booleanExpr = new BooleanExpr(token.Type, token.Value); // Return the boolean expression entity. return(booleanExpr); }
public Expr Parse(ParserContext context) { // Capture the current token's type. Token token = context.Stream.Current; // Variable declaration expression. if (TokenIdentifier.IsType(token, context)) { return(new VarDeclareExprParser().Parse(context)); } // If expression. else if (token.Type == TokenType.KeywordIf) { return(new IfExprParser().Parse(context)); } // Otherwise, delegate to the expression parser. Expr expr = new ExprParser().Parse(context); // Return the parsed expression. return(expr); }
/// <exception cref="System.Exception"/> public virtual void TestTokenIdentifiers() { UserGroupInformation ugi = UserGroupInformation.CreateUserForTesting("TheDoctor", new string[] { "TheTARDIS" }); TokenIdentifier t1 = Org.Mockito.Mockito.Mock <TokenIdentifier>(); TokenIdentifier t2 = Org.Mockito.Mockito.Mock <TokenIdentifier>(); ugi.AddTokenIdentifier(t1); ugi.AddTokenIdentifier(t2); ICollection <TokenIdentifier> z = ugi.GetTokenIdentifiers(); Assert.True(z.Contains(t1)); Assert.True(z.Contains(t2)); Assert.Equal(2, z.Count); // ensure that the token identifiers are passed through doAs ICollection <TokenIdentifier> otherSet = ugi.DoAs(new _PrivilegedExceptionAction_639 ()); Assert.True(otherSet.Contains(t1)); Assert.True(otherSet.Contains(t2)); Assert.Equal(2, otherSet.Count); }