#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

962 lines
17 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Parser;
PUSHCOMPILER VBIndentationStrategy
$tokenKindFieldName=Kind
/* START AUTOGENERATED TOKENS SECTION */
TOKENS
/* ----- terminal classes ----- */
/* EOF is 0 */
EOL
ident
LiteralString
LiteralCharacter
LiteralInteger
LiteralDouble
LiteralSingle
LiteralDecimal
LiteralDate
XmlOpenTag
XmlCloseTag
XmlStartInlineVB
XmlEndInlineVB
XmlCloseTagEmptyElement
XmlOpenEndTag
XmlContent
XmlComment
XmlCData
XmlProcessingInstruction
/* ----- special character ----- */
"="
":"
","
"&"
"/"
"\\"
"."
"..."
".@"
"!"
"-"
"+"
"^"
"?"
"*"
"{"
"}"
"("
")"
">"
"<"
"<>"
">="
"<="
"<<"
">>"
"+="
"^="
"-="
"*="
"/="
"\\="
"<<="
">>="
"&="
":="
/* ----- keywords ----- */
"AddHandler"
"AddressOf"
"Aggregate"
"Alias"
"And"
"AndAlso"
"Ansi"
"As"
"Ascending"
"Assembly"
"Auto"
"Binary"
"Boolean"
"ByRef"
"By"
"Byte"
"ByVal"
"Call"
"Case"
"Catch"
"CBool"
"CByte"
"CChar"
"CDate"
"CDbl"
"CDec"
"Char"
"CInt"
"Class"
"CLng"
"CObj"
"Compare"
"Const"
"Continue"
"CSByte"
"CShort"
"CSng"
"CStr"
"CType"
"CUInt"
"CULng"
"CUShort"
"Custom"
"Date"
"Decimal"
"Declare"
"Default"
"Delegate"
"Descending"
"Dim"
"DirectCast"
"Distinct"
"Do"
"Double"
"Each"
"Else"
"ElseIf"
"End"
"EndIf"
"Enum"
"Equals"
"Erase"
"Error"
"Event"
"Exit"
"Explicit"
"False"
"Finally"
"For"
"Friend"
"From"
"Function"
"Get"
"GetType"
"Global"
"GoSub"
"GoTo"
"Group"
"Handles"
"If"
"Implements"
"Imports"
"In"
"Infer"
"Inherits"
"Integer"
"Interface"
"Into"
"Is"
"IsNot"
"Join"
"Key"
"Let"
"Lib"
"Like"
"Long"
"Loop"
"Me"
"Mod"
"Module"
"MustInherit"
"MustOverride"
"MyBase"
"MyClass"
"Namespace"
"Narrowing"
"New"
"Next"
"Not"
"Nothing"
"NotInheritable"
"NotOverridable"
"Object"
"Of"
"Off"
"On"
"Operator"
"Option"
"Optional"
"Or"
"Order"
"OrElse"
"Out"
"Overloads"
"Overridable"
"Overrides"
"ParamArray"
"Partial"
"Preserve"
"Private"
"Property"
"Protected"
"Public"
"RaiseEvent"
"ReadOnly"
"ReDim"
"Rem"
"RemoveHandler"
"Resume"
"Return"
"SByte"
"Select"
"Set"
"Shadows"
"Shared"
"Short"
"Single"
"Skip"
"Static"
"Step"
"Stop"
"Strict"
"String"
"Structure"
"Sub"
"SyncLock"
"Take"
"Text"
"Then"
"Throw"
"To"
"True"
"Try"
"TryCast"
"TypeOf"
"UInteger"
"ULong"
"Unicode"
"Until"
"UShort"
"Using"
"Variant"
"Wend"
"When"
"Where"
"While"
"Widening"
"With"
"WithEvents"
"WriteOnly"
"Xor"
"GetXmlNamespace"
/* END AUTOGENERATED TOKENS SECTION */
PRODUCTIONS
/*------------------------------------------------------------------------*/
VBIndentationStrategy =
{ ANY }
{ NamespaceMemberDeclaration { ANY } }
.
StatementTerminator =
EOL | ":"
.
NamespaceMemberDeclaration =
NamespaceDeclaration
| TypeDeclaration
.
NamespaceDeclaration =
"Namespace" { ANY } StatementTerminator
(. Indent(la); .)
{ NamespaceMemberDeclaration { ANY } }
(. Unindent(la); .)
"End" "Namespace" StatementTerminator
.
TypeDeclaration =
ClassOrModuleOrStructureTypeDeclaration |
DelegateTypeDeclaration |
EnumTypeDeclaration |
InterfaceDeclaration
.
ClassOrModuleOrStructureTypeDeclaration =
( "Module" | "Class" | "Structure" ) ANY
[ "(" "Of" GenericTypeParameterDeclaration ")" ] StatementTerminator
(. Indent(la); .)
{
( ClassOrModuleOrStructureTypeDeclaration | DelegateTypeDeclaration | EnumTypeDeclaration
| InterfaceDeclaration | MemberDeclaration )
}
(. Unindent(la); .)
"End" ( "Module" | "Class" | "Structure" ) StatementTerminator
.
EnumTypeDeclaration =
"Enum" { ANY } StatementTerminator
(. Indent(la); .)
{ ANY [ "=" Expression ] StatementTerminator }
(. Unindent(la); .)
"End" "Enum" StatementTerminator
.
InterfaceDeclaration =
"Interface" ANY [ "(" "Of" GenericTypeParameterDeclaration ")" ] StatementTerminator
(. Indent(la); .)
[ "Inherits" TypeName { "," TypeName } StatementTerminator ]
{
( ClassOrModuleOrStructureTypeDeclaration | DelegateTypeDeclaration | EnumTypeDeclaration
| InterfaceDeclaration | InterfaceMemberDeclaration ) { ANY }
}
(. Unindent(la); .)
"End" "Interface" StatementTerminator
.
InterfaceMemberDeclaration =
InterfaceEvent | InterfaceProperty | InterfaceSubOrFunction
.
InterfaceEvent =
"Event" { ANY } StatementTerminator
.
InterfaceProperty =
"Property" { ANY } StatementTerminator
.
InterfaceSubOrFunction =
("Sub" | "Function") { ANY }
{ "(" [ ( "Of" GenericTypeParameterDeclaration | ParameterList ) ] ")" }
[ "As" TypeName ]
StatementTerminator
.
GenericConstraint =
TypeName | "New" | "Class" | "Structure"
.
GenericConstraintList =
GenericConstraint | "{" GenericConstraint { "," GenericConstraint } "}"
.
GenericTypeParameterDeclaration =
[ "Out" | "In" ] ANY [ "As" GenericConstraintList ]
{ "," [ "Out" | "In" ] ANY [ "As" GenericConstraintList ] }
.
DelegateTypeDeclaration =
"Delegate" ("Sub" | "Function") ANY
[ "(" [ ParameterList ] ")" ] [ "As" TypeName ] StatementTerminator
.
MemberDeclaration =
(
MemberVariableOrConstantDeclaration |
SubOrFunctionDeclaration |
ExternalMemberDeclaration |
EventMemberDeclaration |
CustomEventMemberDeclaration |
PropertyDeclaration |
OperatorDeclaration
)
.
SubOrFunctionDeclaration =
("Sub" | "Function")
ANY
{ "(" [ ( "Of" GenericTypeParameterDeclaration | ParameterList ) ] ")" }
[ "As" TypeName ]
StatementTerminatorAndBlock
"End" ("Sub" | "Function") StatementTerminator
.
ExternalMemberDeclaration =
"Declare" [ "Ansi" | "Unicode" | "Auto" ] ( "Sub" | "Function" ) ANY
"Lib" LiteralString [ "Alias" LiteralString ] [ "(" [ ParameterList ] ")" ] [ "As" TypeName ] StatementTerminator
.
EventMemberDeclaration =
"Event" ANY ( "As" TypeName | [ "(" [ ParameterList ] ")" ] )
[ "Implements" TypeName /*"." IdentifierOrKeyword*/ { "," TypeName /*"." IdentifierOrKeyword*/ } ]
/* the TypeName production already allows the "." IdentifierOrKeyword syntax, so to avoid an ambiguous grammer we just leave that out */
StatementTerminator
.
CustomEventMemberDeclaration =
"Custom" EventMemberDeclaration
{
( "AddHandler" | "RemoveHandler" | "RaiseEvent" ) "(" ParameterList ")"
StatementTerminatorAndBlock
"End" ( "AddHandler" | "RemoveHandler" | "RaiseEvent" ) StatementTerminator
}
"End" "Event" StatementTerminator
.
PropertyDeclaration =
"Property" { ANY } [ "=" Expression ] StatementTerminator
{ ANY }
[ (. Indent(la); .)
( "Get" | "Set" ) [ "(" [ ParameterList ] ")" ]
StatementTerminatorAndBlock
"End" ( "Get" | "Set" ) StatementTerminator
[ ( "Get" | "Set" ) [ "(" [ ParameterList ] ")" ]
StatementTerminatorAndBlock
"End" ( "Get" | "Set" ) StatementTerminator ]
(. Unindent(la); .)
"End" "Property" StatementTerminator ]
.
OperatorDeclaration =
"Operator" { ANY }
StatementTerminatorAndBlock
"End" "Operator" StatementTerminator
.
MemberVariableOrConstantDeclaration =
MemberVariableOrConstantDeclarator { "," MemberVariableOrConstantDeclarator } StatementTerminator
.
MemberVariableOrConstantDeclarator =
[ "Const" ]
ANY
[ "As" ( NewExpression | TypeName ) ]
[ "=" Expression ]
.
ParameterList =
Parameter { "," Parameter }
.
Parameter =
ANY
{ ANY }
[ "As" TypeName ]
[ "=" Expression ]
.
StatementTerminatorAndBlock =
(. Indent(la); .)
StatementTerminator
{ EXPECTEDCONFLICT("End")
(
[ Statement] StatementTerminator
| "End"
( StatementTerminator /* End+StatementTerminator is end statement */
| /* End+anything else is the end of this block. */
(.
currentState = endOfStatementTerminatorAndBlock; /* leave this block */
InformToken(t); /* process End again*/
/* for processing current token (la): go to the position after processing End */
goto switchlbl;
.)
ANY /* never reached due to goto above: */
/* this ANY is just so that Coco knows this branch isn't empty */
)
)
}
(.NamedState:endOfStatementTerminatorAndBlock.)
(. Unindent(la); .)
.
Expression
(.NamedState:startOfExpression.)
= SimpleExpressionWithSuffix { BinaryOperator SimpleExpressionWithSuffix } .
BinaryOperator =
"+" | "-" | "*" | "\\" | "/" | "^" | "Mod"
| "=" | "<>" | "<" | ">" | "<=" | ">="
| "Like" | "&" | "And" | "AndAlso" | "Or" | "OrElse"
| "Xor" | "<<" | ">>" | "Is" | "IsNot"
| "^=" | "*=" | "/=" | "\\=" | "+=" | "-=" | "&=" | "<<=" | ">>=" | "To" | ":="
.
UnaryOperator =
"+" | "-" | "Not" | "AddressOf"
.
SimpleExpressionWithSuffix =
{ UnaryOperator }
(
SimpleExpression { ExpressionSuffix }
| "TypeOf" SimpleExpressionWithSuffix "Is" TypeName
| NewExpression
| CollectionInitializer
)
.
SimpleExpression =
( ANY
| XmlLiteral
| LambdaExpression
| ConditionalExpression
)
.
NewExpression =
"New" (
TypeName
[
EXPECTEDCONFLICT("From")
(
"From"
(
CollectionInitializer /* From + CollectionInitializer is a NewExpression */
|
(.
currentState = endOfStatementTerminatorAndBlock; /* leave this block */
InformToken(t); /* process From again*/
/* for processing current token (la): go to the position after processing End */
goto switchlbl;
.)
ANY /* never reached due to goto above: */
/* this ANY is just so that Coco knows this branch isn't empty */
)
|
"With" ObjectInitializer
)
]
|
"With" ObjectInitializer
)
.
ObjectInitializer =
"{" [ "Key" ] "." ANY "=" Expression { "," [ "Key" ] "." ANY "=" Expression } "}"
.
CollectionInitializer =
"{" Expression { "," Expression } "}"
.
ExpressionSuffix =
"(" ( "Of" TypeName { "," TypeName } ")" | [ ArgumentList ] ")" )
| ( "." | "!" | ".@" | "..." ) [ XmlOpenTag ] ANY [ XmlCloseTag ]
.
ConditionalExpression =
"If" "(" Expression "," Expression [ "," Expression ] ")"
.
LambdaExpression =
SubLambdaExpression |
FunctionLambdaExpression
.
SubLambdaExpression =
"Sub" "(" [ ParameterList ] ")"
( GREEDY Statement | StatementTerminatorAndBlock "End" "Sub" )
.
FunctionLambdaExpression =
"Function" "(" [ ParameterList ] ")"
( GREEDY Expression | [ "As" TypeName ] StatementTerminatorAndBlock "End" "Function" )
.
/* semantic action will be inserted on all paths that possibly lead to XmlLiteral */
XmlLiteral =
(
( XmlComment | XmlProcessingInstruction | XmlCData ) [ XmlContent ] { ( XmlComment | XmlProcessingInstruction ) [ XmlContent ] } [ XmlElement { XmlComment [ XmlContent ] } ]
|
XmlElement { XmlComment [ XmlContent ] }
)
.
XmlElement =
XmlOpenTag { ANY | XmlEmbeddedExpression } ( XmlCloseTagEmptyElement | XmlCloseTag { ANY | XmlEmbeddedExpression | XmlElement } XmlOpenEndTag { ANY | XmlEmbeddedExpression } XmlCloseTag )
.
XmlEmbeddedExpression =
XmlStartInlineVB Expression XmlEndInlineVB
.
PrimitiveTypeName =
"Byte" |
"SByte" |
"UShort" |
"Short" |
"UInteger" |
"Integer" |
"ULong" |
"Long" |
"Single" |
"Double" |
"Decimal" |
"Boolean" |
"Date" |
"Char" |
"String" |
"Object"
.
TypeName = ( "Global" | ident | PrimitiveTypeName | "?" /* used for ? = completion */ ) { TypeSuffix } { "." IdentifierOrKeyword { TypeSuffix } } .
TypeSuffix = "(" ( "Of" [ TypeName ] { "," [ TypeName ] } | [ ArgumentList ] ) ")" .
IdentifierOrKeyword = ident
| "AddHandler"
| "AddressOf"
| "Aggregate"
| "Alias"
| "And"
| "AndAlso"
| "Ansi"
| "As"
| "Ascending"
| "Assembly"
| "Auto"
| "Binary"
| "Boolean"
| "ByRef"
| "By"
| "Byte"
| "ByVal"
| "Call"
| "Case"
| "Catch"
| "CBool"
| "CByte"
| "CChar"
| "CDate"
| "CDbl"
| "CDec"
| "Char"
| "CInt"
| "Class"
| "CLng"
| "CObj"
| "Compare"
| "Const"
| "Continue"
| "CSByte"
| "CShort"
| "CSng"
| "CStr"
| "CType"
| "CUInt"
| "CULng"
| "CUShort"
| "Custom"
| "Date"
| "Decimal"
| "Declare"
| "Default"
| "Delegate"
| "Descending"
| "Dim"
| "DirectCast"
| "Distinct"
| "Do"
| "Double"
| "Each"
| "Else"
| "ElseIf"
| "End"
| "EndIf"
| "Enum"
| "Equals"
| "Erase"
| "Error"
| "Event"
| "Exit"
| "Explicit"
| "False"
| "Finally"
| "For"
| "Friend"
| "From"
| "Function"
| "Get"
| "GetType"
| "Global"
| "GoSub"
| "GoTo"
| "Group"
| "Handles"
| "If"
| "Implements"
| "Imports"
| "In"
| "Infer"
| "Inherits"
| "Integer"
| "Interface"
| "Into"
| "Is"
| "IsNot"
| "Join"
| "Key"
| "Let"
| "Lib"
| "Like"
| "Long"
| "Loop"
| "Me"
| "Mod"
| "Module"
| "MustInherit"
| "MustOverride"
| "MyBase"
| "MyClass"
| "Namespace"
| "Narrowing"
| "New"
| "Next"
| "Not"
| "Nothing"
| "NotInheritable"
| "NotOverridable"
| "Object"
| "Of"
| "Off"
| "On"
| "Operator"
| "Option"
| "Optional"
| "Or"
| "Order"
| "OrElse"
| "Out"
| "Overloads"
| "Overridable"
| "Overrides"
| "ParamArray"
| "Partial"
| "Preserve"
| "Private"
| "Property"
| "Protected"
| "Public"
| "RaiseEvent"
| "ReadOnly"
| "ReDim"
| "Rem"
| "RemoveHandler"
| "Resume"
| "Return"
| "SByte"
| "Select"
| "Set"
| "Shadows"
| "Shared"
| "Short"
| "Single"
| "Skip"
| "Static"
| "Step"
| "Stop"
| "Strict"
| "String"
| "Structure"
| "Sub"
| "SyncLock"
| "Take"
| "Text"
| "Then"
| "Throw"
| "To"
| "True"
| "Try"
| "TryCast"
| "TypeOf"
| "UInteger"
| "ULong"
| "Unicode"
| "Until"
| "UShort"
| "Using"
| "Variant"
| "Wend"
| "When"
| "Where"
| "While"
| "Widening"
| "With"
| "WithEvents"
| "WriteOnly"
| "Xor"
| "GetXmlNamespace"
.
Statement =
VariableDeclarationStatement
| WithOrLockStatement
| AddOrRemoveHandlerStatement
| RaiseEventStatement
| EXPECTEDCONFLICT("If") IfStatement /* prefer if-statement to if-expression */
| SelectStatement
| WhileStatement
| DoLoopStatement
| ForStatement
| ErrorHandlingStatement
| ThrowStatement
| TryStatement
| BranchStatement
| ReDimStatement
| EraseStatement
| UsingStatement
| InvocationStatement
.
VariableDeclarationStatement =
( "Dim" | "Static" | "Const" ) ANY [ "?" ] [ ( "(" { "," } ")" ) ]
{ "," ANY [ "?" ] [ ( "(" { "," } ")" ) ] }
[ "As" ( NewExpression | TypeName ) ]
[ "=" Expression ]
.
WithOrLockStatement =
( "With" | "SyncLock" ) Expression StatementTerminatorAndBlock "End" ( "With" | "SyncLock" )
.
AddOrRemoveHandlerStatement =
( "AddHandler" | "RemoveHandler" ) Expression "," Expression
.
RaiseEventStatement =
"RaiseEvent" IdentifierOrKeyword [ "(" [ ArgumentList ] ")" ]
.
IfStatement =
"If" Expression
( "Then"
( Statement { EXPECTEDCONFLICT(":") ":" [Statement] } [ EXPECTEDCONFLICT("Else") "Else" [Statement] { EXPECTEDCONFLICT(":") ":" [Statement] } ]
| MultilineIfRemainder
)
| MultilineIfRemainder
)
.
MultilineIfRemainder =
StatementTerminatorAndBlock
{
("Else" [ "If" Expression [ "Then" ] ]
| "ElseIf" Expression [ "Then" ]
)
StatementTerminatorAndBlock
}
"End" "If"
.
SelectStatement =
"Select" [ "Case" ] Expression StatementTerminator
{
"Case" (
"Else" |
( [ "Is" ] ComparisonOperator SimpleExpressionWithSuffix | Expression )
{ "," ( [ "Is" ] ComparisonOperator SimpleExpressionWithSuffix | Expression ) }
)
StatementTerminatorAndBlock
}
"End" "Select"
.
ComparisonOperator =
"=" | "<>" | "<" | ">" | ">=" | "<="
.
WhileStatement =
"While" Expression StatementTerminatorAndBlock "End" "While"
.
DoLoopStatement =
"Do" ( DoTopLoopStatement | DoBottomLoopStatement )
.
DoTopLoopStatement =
( "While" | "Until" ) Expression
StatementTerminatorAndBlock
"Loop"
.
DoBottomLoopStatement =
StatementTerminatorAndBlock
"Loop" [ ( "While" | "Until" ) Expression ]
.
ForStatement =
"For" ( ForLoopStatement | ForEachLoopStatement )
.
ForLoopStatement =
ForLoopVariable "=" Expression /* "To" is binary operator */ [ "Step" Expression ]
StatementTerminatorAndBlock
"Next" [ Expression { "," Expression } ]
.
ForEachLoopStatement =
"Each" ForLoopVariable "In" Expression
StatementTerminatorAndBlock
"Next" [ Expression { "," Expression } ]
.
ForLoopVariable =
SimpleExpression
[ "?" ] { ExpressionSuffix }
[ "As" TypeName ]
.
ErrorHandlingStatement =
[ "On" ] "Error" ( Expression | "GoTo" ( LiteralInteger | ident ) | "Resume" "Next" )
| "Resume" ( "Next" | LiteralInteger | ident )
.
ThrowStatement =
"Throw" [ Expression ]
.
TryStatement =
"Try"
StatementTerminatorAndBlock
{
"Catch"
[ ANY [ "As" TypeName ] ]
[ "When" Expression ]
StatementTerminatorAndBlock
}
[
"Finally"
StatementTerminatorAndBlock
]
"End" "Try"
.
BranchStatement =
"GoTo" ( ident | LiteralInteger )
| "Exit" ( "Do" | "For" | "While" | "Select" | "Sub" | "Function" | "Property" | "Try" )
| "Continue" ( "Do" | "For" | "While" )
| "Stop"
/*| "End" HACK End-Statements has special handling in Block */
| "Return" [ Expression ]
.
ReDimStatement =
"ReDim"
[ EXPECTEDCONFLICT("Preserve") "Preserve" ] /* Preserve is context-dependend keyword */
Expression
.
EraseStatement =
"Erase" Expression { "," Expression }
.
UsingStatement =
"Using" Expression
StatementTerminatorAndBlock
"End" "Using"
.
InvocationStatement =
[ "Call" ] Expression
.
ArgumentList =
Expression { "," [ Expression ] }
| "," [ Expression ] { "," [ Expression ] }
.
END VBIndentationStrategy.