1 module pegged.performancetest.cursive.generator;
2 
3 import pegged.grammar;
4 
5 void main()
6 {
7     asModule("pegged.performancetest.cursive.parser2",
8              "parser2",
9 
10 
11              "Cursive:
12               Program <- Spacing Module Spacing (Declaration Spacing)* Spacing eoi
13               LineComment <- :(slash slash (&(endOfLine / eoi) (endOfLine / eoi) / .*))
14                BlockComment <- :(slash '*' (&('*' slash) '*' slash / .*))
15 
16                Boolean <- 'true' / 'false'
17                Null <- 'null'
18 
19                IntegerSuffix <- slash ('i8' / 'u8' / 'i16' / 'u16' / 'i32' / 'u32' / 'i64' / 'u64')
20                RealSuffix <- slash ('f32' / 'f64')
21 
22                Sign <- '+' / '-'
23 
24                Decimal <~ [0-9]+
25                Binary <~ '0' ('b' / 'B') [0-1]+
26                Octal <~ '0' ('o' / 'O') [0-7]+
27                Hexadecimal <~ '0' ('x' / 'X') [0-9a-fA-F]+
28 
29                Size <- Binary / Octal / Hexadecimal / Decimal
30                Integer <- Sign? (Binary / Octal / Hexadecimal / Decimal) IntegerSuffix
31                Real <- Sign? Decimal '.' Decimal (('e' / 'E') Sign? Decimal)? RealSuffix
32 
33                EscapeSequence <- backslash (quote / doublequote / backslash / 'a' / 'b' / 'f' / 'n' / 'r' / 't' / 'v' / '0')
34                UnicodeSequence <- backslash ('u' / 'U') '+'? [0-9a-fA-F]+
35 
36                Character <~ :quote (EscapeSequence / UnicodeSequence / !quote .) :quote
37                String <~ :doublequote (EscapeSequence / UnicodeSequence / !doublequote .)* :doublequote
38 
39                Literal <- Boolean / Null / Real / Integer / Character / String
40 
41                Qualifiedidentifier <- identifier (Spacing '.' Spacing identifier)*
42 
43                FixedIntegralType <- 'int8' / 'uint8' / 'int16' / 'uint16' / 'int32' / 'uint32' / 'int64' / 'uint64'
44                IntegralType <- FixedIntegralType / 'int' / 'uint'
45                FloatingPointType <- 'float32' / 'float64'
46                CoreType <- 'object' / 'bool' / IntegralType / FloatingPointType
47 
48                TypeReference <- Qualifiedidentifier (Spacing GenericParameters)?
49                TypeSpecification <- (CoreType / TypeReference) Spacing NullableType?
50                GenericParameters <- '<' Spacing Type (Spacing ',' Spacing Type)* Spacing '>'
51 
52                FunctionType <- CallingConvention? Spacing ParameterTypes Spacing NullableType?
53                ParameterTypes <- '(' Spacing (Type (Spacing ',' Spacing Type)*)? ')'
54 
55                PointerType <- '*'
56                ArrayType <- '[' Spacing ']'
57                VectorType <- '[' Spacing Size Spacing ']'
58                NullableType <- '?'
59 
60                TupleType <- '{' Spacing Type (Spacing ',' Spacing Type)* Spacing '}'
61 
62                TypeModifiers <- (PointerType / ArrayType / VectorType)+ Spacing NullableType?
63                Type <- TupleType / TypeSpecification (Spacing (TypeModifiers / FunctionType))?
64                InferredType <- 'var' / Type
65 
66                ReturnType <- 'void' / Type
67                CallingConvention <- 'cdecl' / 'stdcall'
68 
69                Module <- 'module' Spacing Qualifiedidentifier Spacing ';'
70 
71                Import <- 'import' Spacing Qualifiedidentifier (Spacing ',' Spacing Qualifiedidentifier)* ';'
72 
73                Declaration <- Import / Class / Interface / Struct / Enum / Data / ModuleConstructor / ModuleFinalizer / Field / ModuleFunction / Operator
74 
75                Visibility <- 'public' / 'internal' / 'private' / 'protected' (('and' / 'or') 'internal')?
76 
77                InheritanceList <- ':' Spacing TypeReference (Spacing ',' Spacing TypeReference)*
78 
79                Class <- Visibility? Spacing ClassModifiers Spacing 'class' Spacing identifier Spacing InheritanceList? '{' Spacing (ClassMember Spacing)* Spacing '}'
80                ClassModifiers <- ('open' / 'abstract')? Spacing ('pure' / 'impure')? Spacing ('safe' / 'unsafe')?
81                ClassMember <- ClassConstructor / ClassFinalizer / Constructor / Finalizer / Field / Property / Method / Operator
82 
83                Interface <- Visibility? Spacing 'interface' Spacing identifier Spacing InheritanceList? Spacing '{' Spacing (InterfaceMember Spacing)* Spacing '}'
84                InterfaceMember <- Property / Method / Operator
85 
86                Struct <- Visibility? Spacing StructModifiers Spacing 'struct' Spacing identifier Spacing InheritanceList? Spacing '{' Spacing (StructMember Spacing)* Spacing '}'
87                StructModifiers <- ('pure' / 'impure')? Spacing ('safe' / 'unsafe')?
88                StructMember <- StructConstructor / StructFinalizer / Constructor / Field / Property / Function / Operator
89 
90                Enum <- Visibility? Spacing 'enum' Spacing identifier Spacing EnumBase Spacing '{' Spacing (EnumMember Spacing)* Spacing '}'
91                EnumBase <- 'of' Spacing FixedIntegralType
92                EnumMember <- identifier (Spacing ',' Spacing identifier)* Spacing '=' Spacing Size Spacing ';'
93 
94                Data <- Visibility? Spacing 'data' Spacing DataSemantics Spacing identifier Spacing '{' Spacing (DataMember Spacing)* Spacing '}'
95                DataSemantics <- 'byref' / 'byval'
96                DataMember <- DataField / DataCase / Property / Function / Operator
97                DataField <- Type Spacing identifier (Spacing ',' Spacing identifier)* Spacing ';'
98                DataCase <- 'case' Spacing identifier '{' Spacing (DataField Spacing)* Spacing '}'
99 
100                StaticConstructorModifiers <- 'thread'? Spacing ('pure' / 'impure')? Spacing ('safe' / 'unsafe')?
101                StaticConstructorBody <- BlockStatement
102 
103                ModuleConstructor <- StaticConstructorModifiers Spacing 'module' Spacing '(' Spacing ')' Spacing StaticConstructorBody
104                ModuleFinalizer <- StaticConstructorModifiers Spacing '~' Spacing 'module' Spacing EmptyParameterList Spacing StaticConstructorBody
105 
106                ClassConstructor <- StaticConstructorModifiers Spacing 'class' Spacing '(' Spacing ')' Spacing StaticConstructorBody
107                ClassFinalizer <- StaticConstructorModifiers Spacing '~' Spacing 'class' Spacing EmptyParameterList Spacing StaticConstructorBody
108 
109                StructConstructor <- StaticConstructorModifiers Spacing 'struct' Spacing '(' Spacing ')' Spacing StaticConstructorBody
110                StructFinalizer <- StaticConstructorModifiers Spacing '~' Spacing 'struct' Spacing EmptyParameterList Spacing StaticConstructorBody
111 
112                Field <- Visibility? Spacing FieldModifiers Spacing Type Spacing identifier (Spacing ',' Spacing identifier)* Spacing ';'
113                FieldModifiers <- 'const' / ('thread' / 'static')? Spacing 'final'?
114 
115                ModuleFunction <- RawFunction / ExternFunction / Function
116 
117                RawFunction <- Visibility? Spacing 'raw' Spacing ReturnType Spacing identifier Spacing ParameterList Spacing RawFunctionBody
118                RawFunctionBody <- BlockStatement
119 
120                ExternFunction <- Visibility? Spacing 'extern' Spacing ExternFunctionLocation Spacing ReturnType Spacing identifier Spacing ParameterList Spacing ';'
121                ExternFunctionLocation <- '(' Spacing String Spacing ',' Spacing String Spacing ')'
122 
123                Function <- Visibility? Spacing FunctionModifiers Spacing ReturnType Spacing identifier Spacing ParameterList Spacing FunctionBody
124                FunctionModifiers <- ('pure' / 'impure')? Spacing ('safe' / 'unsafe')?
125                FunctionBody <- BlockStatement
126 
127                EmptyParameterList <- '(' Spacing ')'
128                ParameterList <- '(' Spacing (Parameter (Spacing ',' Spacing Parameter)*)? Spacing ')'
129                Parameter <- ParameterModifiers Spacing Type Spacing identifier
130                ParameterModifiers <- ('ref' / 'out' / 'params')?
131 
132                Operator <- Visibility? Spacing Type Spacing 'operator' Spacing CustomOperator Spacing ParameterList Spacing OperatorBody
133                CustomOperator <- '+' / '-' / '*' / slash / '%' / '&' / '|' / '^'
134                OperatorBody <- BlockStatement
135 
136                Property <- Visibility? Spacing PropertyModifiers Spacing Type Spacing identifier Spacing '{' Spacing PropertyBody Spacing '}'
137                PropertyModifiers <- ('pure' / 'impure')? Spacing ('safe' / 'unsafe')? Spacing (('virtual' / 'abstract') / 'override'? Spacing 'final'?)
138                PropertyBody <- PropertyGetter Spacing PropertySetter / PropertyGetter / PropertySetter
139                PropertyGetter <- AccessorModifiers Spacing 'get' Spacing AccessorBody
140                PropertySetter <- AccessorModifiers Spacing 'set' Spacing AccessorBody
141                AccessorModifiers <- ('pure' / 'impure')? Spacing ('safe' / 'unsafe')?
142                AccessorBody <- BlockStatement / ';'
143 
144                Method <- Visibility? Spacing MethodModifiers Spacing ReturnType Spacing identifier Spacing ParameterList Spacing MethodBody
145                MethodModifiers <- ('pure' / 'impure')? Spacing ('safe' / 'unsafe')? Spacing (('virtual' / 'abstract') / 'override'? Spacing 'final'?)
146                MethodBody <- BlockStatement / ';'
147 
148                Constructor <- Visibility? Spacing 'this' Spacing ParameterList Spacing FunctionBody
149                Finalizer <- '~' Spacing 'this' Spacing EmptyParameterList Spacing FunctionBody
150 
151                BlockStatement <- '{' Spacing '}'
152 
153                ");
154 }