ometa-boot.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.
0
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     1
-- -*- text -*-
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     2
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
     3
productions =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
     4
(production)+
0
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     5
;
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     6
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
     7
production =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
     8
&name:n production-part(n):x (token(";") production-part(n))*:xs token(";") spaces ->(quasiquote ((unquote n) (or (unquote x) (unquote-splicing xs))))
0
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     9
;
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    10
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    11
production-part =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    12
:required-name name:n ->(or (eq? n required-name) (error (quote clause-name-mismatch))) expr-seq:body (token("=") expr:rhs ->(quasiquote (seq (unquote body) (unquote rhs))) | ->body)
0
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    13
;
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    14
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    15
expr-seq =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    16
(expr3)*:xs ->(quasiquote (seq (unquote-splicing xs)))
4
3d59c8de1691 Complete bootstrapping and optimisation
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 1
diff changeset
    17
;
3d59c8de1691 Complete bootstrapping and optimisation
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 1
diff changeset
    18
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    19
expr3 =
32
5deee5dae03d Support @ for current parse position.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents: 31
diff changeset
    20
((expr2:r (token("*") ->(quasiquote (many (unquote r))) | token("+") ->(quasiquote (many1 (unquote r))) | ->r) | token("@") ->(quasiquote (position))):r ($: name:n ->(quasiquote (bind (unquote n) (unquote r))) | ->r) | token(":") name:n ->(quasiquote (bind (unquote n) (anything))))
0
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    21
;
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    22
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    23
expr2 =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    24
(token("~") expr2:x ->(quasiquote (not (unquote x))) | token("&") expr1:x ->(quasiquote (follow (unquote x))) | expr1)
0
d1020e9e43c6 A day's hacking
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    25
;
4
3d59c8de1691 Complete bootstrapping and optimisation
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 1
diff changeset
    26
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    27
expr1 =
31
dd9850e5e4fc Apply some of the changes from the previous commit to the .g files
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents: 9
diff changeset
    28
(token("<{") host-language-expression:s token("}>") ->(quasiquote (sequence (unquote s))) | name:prod-exp apply-arguments:arg-exps ->(quasiquote (apply (unquote prod-exp) (unquote-splicing arg-exps))) | token("->") host-language-expression:r ->(quasiquote (action (unquote r))) | token("?") host-language-expression:r ->(quasiquote (action (or (unquote r) (error)))) | literal:x ->(quasiquote (exactly (unquote x))) | token("_") ->(quasiquote (anything)) | token("(") expr:x token(")") ->x | token("{") expr-seq:xs token("}") ->(quasiquote (nest (unquote xs))))
9
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    29
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    30
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    31
apply-arguments =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    32
($( (token(")") ->(quote ()) | scheme-term:a1 (token(",") scheme-term)*:aa token(")") ->(cons a1 aa)) | ->(quote ()))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    33
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    34
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    35
literal =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    36
(okeyword("nil", ()) | okeyword("true", #t) | okeyword("false", #f) | onumber | ostring(#\') | token("$") ochar | token("#") (name | ostring(#\'):s ->(string->symbol s)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    37
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    38
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    39
onumber =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    40
spaces (digit)+:ip ($. (digit)+:fp ->(string->number (string-append (list->string ip) "." (list->string fp))) | ->(string->number (list->string ip)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    41
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    42
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    43
ostring =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    44
ochar:quo spaces ochar:s1 ->(or (eqv? s1 quo) (error (quote expected) (quote string-open-quote))) (($\ ($\ | ochar:c ->(if (eqv? c quo) c (error (quote expected) (quote escaped-quote)))) | ochar:c ->(if (eqv? c quo) (error (quote expected) (quote string-char)) c)))*:cs ochar:s2 ->(if (eqv? s2 quo) (list->string cs) (error (quote expected) (quote string-close-quote)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    45
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    46
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    47
ochar =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    48
:c ->(if (char? c) c (error (quote expected) (quote char?)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    49
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    50
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    51
expr =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    52
expr-seq:x (token("|") expr-seq)*:xs ->(quasiquote (or (unquote x) (unquote-splicing xs)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    53
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    54
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    55
okeyword =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    56
:xs :val spaces <{xs}> ~name-subsequent((quote (#\- #\? #\! #\* #\+ #\/ #\= #\: #\'))) ->val
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    57
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    58
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    59
token =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    60
:xs spaces <{xs}>
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    61
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    62
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    63
name =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    64
generic-name((quote ()), (quote (#\- #\_)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    65
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    66
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    67
generic-name =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    68
:initial-chars :subsequent-chars spaces name-initial(initial-chars):x (name-subsequent(subsequent-chars))*:xs ->(string->symbol (list->string (cons x xs)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    69
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    70
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    71
name-initial =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    72
:initial-chars ochar:c ->(if (or (char-alphabetic? c) (memv c initial-chars)) c (error (quote expected) (quote name-initial)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    73
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    74
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    75
name-subsequent =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    76
:subsequent-chars ochar:x ->(if (or (char-alphabetic? x) (char-numeric? x) (memv x subsequent-chars)) x (error (quote expected) (quote name-subsequent)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    77
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    78
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    79
digit =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    80
ochar:c ->(if (char-numeric? c) c (error (quote expected) (quote char-numeric?)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    81
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    82
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    83
spaces =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    84
((ochar:c ->(if (char-whitespace? c) c (error (quote expected) (quote char-whitespace?))))+ spaces | $- $- (:x ->(if (memv x (quote (#\return #\newline))) (error (quote expected) (quote non-eol)) x))* spaces | ->#t)
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    85
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    86
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    87
host-language-expression =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    88
scheme-term
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    89
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    90
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    91
scheme-term =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    92
(scheme-atom | scheme-quoted("'", (quote quote)) | scheme-quoted("`", (quote quasiquote)) | scheme-quoted(",", (quote unquote)) | scheme-quoted(",@", (quote unquote-splicing)) | token("(") scheme-sequence:xs token(")") ->xs)
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    93
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    94
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    95
scheme-quoted =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    96
:quo :sym spaces <{quo}> scheme-term:x ->(quasiquote ((unquote sym) (unquote x)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    97
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    98
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
    99
scheme-atom =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   100
(okeyword("#t", #t) | okeyword("#f", #f) | onumber | ostring(#\") | token("#\\") (token("return") ->#\return | token("newline") ->#\newline | ochar) | scheme-symbol | ostring(#\|):s ->(string->symbol s))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   101
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   102
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   103
scheme-symbol =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   104
generic-name((quote (#\? #\! #\* #\+ #\/ #\= #\: #\< #\>)), (quote (#\? #\! #\* #\+ #\/ #\= #\: #\< #\> #\' #\-)))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   105
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   106
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   107
scheme-sequence =
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   108
(scheme-term:a token(".") scheme-term:d ->(cons a d) | scheme-term:a scheme-sequence:d ->(cons a d) | ->(quote ()))
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   109
;
085b12f75c9f Major improvements to ometa syntax.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents: 6
diff changeset
   110