etng-r2/etng-parser.g
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 274 dbc75d602637
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     1
-- -*- text -*-
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     2
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
     3
toplevel = toplevel-item:v ~_ -> v;
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     4
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
     5
toplevel-item =
198
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     6
	  {#paren #namespace :prefix ?(symbol? prefix) equal :urn ?(string? urn) ~_
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     7
	  	  -> `(define-namespace ,prefix ,urn)}
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     8
	| {#paren #namespace :urn ?(string? urn) ~_
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     9
	  	  -> `(declare-default-namespace ,urn)}
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
    10
	| {#paren #define :q ?(qname-or-symbol? q) equal expr:exp ~_
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    11
		  -> `(define-value ,q ,exp)}
198
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
    12
	| {#paren #define :q ?(qname-or-symbol? q) normal-method:def ~_
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    13
	  	  -> `(define-function ,q ,def)}
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    14
	| parse
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    15
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    16
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    17
parse =
230
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
    18
	  ~(comma | semi | arrow | equal | pipe)
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    19
	  :n
203
580fc03b9e18 Take advantage of the corrected ometa sequence behaviour.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 202
diff changeset
    20
	  ( grouping(n)
198
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
    21
	  | ?(qname-or-symbol? n) -> `(ref ,n)
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    22
	  | ?(or (string? n) (number? n)) -> `(lit ,n) )
209
2f3f59f1aa69 More precise error reports.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 206
diff changeset
    23
	| comma -> (error 'extra 'comma)
2f3f59f1aa69 More precise error reports.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 206
diff changeset
    24
	| semi -> (error 'extra 'semi)
212
4dc299259002 Be more thorough about detecting misplaced -> and =.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 209
diff changeset
    25
	| arrow -> (error 'extra 'arrow)
4dc299259002 Be more thorough about detecting misplaced -> and =.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 209
diff changeset
    26
	| equal -> (error 'extra 'equal)
230
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
    27
	| pipe -> (error 'extra 'pipe)
