public Token Read() { if (Index >= Tokens.Count - 1) { throw ScriptError.UnexpectedEOF(null); } return(Tokens[Index++]); }
public bool Match(params TokenType[] types) { if (Index >= Tokens.Count) { throw ScriptError.UnexpectedEOF(null); } foreach (var type in types) { if (Tokens[Index].Type == type) { return(true); } } return(false); }
public Token Expect(params TokenType[] types) { if (Index >= Tokens.Count) { throw ScriptError.UnexpectedEOF(null); } foreach (var type in types) { if (Tokens[Index].Type == type) { var token = Tokens[Index]; Index++; return(token); } } throw ScriptError.UnexpectedToken(Tokens[Index], Tokens[Index].Contents); }