<commit_before>package parser

import (
	"strings"
)

const EOFCHAR = 0x100

type StateFn func(*Lexer) StateFn
type TokenType uint8
type Token struct {
	Type  TokenType
	Value string
}

const (
	TokenNumber     TokenType = iota //numbers
	TokenIdentifier                  //identifiers
	TokenOperator                    //operators, like >, <
	TokenString                      //quoted strings
)

// Tokenizer is the struct used to generate SQL
// tokens for the parser.
type Lexer struct {
	InStream  *strings.Reader
	lastChar  uint16
	Name      string
	Position  int
	Start     int
	Width     int
	ParseTree Rule
}

func stateStart(lex *Lexer) StateFn {
	return nil
}

func (self *Lexer) skipBlank() {
	ch := self.lastChar
	for ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' {
		self.next()
		ch = self.lastChar
	}
}

func (self *Lexer) next() {
	if ch, err := self.InStream.ReadByte(); err != nil {
		// Only EOF is possible.
		self.lastChar = EOFCHAR
	} else {
		self.lastChar = uint16(ch)
	}
	self.Position++
}

func NewStringLexer(expr string) *Lexer {
	return &Lexer{InStream: strings.NewReader(expr)}
}

func (self *Lexer) Run() {
	for state := stateStart; state != nil; {
		state(self)
	}
}

// Lex returns the next token form the Tokenizer.
// This function is used by go yacc.
func (self *Lexer) Lex(lval *yySymType) int {
	return 0
}

// Error is called by go yacc if there's a parsing error.
func (self *Lexer) Error(err string) {
}<commit_msg>more lexer.go<commit_after>package parser

import (
	"fmt"
	"strings"
	"unicode/utf8"
)

type itemType uint8

const (
	itemError itemType = iota //numbers
	itemEOF
	itemIdentifier
	itemKeyword
	itemThen
	itemAnd
)

type item struct {
	typ itemType
	pos int
	val string
}

func (i item) String() string {
	switch {
	case i.typ == itemEOF:
		return "EOF"
	case i.typ == itemError:
		return i.val
	case i.typ > itemKeyword:
		return fmt.Sprintf("<%s>", i.val)
	}
	return fmt.Sprintf("%q", i.val)
}

const eof = -1

type stateFn func(*Lexer) stateFn

type Lexer struct {
	name    string
	input   string
	state   stateFn
	pos     int
	start   int
	width   int
	lastPos int
	items   chan item
}

func (l *Lexer) next() rune {
	if l.pos >= len(l.input) {
		l.width = 0
		return eof
	}
	r, w := utf8.DecodeRuneInString(l.input[l.pos:])
	l.width = w
	l.pos += l.width
	return r
}

func (l *Lexer) peek() rune {
	r := l.next()
	l.backup()
	return r
}

func (l *Lexer) backup() {
	l.pos -= l.width
}

func (l *Lexer) emit(t itemType) {
	l.items <- item{t, l.start, l.input[l.start:l.pos]}
	l.start = l.pos
}

func (l *Lexer) ignore() {
	l.start = l.pos
}

func (l *Lexer) accept(valid string) bool {
	if strings.IndexRune(valid, l.next()) >= 0 {
		return true
	}
	l.backup()
	return false
}

func (l *Lexer) acceptRun(valid string) {
	for strings.IndexRune(valid, l.next()) >= 0 {
	}
	l.backup()
}

func (l *Lexer) errorf(format string, args ...interface{}) stateFn {
	l.items <- item{itemError, l.start, fmt.Sprintf(format, args...)}
	return nil
}

func (l *Lexer) nextItem() item {
	item := <-l.items
	l.lastPos = item.pos
	return item
}

func (l *Lexer) drain() {
	for range l.items {
	}
}

func lex(name, input string) *Lexer {
	l := &lexer{
		name:  name,
		input: input,
		items: make(chan item),
	}
	go l.run()
	return l
}

func (l *Lexer) run() {
	for state := stateStart; state != nil; {
		state = state(l)
	}
	close(l.items)
}

func stateStart(l *Lexer) stateFn {
	return nil
}

// Lex returns the next token form the Tokenizer.
// This function is used by go yacc.
func (self *Lexer) Lex(lval *yySymType) int {
	return 0
}

// Error is called by go yacc if there's a parsing error.
func (self *Lexer) Error(err string) {
}
{'fraction_non_alphanumeric': 0.13572204125950055, 'fraction_numerical': 0.004885993485342019, 'mean_word_length': 2.988095238095238, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2045053', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1406, 'n_words': 430}