<commit_before>package filter;

import java.util.ArrayList;

public class Parser {

	public static void main(String[] args) {
		FilterExpression p = Parser.parse("milestone(0.4) state(open) or label(urgent)");
		System.out.println(p);
	}
	
	private Parser(ArrayList<Token> input) {
		this.input = input;
	}
	public static FilterExpression parse(String input) {
		if (input == null) return null;
		else if (input.isEmpty()) return Predicate.EMPTY;
		return new Parser(new Lexer(input).lex()).parseExpression(0);
	}
		
	private ArrayList<Token> input;
	private int position = 0;
	
	private Token consume(TokenType type) {
		if (input.get(position).getType() == type) {
			return input.get(position++);
		} else {
			throw new ParseException("Invalid token " + input.get(position) + " where " + type + " expected");
		}
	}
	
	private Token consume() {
		return input.get(position++);
	}

	private Token lookAhead() {
		return input.get(position);
	}
		
	private FilterExpression parseExpression(int precedence) {
		Token token = consume();
		assert token.getType() != TokenType.EOF;
		
		// Prefix
		
		FilterExpression left;
		
		switch (token.getType()) {
		case LBRACKET:
			left = parseGroup(token);
			break;
		case NEGATE:
			left = parseNegation(token);
			break;
		case SYMBOL:
			left = parsePredicate(token);
			break;
		default:
			throw new ParseException("Invalid prefix token " + token);
		}
		
		if (lookAhead().getType() == TokenType.EOF) return left;

		// Infix
		
		while (precedence < getInfixPrecedence(token = lookAhead())) {
			switch (token.getType()) {
			case AND:
				consume();
				left = parseConjunction(left, token);
				break;<commit_msg>Fixed bug where incomplete inputs caused an assertion failure instead of a ParseException<commit_after>package filter;

import java.util.ArrayList;

public class Parser {

	public static void main(String[] args) {
		FilterExpression p = Parser.parse("~");
		System.out.println(p);
	}
	
	private Parser(ArrayList<Token> input) {
		this.input = input;
	}
	public static FilterExpression parse(String input) {
		if (input == null) return null;
		else if (input.isEmpty()) return Predicate.EMPTY;
		return new Parser(new Lexer(input).lex()).parseExpression(0);
	}

	private ArrayList<Token> input;
	private int position = 0;
	
	private Token consume(TokenType type) {
		if (input.get(position).getType() == type) {
			return input.get(position++);
		} else {
			throw new ParseException("Invalid token " + input.get(position) + " where " + type + " expected");
		}
	}
	
	private Token consume() {
		return input.get(position++);
	}

	private Token lookAhead() {
		return input.get(position);
	}
		
	private FilterExpression parseExpression(int precedence) {
		Token token = consume();
		if (token.getType() == TokenType.EOF) {
			throw new ParseException("Unexpected EOF while parsing at " + position);
		}
		
		// Prefix
		
		FilterExpression left;
		
		switch (token.getType()) {
		case LBRACKET:
			left = parseGroup(token);
			break;
		case NEGATE:
			left = parseNegation(token);
			break;
		case SYMBOL:
			left = parsePredicate(token);
			break;
		default:
			throw new ParseException("Invalid prefix token " + token);
		}
		
		if (lookAhead().getType() == TokenType.EOF) return left;

		// Infix
		
		while (precedence < getInfixPrecedence(token = lookAhead())) {
			switch (token.getType()) {
			case AND:
				consume();
				left = parseConjunction(left, token);
				break;
{'fraction_non_alphanumeric': 0.12801161103047895, 'fraction_numerical': 0.0017416545718432512, 'mean_word_length': 3.786111111111111, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3588703', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1061, 'n_words': 284}