curly-infix comparse added by dieggsy on Thu Oct 24 06:23:22 2019
#!/usr/bin/csi -s (import comparse) (import srfi-14) (define (as-symbol parser) (bind (as-string parser) (lambda (s) (result (string->symbol s))))) (define (as-number parser) (bind (as-string parser) (lambda (s) (result (string->number s))))) (define symbol (as-symbol (char-seq-match '(: symbol)))) (define ws (zero-or-more (in char-set:whitespace))) (define begin-curly (is #\{)) (define end-curly (is #\})) (define curly (recursive-parser (enclosed-by (preceded-by begin-curly ws) (any-of (sequence* ((first-value value) (more-values (zero-or-more value))) (result (cons first-value more-values))) (result '())) end-curly))) (define value (enclosed-by ws (any-of curly symbol) ws)) (define infix-expr (enclosed-by ws curly ws)) (print "Works: {a b c {d e}}") (write (parse infix-expr "{a b c {d e}}")) (newline) (print "Doesn't work: {a b c {d e} a}") (write (parse infix-expr "{a b c {d e} a}")) (newline)