<commit_before>import Box
import Madness
import Prelude

enum Term: Printable {
	case Variable(String)
	case Abstraction(String, Box<Term>)
	case Application(Box<Term>, Box<Term>)

	var description: String {
		switch self {
		case let Variable(symbol):
			return symbol
		case let Abstraction(symbol, body):
			return "λ\(symbol).\(body.value.description)"
		case let Application(x, y):
			return "(\(x.value.description) \(y.value.description))"
		}
	}
}


let symbol = range("a"..."z")

let term: Parser<Term>.Function = fix { term in
	let variable = symbol --> { Term.Variable($0) }
	let abstraction = ignore(%"λ") ++ symbol ++ ignore(%".") ++ term --> { Term.Abstraction($0, Box($1)) }
	let application = ignore(%"(") ++ term ++ ignore(%" ") ++ term ++ ignore(%")") --> { Term.Application(Box($0), Box($1)) }
	return variable | abstraction | application
}

let parse: String -> Term? = {
	term($0)?.0
}

parse("λx.(x x)")?.description<commit_msg>Parse ⍵ in the playground.<commit_after>import Box
import Madness
import Prelude

enum Term: Printable {
	case Variable(String)
	case Abstraction(String, Box<Term>)
	case Application(Box<Term>, Box<Term>)

	var description: String {
		switch self {
		case let Variable(symbol):
			return symbol
		case let Abstraction(symbol, body):
			return "λ\(symbol).\(body.value.description)"
		case let Application(x, y):
			return "(\(x.value.description) \(y.value.description))"
		}
	}
}


let symbol = range("a"..."z")

let term: Parser<Term>.Function = fix { term in
	let variable = symbol --> { Term.Variable($0) }
	let abstraction = ignore(%"λ") ++ symbol ++ ignore(%".") ++ term --> { Term.Abstraction($0, Box($1)) }
	let application = ignore(%"(") ++ term ++ ignore(%" ") ++ term ++ ignore(%")") --> { Term.Application(Box($0), Box($1)) }
	return variable | abstraction | application
}

let parse: String -> Term? = {
	term($0)?.0
}

parse("λx.(x x)")?.description
parse("(λx.(x x) λx.(x x))")?.description
{'fraction_non_alphanumeric': 0.19539641943734015, 'fraction_numerical': 0.007161125319693095, 'mean_word_length': 4.216, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '1060251', 'n_tokens_mistral': 689, 'n_tokens_neox': 643, 'n_words': 169}