PageRenderTime 32ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/NRefactory/ICSharpCode.NRefactory.VB/Parser/vb.atg

http://github.com/icsharpcode/ILSpy
Unknown | 460 lines | 427 code | 33 blank | 0 comment | 0 complexity | 47b6d4e82f68d93dc1ae41281a23c8e2 MD5 | raw file
  1using System;
  2using System.Collections;
  3using System.Collections.Generic;
  4using System.Collections.Specialized;
  5using System.Linq;
  6using System.Text;
  7using ICSharpCode.NRefactory.VB.Ast;
  8using ICSharpCode.NRefactory.VB.Parser;
  9using ASTAttribute = ICSharpCode.NRefactory.VB.Ast.Attribute;
 10using Roles = ICSharpCode.NRefactory.VB.AstNode.Roles;
 11
 12COMPILER VB
 13
 14#region AUTOGENERATED TOKENS SECTION
 15TOKENS
 16	/* ----- terminal classes ----- */
 17	/* EOF is 0 */
 18	EOL
 19	ident
 20	LiteralString
 21	LiteralCharacter
 22	LiteralInteger
 23	LiteralDouble
 24	LiteralSingle
 25	LiteralDecimal
 26	LiteralDate
 27	XmlOpenTag					// <
 28	XmlCloseTag				// >
 29	XmlStartInlineVB			// <%=
 30	XmlEndInlineVB				// %>
 31	XmlCloseTagEmptyElement	// />
 32	XmlOpenEndTag				// </
 33	XmlContent					// ...
 34	XmlComment					// <!-- ... -->
 35	XmlCData					// <![CDATA[...]]>
 36	XmlProcessingInstruction	
 37
 38	/* ----- special character ----- */
 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	/* ----- keywords ----- */
 77	"AddHandler"
 78	"AddressOf"
 79	"Aggregate"
 80	"Alias"
 81	"And"
 82	"AndAlso"
 83	"Ansi"
 84	"As"
 85	"Ascending"
 86	"Assembly"
 87	"Auto"
 88	"Binary"
 89	"Boolean"
 90	"ByRef"
 91	"By"
 92	"Byte"
 93	"ByVal"
 94	"Call"
 95	"Case"
 96	"Catch"
 97	"CBool"
 98	"CByte"
 99	"CChar"
