summaryrefslogtreecommitdiff
path: root/src/piraha/pegs/param.peg
blob: e5b54cd3961da07f3c49e62222df045c33c0e9bd (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
uses = (?i:uses|)

# The skipper is a crucial sub-pattern
# that is activated by any whitespace in the
# grammar file
skipper = \b([\ \t\n\r\b]|\#[^\n]*|\\[\r\n])*

any = [^]
name = (?i:[a-z_][a-z0-9_]*)
accname = {-name}(::{-name})*
steerable = (?i:never|always|recover)
accumexpr = \( ([^()]+|{accumexpr}) \)

# Note slop on shared
access = (?i: global : | restricted : | private : | shares :([\ \t]*{name}|) )
#access = (?i: global : | restricted : | private : | shares : {name} )

quote = "(\\{any}|[^"])*"

num = [+\-]?[0-9]+
intbound = (\* | {num} | ) 
intrange = ([\[\(]?{intbound} :(?!:) {intbound}[\]\)]? | {intbound} )

real = [+\-]?([0-9]+\.[0-9]+|[0-9]+\.|\.[0-9]+|[0-9]+)([eEdD][+\-]?{num}|)
realbound = (\*|{real}| )
realrange = [\(\[]?{realbound} :(?!:) {realbound}[\)\]]? | {realbound}

boolraw = (?i:true|t|yes|y|false|f|no|n|1|0)
bool = {-boolraw}|"{-boolraw}"

string = {quote}|{name}|(\\[^]|[^\\ \t\r\n\b}])+

keyword = {name}|{quote}

intguts = (?i:
	(CCTK_|)INT {name}(\[{num}\]|)
	({quote}|)
    (as {name} |)
    (steerable = {steerable} |accumulator = {accumexpr} |accumulator-base = {accname} )*
  )
  
intpar = (?i:
	(uses|extends) {intguts}
    ( \{
    	( {intrange} (:: {quote}|) )*
    \} |)|
	{intguts} 
    ( \{
    	# some special slop here
    	#( {intrange} (:: {quote}|:: [a-z][^\n]*|) )*
    	( {intrange} (:: {quote}|) )*
    \} {num}|)
  )

realguts = (?i:
	(CCTK_|)REAL {name}( \[{num}\]|)
	({quote}|)
    (as {name} |)
    (steerable = {steerable}|)
    (accumulator = {accumexpr} |)
    (accumulator-base = {accname} |)
  )
  
realpar = (?i:
	(uses|extends) {realguts} 
    (\{
    	( {realrange} (:: {quote} |) )*
    \}|)|
	{realguts}
    (\{
    	# Note that we allow for lots of slop here
    	#( {realrange} (:: {quote} | {quote} | :: [a-z][^\n]*) )*
    	( ("{realrange}"|{realrange}) (:: {quote}|) )*
    \} {real}|)
  )
  
keywordguts = (?i:
	(CCTK_|)KEYWORD {name}(\[{num}\]|)
	({quote}|)
    (as {name} |)
    (steerable = {steerable}|)
    (accumulator = {accumexpr} |)
    (accumulator-base = {accname} |)
  )
  
keywordpar = (?i:
	(extends|uses) {keywordguts} 
    (\{
    	( {keyword} (, {keyword})* (:: {-quote}|) )*
    \}|)|
	{keywordguts} 
    (\{
    	( {keyword} (, {keyword})* (:: {-quote}|) )*
    \} {keyword}|)
  )
  
stringguts = (?i:
	(CCTK_|)STRING {name}(\[{num}\]|)
	({quote}|)
    (as {name} |)
    (steerable = {steerable} |accumulator = {accumexpr} |accumulator-base = {accname} )*
  )
  
stringpar = (?i:
	(uses|extends) {stringguts} 
    (\{
    	( {string} (, {string})* (:: {quote}|) )*
    \}|)|
	{stringguts}
    (\{
    	# first option is weird
    	( :: {quote} |{string} (, {string})* (:: {quote}|) )*
    	#({string} (, {string})* (:: {quote}|) )*
    	# no default is permitted!
    \} ({string}|$)|)
  )

boolguts = (?i:
	(CCTK_|)BOOLEAN {name}(\[{num}\]|)
	({quote}|)
    (as {name} |)
    (steerable = {steerable}|)
    (accumulator = {accumexpr} |)
    (accumulator-base = {accname} |)
  )
  
boolpar = (?i:
	(uses|extends) {boolguts} 
    (\{
    ({bool} (:: {quote} |))*
    \}|)|
	{boolguts} 
    (\{
    # Note the weird slop here
    #({bool} (:: {quote} |)|: :: {quote}|:: {quote})*
    (:: {quote}|{bool} (:: {quote} |) )*
    ( : :: {quote} )*
    \} {bool}|)
  )
  
pars = ^ ({access}|{intpar}|{realpar}|{keywordpar}|{stringpar}|{boolpar})* $