-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.m.txt
82 lines (65 loc) · 1.81 KB
/
syntax.m.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# macro types:
# block, atom, brackets, literal
# operator types:
# postfix, prefix, infix
# prefix is: prefix $atom
# postfix is: $atom postfix
# infix is: $atom infix $atom
# block is: block: $statement*
# atom is: atom
type Binary:
object: left
object: right
type ConditionalDot:
is: Binary
macro: ?.
is: postfix
as: emit(ConditionalDot, { value: this.$atom })
macro: ?.
is: postfix
type WitnessedAttribute is VisitAttribute:
void visit(context: object):
pass
macro witnessed for methoddef:
static WitnessedAttribute: witnessedAttribute = new WitnessedAttribute
rule witnessed $methoddef:
# add attribute to method to make sure it get's visited
# this variable should be static (as in global for the witnessed macro type)
$methoddef.attributes.add(new Attribute():
body = [
new Reference():
name = "witnessed"
]
)
# patch body to throw at runtime
$methoddef.body = <[
if not context.witnessed:
throw "this method was not witnessed"
$methoddef.body
]>
macro witnessedmethoddef for $methoddef:
as witnessed $methoddef:
$methoddef.attributes.add context.parse(context.rules.attribute, "@witnessed")
$methoddef.body.shift <[
if not runtime.context.witnessed:
throw "this method was not witnessed"
]>
macro witnessed for $methoddef:
const string: pattern = "witnessed"
constructor():
$methoddef.keyword.push(parserVisitor)
void visit($methoddef:context):
pass
===========
program
import
import $name:Reference (from $library:Reference)?
macro
type
statement
pipeline:
parse
- build tree
- register macros
visit macros
- transform tree