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.
2
750cff2fd084 Start sketching out ometa-opt phase.
tonyg@lshift.net
parents:
diff changeset
     1
-- -*- text -*-
750cff2fd084 Start sketching out ometa-opt phase.
tonyg@lshift.net
parents:
diff changeset
     2
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
     3
opt-grammar = {opt-production}*;
2
750cff2fd084 Start sketching out ometa-opt phase.
tonyg@lshift.net
parents:
diff changeset
     4
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
     5
end = ~_ ;
2
750cff2fd084 Start sketching out ometa-opt phase.
tonyg@lshift.net
parents:
diff changeset
     6
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
     7
opt-production = :n opt:o -> `(,n ,o);
2
750cff2fd084 Start sketching out ometa-opt phase.
tonyg@lshift.net
parents:
diff changeset
     8
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
     9
opt = {:t t};
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    10
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    11
opt-inside :t =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    12
  {:t1 ->(or (eq? t t1) (error 'expected t)) opt-inside(t):xs} opt-inside(t):ys -> (append xs ys)
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    13
| opt:x							       opt-inside(t):xs -> (cons x xs)
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    14
|										-> '()
4
3d59c8de1691 Complete bootstrapping and optimisation
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 2
diff changeset
    15
;
3d59c8de1691 Complete bootstrapping and optimisation
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 2
diff changeset
    16
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    17
apply :prod (_*):args -> `(apply ,prod ,@args);
4
3d59c8de1691 Complete bootstrapping and optimisation
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 2
diff changeset
    18
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    19
or opt:o end -> o;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    20
or opt-inside('or):os -> (if (= (length os) 1) (car os) `(or ,@os));
4
3d59c8de1691 Complete bootstrapping and optimisation
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 2
diff changeset
    21
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    22
seq opt:o end -> o;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    23
seq opt-inside('seq):os -> (if (= (length os) 1) (car os) `(seq ,@os));
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    24
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    25
nest opt:m end -> `(nest ,m);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    26
not opt:m end -> `(not ,m);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    27
follow opt:m end -> `(follow ,m);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    28
many opt:m end -> `(many ,m);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    29
many1 opt:m end -> `(many1 ,m);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    30
anything end -> `(anything);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    31
bind :n opt:m -> `(bind ,n ,m);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    32
action :exp -> `(action ,exp);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    33
exactly :datum -> `(exactly ,datum);
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 4
diff changeset
    34
sequence :exp -> `(sequence ,exp);
32
5deee5dae03d Support @ for current parse position.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents: 9
diff changeset
    35
position -> `(position);