diff options
Diffstat (limited to 'src/piraha/pegs')
-rw-r--r-- | src/piraha/pegs/configuration.peg | 32 | ||||
-rw-r--r-- | src/piraha/pegs/interface.peg | 73 | ||||
-rw-r--r-- | src/piraha/pegs/param.peg | 141 | ||||
-rw-r--r-- | src/piraha/pegs/schedule.peg | 70 |
4 files changed, 316 insertions, 0 deletions
diff --git a/src/piraha/pegs/configuration.peg b/src/piraha/pegs/configuration.peg new file mode 100644 index 00000000..ade602bc --- /dev/null +++ b/src/piraha/pegs/configuration.peg @@ -0,0 +1,32 @@ +# 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 = [^] +keywords = \b(?i:script|lang|provides|requires|optional)\b +name = (?!{-keywords})(?i:[a-z_][a-z0-9_\.]*\b) +num = [+\-]?[0-9]+ +script = (?i: script( {name}|)) +lang = (?i: lang( {name}|)) + +option = {name} + +provides = (?i: + provides {name} \{ + ({script}? + {lang} + ( options {option}( {option})* |)|) + \} + ) + +requires = (?i: + requires (thorns:|) {name}([ \t]*{name})* + ) + +ifactive = (?i:_ifactive) +optional = (?i: + optional{ifactive}? {name}([ \t]+{name})* \{ ( {name} )* \} + ) + +config = ({provides} |{requires} |{optional} )* $ diff --git a/src/piraha/pegs/interface.peg b/src/piraha/pegs/interface.peg new file mode 100644 index 00000000..99ba1508 --- /dev/null +++ b/src/piraha/pegs/interface.peg @@ -0,0 +1,73 @@ +skipper = (([ \t\n\r\b]|\#[^\n\r]*|\\[\r\n])+|\b) + +any = [^] +name = (?i:[a-z_][a-z0-9_]*) +filename = (?i:([.a-z0-9_]|\\[^])*) +accname = {-name}(::{-name})* +inum = [1248] +rnum = [48] +cnum = 8|16 +type = (void|CCTK_INT{inum}?|CCTK_REAL{rnum}?|CCTK_COMPLEX{cnum}?|CCTK|CCTK_POINTER|CCTK_TO_CONST) + +num = [0-9]+ +boolraw = (?i:true|t|yes|y|false|f|no|n|1|0) +bool = {-boolraw}|"{-boolraw}" + +powexpr = \( {expr} \)|-{expr}|{accname}|{num} +mulexpr = {powexpr}( \^ {powexpr})? +mulop = [/*%] +addexpr = {mulexpr}( {mulop} {mulexpr})* +addop = [+-] +expr = {addexpr}( {addop} {addexpr})* +n = ([\ \t]|\\[\r\n])* + +IMPLEMENTS = (?i:implements):{-n}{name} +INHERITS = (?i:inherits):{-n}({name}({-n},?{-n}{name})*)? +FRIEND = (?i:friend):{-n}({name}({-n},?{-n}{name})*)? + +what = (?i:SOURCE|HEADER) +INCLUDE = (?i:INCLUDE(S)? {what}?: {filename} in {filename}) + +ret_type = (?i:void|CCTK_INT{num}?|CCTK_REAL|CCTK_COMPLEX|CCTK_POINTER_TO_CONST|CCTK_POINTER) +arg_type = (?i:CCTK_STRING|CCTK_INT{num}?|CCTK_REAL|CCTK_COMPLEX|CCTK_POINTER_TO_CONST|CCTK_POINTER|STRING) +intent = (?i:INOUT|OUT|IN) +array = (?i:array) +fpointer = ({intent} (?i:CCTK_FPOINTER)|(?i:CCTK_FPOINTER) {intent}|(?i:CCTK_FPOINTER)) {name} {args} +arg = {arg_type} ({fpointer}|{array} {intent} {name}|{intent} {array} {name}|{intent} {name}) +args = \( ({arg}( , {arg})* )?\) + +FUNCTION_ALIAS = (?i:{ret_type} FUNCTION | SUBROUTINE ) {name} {args} +FUNCTION_PTR = (?i:CCTK_FPOINTER {name} \( {arg_type} {intent} {name} (, {arg_type} {intent} {name} )*\)) +REQUIRES_FUN = (?i:REQUIRES FUNCTION {name}) +USES_FUN = (?i:USES FUNCTION {name}|USES INCLUDE {what}?: {filename}([ \t]+{filename})*) +PROVIDES_FUN = (?i:PROVIDES FUNCTION {name} WITH {name} LANGUAGE (?i:C|FORTRAN)) +FUNCTION = ({FUNCTION_ALIAS}|{FUNCTION_PTR}|{REQUIRES_FUN}|{USES_FUN}|{PROVIDES_FUN}) + +access = (?i:protected|public|private) +vtype = (?i:(CHAR|BYTE|INT{inum}?|REAL{rnum}?|COMPLEX{cnum}?)) +VARS = ({name}( ,? {name} )*)( ,)? +gtype = (?i:GF|ARRAY|SCALAR) +dim = {-num} +timelevels = {-num} +size = {expr}( , {expr})*|" {expr}( , {expr})* " +distrib = (?i:CONSTANT|DEFAULT) +ghostsize = {-size} +stagger = (?i:[MCP](,[MCP])*) +tags = {-quote} + +GROUP_VARS = (?i:CCTK_|){vtype} {name}( \[ {expr} \])? (?i:TYPE = {gtype} | DIM = {dim} | + TIMELEVELS = {timelevels} | SIZE = {size} | DISTRIB = {distrib} | + GHOSTSIZE = {ghostsize} | STAGGER = {stagger} | TAGS = {tags})* {dquote}? ( + \{ + {VARS} + \} {dquote}? + )? + + +FUNC_GROUP = ({FUNCTION} |{access}: |{GROUP_VARS} |{INCLUDE} |{IMPLEMENTS} |{INHERITS} |{FRIEND} ) + +dquote = "(\\{-any}|[^"])*" +squote = '(\\{-any}|[^'])*' +quote = {dquote}|{squote} + +intr = ^(?i: {FUNC_GROUP}*)$ diff --git a/src/piraha/pegs/param.peg b/src/piraha/pegs/param.peg new file mode 100644 index 00000000..e5b54cd3 --- /dev/null +++ b/src/piraha/pegs/param.peg @@ -0,0 +1,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})* $ diff --git a/src/piraha/pegs/schedule.peg b/src/piraha/pegs/schedule.peg new file mode 100644 index 00000000..4a19d046 --- /dev/null +++ b/src/piraha/pegs/schedule.peg @@ -0,0 +1,70 @@ +skipper = \b([\ \t\n\r\b]|{-ccomment}|\#[^\n]*|\\[\r\n])* + +any = [^] +name = (?i:[a-zA-Z_][a-zA-Z0-9_\-]*\b) +expr = {name}|{num} +vname = {name}( :: {name})*( \[ {expr} \]|) +quote = "(\\{any}|[^"])*" +ccomment = /\*((?!\*/){-any})*\*/ +num = [+\-]?[0-9]+(\.[0-9]+)? +string = {name}|{quote} +term = {num}|{name} +par = \b(?i:as|at|in|while|if|before|after|while)\b +pararg = ({vname}|\( {vname}( ,? {vname} )* \)) +assign = {name} = {num} + +boolpar = \( {boolexpr} \) +eqfun = (?i:CCTK_Equals) +actfun = (?i:CCTK_IsThornActive) +actifun = (?i:CCTK_IsImplementationActive) +booleq = {eqfun} \( {string} , {string} \) +boolact = ({actfun}|{actifun}) \( {string} \) +boolstar = \* {name} +boolneg = \! {boolexpr} +boolterm = (?i:{boolneg} + | {boolpar} + | {booleq} + | {boolact} + | {boolstar} + | {name} ) + +boolop = (&&|\|\|) +boolcmp = (>=|<=|==|!=|<|>) +boolexpr = {boolterm} ({boolop} {boolexpr} )+ + | {term} {boolcmp} {term} | {boolterm} + +lang = (?i:lang(uage|) : {name}) +group = (?i:group) +nogroup = +prepositions = ({preposition} )* +preposition = {par} {pararg} +sync = (?i:sync) : {vname}( , {vname}|[ \t]{vname})* +options = (?i:options?) : {vname}( , {vname}|[ \t]{vname})* +storage = (?i:storage) : {vname}( , {vname}|[ \t]{vname})* +triggers = (?i:triggers?) : {vname}( , {vname}|[ \t]{vname})* +reads = (?i:reads) : {qname}( , {qname}|[ \t]{qname})* +writes = (?i:writes) : {qname}( , {qname}|[ \t]{qname})* +qname = {vname}(\({region}(;{region})*\))? +region = (everywhere|interior|boundary_ghostzones|boundary|all_timelevels|all_maps|all_reflevels) +tags = (?i:tags) : {assign}( , {assign}|[ \t]{assign})* +schedule = (?i: + schedule ({group}|{nogroup}) {name} {prepositions} \{ + ( {storage} + | {lang} + | {sync} + | {options} + | {triggers} + | {reads} + | {writes} + | {tags} + )* + \} {quote} + ) +if = (?i: + if \( {boolexpr} \) {block} (else {if}|else {block}|) + ) +storage = (?i:storage: {vname}( , {vname}|([ \t]|\\\r?\n)+{vname})* ) +block = \{ (({statement}|{block}) )* \} | {statement} + +statement = ({schedule} |{if} |{storage} ) +sched = {-skipper}({statement}|{block})*$ |