// Returns the tokens[current position + shift] token if the
// given type AND value matches for that token.
// DOES NOT consume the token.
169221
func (p *Parser) PeekN(shift int, typ TokenType, val string) *Token {
	t := p.Get(p.idx + shift)
	if t != nil {
		if t.Typ == typ && t.Val == val {
			return t
		}
	}
	return nil
}
500898
func (p *Parser) GetR(shift int) *Token {
	i := p.idx + shift
	return p.Get(i)
}
1285739
func (pctx *parseCtx) peek() *Token {
	if pctx.peekCount < 0 {
		select {
		case <-pctx.Context.Done():
			return &eofToken
		case t, ok := <-pctx.lexsrc:
			if !ok {
				return &eofToken
			}
			pctx.peekCount++
			pctx.peekTokens[pctx.peekCount] = t
		}
	}
	return pctx.peekTokens[pctx.peekCount]
}
1363962
func (l *Lexer) shiftRawText() []byte {
	if l.rawTag == Plaintext {
		for {
			if l.r.Peek(0) == 0 && l.r.Err() != nil {
				return l.r.Shift()
			}
			l.r.Move(1)
		}
	} else { // RCDATA, RAWTEXT and SCRIPT
		for {
			c := l.r.Peek(0)
			if c == '<' {
				if l.r.Peek(1) == '/' {
					mark := l.r.Pos()
					l.r.Move(2)
					for {
						if c = l.r.Peek(0); !('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
							break
						}
						l.r.Move(1)
					}
					if h := ToHash(parse.ToLower(parse.Copy(l.r.Lexeme()[mark+2:]))); h == l.rawTag { // copy so that ToLower doesn't change the case of the underlying slice
						l.r.Rewind(mark)
						return l.r.Shift()
					}
				} else if l.rawTag == Script && l.r.Peek(1) == '!' && l.r.Peek(2) == '-' && l.r.Peek(3) == '-' {
					l.r.Move(4)
					inScript := false
					for {
						c := l.r.Peek(0)
						if c == '-' && l.r.Peek(1) == '-' && l.r.Peek(2) == '>' {
							l.r.Move(3)
							break
						} else if c == '<' {
							isEnd := l.r.Peek(1) == '/'
							if isEnd {
								l.r.Move(2)
							} else {
								l.r.Move(1)
							}
							mark := l.r.Pos()
							for {
								if c = l.r.Peek(0); !('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
									break
								}
								l.r.Move(1)
							}
							if h := ToHash(parse.ToLower(parse.Copy(l.r.Lexeme()[mark:]))); h == Script { // copy so that ToLower doesn't change the case of the underlying slice
								if !isEnd {
									inScript = true
								} else {
									if !inScript {
										l.r.Rewind(mark - 2)
										return l.r.Shift()
									}
									inScript = false
								}
							}
						} else if c == 0 && l.r.Err() != nil {
							return l.r.Shift()
						} else {
							l.r.Move(1)
						}
					}
				} else {
					l.r.Move(1)
				}
			} else if c == 0 && l.r.Err() != nil {
				return l.r.Shift()
			} else {
				l.r.Move(1)
			}
		}
	}
}
1254327
func (z *StreamLexer) ShiftLen() int {
	n := z.start - z.prevStart
	z.prevStart = z.start
	return n
}
275874
func (bc Bytecode) Tokens() ([]string, error) {
	// Overestimate of capacity in the presence of pushes
	tokens := make([]string, 0, len(bc))

	for i := 0; i < len(bc); i++ {
		op, ok := asm.GetOpCode(bc[i])
		if !ok {
			return tokens, fmt.Errorf("did not recognise byte %#x at position %v as an OpCode:\n %s",
				bc[i], i, lexingPositionString(bc, i, tokens))
		}
		pushes := op.Pushes()
		tokens = append(tokens, op.Name())
		if pushes > 0 {
			// This is a PUSH<N> OpCode so consume N bytes from the input, render them as hex, and skip to next OpCode
			if i+pushes >= len(bc) {
				return tokens, fmt.Errorf("token %v of input is %s but not enough input remains to push %v: %s",
					i, op.Name(), pushes, lexingPositionString(bc, i, tokens))
			}
			pushedBytes := bc[i+1 : i+pushes+1]
			tokens = append(tokens, fmt.Sprintf("0x%s", pushedBytes))
			i += pushes
		}
	}
	return tokens, nil
}
114249
func checkMatch(f *ast.File, pos token.Pos) (match, error) {
	path, _ := astutil.PathEnclosingInterval(f, pos, pos)
	result := match{}
	if path == nil {
		return result, fmt.Errorf("can't find node enclosing position")
	}
	switch node := path[0].(type) {
	case *ast.Ident:
		result.ident = node
	case *ast.SelectorExpr:
		result.ident = node.Sel
	case *ast.BasicLit:
		// if there was a literal import path, we build a special ident of
		// the same value, which we eventually use to print the path
		if len(path) > 1 {
			if spec, ok := path[1].(*ast.ImportSpec); ok {
				if p, err := strconv.Unquote(spec.Path.Value); err == nil {
					result.ident = ast.NewIdent(p)
				}
			}
		}
	}
	if result.ident != nil {
		for _, n := range path[1:] {
			if field, ok := n.(*ast.Field); ok {
				result.wasEmbeddedField = len(field.Names) == 0
			}
		}
	}
	return result, nil
}
25679
func Match(t1 Token, t2 Token) bool {
	var temp Token
	if t1.Type() > t2.Type() {
		temp = t1
		t1 = t2
		t2 = temp
	}

	switch t1.Type() {
	case TTCharacter:
		ch := t1.(*character)

		switch t2.Type() {
		case TTCharacter:
			return matchCharacters(ch, t2.(*character))
		case TTDot:
			return matchCharacterDot(ch, t2.(*dot))
		case TTSet:
			return matchCharacterSet(ch, t2.(*set))
		default:
			panic(errBadImplementation)
		}

	case TTDot:
		d := t1.(*dot)

		switch t2.Type() {
		case TTDot:
			return matchDots(d, t2.(*dot))
		case TTSet:
			return matchDotSet(d, t2.(*set))
		default:
			panic(errBadImplementation)
		}

	case TTSet:
		switch t2.Type() {
		case TTSet:
			return matchSets(t1.(*set), t2.(*set))
		default:
			panic(errBadImplementation)
		}

	default:
		panic(errBadImplementation)

	}
}
852203
func (i Iterator) Tokens() []Token {
	var out []Token
	for t := i(); t != EOF; t = i() {
		out = append(out, t)
	}
	return out
}
760623
func (b *PositionBuilder) NewOptionalListTokensPosition(list []node.Node, t *scanner.Token, endToken *scanner.Token) *position.Position {
	if list == nil {
		return &position.Position{
			StartLine: t.StartLine,
			EndLine:   endToken.EndLine,
			StartPos:  t.StartPos,
			EndPos:    endToken.EndPos,
		}
	}

	return &position.Position{
		StartLine: b.getListStartPos(list).startLine,
		EndLine:   endToken.EndLine,
		StartPos:  b.getListStartPos(list).startPos,
		EndPos:    endToken.EndPos,
	}
}
431918
func (parser *Parser) tokenCDOorCDC() bool {
	switch parser.nextToken().Type {
	case scanner.TokenCDO, scanner.TokenCDC:
		return true
	default:
		return false
	}
}
1308892
func peek(parser *Parser, Kind lexer.TokenKind) bool {
	return parser.Token.Kind == Kind
}
804268
func lookahead(parser *Parser) (lexer.Token, error) {
	return parser.LexToken(parser.Token.End)
}
1122226
func (p *Parser) PeekTypeN(shift int, typ TokenType) *Token {
	t := p.Get(p.idx + shift)
	if t != nil {
		if t.Typ == typ {
			return t
		}
	}
	return nil
}
192037
func (l *Lexer) Next() (TokenType, []byte) {
	switch l.r.Peek(0) {
	case ' ', '\t', '\n', '\r', '\f':
		l.r.Move(1)
		for l.consumeWhitespace() {
		}
		return WhitespaceToken, l.r.Shift()
	case ':':
		l.r.Move(1)
		return ColonToken, l.r.Shift()
	case ';':
		l.r.Move(1)
		return SemicolonToken, l.r.Shift()
	case ',':
		l.r.Move(1)
		return CommaToken, l.r.Shift()
	case '(', ')', '[', ']', '{', '}':
		if t := l.consumeBracket(); t != ErrorToken {
			return t, l.r.Shift()
		}
	case '#':
		if l.consumeHashToken() {
			return HashToken, l.r.Shift()
		}
	case '"', '\'':
		if t := l.consumeString(); t != ErrorToken {
			return t, l.r.Shift()
		}
	case '.', '+':
		if t := l.consumeNumeric(); t != ErrorToken {
			return t, l.r.Shift()
		}
	case '-':
		if t := l.consumeNumeric(); t != ErrorToken {
			return t, l.r.Shift()
		} else if t := l.consumeIdentlike(); t != ErrorToken {
			return t, l.r.Shift()
		} else if l.consumeCDCToken() {
			return CDCToken, l.r.Shift()
		} else if l.consumeCustomVariableToken() {
			return CustomPropertyNameToken, l.r.Shift()
		}
	case '@':
		if l.consumeAtKeywordToken() {
			return AtKeywordToken, l.r.Shift()
		}
	case '$', '*', '^', '~':
		if t := l.consumeMatch(); t != ErrorToken {
			return t, l.r.Shift()
		}
	case '/':
		if l.consumeComment() {
			return CommentToken, l.r.Shift()
		}
	case '<':
		if l.consumeCDOToken() {
			return CDOToken, l.r.Shift()
		}
	case '\\':
		if t := l.consumeIdentlike(); t != ErrorToken {
			return t, l.r.Shift()
		}
	case 'u', 'U':
		if l.consumeUnicodeRangeToken() {
			return UnicodeRangeToken, l.r.Shift()
		} else if t := l.consumeIdentlike(); t != ErrorToken {
			return t, l.r.Shift()
		}
	case '|':
		if t := l.consumeMatch(); t != ErrorToken {
			return t, l.r.Shift()
		} else if l.consumeColumnToken() {
			return ColumnToken, l.r.Shift()
		}
	case 0:
		if l.r.Err() != nil {
			return ErrorToken, nil
		}
	default:
		if t := l.consumeNumeric(); t != ErrorToken {
			return t, l.r.Shift()
		} else if t := l.consumeIdentlike(); t != ErrorToken {
			return t, l.r.Shift()
		}
	}
	// can't be rune because consumeIdentlike consumes that as an identifier
	l.r.Move(1)
	return DelimToken, l.r.Shift()
}
1189475
func NewToken(t TokenType, word []rune, pos Position) *Token {
	// ensure the type is valid
	if t < ILLEGAL || t > BAD {
		t = BAD
	}

	// return the token
	return &Token{Type: t, Word: word, Position: pos}
}
975411
func (p *Parser) lookahead() (Token, string) {
	tok, lit := p.scannedItems[p.position].tok, p.scannedItems[p.position].literal
	return tok, lit
}