206
dd9c8ffca09a Improve error reporting by being more discriminating about a common error case.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 204
diff changeset
    28
	| -> (error)
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    29
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    30
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    31
grouping =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    32
	  {#paren expr:e ~_ -> e}
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 230
diff changeset
    33
	| #rec {#brace methods:ms -> `(object self ,@ms)}
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 230
diff changeset
    34
	| #rec :selfid {#brace methods:ms -> `(object ,selfid ,@ms)}
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    35
	| {#brace methods:ms -> `(function ,@ms)}
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    36
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    37
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    38
expr =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    39
	  :head ?(special-segment-head? head) special-segment(head)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    40
	| tuple:elts -> (if (= (length elts) 1) (car elts) `(tuple ,@elts))
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    41
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    42
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    43
special-segment =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    44
	  :head ?(equal? head QUOTE-QNAME) :n -> `(lit ,n)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    45
	| :head ?(equal? head UNQUOTE-QNAME) -> (error 'naked-unquote)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    46
	| #do expr:e1 semis expr:e2
202
65694ce5407c Make (discard) like all other pattern ASTs: wrapped in parens.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 201
diff changeset
    47
	  -> `(send (function (method ((discard)) ,e2)) ,e1)
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    48
	| #let pattern:p equal expr:e semis expr:body
201
9b22b7a23e39 Convert constant-methods to normal methods.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 198
diff changeset
    49
	  -> `(send (function (method (,p) ,body)) ,e)
204
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    50
	| #'%assemble' {#paren assemble-bindings:bindings ~_} {#brace assemble-clauses:clauses ~_}
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    51
	  -> `(assemble ,bindings ,clauses)
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    52
;
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    53
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    54
assemble-bindings =
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    55
	  assemble-binding:b (comma assemble-binding)*:bs -> (cons b bs)
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    56
	| ~_ -> '()
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    57
;
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    58
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    59
assemble-binding = :n ?(qname-or-symbol? n) equal send:e -> (list n e);
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    60
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    61
assemble-clauses =
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    62
	  ({#paren quote :n ?(qname-or-symbol? n)} | -> (error 'expected 'quoted-language-name))
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    63
	  arrow :item &(semi | ~_)
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    64
	  semis assemble-clauses:more -> (cons (list n item) more)
90899a08ca40 Parse '%assemble' construct.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 203
diff changeset
    65
	| ~_ -> '()
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    66
;
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    67
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    68
tuple =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    69
	  send:s (comma send)*:ss -> (cons s ss)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    70
	| ~_ -> '()
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    71
;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    72
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    73
send =
258
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    74
	  parse:receiver parse*:arguments pipeline:continuation
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    75
	    -> (continuation (if (null? arguments) receiver `(send ,receiver ,@arguments)))
274
dbc75d602637 Bug fix: missing variable capture in parser
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 258
diff changeset
    76
	| &pipe pipeline:continuation
230
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
    77
	    -> (let ((g (gensym 'pipe)))
258
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    78
	       	 `(function (method ((bind ,g)) ,(continuation `(ref ,g)))))
230
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
    79
;
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
    80
258
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    81
pipeline =
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    82
	  pipe parse:receiver parse*:arguments pipeline:continuation
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    83
	    -> (lambda (first-argument-ast)
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    84
	         (continuation `(send ,receiver ,first-argument-ast ,@arguments)))
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    85
	|   -> (lambda (first-argument-ast)
4d06e035b80e Begin adapting evaluator to codegen
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 236
diff changeset
    86
	         first-argument-ast)
230
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
    87
;
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
    88
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    89
methods =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    90
	  normal-method:m semis methods:ms -> (cons m ms)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    91
	| constant-method:m semis methods:ms -> (cons m ms)
202
65694ce5407c Make (discard) like all other pattern ASTs: wrapped in parens.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 201
diff changeset
    92
	| &_ expr:e semis ~_ -> (list `(method ((discard)) ,e))
198
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
    93
	| semis ~_ -> '()
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    94
;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    95
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    96
normal-method =
201
9b22b7a23e39 Convert constant-methods to normal methods.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 198
diff changeset
    97
	(~&(arrow | equal) pattern)+:patterns arrow expr:body
9b22b7a23e39 Convert constant-methods to normal methods.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 198
diff changeset
    98
	-> `(method ,patterns ,body)
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
    99
;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   100
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   101
constant-method =
201
9b22b7a23e39 Convert constant-methods to normal methods.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 198
diff changeset
   102
	(~&(arrow | equal) pattern)+:patterns equal expr:body
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   103
	-> `(constant-method ,patterns ,body)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   104
;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   105
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   106
pattern = pattern-tuple-nonempty:elts -> (if (= (length elts) 1) (car elts) `(tuple ,@elts));
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   107
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   108
pattern-tuple-nonempty =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   109
	pattern-element:e (comma pattern-element)*:es
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   110
	-> (cons e es)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   111
;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   112
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   113
pattern-tuple = pattern | -> `(tuple);
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   114
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   115
pattern-element =
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   116
	  ~(#do | #let)
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   117
	  :n
203
580fc03b9e18 Take advantage of the corrected ometa sequence behaviour.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 202
diff changeset
   118
	  ( pattern-grouping(n)
202
65694ce5407c Make (discard) like all other pattern ASTs: wrapped in parens.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 201
diff changeset
   119
	  | ?(eq? n DISCARD) -> `(discard)
198
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
   120
	  | ?(qname-or-symbol? n) -> `(bind ,n)
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   121
	  | ?(or (string? n) (number? n)) -> `(lit ,n)
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   122
	  )
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   123
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   124
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   125
pattern-grouping =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   126
	  {#paren quote :n -> `(lit ,n)}
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   127
	| {#paren pattern-tuple:p ~_ -> p}
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   128
	| {#brace -> (error 'object-matching-not-supported)}
234
10e62e160cb0 Switch from "[]" to "rec {}", and add "rec selfid {}" form
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 230
diff changeset
   129
	| {#brack -> (error 'list-matching-not-supported)}
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   130
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   131
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   132
semis = (:x ?(eq? x SEMI))*;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   133
semi = :x ?(eq? x SEMI) -> x;
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
   134
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   135
quote = :x ?(equal? x QUOTE-QNAME) -> x;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   136
comma = :x ?(eq? x COMMA) -> x;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   137
arrow = :x ?(eq? x ARROW) -> x;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 184
diff changeset
   138
equal = :x ?(eq? x '=) -> x;
230
70e311e51c29 Add pipe syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 212
diff changeset
   139
pipe = :x ?(eq? x PIPE) -> x;