/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

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