def parse(self,s): return pc.choice(immediate, primitive, conditional, logical).parse(s)
from lang import * import parser.combinator as pc from parser.combinator import cond, choice, concat, oneOf, many, lexeme, inject, string, letter, many_list, optional zero = pc.char('0') positive_digit = pc.oneOf('123456789') digit = choice(zero, positive_digit) fixnum = concat(optional(oneOf('+-')).bind(lambda sign: inject(sign or '')), choice(zero, concat(positive_digit, many(digit)))).bind(lambda i: inject(Fixnum(int(i))))\ .with_name('fixnum') bool = pc.char('#').skip( oneOf('tf').bind(lambda b: inject(Bool(b == 't'))))\ .with_name('bool') extended_alph_char = choice(letter, oneOf('+-.*/<=>!?:$%_&~^')) char = string('#\\').skip( letter.bind(lambda c: inject(Char(c)))) \ .with_name('char') nil = string('()').skip( pc.inject(empty_list)).with_name('nil') immediate = choice(fixnum, char, bool, nil).with_name('immediate')