-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-powershell.ebnf
185 lines (134 loc) · 4.74 KB
/
tree-sitter-powershell.ebnf
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// From tree-sitter-powershell/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
script ::=
script_block? signature_block?
script_block ::=
param_block? statement_list
param_block ::=
[pP][aA][rR][aA][mM] parameter_list
parameter_list ::=
'(' ( parameter_declaration ( ',' parameter_declaration )* )? ')'
parameter_declaration ::=
attribute* user_variable
attribute ::=
'[' identifier attribute_arguments? ']'
array_declaration ::=
'[' ','*? ']'
attribute_arguments ::=
'(' ( attribute_argument ( ',' attribute_argument )* )? ')'
attribute_argument ::=
identifier ( '=' ( string | identifier | number ) )?
statement_block ::=
'{' statement_list? '}'
statement_list ::=
( statement statement_terminator? )+
statement_terminator ::=
';'
statement ::=
function_definition
| if
| while
| do
| for
| foreach
| try
| trap
| data
| switch
| flow_control_statement
| labeled_statement
| user_variable
| boolean_value
| number
| string
| expandable_here_string
pipeline ::=
boolean_value
| user_variable
function_definition ::=
( [fF][uU][nN][cC][tT][iI][oO][nN] | [fF][iI][lL][tT][eE][rR] | [wW][oO][rR][kK][fF][lL][oO][wW] ) identifier parameter_list? '{' script_block '}'
if ::=
[iI][fF] '(' boolean_value ')' statement_block elseif* else?
elseif ::=
[eE][lL][sS][eE][iI][fF] statement_block
else ::=
[eE][lL][sS][eE] statement_block
while ::=
[wW][hH][iI][lL][eE] '(' boolean_value ')' statement_block
do ::=
[dD][oO] statement_block ( [wW][hH][iI][lL][eE] | [uU][nN][tT][iI][lL] ) '(' boolean_value ')'
for ::=
[fF][oO][rR] '(' ( pipeline statement_terminator? )? ( pipeline statement_terminator? )? pipeline? ')' statement_block
foreach ::=
[fF][oO][rR][eE][aA][cC][hH] foreach_parameter? '(' user_variable [iI][nN] user_variable ')' statement_block
foreach_parameter ::=
'-' [pP][aA][rR][aA][lL][lL][eE][lL]
try ::=
[tT][rR][yY] statement_block catch* finally?
catch ::=
[cC][aA][tT][cC][hH] type_literal* statement_block
finally ::=
[fF][iI][nN][aA][lL][lL][yY] statement_block
trap ::=
[tT][rR][aA][pP] type_literal? statement_block
data ::=
[dD][aA][tT][aA] identifier? statement_block
labeled_statement ::=
label ( switch | foreach | for | while | do )
label ::=
':' identifier
flow_control_statement ::=
flow_break_continue
| [rR][eE][tT][uU][rR][nN]
| [tT][hH][rR][oO][wW]
| [eE][xX][iI][tT]
flow_break_continue ::=
( [bB][rR][eE][aA][kK] | [cC][oO][nN][tT][iI][nN][uU][eE] ) identifier?
switch ::=
[sS][wW][iI][tT][cC][hH] switch_parameter* switch_condition switch_body
switch_parameter ::=
'-' ( [rR] | [rR][eE] | [rR][eE][gG] | [rR][eE][gG][eE] | [rR][eE][gG][eE][xX] | [wW] | [wW][iI] | [wW][iI][lL] | [wW][iI][lL][dD] | [wW][iI][lL][dD][cC] | [wW][iI][lL][dD][cC][aA] | [wW][iI][lL][dD][cC][aA][rR] | [wW][iI][lL][dD][cC][aA][rR][dD] | [eE] | [eE][xX] | [eE][xX][aA] | [eE][xX][aA][cC] | [eE][xX][aA][cC][tT] | [cC] | [cC][aA] | [cC][aA][sS] | [cC][aA][sS][eE] | [cC][aA][sS][eE][sS] | [cC][aA][sS][eE][sS][eE] | [cC][aA][sS][eE][sS][eE][nN] | [cC][aA][sS][eE][sS][eE][nN][sS] | [cC][aA][sS][eE][sS][eE][nN][sS][iI] | [cC][aA][sS][eE][sS][eE][nN][sS][iI][tT] | [cC][aA][sS][eE][sS][eE][nN][sS][iI][tT][iI] | [cC][aA][sS][eE][sS][eE][nN][sS][iI][tT][iI][vV] | [cC][aA][sS][eE][sS][eE][nN][sS][iI][tT][iI][vV][eE] | [pP] | [pP][aA] | [pP][aA][rR] | [pP][aA][rR][aA] | [pP][aA][rR][aA][lL] | [pP][aA][rR][aA][lL][lL] | [pP][aA][rR][aA][lL][lL][eE] | [pP][aA][rR][aA][lL][lL][eE][lL] )
switch_condition ::=
'(' boolean_value ')'
switch_body ::=
'{' switch_clause* '}'
switch_clause ::=
switch_clause_condition statement_block
switch_clause_condition ::=
identifier
type_literal ::=
'[' identifier ( array_declaration | type_literal )? ']'
boolean_value ::=
( '$' ( [tT][rR][uU][eE] | [fF][aA][lL][sS][eE] ) )
user_variable ::=
'\$'[a-zA-Z][a-zA-Z_]*
identifier ::=
[a-zA-Z][a-zA-Z_]*
string ::=
( '"' ( [^\"#x0A] | '\'('.'|'#x0A') )* '"' | "'" ( [^\'#x0A] | '\'('.'|'#x0A') )* "'" | "@'" [^(\'@)]* [#x0D|#x0D#x0A|#x0A]"'@" )
expandable_here_string ::=
'@"' ( expandable_string_chars | expandable_string_part )* '"@'
expandable_string_chars ::=
( [^"@$] | '\$'[^(] | '"'[^@] )+
expandable_string_part ::=
'$' '(' statement ')'
number ::=
( ( '0x' | '0X' ) [0-9a-fA-F]+ | ( '0' | [1-9] [0-9]+? ) '.' [0-9]+? ( ( 'e' | 'E' ) ( '-' | '+' )? [0-9]+ )? | '.' [0-9]+ ( ( 'e' | 'E' ) ( '-' | '+' )? [0-9]+ )? | ( '0' | [1-9] [0-9]+? ) ( ( 'e' | 'E' ) ( '-' | '+' )? [0-9]+ )? ) suffix*
suffix ::=
[lL]
| [dD]
| [kK][bB]
| [mM][bB]
| [gG][bB]
| [tT][bB]
| [pP][bB]
comment ::=
( '#.'* | '<#' [^#x23]*'\#'+(?':'[^<#x23][^#x23]*'#'+)* '>' )
signature_block ::=
'# SIG'