100	"CDate"
101	"CDbl"
102	"CDec"
103	"Char"
104	"CInt"
105	"Class"
106	"CLng"
107	"CObj"
108	"Compare"
109	"Const"
110	"Continue"
111	"CSByte"
112	"CShort"
113	"CSng"
114	"CStr"
115	"CType"
116	"CUInt"
117	"CULng"
118	"CUShort"
119	"Custom"
120	"Date"
121	"Decimal"
122	"Declare"
123	"Default"
124	"Delegate"
125	"Descending"
126	"Dim"
127	"DirectCast"
128	"Distinct"
129	"Do"
130	"Double"
131	"Each"
132	"Else"
133	"ElseIf"
134	"End"
135	"EndIf"
136	"Enum"
137	"Equals"
138	"Erase"
139	"Error"
140	"Event"
141	"Exit"
142	"Explicit"
143	"False"
144	"Finally"
145	"For"
146	"Friend"
147	"From"
148	"Function"
149	"Get"
150	"GetType"
151	"Global"
152	"GoSub"
153	"GoTo"
154	"Group"
155	"Handles"
156	"If"
157	"Implements"
158	"Imports"
159	"In"
160	"Infer"
161	"Inherits"
162	"Integer"
163	"Interface"
164	"Into"
165	"Is"
166	"IsNot"
167	"Join"
168	"Key"
169	"Let"
170	"Lib"
171	"Like"
172	"Long"
173	"Loop"
174	"Me"
175	"Mod"
176	"Module"
177	"MustInherit"
178	"MustOverride"
179	"MyBase"
180	"MyClass"
181	"Namespace"
182	"Narrowing"
183	"New"
184	"Next"
185	"Not"
186	"Nothing"
187	"NotInheritable"
188	"NotOverridable"
189	"Object"
190	"Of"
191	"Off"
192	"On"
193	"Operator"
194	"Option"
195	"Optional"
196	"Or"
197	"Order"
198	"OrElse"
199	"Out"
200	"Overloads"
201	"Overridable"
202	"Overrides"
203	"ParamArray"
204	"Partial"
205	"Preserve"
206	"Private"
207	"Property"
208	"Protected"
209	"Public"
210	"RaiseEvent"
211	"ReadOnly"
212	"ReDim"
213	"Rem"
214	"RemoveHandler"
215	"Resume"
216	"Return"
217	"SByte"
218	"Select"
219	"Set"
220	"Shadows"
221	"Shared"
222	"Short"
223	"Single"
224	"Skip"
225	"Static"
226	"Step"
227	"Stop"
228	"Strict"
229	"String"
230	"Structure"
231	"Sub"
232	"SyncLock"
233	"Take"
234	"Text"
235	"Then"
236	"Throw"
237	"To"
238	"True"
239	"Try"
240	"TryCast"
241	"TypeOf"
242	"UInteger"
243	"ULong"
244	"Unicode"
245	"Until"
246	"UShort"
247	"Using"
248	"Variant"
249	"Wend"
250	"When"
251	"Where"
252	"While"
253	"Widening"
254	"With"
255	"WithEvents"
256	"WriteOnly"
257	"Xor"
258	"GetXmlNamespace"
259#endregion
260
261PRODUCTIONS
262
263#region General
264
265VB =
266(.
267	compilationUnit = new CompilationUnit();
268	NodeStart(compilationUnit);
269	Get();
270.)
271	{ StatementTerminator }
272	{ OptionStatement<CompilationUnit.MemberRole> { StatementTerminator } }
273	{ ImportsStatement<CompilationUnit.MemberRole> { StatementTerminator } }
274/*	{ IF (IsGlobalAttrTarget()) GlobalAttributeSection { StatementTerminator } }
275	{ NamespaceMemberDecl { StatementTerminator } } */
276.
277
278StatementTerminator = SYNC ( EOL<Roles.StatementTerminator> | ":"<Roles.StatementTerminator> ) .
279
280#region Identifier
281
282//IdentifierOrKeyword<out string identifier> = ANY (. identifier = t.val; .) .
283
284// This production handles pseudo keywords that are needed in the grammar
285Identifier	=
286	IdentifierForFieldDeclaration
287	| "Custom"
288.
289
290IdentifierForFieldDeclaration =
291	ident
292	| "Aggregate"
293	| "Ansi"
294	| "Ascending"
295	| "Assembly"
296	| "Auto"
297	| "Binary"
298	| "By"
299	| "Compare"
300	| "Descending"
301	| "Distinct"
302	| "Equals"
303	| "Explicit"
304	| "From"
305	| "Group"
306	| "Infer"
307	| "Into"
308	| "Join"
309	| "Key"
310	| "Off"
311	| "Order"
312	| "Out"
313	| "Preserve"
314	| "Skip"
315	| "Take"
316	| "Text"
317	| "Unicode"
318	| "Until"
319	| "Where"
320.
321#endregion
322
323TypeName<out AstType type> (. type = null; .) =
324	PrimitiveTypeName<out type> |
325	QualifiedTypeName<out type>
326.
327QualifiedTypeName<out AstType type> =
328	( "Global" | Identifier ) (. type = new SimpleType(t.val, t.Location); .)
329	{ "." Identifier (. type = new QualifiedType(type, new Identifier(t.val, t.Location)); .) }
330	// TODO : add TypeArguments
331.
332
333PrimitiveTypeName<out AstType type> (. type = null; .) =
334	"Object"		(. type = new PrimitiveType("Object", t.Location); .)
335	| "Boolean"	(. type = new PrimitiveType("Boolean", t.Location); .)
336	| "Date"		(. type = new PrimitiveType("Date", t.Location); .)
337	| "Char"		(. type = new PrimitiveType("Char", t.Location); .)
338	| "String"		(. type = new PrimitiveType("String", t.Location); .)
339	| "Decimal"	(. type = new PrimitiveType("Decimal", t.Location); .)
340	| "Byte"		(. type = new PrimitiveType("Byte", t.Location); .)
341	| "Short"		(. type = new PrimitiveType("Short", t.Location); .)
342	| "Integer"	(. type = new PrimitiveType("Integer", t.Location); .)
343	| "Long"		(. type = new PrimitiveType("Long", t.Location); .)
344	| "Single"		(. type = new PrimitiveType("Single", t.Location); .)
345	| "Double"		(. type = new PrimitiveType("Double", t.Location); .)
346	| "UInteger"	(. type = new PrimitiveType("UInteger", t.Location); .)
347	| "ULong"		(. type = new PrimitiveType("ULong", t.Location); .)
348	| "UShort"		(. type = new PrimitiveType("UShort", t.Location); .)
349	| "SByte"		(. type = new PrimitiveType("SByte", t.Location); .)
350.
351
352/*
353ParameterModifier<ParamModifierList m> =
354	"ByVal"			(. m.Add(ParameterModifiers.In); .)
355	| "ByRef"			(. m.Add(ParameterModifiers.Ref); .)
356	| "Optional"		(. m.Add(ParameterModifiers.Optional); .)
357	| "ParamArray"	(. m.Add(ParameterModifiers.Params); .)
358.
359
360TypeModifier<ModifierList m> =
361	  "Public"				(. m.Add(Modifiers.Public, t.Location); .)
362	| "Protected"			(. m.Add(Modifiers.Protected, t.Location); .)
363	| "Friend"				(. m.Add(Modifiers.Internal, t.Location); .)
364	| "Private"			(. m.Add(Modifiers.Private, t.Location); .)
365	| "Shared"				(. m.Add(Modifiers.Static, t.Location); .)
366	| "Shadows"			(. m.Add(Modifiers.New, t.Location); .)
367	| "MustInherit"		(. m.Add(Modifiers.Abstract, t.Location); .)
368	| "NotInheritable"	(. m.Add(Modifiers.Sealed, t.Location); .)
369	| "Partial"			(. m.Add(Modifiers.Partial, t.Location); .)
370.
371
372MemberModifier<ModifierList m> =
373	  "MustInherit"		(.m.Add(Modifiers.Abstract, t.Location);.)
374	| "Default"			(.m.Add(Modifiers.Default, t.Location);.)
375	| "Friend"			(.m.Add(Modifiers.Internal, t.Location);.)
376	| "Shadows"			(.m.Add(Modifiers.New, t.Location);.)
377	| "Overrides"		(.m.Add(Modifiers.Override, t.Location);.)
378	| "MustOverride"	(.m.Add(Modifiers.Abstract, t.Location);.)
379	| "Private"			(.m.Add(Modifiers.Private, t.Location);.)
380	| "Protected"		(.m.Add(Modifiers.Protected, t.Location);.)
381	| "Public"			(.m.Add(Modifiers.Public, t.Location);.)
382	| "NotInheritable"	(.m.Add(Modifiers.Sealed, t.Location);.)
383	| "NotOverridable"	(.m.Add(Modifiers.Sealed, t.Location);.)
384	| "Shared"			(.m.Add(Modifiers.Static, t.Location);.)
385	| "Overridable"		(.m.Add(Modifiers.Virtual, t.Location);.)
386	| "Overloads"		(.m.Add(Modifiers.Overloads, t.Location);.)
387	| "ReadOnly"		(.m.Add(Modifiers.ReadOnly, t.Location);.)
388	| "WriteOnly"		(.m.Add(Modifiers.WriteOnly, t.Location);.)
389	| "WithEvents"		(.m.Add(Modifiers.WithEvents, t.Location);.)
390	| "Dim"				(.m.Add(Modifiers.Dim, t.Location);.)
391	| "Partial"			(.m.Add(Modifiers.Partial, t.Location);.)
392.
393
394PropertyAccessorAccessModifier<out Modifiers m> =
395	(. m = Modifiers.None; .)
396	{
397		"Public"    (. m |= Modifiers.Public; .)
398	 |  "Protected" (. m |= Modifiers.Protected; .)
399	 |  "Friend"    (. m |= Modifiers.Internal; .)
400	 |  "Private"   (. m |= Modifiers.Private; .)
401	}
402.
403*/
404#endregion
405
406#region Global
407
408#region OptionStatement
409
410OptionStatement<auto> =
411	"Option"<Roles.Keyword> (
412		"Explicit"<Ast.OptionStatement.OptionTypeRole> (. result.OptionType = OptionType.Explicit; .) [ OnOff<result> ]
413		| "Strict"<Ast.OptionStatement.OptionTypeRole> (. result.OptionType = OptionType.Strict; .) [ OnOff<result> ]
414		| "Infer"<Ast.OptionStatement.OptionTypeRole> (. result.OptionType = OptionType.Infer; .) [ OnOff<result> ]
415		| "Compare"<Ast.OptionStatement.OptionTypeRole> (. result.OptionType = OptionType.Compare; .) BinaryText<result>
416	) StatementTerminator
417.
418
419OnOff<OptionStatement os> =
420	"On"<Ast.OptionStatement.OptionValueRole> (. os.OptionValue = OptionValue.On; .)
421	| "Off"<Ast.OptionStatement.OptionValueRole> (. os.OptionValue  = OptionValue.Off; .)
422.
423
424BinaryText<OptionStatement os> =
425	"Text"<Ast.OptionStatement.OptionValueRole> (. os.OptionValue = OptionValue.Text; .)
426	| "Binary"<Ast.OptionStatement.OptionValueRole> (. os.OptionValue  = OptionValue.Binary; .)
427.
428
429#endregion
430
431#region ImportsStatement
432
433ImportsStatement<auto> =
434	"Imports"<Roles.Keyword> ImportsClause { "," ImportsClause } StatementTerminator
435.
436
437ImportsClause =
438	( IF (IsAliasImportsClause())
439		AliasImportsClause<Ast.ImportsStatement.ImportsClauseRole> |
440	MemberImportsClause<Ast.ImportsStatement.ImportsClauseRole> |
441	XmlNamespaceImportsClause<Ast.ImportsStatement.ImportsClauseRole> ) SYNC .
442
443AliasImportsClause<auto> (. AstType alias; .) =
444	// Type characters are not allowed in identifiers here
445	Identifier (. result.Name = new Identifier(t.val, t.Location); .) "=" TypeName<out alias> (. result.Alias = alias; .)
446.
447
448MemberImportsClause<auto> (. AstType member; .) =
449	TypeName<out member> (. result.Member = member; .)
450.
451
452XmlNamespaceImportsClause<auto> =
453	XmlOpenTag<Roles.XmlOpenTag> Identifier/*<Roles.XmlIdentifier>*/ "="<Roles.Assign> LiteralString/*<Roles.XmlLiteralString>*/ XmlCloseTag<Roles.XmlCloseTag>
454.
455
456#endregion
457
458#endregion
459
460END VB .