📄 vbnet.atg
字号:
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Parser.VB;
using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute;
COMPILER VBNET
/* START AUTOGENERATED TOKENS SECTION */
TOKENS
/* ----- terminal classes ----- */
/* EOF is 0 */
EOL
ident
LiteralString
LiteralCharacter
LiteralInteger
LiteralDouble
LiteralSingle
LiteralDecimal
LiteralDate
/* ----- special character ----- */
"."
"="
","
":"
"+"
"-"
"*"
"/"
"\\"
"&"
"^"
"?"
"{"
"}"
"("
")"
">"
"<"
"<>"
">="
"<="
"<<"
">>"
"+="
"^="
"-="
"*="
"/="
"\\="
"<<="
">>="
"&="
/* ----- keywords ----- */
"AddHandler"
"AddressOf"
"Alias"
"And"
"AndAlso"
"Ansi"
"As"
"Assembly"
"Auto"
"Binary"
"Boolean"
"ByRef"
"Byte"
"ByVal"
"Call"
"Case"
"Catch"
"CBool"
"CByte"
"CChar"
"CDate"
"CDbl"
"CDec"
"Char"
"CInt"
"Class"
"CLng"
"CObj"
"Compare"
"Const"
"CShort"
"CSng"
"CStr"
"CType"
"Date"
"Decimal"
"Declare"
"Default"
"Delegate"
"Dim"
"DirectCast"
"Do"
"Double"
"Each"
"Else"
"ElseIf"
"End"
"EndIf"
"Enum"
"Erase"
"Error"
"Event"
"Exit"
"Explicit"
"False"
"Finally"
"For"
"Friend"
"Function"
"Get"
"GetType"
"GoSub"
"GoTo"
"Handles"
"If"
"Implements"
"Imports"
"In"
"Inherits"
"Integer"
"Interface"
"Is"
"Let"
"Lib"
"Like"
"Long"
"Loop"
"Me"
"Mod"
"Module"
"MustInherit"
"MustOverride"
"MyBase"
"MyClass"
"Namespace"
"New"
"Next"
"Not"
"Nothing"
"NotInheritable"
"NotOverridable"
"Object"
"Off"
"On"
"Option"
"Optional"
"Or"
"OrElse"
"Overloads"
"Overridable"
"Overrides"
"ParamArray"
"Preserve"
"Private"
"Property"
"Protected"
"Public"
"RaiseEvent"
"ReadOnly"
"ReDim"
"RemoveHandler"
"Resume"
"Return"
"Select"
"Set"
"Shadows"
"Shared"
"Short"
"Single"
"Static"
"Step"
"Stop"
"Strict"
"String"
"Structure"
"Sub"
"SyncLock"
"Text"
"Then"
"Throw"
"To"
"True"
"Try"
"TypeOf"
"Unicode"
"Until"
"Variant"
"Wend"
"When"
"While"
"With"
"WithEvents"
"WriteOnly"
"Xor"
"Continue"
"Operator"
"Using"
"IsNot"
"SByte"
"UInteger"
"ULong"
"UShort"
"CSByte"
"CUShort"
"CUInt"
"CULng"
"Global"
"TryCast"
"Of"
"Narrowing"
"Widening"
"Partial"
"Custom"
/* END AUTOGENERATED TOKENS SECTION */
PRODUCTIONS
VBNET
(.
lexer.NextToken(); // get the first token
compilationUnit = new CompilationUnit();
.) =
{ EOL }
{ OptionStmt }
{ ImportsStmt}
{ IF (IsGlobalAttrTarget()) GlobalAttributeSection }
{ NamespaceMemberDecl }
EOF
.
OptionStmt (. INode node = null; bool val = true; .) =
"Option" (. Location startPos = t.Location; .)
(
"Explicit" [ OptionValue<ref val> ]
(. node = new OptionDeclaration(OptionType.Explicit, val); .)
|
"Strict" [ OptionValue<ref val> ]
(. node = new OptionDeclaration(OptionType.Strict, val); .)
|
"Compare" ( "Binary" (. node = new OptionDeclaration(OptionType.CompareBinary, val); .)
| "Text" (. node = new OptionDeclaration(OptionType.CompareText, val); .)
)
)
EndOfStmt
(.
if (node != null) {
node.StartLocation = startPos;
node.EndLocation = t.Location;
compilationUnit.AddChild(node);
}
.)
.
OptionValue<ref bool val> =
(
"On" (. val = true; .)
|
"Off" (. val = false; .)
)
.
EndOfStmt =
EOL
|
":" [ EOL ]
.
ImportsStmt
(.List<Using> usings = new List<Using>();
.) =
"Imports"
(.
Location startPos = t.Location;
Using u;
.)
ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
{
"," ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
}
EndOfStmt
(.
UsingDeclaration usingDeclaration = new UsingDeclaration(usings);
usingDeclaration.StartLocation = startPos;
usingDeclaration.EndLocation = t.Location;
compilationUnit.AddChild(usingDeclaration);
.)
.
ImportClause<out Using u>
(.
string qualident = null;
TypeReference aliasedType = null;
u = null;
.) =
Qualident<out qualident>
[ "=" TypeName<out aliasedType> ]
(.
if (qualident != null && qualident.Length > 0) {
if (aliasedType != null) {
u = new Using(qualident, aliasedType);
} else {
u = new Using(qualident);
}
}
.)
.
/* 6.4.2 */
NamespaceMemberDecl
(.
ModifierList m = new ModifierList();
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
string qualident;
.) =
"Namespace"
(.
Location startPos = t.Location;
.)
Qualident<out qualident>
(.
INode node = new NamespaceDeclaration(qualident);
node.StartLocation = startPos;
compilationUnit.AddChild(node);
compilationUnit.BlockStart(node);
.)
EOL
NamespaceBody
(.
node.EndLocation = t.Location;
compilationUnit.BlockEnd();
.)
|
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ TypeModifier<m> } NonModuleDeclaration<m, attributes>
.
/* 4.9.1 */
TypeParameterList<List<TemplateDefinition> templates>
(.
TemplateDefinition template;
.) =
[
IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of" TypeParameter<out template>
(.
if (template != null) templates.Add(template);
.)
{
"," TypeParameter<out template>
(.
if (template != null) templates.Add(template);
.)
}
")"
]
.
/* 4.9.1 */
TypeParameter<out TemplateDefinition template>
=
Identifier (. template = new TemplateDefinition(t.val, null); .)
[TypeParameterConstraints<template>]
.
/* 4.9.2 */
TypeParameterConstraints<TemplateDefinition template>
(.
TypeReference constraint;
.)
=
"As"
(
"{"
TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
{
","
TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
}
"}"
| TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
)
.
TypeParameterConstraint<out TypeReference constraint>
(. constraint = null; .)
= "Class" (. constraint = TypeReference.ClassConstraint; .)
| "Structure" (. constraint = TypeReference.StructConstraint; .)
| "New" (. constraint = TypeReference.NewConstraint; .)
| TypeName<out constraint>
.
/* 6.4.2 */
NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
(.
TypeReference typeRef = null;
List<TypeReference> baseInterfaces = null;
.) =
(. m.Check(Modifiers.Classes); .)
/* Spec, 7.5 */
"Class"
(. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
newType.StartLocation = t.Location;
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.Type = ClassType.Class;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
[ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
ClassBody<newType>
"End" "Class" (. newType.EndLocation = t.EndLocation; .)
EOL
(.
compilationUnit.BlockEnd();
.)
| "Module"
(.
m.Check(Modifiers.VBModules);
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.StartLocation = m.GetDeclarationLocation(t.Location);
newType.Type = ClassType.Module;
.)
Identifier (. newType.Name = t.val; .)
EOL
(. newType.BodyStartLocation = t.Location; .)
ModuleBody<newType>
(.
compilationUnit.BlockEnd();
.)
| "Structure"
(.
m.Check(Modifiers.VBStructures);
TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.StartLocation = m.GetDeclarationLocation(t.Location);
newType.Type = ClassType.Struct;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates>
EOL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -