📄 parser.cs
字号:
#line 1 "cs.ATG"
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using ICSharpCode.NRefactory.Parser;
using ICSharpCode.NRefactory.Ast;
using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute;
using Types = ICSharpCode.NRefactory.Ast.ClassType;
/*
Parser.frame file for NRefactory.
*/
using System;
using System.Reflection;
namespace ICSharpCode.NRefactory.Parser.CSharp {
partial class Parser : AbstractParser
{
const int maxT = 125;
const bool T = true;
const bool x = false;
#line 18 "cs.ATG"
/*
*/
void CS() {
#line 159 "cs.ATG"
lexer.NextToken(); /* get the first token */
compilationUnit = new CompilationUnit();
while (la.kind == 120) {
UsingDirective();
}
while (
#line 163 "cs.ATG"
IsGlobalAttrTarget()) {
GlobalAttributeSection();
}
while (StartOf(1)) {
NamespaceMemberDecl();
}
Expect(0);
}
void UsingDirective() {
#line 170 "cs.ATG"
string qualident = null; TypeReference aliasedType = null;
Expect(120);
#line 173 "cs.ATG"
Location startPos = t.Location;
Qualident(
#line 174 "cs.ATG"
out qualident);
if (la.kind == 3) {
lexer.NextToken();
NonArrayType(
#line 175 "cs.ATG"
out aliasedType);
}
Expect(11);
#line 177 "cs.ATG"
if (qualident != null && qualident.Length > 0) {
INode node;
if (aliasedType != null) {
node = new UsingDeclaration(qualident, aliasedType);
} else {
node = new UsingDeclaration(qualident);
}
node.StartLocation = startPos;
node.EndLocation = t.EndLocation;
compilationUnit.AddChild(node);
}
}
void GlobalAttributeSection() {
Expect(18);
#line 193 "cs.ATG"
Location startPos = t.Location;
Expect(1);
#line 194 "cs.ATG"
if (t.val != "assembly") Error("global attribute target specifier (\"assembly\") expected");
string attributeTarget = t.val;
List<ASTAttribute> attributes = new List<ASTAttribute>();
ASTAttribute attribute;
Expect(9);
Attribute(
#line 199 "cs.ATG"
out attribute);
#line 199 "cs.ATG"
attributes.Add(attribute);
while (
#line 200 "cs.ATG"
NotFinalComma()) {
Expect(14);
Attribute(
#line 200 "cs.ATG"
out attribute);
#line 200 "cs.ATG"
attributes.Add(attribute);
}
if (la.kind == 14) {
lexer.NextToken();
}
Expect(19);
#line 202 "cs.ATG"
AttributeSection section = new AttributeSection(attributeTarget, attributes);
section.StartLocation = startPos;
section.EndLocation = t.EndLocation;
compilationUnit.AddChild(section);
}
void NamespaceMemberDecl() {
#line 293 "cs.ATG"
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
ModifierList m = new ModifierList();
string qualident;
if (la.kind == 87) {
lexer.NextToken();
#line 299 "cs.ATG"
Location startPos = t.Location;
Qualident(
#line 300 "cs.ATG"
out qualident);
#line 300 "cs.ATG"
INode node = new NamespaceDeclaration(qualident);
node.StartLocation = startPos;
compilationUnit.AddChild(node);
compilationUnit.BlockStart(node);
Expect(16);
while (la.kind == 120) {
UsingDirective();
}
while (StartOf(1)) {
NamespaceMemberDecl();
}
Expect(17);
if (la.kind == 11) {
lexer.NextToken();
}
#line 309 "cs.ATG"
node.EndLocation = t.EndLocation;
compilationUnit.BlockEnd();
} else if (StartOf(2)) {
while (la.kind == 18) {
AttributeSection(
#line 313 "cs.ATG"
out section);
#line 313 "cs.ATG"
attributes.Add(section);
}
while (StartOf(3)) {
TypeModifier(
#line 314 "cs.ATG"
m);
}
TypeDecl(
#line 315 "cs.ATG"
m, attributes);
} else SynErr(126);
}
void Qualident(
#line 437 "cs.ATG"
out string qualident) {
Expect(1);
#line 439 "cs.ATG"
qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val);
while (
#line 440 "cs.ATG"
DotAndIdent()) {
Expect(15);
Expect(1);
#line 440 "cs.ATG"
qualidentBuilder.Append('.');
qualidentBuilder.Append(t.val);
}
#line 443 "cs.ATG"
qualident = qualidentBuilder.ToString();
}
void NonArrayType(
#line 550 "cs.ATG"
out TypeReference type) {
#line 552 "cs.ATG"
string name;
int pointer = 0;
type = null;
if (la.kind == 1 || la.kind == 90 || la.kind == 107) {
ClassType(
#line 557 "cs.ATG"
out type, false);
} else if (StartOf(4)) {
SimpleType(
#line 558 "cs.ATG"
out name);
#line 558 "cs.ATG"
type = new TypeReference(name);
} else if (la.kind == 122) {
lexer.NextToken();
Expect(6);
#line 559 "cs.ATG"
pointer = 1; type = new TypeReference("void");
} else SynErr(127);
if (la.kind == 12) {
NullableQuestionMark(
#line 562 "cs.ATG"
ref type);
}
while (
#line 564 "cs.ATG"
IsPointer()) {
Expect(6);
#line 565 "cs.ATG"
++pointer;
}
#line 567 "cs.ATG"
if (type != null) { type.PointerNestingLevel = pointer; }
}
void Attribute(
#line 209 "cs.ATG"
out ASTAttribute attribute) {
#line 210 "cs.ATG"
string qualident;
string alias = null;
if (
#line 214 "cs.ATG"
la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) {
lexer.NextToken();
#line 215 "cs.ATG"
alias = t.val;
Expect(10);
}
Qualident(
#line 218 "cs.ATG"
out qualident);
#line 219 "cs.ATG"
List<Expression> positional = new List<Expression>();
List<NamedArgumentExpression> named = new List<NamedArgumentExpression>();
string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident;
if (la.kind == 20) {
AttributeArguments(
#line 223 "cs.ATG"
positional, named);
}
#line 223 "cs.ATG"
attribute = new ASTAttribute(name, positional, named);
}
void AttributeArguments(
#line 226 "cs.ATG"
List<Expression> positional, List<NamedArgumentExpression> named) {
#line 228 "cs.ATG"
bool nameFound = false;
string name = "";
Expression expr;
Expect(20);
if (StartOf(5)) {
if (
#line 236 "cs.ATG"
IsAssignment()) {
#line 236 "cs.ATG"
nameFound = true;
lexer.NextToken();
#line 237 "cs.ATG"
name = t.val;
Expect(3);
}
Expr(
#line 239 "cs.ATG"
out expr);
#line 239 "cs.ATG"
if (expr != null) {if(name == "") positional.Add(expr);
else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
}
while (la.kind == 14) {
lexer.NextToken();
if (
#line 247 "cs.ATG"
IsAssignment()) {
#line 247 "cs.ATG"
nameFound = true;
Expect(1);
#line 248 "cs.ATG"
name = t.val;
Expect(3);
} else if (StartOf(5)) {
#line 250 "cs.ATG"
if (nameFound) Error("no positional argument after named argument");
} else SynErr(128);
Expr(
#line 251 "cs.ATG"
out expr);
#line 251 "cs.ATG"
if (expr != null) { if(name == "") positional.Add(expr);
else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
}
}
}
Expect(21);
}
void Expr(
#line 1609 "cs.ATG"
out Expression expr) {
#line 1610 "cs.ATG"
expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op;
UnaryExpr(
#line 1612 "cs.ATG"
out expr);
if (StartOf(6)) {
AssignmentOperator(
#line 1615 "cs.ATG"
out op);
Expr(
#line 1615 "cs.ATG"
out expr1);
#line 1615 "cs.ATG"
expr = new AssignmentExpression(expr, op, expr1);
} else if (
#line 1616 "cs.ATG"
la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) {
AssignmentOperator(
#line 1617 "cs.ATG"
out op);
Expr(
#line 1617 "cs.ATG"
out expr1);
#line 1617 "cs.ATG"
expr = new AssignmentExpression(expr, op, expr1);
} else if (StartOf(7)) {
ConditionalOrExpr(
#line 1619 "cs.ATG"
ref expr);
if (la.kind == 13) {
lexer.NextToken();
Expr(
#line 1620 "cs.ATG"
out expr1);
#line 1620 "cs.ATG"
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1);
}
if (la.kind == 12) {
lexer.NextToken();
Expr(
#line 1621 "cs.ATG"
out expr1);
Expect(9);
Expr(
#line 1621 "cs.ATG"
out expr2);
#line 1621 "cs.ATG"
expr = new ConditionalExpression(expr, expr1, expr2);
}
} else SynErr(129);
}
void AttributeSection(
#line 260 "cs.ATG"
out AttributeSection section) {
#line 262 "cs.ATG"
string attributeTarget = "";
List<ASTAttribute> attributes = new List<ASTAttribute>();
ASTAttribute attribute;
Expect(18);
#line 268 "cs.ATG"
Location startPos = t.Location;
if (
#line 269 "cs.ATG"
IsLocalAttrTarget()) {
if (la.kind == 68) {
lexer.NextToken();
#line 270 "cs.ATG"
attributeTarget = "event";
} else if (la.kind == 100) {
lexer.NextToken();
#line 271 "cs.ATG"
attributeTarget = "return";
} else {
lexer.NextToken();
#line 272 "cs.ATG"
if (t.val != "field" || t.val != "method" ||
t.val != "module" || t.val != "param" ||
t.val != "property" || t.val != "type")
Error("attribute target specifier (event, return, field," +
"method, module, param, property, or type) expected");
attributeTarget = t.val;
}
Expect(9);
}
Attribute(
#line 282 "cs.ATG"
out attribute);
#line 282 "cs.ATG"
attributes.Add(attribute);
while (
#line 283 "cs.ATG"
NotFinalComma()) {
Expect(14);
Attribute(
#line 283 "cs.ATG"
out attribute);
#line 283 "cs.ATG"
attributes.Add(attribute);
}
if (la.kind == 14) {
lexer.NextToken();
}
Expect(19);
#line 285 "cs.ATG"
section = new AttributeSection(attributeTarget, attributes);
section.StartLocation = startPos;
section.EndLocation = t.EndLocation;
}
void TypeModifier(
#line 637 "cs.ATG"
ModifierList m) {
switch (la.kind) {
case 88: {
lexer.NextToken();
#line 639 "cs.ATG"
m.Add(Modifiers.New, t.Location);
break;
}
case 97: {
lexer.NextToken();
#line 640 "cs.ATG"
m.Add(Modifiers.Public, t.Location);
break;
}
case 96: {
lexer.NextToken();
#line 641 "cs.ATG"
m.Add(Modifiers.Protected, t.Location);
break;
}
case 83: {
lexer.NextToken();
#line 642 "cs.ATG"
m.Add(Modifiers.Internal, t.Location);
break;
}
case 95: {
lexer.NextToken();
#line 643 "cs.ATG"
m.Add(Modifiers.Private, t.Location);
break;
}
case 118: {
lexer.NextToken();
#line 644 "cs.ATG"
m.Add(Modifiers.Unsafe, t.Location);
break;
}
case 48: {
lexer.NextToken();
#line 645 "cs.ATG"
m.Add(Modifiers.Abstract, t.Location);
break;
}
case 102: {
lexer.NextToken();
#line 646 "cs.ATG"
m.Add(Modifiers.Sealed, t.Location);
break;
}
case 106: {
lexer.NextToken();
#line 647 "cs.ATG"
m.Add(Modifiers.Static, t.Location);
break;
}
case 1: {
lexer.NextToken();
#line 648 "cs.ATG"
if (t.val == "partial") { m.Add(Modifiers.Partial, t.Location); } else { Error("Unexpected identifier"); }
break;
}
default: SynErr(130); break;
}
}
void TypeDecl(
#line 318 "cs.ATG"
ModifierList m, List<AttributeSection> attributes) {
#line 320 "cs.ATG"
TypeReference type;
List<TypeReference> names;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
string name;
List<TemplateDefinition> templates;
if (la.kind == 58) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -