ometa-opt.g
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Mon, 04 Jul 2011 10:59:25 -0400
changeset 37 c28094727b3d
parent 32 5deee5dae03d
permissions -rw-r--r--
Cope with no reported error when formatting error messages.
-- -*- text -*-

opt-grammar = {opt-production}*;

end = ~_ ;

opt-production = :n opt:o -> `(,n ,o);

opt = {:t t};

opt-inside :t =
  {:t1 ->(or (eq? t t1) (error 'expected t)) opt-inside(t):xs} opt-inside(t):ys -> (append xs ys)
| opt:x							       opt-inside(t):xs -> (cons x xs)
|										-> '()
;

apply :prod (_*):args -> `(apply ,prod ,@args);

or opt:o end -> o;
or opt-inside('or):os -> (if (= (length os) 1) (car os) `(or ,@os));

seq opt:o end -> o;
seq opt-inside('seq):os -> (if (= (length os) 1) (car os) `(seq ,@os));

nest opt:m end -> `(nest ,m);
not opt:m end -> `(not ,m);
follow opt:m end -> `(follow ,m);
many opt:m end -> `(many ,m);
many1 opt:m end -> `(many1 ,m);
anything end -> `(anything);
bind :n opt:m -> `(bind ,n ,m);
action :exp -> `(action ,exp);
exactly :datum -> `(exactly ,datum);
sequence :exp -> `(sequence ,exp);
position -> `(position);