📄 parser.cs
字号:
#line 1 "VBNET.ATG"
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using ICSharpCode.NRefactory.Parser.AST;
using ICSharpCode.NRefactory.Parser.VB;
using ASTAttribute = ICSharpCode.NRefactory.Parser.AST.Attribute;
/*
Parser.frame file for NRefactory.
*/
using System;
using System.Reflection;
namespace ICSharpCode.NRefactory.Parser.VB {
internal class Parser : AbstractParser
{
const int maxT = 205;
const bool T = true;
const bool x = false;
#line 12 "VBNET.ATG"
private string assemblyName = null;
private Stack withStatements;
private StringBuilder qualidentBuilder = new StringBuilder();
public string ContainingAssembly
{
set { assemblyName = value; }
}
Token t
{
get {
return lexer.Token;
}
}
Token la
{
get {
return lexer.LookAhead;
}
}
/* Return the n-th token after the current lookahead token */
void StartPeek()
{
lexer.StartPeek();
}
Token Peek()
{
return lexer.Peek();
}
Token Peek (int n)
{
lexer.StartPeek();
Token x = la;
while (n > 0) {
x = lexer.Peek();
n--;
}
return x;
}
public void Error(string s)
{
if (errDist >= minErrDist) {
errors.Error(la.line, la.col, s);
}
errDist = 0;
}
public override Expression ParseExpression()
{
lexer.NextToken();
Expression expr;
Expr(out expr);
return expr;
}
bool LeaveBlock()
{
int peek = Peek(1).kind;
return Tokens.BlockSucc[la.kind] && (la.kind != Tokens.End || peek == Tokens.EOL || peek == Tokens.Colon);
}
/* True, if "." is followed by an ident */
bool DotAndIdentOrKw () {
int peek = Peek(1).kind;
return la.kind == Tokens.Dot && (peek == Tokens.Identifier || peek >= Tokens.AddHandler);
}
bool IsEndStmtAhead()
{
int peek = Peek(1).kind;
return la.kind == Tokens.End && (peek == Tokens.EOL || peek == Tokens.Colon);
}
bool IsNotClosingParenthesis() {
return la.kind != Tokens.CloseParenthesis;
}
/*
True, if ident is followed by "="
*/
bool IdentAndAsgn () {
if(la.kind == Tokens.Identifier) {
if(Peek(1).kind == Tokens.Assign) return true;
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
}
return false;
}
/*
True, if ident is followed by "=" or by ":" and "="
*/
bool IsNamedAssign() {
// if(Peek(1).kind == Tokens.Assign) return true; // removed: not in the lang spec
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
return false;
}
bool IsObjectCreation() {
return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
}
/*
True, if "<" is followed by the ident "assembly" or "module"
*/
bool IsGlobalAttrTarget () {
Token pt = Peek(1);
return la.kind == Tokens.LessThan && ( string.Equals(pt.val, "assembly", StringComparison.InvariantCultureIgnoreCase) || string.Equals(pt.val, "module", StringComparison.InvariantCultureIgnoreCase));
}
/*
True if the next token is a "(" and is followed by "," or ")"
*/
bool IsDims()
{
int peek = Peek(1).kind;
return la.kind == Tokens.OpenParenthesis
&& (peek == Tokens.Comma || peek == Tokens.CloseParenthesis);
}
bool IsSize()
{
return la.kind == Tokens.OpenParenthesis;
}
/*
True, if the comma is not a trailing one,
like the last one in: a, b, c,
*/
bool NotFinalComma() {
int peek = Peek(1).kind;
return la.kind == Tokens.Comma &&
peek != Tokens.CloseCurlyBrace;
}
/*
True, if the next token is "Else" and this one
if followed by "If"
*/
bool IsElseIf()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Else && peek == Tokens.If;
}
/*
True if the next token is goto and this one is
followed by minus ("-") (this is allowd in in
error clauses)
*/
bool IsNegativeLabelName()
{
int peek = Peek(1).kind;
return la.kind == Tokens.GoTo && peek == Tokens.Minus;
}
/*
True if the next statement is a "Resume next" statement
*/
bool IsResumeNext()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Resume && peek == Tokens.Next;
}
/*
True, if ident/literal integer is followed by ":"
*/
bool IsLabel()
{
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
&& Peek(1).kind == Tokens.Colon;
}
bool IsNotStatementSeparator()
{
return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL;
}
bool IsAssignment ()
{
return IdentAndAsgn();
}
bool IsMustOverride(Modifiers m)
{
return m.Contains(Modifier.Abstract);
}
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
b.Append(fre.FieldName);
return result;
} else if (expr is IdentifierExpression) {
b.Append(((IdentifierExpression)expr).Identifier);
return true;
} else {
return false;
}
}
/*
True, if lookahead is a local attribute target specifier,
i.e. one of "event", "return", "field", "method",
"module", "param", "property", or "type"
*/
bool IsLocalAttrTarget() {
// TODO
return false;
}
/* START AUTOGENERATED TOKENS SECTION */
/*
*/
void VBNET() {
#line 480 "VBNET.ATG"
lexer.NextToken(); // get the first token
compilationUnit = new CompilationUnit();
withStatements = new Stack();
while (la.kind == 1) {
lexer.NextToken();
}
while (la.kind == 136) {
OptionStmt();
}
while (la.kind == 108) {
ImportsStmt();
}
while (
#line 487 "VBNET.ATG"
IsGlobalAttrTarget()) {
GlobalAttributeSection();
}
while (StartOf(1)) {
NamespaceMemberDecl();
}
Expect(0);
}
void OptionStmt() {
#line 492 "VBNET.ATG"
INode node = null; bool val = true;
Expect(136);
#line 493 "VBNET.ATG"
Point startPos = t.Location;
if (la.kind == 95) {
lexer.NextToken();
if (la.kind == 134 || la.kind == 135) {
OptionValue(
#line 495 "VBNET.ATG"
ref val);
}
#line 496 "VBNET.ATG"
node = new OptionDeclaration(OptionType.Explicit, val);
} else if (la.kind == 164) {
lexer.NextToken();
if (la.kind == 134 || la.kind == 135) {
OptionValue(
#line 498 "VBNET.ATG"
ref val);
}
#line 499 "VBNET.ATG"
node = new OptionDeclaration(OptionType.Strict, val);
} else if (la.kind == 70) {
lexer.NextToken();
if (la.kind == 51) {
lexer.NextToken();
#line 501 "VBNET.ATG"
node = new OptionDeclaration(OptionType.CompareBinary, val);
} else if (la.kind == 169) {
lexer.NextToken();
#line 502 "VBNET.ATG"
node = new OptionDeclaration(OptionType.CompareText, val);
} else SynErr(206);
} else SynErr(207);
EndOfStmt();
#line 507 "VBNET.ATG"
if (node != null) {
node.StartLocation = startPos;
node.EndLocation = t.Location;
compilationUnit.AddChild(node);
}
}
void ImportsStmt() {
#line 530 "VBNET.ATG"
List<Using> usings = new List<Using>();
Expect(108);
#line 534 "VBNET.ATG"
Point startPos = t.Location;
Using u;
ImportClause(
#line 537 "VBNET.ATG"
out u);
#line 537 "VBNET.ATG"
if (u != null) { usings.Add(u); }
while (la.kind == 12) {
lexer.NextToken();
ImportClause(
#line 539 "VBNET.ATG"
out u);
#line 539 "VBNET.ATG"
if (u != null) { usings.Add(u); }
}
EndOfStmt();
#line 543 "VBNET.ATG"
UsingDeclaration usingDeclaration = new UsingDeclaration(usings);
usingDeclaration.StartLocation = startPos;
usingDeclaration.EndLocation = t.Location;
compilationUnit.AddChild(usingDeclaration);
}
void GlobalAttributeSection() {
#line 2184 "VBNET.ATG"
Point startPos = t.Location;
Expect(27);
if (la.kind == 49) {
lexer.NextToken();
} else if (la.kind == 121) {
lexer.NextToken();
} else SynErr(208);
#line 2186 "VBNET.ATG"
string attributeTarget = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
List<ASTAttribute> attributes = new List<ASTAttribute>();
ASTAttribute attribute;
Expect(13);
Attribute(
#line 2190 "VBNET.ATG"
out attribute);
#line 2190 "VBNET.ATG"
attributes.Add(attribute);
while (
#line 2191 "VBNET.ATG"
NotFinalComma()) {
if (la.kind == 12) {
lexer.NextToken();
if (la.kind == 49) {
lexer.NextToken();
} else if (la.kind == 121) {
lexer.NextToken();
} else SynErr(209);
Expect(13);
}
Attribute(
#line 2191 "VBNET.ATG"
out attribute);
#line 2191 "VBNET.ATG"
attributes.Add(attribute);
}
if (la.kind == 12) {
lexer.NextToken();
}
Expect(26);
EndOfStmt();
#line 2196 "VBNET.ATG"
AttributeSection section = new AttributeSection(attributeTarget, attributes);
section.StartLocation = startPos;
section.EndLocation = t.EndLocation;
compilationUnit.AddChild(section);
}
void NamespaceMemberDecl() {
#line 572 "VBNET.ATG"
Modifiers m = new Modifiers();
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
string qualident;
if (la.kind == 126) {
lexer.NextToken();
#line 579 "VBNET.ATG"
Point startPos = t.Location;
Qualident(
#line 581 "VBNET.ATG"
out qualident);
#line 583 "VBNET.ATG"
INode node = new NamespaceDeclaration(qualident);
node.StartLocation = startPos;
compilationUnit.AddChild(node);
compilationUnit.BlockStart(node);
Expect(1);
NamespaceBody();
#line 591 "VBNET.ATG"
node.EndLocation = t.Location;
compilationUnit.BlockEnd();
} else if (StartOf(2)) {
while (la.kind == 27) {
AttributeSection(
#line 595 "VBNET.ATG"
out section);
#line 595 "VBNET.ATG"
attributes.Add(section);
}
while (StartOf(3)) {
TypeModifier(
#line 596 "VBNET.ATG"
m);
}
NonModuleDeclaration(
#line 596 "VBNET.ATG"
m, attributes);
} else SynErr(210);
}
void OptionValue(
#line 515 "VBNET.ATG"
ref bool val) {
if (la.kind == 135) {
lexer.NextToken();
#line 517 "VBNET.ATG"
val = true;
} else if (la.kind == 134) {
lexer.NextToken();
#line 519 "VBNET.ATG"
val = false;
} else SynErr(211);
}
void EndOfStmt() {
if (la.kind == 1) {
lexer.NextToken();
} else if (la.kind == 13) {
lexer.NextToken();
if (la.kind == 1) {
lexer.NextToken();
}
} else SynErr(212);
}
void ImportClause(
#line 550 "VBNET.ATG"
out Using u) {
#line 552 "VBNET.ATG"
string qualident = null;
TypeReference aliasedType = null;
u = null;
Qualident(
#line 556 "VBNET.ATG"
out qualident);
if (la.kind == 11) {
lexer.NextToken();
TypeName(
#line 557 "VBNET.ATG"
out aliasedType);
}
#line 559 "VBNET.ATG"
if (qualident != null && qualident.Length > 0) {
if (aliasedType != null) {
u = new Using(qualident, aliasedType);
} else {
u = new Using(qualident);
}
}
}
void Qualident(
#line 2912 "VBNET.ATG"
out string qualident) {
#line 2914 "VBNET.ATG"
string name;
qualidentBuilder.Length = 0;
Identifier();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -