/// <summary> /// Check if the next token matches the given type. If they match, take the token. /// </summary> public bool MatchAndTake(LoonyTokenType type) { var isMatch = Match(type); if (isMatch) Take(); return isMatch; }
/// <summary> /// Take a token from the stream. Throws an exception if the given type does not match the token type. /// </summary> public LoonyToken Take(LoonyTokenType type) { var token = Take(); if (token.Type != type) throw new CompilerException(token, CompilerError.ExpectedButFound, type, token); return token; }
/// <summary> /// Take a token from the stream. Throws an exception if the given type does not match the token type. /// </summary> public LoonyToken Take(LoonyTokenType type) { var token = Take(); if (token.Type != type) { throw new CompilerException(token, CompilerError.ExpectedButFound, type, token); } return(token); }
/// <summary> /// Check if the next token matches the given type. If they match, take the token. /// </summary> public bool MatchAndTake(LoonyTokenType type) { var isMatch = Match(type); if (isMatch) { Take(); } return(isMatch); }
static void RegisterInfix(LoonyTokenType type, IInfixParselet parselet) { _infixParselets.Add(type, parselet); }
static void RegisterPrefix(LoonyTokenType type, IPrefixParselet parselet) { _prefixParselets.Add(type, parselet); }
static void RegisterStatement(LoonyTokenType type, IStatementParselet parselet) { _statementParselets.Add(type, parselet); }
static void RegisterDeclaration(LoonyTokenType type, IDeclarationParselet parselet) { _declarationParselets.Add(type, parselet); }
/// <summary> /// Check if the next token matches the given type. /// </summary> public bool Match(LoonyTokenType type, int distance = 0) { return(Peek(distance).Type == type); }
/// <summary> /// Check if the next token matches the given type. /// </summary> public bool Match(LoonyTokenType type, int distance = 0) { return Peek(distance).Type == type; }