etng-r2/etng-reader.g
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 198 072745b48add
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
198
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     3
sexp-toplevel = (ws $;)* ( (~toplevel-stop sexp)*:ss toplevel-stop -> ss
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     4
	      	    	 | ws ~_ -> 'eof);
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     5
072745b48add Improve parser to the point where metaeval.tng at least parses.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 186
diff changeset
     6
toplevel-stop = ws $; ;
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     7
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
     8
sexp =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
     9
	  ws (   $. sexp:s -> `(paren ,QUOTE-QNAME ,s)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    10
	       | $` sexp:s -> `(paren ,UNQUOTE-QNAME ,s)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    11
	       | $( sexp*:ss ws $) -> `(paren ,@ss)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    12
	       | $[ sexp*:ss ws $] -> `(brack ,@ss)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    13
	       | ${ sexp*:ss ws $} -> `(brace ,@ss)
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    14
	       )
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    15
	| leaf
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    16
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    17
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    18
leaf = qname | id | word | string;
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    19
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    20
qname =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    21
	  id:lhs $: id:rhs -> (make-qname lhs rhs)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    22
	| ws     $: id:rhs -> (make-qname EMPTY-SYMBOL rhs)
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    23
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    24
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    25
id =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    26
	ws ( id1:i -> (string->symbol (string-concatenate (list-interleave "'" i)))
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    27
	   | $; -> (string->symbol ";")
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    28
	   | $, -> (string->symbol ",")
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    29
	   | id-alpha:a (id-alpha | digit)*:r
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    30
	       -> (string->symbol (list->string (cons a r)))
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    31
	   | id-punct+:p -> (string->symbol (list->string p))
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    32
	   )
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    33
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    34
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    35
id1 =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    36
	  id-subunit:i id1:is -> (cons i is)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    37
	| id-subunit:i -> (list i)
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    38
;
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    39
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    40
id-subunit = $' (:c ?(not (eqv? c #\')) ->c)*:cs $' -> (list->string cs);
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    41
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    42
word = positive-word | ws $- positive-word:w -> (invert-sign w);
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    43
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    44
positive-word = ws digit+:d -> (string->number (list->string d));
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    45
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    46
string = ws string1:s -> (string-concatenate (list-interleave "\"" s));
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    47
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    48
string1 =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    49
	  string-subunit:s string1:ss -> (cons s ss)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    50
	| string-subunit:s -> (list s)
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    51
;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    52
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    53
string-subunit = $" (:c ?(not (eqv? c #\")) ->c)*:cs $" -> (list->string cs);
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    54
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    55
id-alpha = :c ?(char-etng-id-alpha? c) -> c;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    56
id-punct = :c ?(char-etng-id-punct? c) -> c;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    57
digit = :c ?(char-numeric? c) -> c;
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    58
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    59
ws =
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    60
	  (:c ?(char-whitespace? c))+ ws
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    61
	| $- $- (:c ?(not (eol-char? c)))*
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    62
	     	(:c ?(eol-char? c))
186
9426a54b733b Update grammars for new ometa-scheme syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 181
diff changeset
    63
		ws
181
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    64
	|
f82ec080be39 etng-r2, using ometa-scheme.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    65
;