Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mkrueger@novell.com>2009-03-31 11:24:18 +0400
committerMike Krüger <mkrueger@novell.com>2009-03-31 11:24:18 +0400
commit903e1e2a5df8a7e7761d100c30c8f0992cb38370 (patch)
tree9031e42eb4eb91d28a7bd68f9998b6e82aeea5c5 /main/contrib
parent8fe675d07d10432850a83999bb10c2c32b36d41a (diff)
* Src/Parser/CSharp/cs.ATG:
* Src/Parser/CSharp/Parser.cs: * Src/Parser/CSharp/CSharpParser.cs: Added ref/out parameters for typed lambda expressions. svn path=/trunk/monodevelop/; revision=130616
Diffstat (limited to 'main/contrib')
-rw-r--r--main/contrib/NRefactory/Project/ChangeLog7
-rw-r--r--main/contrib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs1225
-rw-r--r--main/contrib/NRefactory/Project/Src/Parser/CSharp/Parser.cs602
-rw-r--r--main/contrib/NRefactory/Project/Src/Parser/CSharp/cs.ATG5146
4 files changed, 3504 insertions, 3476 deletions
diff --git a/main/contrib/NRefactory/Project/ChangeLog b/main/contrib/NRefactory/Project/ChangeLog
index db6859d8b8..e50b6423af 100644
--- a/main/contrib/NRefactory/Project/ChangeLog
+++ b/main/contrib/NRefactory/Project/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-31 Mike Krüger <mkrueger@novell.com>
+
+ * Src/Parser/CSharp/cs.ATG:
+ * Src/Parser/CSharp/Parser.cs:
+ * Src/Parser/CSharp/CSharpParser.cs: Added ref/out parameters
+ for typed lambda expressions.
+
2009-03-30 Mike Krüger <mkrueger@novell.com>
* Src/Lexer/CSharp/Lexer.cs:
diff --git a/main/contrib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs b/main/contrib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
index 98fe0bcfe0..f5a49eeb38 100644
--- a/main/contrib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
+++ b/main/contrib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
@@ -1,611 +1,614 @@
-// <file>
-// <copyright see="prj:///doc/copyright.txt"/>
-// <license see="prj:///doc/license.txt"/>
-// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
-// <version>$Revision: 3717M $</version>
-// </file>
-
-using ICSharpCode.NRefactory.Visitors;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
-using ICSharpCode.NRefactory.Ast;
-
-namespace ICSharpCode.NRefactory.Parser.CSharp
-{
- internal sealed partial class Parser : AbstractParser
- {
- Lexer lexer;
-
- public Parser(ILexer lexer) : base(lexer)
- {
- this.lexer = (Lexer)lexer;
- // due to anonymous methods, we always need a compilation unit, so
- // create it in the constructor
- compilationUnit = new CompilationUnit();
- }
-
- StringBuilder qualidentBuilder = new StringBuilder();
-
- Token t {
- [System.Diagnostics.DebuggerStepThrough]
- get {
- return lexer.Token;
- }
- }
-
- Token la {
- [System.Diagnostics.DebuggerStepThrough]
- get {
- return lexer.LookAhead;
- }
- }
-
- public void Error(string s)
- {
- if (errDist >= MinErrDist) {
- this.Errors.Error(la.line, la.col, s);
- }
- errDist = 0;
- }
-
- public override void Parse()
- {
- ParseRoot();
- compilationUnit.AcceptVisitor(new SetParentVisitor(), null);
- }
-
- public override TypeReference ParseTypeReference ()
- {
- lexer.NextToken();
- TypeReference type;
- Type(out type);
- return type;
- }
-
- public override Expression ParseExpression()
- {
- lexer.NextToken();
- Location startLocation = la.Location;
- Expression expr;
- Expr(out expr);
- // SEMICOLON HACK : without a trailing semicolon, parsing expressions does not work correctly
- if (la.kind == Tokens.Semicolon) lexer.NextToken();
- if (expr != null) {
- expr.StartLocation = startLocation;
- expr.EndLocation = t.EndLocation;
- expr.AcceptVisitor(new SetParentVisitor(), null);
- }
- Expect(Tokens.EOF);
- return expr;
- }
-
- public override BlockStatement ParseBlock()
- {
- lexer.NextToken();
- compilationUnit = new CompilationUnit();
-
- BlockStatement blockStmt = new BlockStatement();
- blockStmt.StartLocation = la.Location;
- compilationUnit.BlockStart(blockStmt);
-
- while (la.kind != Tokens.EOF) {
- Token oldLa = la;
- Statement();
- if (la == oldLa) {
- // did not advance lexer position, we cannot parse this as a statement block
- return null;
- }
- }
-
- compilationUnit.BlockEnd();
- blockStmt.EndLocation = t.EndLocation;
- Expect(Tokens.EOF);
- blockStmt.AcceptVisitor(new SetParentVisitor(), null);
- return blockStmt;
- }
-
- public override List<INode> ParseTypeMembers()
- {
- lexer.NextToken();
- compilationUnit = new CompilationUnit();
-
- TypeDeclaration newType = new TypeDeclaration(Modifiers.None, null);
- compilationUnit.BlockStart(newType);
- ClassBody();
- compilationUnit.BlockEnd();
- Expect(Tokens.EOF);
- newType.AcceptVisitor(new SetParentVisitor(), null);
- return newType.Children;
- }
-
- // Begin ISTypeCast
- bool IsTypeCast()
- {
- if (la.kind != Tokens.OpenParenthesis) {
- return false;
- }
- bool isPossibleExpression = true;
-
- lexer.StartPeek();
- Token pt = lexer.Peek();
-
- if (!IsTypeNameOrKWForTypeCast(ref pt, ref isPossibleExpression)) {
- return false;
- }
-
- // ")"
- if (pt.kind != Tokens.CloseParenthesis) {
- return false;
- }
- if (isPossibleExpression) {
- // check successor
- pt = lexer.Peek();
- return Tokens.CastFollower[pt.kind];
- } else {
- // not possibly an expression: don't check cast follower
- return true;
- }
- }
-
- /* !!! Proceeds from current peek position !!! */
- bool IsTypeKWForTypeCast(ref Token pt)
- {
- if (Tokens.TypeKW[pt.kind]) {
- pt = lexer.Peek();
- return IsPointerOrDims(ref pt) && SkipQuestionMark(ref pt);
- } else if (pt.kind == Tokens.Void) {
- pt = lexer.Peek();
- return IsPointerOrDims(ref pt);
- }
- return false;
- }
-
- /* !!! Proceeds from current peek position !!! */
- bool IsTypeNameOrKWForTypeCast(ref Token pt, ref bool isPossibleExpression)
- {
- if (Tokens.TypeKW[pt.kind] || pt.kind == Tokens.Void) {
- isPossibleExpression = false;
- return IsTypeKWForTypeCast(ref pt);
- } else {
- return IsTypeNameForTypeCast(ref pt, ref isPossibleExpression);
- }
- }
-
- bool IsTypeNameOrKWForTypeCast(ref Token pt)
- {
- bool tmp = false;
- return IsTypeNameOrKWForTypeCast(ref pt, ref tmp);
- }
-
- // TypeName = ident [ "::" ident ] { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident } ["?"] PointerOrDims
- /* !!! Proceeds from current peek position !!! */
- bool IsTypeNameForTypeCast(ref Token pt, ref bool isPossibleExpression)
- {
- // ident
- if (!IsIdentifierToken(pt)) {
- return false;
- }
- pt = Peek();
- // "::" ident
- if (pt.kind == Tokens.DoubleColon) {
- pt = Peek();
- if (!IsIdentifierToken(pt)) {
- return false;
- }
- pt = Peek();
- }
- // { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident }
- while (true) {
- if (pt.kind == Tokens.LessThan) {
- do {
- pt = Peek();
- if (!IsTypeNameOrKWForTypeCast(ref pt)) {
- return false;
- }
- } while (pt.kind == Tokens.Comma);
- if (pt.kind != Tokens.GreaterThan) {
- return false;
- }
- pt = Peek();
- }
- if (pt.kind != Tokens.Dot)
- break;
- pt = Peek();
- if (pt.kind != Tokens.Identifier) {
- return false;
- }
- pt = Peek();
- }
- // ["?"]
- if (pt.kind == Tokens.Question) {
- pt = Peek();
- }
- if (pt.kind == Tokens.Times || pt.kind == Tokens.OpenSquareBracket) {
- isPossibleExpression = false;
- return IsPointerOrDims(ref pt);
- }
- return true;
- }
- // END IsTypeCast
-
- // Gets if the token is a possible token for an expression start
- // Is used to determine if "a is Type ? token" a the start of a ternary
- // expression or a type test for Nullable<Type>
- bool IsPossibleExpressionStart(int token)
- {
- return Tokens.CastFollower[token] || Tokens.UnaryOp[token];
- }
-
- // ( { [TypeNameOrKWForTypeCast] ident "," } )
- bool IsLambdaExpression()
- {
- if (la.kind != Tokens.OpenParenthesis) {
- return false;
- }
- StartPeek();
- Token pt = Peek();
- while (pt.kind != Tokens.CloseParenthesis) {
- if (!IsTypeNameOrKWForTypeCast(ref pt)) {
- return false;
- }
- if (IsIdentifierToken(pt)) {
- // make ident optional: if implicitly typed lambda arguments are used, IsTypeNameForTypeCast
- // has already accepted the identifier
- pt = Peek();
- }
- if (pt.kind == Tokens.CloseParenthesis) {
- break;
- }
- // require comma between parameters:
- if (pt.kind == Tokens.Comma) {
- pt = Peek();
- } else {
- return false;
- }
- }
- pt = Peek();
- return pt.kind == Tokens.LambdaArrow;
- }
-
- /* Checks whether the next sequences of tokens is a qualident *
- * and returns the qualident string */
- /* !!! Proceeds from current peek position !!! */
- bool IsQualident(ref Token pt, out string qualident)
- {
- if (IsIdentifierToken(pt)) {
- qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val);
- pt = Peek();
- while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) {
- pt = Peek();
- if (!IsIdentifierToken(pt)) {
- qualident = String.Empty;
- return false;
- }
- qualidentBuilder.Append('.');
- qualidentBuilder.Append(pt.val);
- pt = Peek();
- }
- qualident = qualidentBuilder.ToString();
- return true;
- }
- qualident = String.Empty;
- return false;
- }
-
- /* Skips generic type extensions */
- /* !!! Proceeds from current peek position !!! */
-
- /* skip: { "*" | "[" { "," } "]" } */
- /* !!! Proceeds from current peek position !!! */
- bool IsPointerOrDims (ref Token pt)
- {
- for (;;) {
- if (pt.kind == Tokens.OpenSquareBracket) {
- do pt = Peek();
- while (pt.kind == Tokens.Comma);
- if (pt.kind != Tokens.CloseSquareBracket) return false;
- } else if (pt.kind != Tokens.Times) break;
- pt = Peek();
- }
- return true;
- }
-
- /* 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;
- }
-
- /*-----------------------------------------------------------------*
- * Resolver routines to resolve LL(1) conflicts: * *
- * These resolution routine return a boolean value that indicates *
- * whether the alternative at hand shall be choosen or not. *
- * They are used in IF ( ... ) expressions. *
- *-----------------------------------------------------------------*/
-
- /* True, if ident is followed by "=" */
- bool IdentAndAsgn ()
- {
- return IsIdentifierToken(la) && Peek(1).kind == Tokens.Assign;
- }
-
- bool IdentAndDoubleColon ()
- {
- return IsIdentifierToken(la) && Peek(1).kind == Tokens.DoubleColon;
- }
-
- bool IsAssignment () { return IdentAndAsgn(); }
-
- /* True, if ident is followed by ",", "=", "[" or ";" */
- bool IsVarDecl () {
- int peek = Peek(1).kind;
- return IsIdentifierToken(la) &&
- (peek == Tokens.Comma || peek == Tokens.Assign || peek == Tokens.Semicolon || peek == Tokens.OpenSquareBracket);
- }
-
- /* 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 && peek != Tokens.CloseSquareBracket;
- }
-
- /* True, if "void" is followed by "*" */
- bool NotVoidPointer () {
- return la.kind == Tokens.Void && Peek(1).kind != Tokens.Times;
- }
-
- /* True, if "checked" or "unchecked" are followed by "{" */
- bool UnCheckedAndLBrace () {
- return la.kind == Tokens.Checked || la.kind == Tokens.Unchecked &&
- Peek(1).kind == Tokens.OpenCurlyBrace;
- }
-
- /* True, if "." is followed by an ident */
- bool DotAndIdent () {
- return la.kind == Tokens.Dot && IsIdentifierToken(Peek(1));
- }
-
- /* True, if ident is followed by ":" */
- bool IdentAndColon () {
- return IsIdentifierToken(la) && Peek(1).kind == Tokens.Colon;
- }
-
- bool IsLabel () { return IdentAndColon(); }
-
- /* True, if ident is followed by "(" */
- bool IdentAndLPar () {
- return IsIdentifierToken(la) && Peek(1).kind == Tokens.OpenParenthesis;
- }
-
- /* True, if "catch" is followed by "(" */
- bool CatchAndLPar () {
- return la.kind == Tokens.Catch && Peek(1).kind == Tokens.OpenParenthesis;
- }
- bool IsTypedCatch () { return CatchAndLPar(); }
-
- /* True, if "[" is followed by the ident "assembly" */
- bool IsGlobalAttrTarget () {
- Token pt = Peek(1);
- return la.kind == Tokens.OpenSquareBracket &&
- IsIdentifierToken(pt) && (pt.val == "assembly" || pt.val == "module");
- }
-
- /* True, if "[" is followed by "," or "]" */
- bool LBrackAndCommaOrRBrack () {
- int peek = Peek(1).kind;
- return la.kind == Tokens.OpenSquareBracket &&
- (peek == Tokens.Comma || peek == Tokens.CloseSquareBracket);
- }
-
- /* True, if "[" is followed by "," or "]" */
- /* or if the current token is "*" */
- bool TimesOrLBrackAndCommaOrRBrack () {
- return la.kind == Tokens.Times || LBrackAndCommaOrRBrack();
- }
- bool IsPointerOrDims () { return TimesOrLBrackAndCommaOrRBrack(); }
- bool IsPointer () { return la.kind == Tokens.Times; }
-
-
- bool SkipGeneric(ref Token pt)
- {
- if (pt.kind == Tokens.LessThan) {
- do {
- pt = Peek();
- if (!IsTypeNameOrKWForTypeCast(ref pt)) return false;
- } while (pt.kind == Tokens.Comma);
- if (pt.kind != Tokens.GreaterThan) return false;
- pt = Peek();
- }
- return true;
- }
- bool SkipQuestionMark(ref Token pt)
- {
- if (pt.kind == Tokens.Question) {
- pt = Peek();
- }
- return true;
- }
-
- /* True, if lookahead is a primitive type keyword, or */
- /* if it is a type declaration followed by an ident */
- bool IsLocalVarDecl () {
- if (IsYieldStatement()) {
- return false;
- }
- if ((Tokens.TypeKW[la.kind] && Peek(1).kind != Tokens.Dot) || la.kind == Tokens.Void) {
- return true;
- }
-
- StartPeek();
- Token pt = la;
- return IsTypeNameOrKWForTypeCast(ref pt) && IsIdentifierToken(pt);
- }
-
- /* True if lookahead is a type argument list (<...>) followed by
- * one of "( ) ] } : ; , . ? == !=" */
- bool IsGenericInSimpleNameOrMemberAccess()
- {
- Token t = la;
- if (t.kind != Tokens.LessThan) return false;
- StartPeek();
- return SkipGeneric(ref t) && Tokens.GenericFollower[t.kind];
- }
-
- bool IsExplicitInterfaceImplementation()
- {
- StartPeek();
- Token pt = la;
- pt = Peek();
- if (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon)
- return true;
- if (pt.kind == Tokens.LessThan) {
- if (SkipGeneric(ref pt))
- return pt.kind == Tokens.Dot;
- }
- return false;
- }
-
- /* True, if lookahead ident is "yield" and than follows a break or return */
- bool IsYieldStatement () {
- return la.kind == Tokens.Yield && (Peek(1).kind == Tokens.Return || Peek(1).kind == Tokens.Break);
- }
-
- /* True, if lookahead is a local attribute target specifier, *
- * i.e. one of "event", "return", "field", "method", *
- * "module", "param", "property", or "type" */
- bool IsLocalAttrTarget () {
- int cur = la.kind;
- string val = la.val;
-
- return (cur == Tokens.Event || cur == Tokens.Return ||
- (Tokens.IdentifierTokens[cur] &&
- (val == "field" || val == "method" || val == "module" ||
- val == "param" || val == "property" || val == "type"))) &&
- Peek(1).kind == Tokens.Colon;
- }
-
- bool IsShiftRight()
- {
- Token next = Peek(1);
- // TODO : Add col test (seems not to work, lexer bug...) : && la.col == next.col - 1
- return (la.kind == Tokens.GreaterThan && next.kind == Tokens.GreaterThan);
- }
-
- bool IsGenericExpression(Expression expr)
- {
- if (expr is IdentifierExpression)
- return ((IdentifierExpression)expr).TypeArguments.Count > 0;
- else if (expr is MemberReferenceExpression)
- return ((MemberReferenceExpression)expr).TypeArguments.Count > 0;
- else
- return false;
- }
-
- bool ShouldConvertTargetExpressionToTypeReference(Expression targetExpr)
- {
- if (targetExpr is IdentifierExpression)
- return ((IdentifierExpression)targetExpr).TypeArguments.Count > 0;
- else if (targetExpr is MemberReferenceExpression)
- return ((MemberReferenceExpression)targetExpr).TypeArguments.Count > 0;
- else
- return false;
- }
-
- TypeReference GetTypeReferenceFromExpression(Expression expr)
- {
- if (expr is TypeReferenceExpression)
- return (expr as TypeReferenceExpression).TypeReference;
-
- IdentifierExpression ident = expr as IdentifierExpression;
- if (ident != null) {
- return new TypeReference(ident.Identifier, ident.TypeArguments);
- }
-
- MemberReferenceExpression member = expr as MemberReferenceExpression;
- if (member != null) {
- TypeReference targetType = GetTypeReferenceFromExpression(member.TargetObject);
- if (targetType != null) {
- if (targetType.GenericTypes.Count == 0 && targetType.IsArrayType == false) {
- TypeReference tr = new TypeReference(targetType.Type + "." + member.MemberName, member.TypeArguments);
- tr.IsGlobal = targetType.IsGlobal;
- return tr;
- } else {
- return new InnerClassTypeReference(targetType, member.MemberName, member.TypeArguments);
- }
- }
- }
- return null;
- }
-
- bool IsMostNegativeIntegerWithoutTypeSuffix()
- {
- Token token = la;
- if (token.kind == Tokens.Literal) {
- return token.val == "2147483648" || token.val == "9223372036854775808";
- } else {
- return false;
- }
- }
-
- bool LastExpressionIsUnaryMinus(System.Collections.ArrayList expressions)
- {
- if (expressions.Count == 0) return false;
- UnaryOperatorExpression uoe = expressions[expressions.Count - 1] as UnaryOperatorExpression;
- if (uoe != null) {
- return uoe.Op == UnaryOperatorType.Minus;
- } else {
- return false;
- }
- }
-
- bool StartOfQueryExpression()
- {
- if (la.kind == Tokens.From) {
- Token p = Peek(1);
- if (IsIdentifierToken(p) || Tokens.TypeKW[p.kind])
- return true;
- }
- return false;
- }
-
- static bool IsIdentifierToken(Token tk)
- {
- return Tokens.IdentifierTokens[tk.kind];
- }
-
- /// <summary>
- /// Adds a child item to a collection stored in the parent node.
- /// Also set's the item's parent to <paramref name="parent"/>.
- /// Does nothing if item is null.
- /// </summary>
- static void SafeAdd<T>(INode parent, List<T> list, T item) where T : class, INode
- {
- Debug.Assert(parent != null);
- Debug.Assert((parent is INullable) ? !(parent as INullable).IsNull : true);
- if (item != null) {
- list.Add(item);
- item.Parent = parent;
- }
- }
- }
-}
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
+// <version>$Revision: 3943 $</version>
+// </file>
+
+using ICSharpCode.NRefactory.Visitors;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Text;
+using ICSharpCode.NRefactory.Ast;
+
+namespace ICSharpCode.NRefactory.Parser.CSharp
+{
+ internal sealed partial class Parser : AbstractParser
+ {
+ Lexer lexer;
+
+ public Parser(ILexer lexer) : base(lexer)
+ {
+ this.lexer = (Lexer)lexer;
+ // due to anonymous methods, we always need a compilation unit, so
+ // create it in the constructor
+ compilationUnit = new CompilationUnit();
+ }
+
+ StringBuilder qualidentBuilder = new StringBuilder();
+
+ Token t {
+ [System.Diagnostics.DebuggerStepThrough]
+ get {
+ return lexer.Token;
+ }
+ }
+
+ Token la {
+ [System.Diagnostics.DebuggerStepThrough]
+ get {
+ return lexer.LookAhead;
+ }
+ }
+
+ public void Error(string s)
+ {
+ if (errDist >= MinErrDist) {
+ this.Errors.Error(la.line, la.col, s);
+ }
+ errDist = 0;
+ }
+
+ public override void Parse()
+ {
+ ParseRoot();
+ compilationUnit.AcceptVisitor(new SetParentVisitor(), null);
+ }
+
+ public override TypeReference ParseTypeReference ()
+ {
+ lexer.NextToken();
+ TypeReference type;
+ Type(out type);
+ return type;
+ }
+
+ public override Expression ParseExpression()
+ {
+ lexer.NextToken();
+ Location startLocation = la.Location;
+ Expression expr;
+ Expr(out expr);
+ // SEMICOLON HACK : without a trailing semicolon, parsing expressions does not work correctly
+ if (la.kind == Tokens.Semicolon) lexer.NextToken();
+ if (expr != null) {
+ expr.StartLocation = startLocation;
+ expr.EndLocation = t.EndLocation;
+ expr.AcceptVisitor(new SetParentVisitor(), null);
+ }
+ Expect(Tokens.EOF);
+ return expr;
+ }
+
+ public override BlockStatement ParseBlock()
+ {
+ lexer.NextToken();
+ compilationUnit = new CompilationUnit();
+
+ BlockStatement blockStmt = new BlockStatement();
+ blockStmt.StartLocation = la.Location;
+ compilationUnit.BlockStart(blockStmt);
+
+ while (la.kind != Tokens.EOF) {
+ Token oldLa = la;
+ Statement();
+ if (la == oldLa) {
+ // did not advance lexer position, we cannot parse this as a statement block
+ return null;
+ }
+ }
+
+ compilationUnit.BlockEnd();
+ blockStmt.EndLocation = t.EndLocation;
+ Expect(Tokens.EOF);
+ blockStmt.AcceptVisitor(new SetParentVisitor(), null);
+ return blockStmt;
+ }
+
+ public override List<INode> ParseTypeMembers()
+ {
+ lexer.NextToken();
+ compilationUnit = new CompilationUnit();
+
+ TypeDeclaration newType = new TypeDeclaration(Modifiers.None, null);
+ compilationUnit.BlockStart(newType);
+ ClassBody();
+ compilationUnit.BlockEnd();
+ Expect(Tokens.EOF);
+ newType.AcceptVisitor(new SetParentVisitor(), null);
+ return newType.Children;
+ }
+
+ // Begin ISTypeCast
+ bool IsTypeCast()
+ {
+ if (la.kind != Tokens.OpenParenthesis) {
+ return false;
+ }
+ bool isPossibleExpression = true;
+
+ lexer.StartPeek();
+ Token pt = lexer.Peek();
+
+ if (!IsTypeNameOrKWForTypeCast(ref pt, ref isPossibleExpression)) {
+ return false;
+ }
+
+ // ")"
+ if (pt.kind != Tokens.CloseParenthesis) {
+ return false;
+ }
+ if (isPossibleExpression) {
+ // check successor
+ pt = lexer.Peek();
+ return Tokens.CastFollower[pt.kind];
+ } else {
+ // not possibly an expression: don't check cast follower
+ return true;
+ }
+ }
+
+ /* !!! Proceeds from current peek position !!! */
+ bool IsTypeKWForTypeCast(ref Token pt)
+ {
+ if (Tokens.TypeKW[pt.kind]) {
+ pt = lexer.Peek();
+ return IsPointerOrDims(ref pt) && SkipQuestionMark(ref pt);
+ } else if (pt.kind == Tokens.Void) {
+ pt = lexer.Peek();
+ return IsPointerOrDims(ref pt);
+ }
+ return false;
+ }
+
+ /* !!! Proceeds from current peek position !!! */
+ bool IsTypeNameOrKWForTypeCast(ref Token pt, ref bool isPossibleExpression)
+ {
+ if (Tokens.TypeKW[pt.kind] || pt.kind == Tokens.Void) {
+ isPossibleExpression = false;
+ return IsTypeKWForTypeCast(ref pt);
+ } else {
+ return IsTypeNameForTypeCast(ref pt, ref isPossibleExpression);
+ }
+ }
+
+ bool IsTypeNameOrKWForTypeCast(ref Token pt)
+ {
+ bool tmp = false;
+ return IsTypeNameOrKWForTypeCast(ref pt, ref tmp);
+ }
+
+ // TypeName = ident [ "::" ident ] { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident } ["?"] PointerOrDims
+ /* !!! Proceeds from current peek position !!! */
+ bool IsTypeNameForTypeCast(ref Token pt, ref bool isPossibleExpression)
+ {
+ // ident
+ if (!IsIdentifierToken(pt)) {
+ return false;
+ }
+ pt = Peek();
+ // "::" ident
+ if (pt.kind == Tokens.DoubleColon) {
+ pt = Peek();
+ if (!IsIdentifierToken(pt)) {
+ return false;
+ }
+ pt = Peek();
+ }
+ // { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident }
+ while (true) {
+ if (pt.kind == Tokens.LessThan) {
+ do {
+ pt = Peek();
+ if (!IsTypeNameOrKWForTypeCast(ref pt)) {
+ return false;
+ }
+ } while (pt.kind == Tokens.Comma);
+ if (pt.kind != Tokens.GreaterThan) {
+ return false;
+ }
+ pt = Peek();
+ }
+ if (pt.kind != Tokens.Dot)
+ break;
+ pt = Peek();
+ if (pt.kind != Tokens.Identifier) {
+ return false;
+ }
+ pt = Peek();
+ }
+ // ["?"]
+ if (pt.kind == Tokens.Question) {
+ pt = Peek();
+ }
+ if (pt.kind == Tokens.Times || pt.kind == Tokens.OpenSquareBracket) {
+ isPossibleExpression = false;
+ return IsPointerOrDims(ref pt);
+ }
+ return true;
+ }
+ // END IsTypeCast
+
+ // Gets if the token is a possible token for an expression start
+ // Is used to determine if "a is Type ? token" a the start of a ternary
+ // expression or a type test for Nullable<Type>
+ bool IsPossibleExpressionStart(int token)
+ {
+ return Tokens.CastFollower[token] || Tokens.UnaryOp[token];
+ }
+
+ // ( { [TypeNameOrKWForTypeCast] ident "," } )
+ bool IsLambdaExpression()
+ {
+ if (la.kind != Tokens.OpenParenthesis) {
+ return false;
+ }
+ StartPeek();
+ Token pt = Peek();
+ while (pt.kind != Tokens.CloseParenthesis) {
+ if (pt.kind == Tokens.Out || pt.kind == Tokens.Ref) {
+ pt = Peek();
+ }
+ if (!IsTypeNameOrKWForTypeCast(ref pt)) {
+ return false;
+ }
+ if (IsIdentifierToken(pt)) {
+ // make ident optional: if implicitly typed lambda arguments are used, IsTypeNameForTypeCast
+ // has already accepted the identifier
+ pt = Peek();
+ }
+ if (pt.kind == Tokens.CloseParenthesis) {
+ break;
+ }
+ // require comma between parameters:
+ if (pt.kind == Tokens.Comma) {
+ pt = Peek();
+ } else {
+ return false;
+ }
+ }
+ pt = Peek();
+ return pt.kind == Tokens.LambdaArrow;
+ }
+
+ /* Checks whether the next sequences of tokens is a qualident *
+ * and returns the qualident string */
+ /* !!! Proceeds from current peek position !!! */
+ bool IsQualident(ref Token pt, out string qualident)
+ {
+ if (IsIdentifierToken(pt)) {
+ qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val);
+ pt = Peek();
+ while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) {
+ pt = Peek();
+ if (!IsIdentifierToken(pt)) {
+ qualident = String.Empty;
+ return false;
+ }
+ qualidentBuilder.Append('.');
+ qualidentBuilder.Append(pt.val);
+ pt = Peek();
+ }
+ qualident = qualidentBuilder.ToString();
+ return true;
+ }
+ qualident = String.Empty;
+ return false;
+ }
+
+ /* Skips generic type extensions */
+ /* !!! Proceeds from current peek position !!! */
+
+ /* skip: { "*" | "[" { "," } "]" } */
+ /* !!! Proceeds from current peek position !!! */
+ bool IsPointerOrDims (ref Token pt)
+ {
+ for (;;) {
+ if (pt.kind == Tokens.OpenSquareBracket) {
+ do pt = Peek();
+ while (pt.kind == Tokens.Comma);
+ if (pt.kind != Tokens.CloseSquareBracket) return false;
+ } else if (pt.kind != Tokens.Times) break;
+ pt = Peek();
+ }
+ return true;
+ }
+
+ /* 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;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Resolver routines to resolve LL(1) conflicts: * *
+ * These resolution routine return a boolean value that indicates *
+ * whether the alternative at hand shall be choosen or not. *
+ * They are used in IF ( ... ) expressions. *
+ *-----------------------------------------------------------------*/
+
+ /* True, if ident is followed by "=" */
+ bool IdentAndAsgn ()
+ {
+ return IsIdentifierToken(la) && Peek(1).kind == Tokens.Assign;
+ }
+
+ bool IdentAndDoubleColon ()
+ {
+ return IsIdentifierToken(la) && Peek(1).kind == Tokens.DoubleColon;
+ }
+
+ bool IsAssignment () { return IdentAndAsgn(); }
+
+ /* True, if ident is followed by ",", "=", "[" or ";" */
+ bool IsVarDecl () {
+ int peek = Peek(1).kind;
+ return IsIdentifierToken(la) &&
+ (peek == Tokens.Comma || peek == Tokens.Assign || peek == Tokens.Semicolon || peek == Tokens.OpenSquareBracket);
+ }
+
+ /* 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 && peek != Tokens.CloseSquareBracket;
+ }
+
+ /* True, if "void" is followed by "*" */
+ bool NotVoidPointer () {
+ return la.kind == Tokens.Void && Peek(1).kind != Tokens.Times;
+ }
+
+ /* True, if "checked" or "unchecked" are followed by "{" */
+ bool UnCheckedAndLBrace () {
+ return la.kind == Tokens.Checked || la.kind == Tokens.Unchecked &&
+ Peek(1).kind == Tokens.OpenCurlyBrace;
+ }
+
+ /* True, if "." is followed by an ident */
+ bool DotAndIdent () {
+ return la.kind == Tokens.Dot && IsIdentifierToken(Peek(1));
+ }
+
+ /* True, if ident is followed by ":" */
+ bool IdentAndColon () {
+ return IsIdentifierToken(la) && Peek(1).kind == Tokens.Colon;
+ }
+
+ bool IsLabel () { return IdentAndColon(); }
+
+ /* True, if ident is followed by "(" */
+ bool IdentAndLPar () {
+ return IsIdentifierToken(la) && Peek(1).kind == Tokens.OpenParenthesis;
+ }
+
+ /* True, if "catch" is followed by "(" */
+ bool CatchAndLPar () {
+ return la.kind == Tokens.Catch && Peek(1).kind == Tokens.OpenParenthesis;
+ }
+ bool IsTypedCatch () { return CatchAndLPar(); }
+
+ /* True, if "[" is followed by the ident "assembly" */
+ bool IsGlobalAttrTarget () {
+ Token pt = Peek(1);
+ return la.kind == Tokens.OpenSquareBracket &&
+ IsIdentifierToken(pt) && (pt.val == "assembly" || pt.val == "module");
+ }
+
+ /* True, if "[" is followed by "," or "]" */
+ bool LBrackAndCommaOrRBrack () {
+ int peek = Peek(1).kind;
+ return la.kind == Tokens.OpenSquareBracket &&
+ (peek == Tokens.Comma || peek == Tokens.CloseSquareBracket);
+ }
+
+ /* True, if "[" is followed by "," or "]" */
+ /* or if the current token is "*" */
+ bool TimesOrLBrackAndCommaOrRBrack () {
+ return la.kind == Tokens.Times || LBrackAndCommaOrRBrack();
+ }
+ bool IsPointerOrDims () { return TimesOrLBrackAndCommaOrRBrack(); }
+ bool IsPointer () { return la.kind == Tokens.Times; }
+
+
+ bool SkipGeneric(ref Token pt)
+ {
+ if (pt.kind == Tokens.LessThan) {
+ do {
+ pt = Peek();
+ if (!IsTypeNameOrKWForTypeCast(ref pt)) return false;
+ } while (pt.kind == Tokens.Comma);
+ if (pt.kind != Tokens.GreaterThan) return false;
+ pt = Peek();
+ }
+ return true;
+ }
+ bool SkipQuestionMark(ref Token pt)
+ {
+ if (pt.kind == Tokens.Question) {
+ pt = Peek();
+ }
+ return true;
+ }
+
+ /* True, if lookahead is a primitive type keyword, or */
+ /* if it is a type declaration followed by an ident */
+ bool IsLocalVarDecl () {
+ if (IsYieldStatement()) {
+ return false;
+ }
+ if ((Tokens.TypeKW[la.kind] && Peek(1).kind != Tokens.Dot) || la.kind == Tokens.Void) {
+ return true;
+ }
+
+ StartPeek();
+ Token pt = la;
+ return IsTypeNameOrKWForTypeCast(ref pt) && IsIdentifierToken(pt);
+ }
+
+ /* True if lookahead is a type argument list (<...>) followed by
+ * one of "( ) ] } : ; , . ? == !=" */
+ bool IsGenericInSimpleNameOrMemberAccess()
+ {
+ Token t = la;
+ if (t.kind != Tokens.LessThan) return false;
+ StartPeek();
+ return SkipGeneric(ref t) && Tokens.GenericFollower[t.kind];
+ }
+
+ bool IsExplicitInterfaceImplementation()
+ {
+ StartPeek();
+ Token pt = la;
+ pt = Peek();
+ if (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon)
+ return true;
+ if (pt.kind == Tokens.LessThan) {
+ if (SkipGeneric(ref pt))
+ return pt.kind == Tokens.Dot;
+ }
+ return false;
+ }
+
+ /* True, if lookahead ident is "yield" and than follows a break or return */
+ bool IsYieldStatement () {
+ return la.kind == Tokens.Yield && (Peek(1).kind == Tokens.Return || Peek(1).kind == Tokens.Break);
+ }
+
+ /* True, if lookahead is a local attribute target specifier, *
+ * i.e. one of "event", "return", "field", "method", *
+ * "module", "param", "property", or "type" */
+ bool IsLocalAttrTarget () {
+ int cur = la.kind;
+ string val = la.val;
+
+ return (cur == Tokens.Event || cur == Tokens.Return ||
+ (Tokens.IdentifierTokens[cur] &&
+ (val == "field" || val == "method" || val == "module" ||
+ val == "param" || val == "property" || val == "type"))) &&
+ Peek(1).kind == Tokens.Colon;
+ }
+
+ bool IsShiftRight()
+ {
+ Token next = Peek(1);
+ // TODO : Add col test (seems not to work, lexer bug...) : && la.col == next.col - 1
+ return (la.kind == Tokens.GreaterThan && next.kind == Tokens.GreaterThan);
+ }
+
+ bool IsGenericExpression(Expression expr)
+ {
+ if (expr is IdentifierExpression)
+ return ((IdentifierExpression)expr).TypeArguments.Count > 0;
+ else if (expr is MemberReferenceExpression)
+ return ((MemberReferenceExpression)expr).TypeArguments.Count > 0;
+ else
+ return false;
+ }
+
+ bool ShouldConvertTargetExpressionToTypeReference(Expression targetExpr)
+ {
+ if (targetExpr is IdentifierExpression)
+ return ((IdentifierExpression)targetExpr).TypeArguments.Count > 0;
+ else if (targetExpr is MemberReferenceExpression)
+ return ((MemberReferenceExpression)targetExpr).TypeArguments.Count > 0;
+ else
+ return false;
+ }
+
+ TypeReference GetTypeReferenceFromExpression(Expression expr)
+ {
+ if (expr is TypeReferenceExpression)
+ return (expr as TypeReferenceExpression).TypeReference;
+
+ IdentifierExpression ident = expr as IdentifierExpression;
+ if (ident != null) {
+ return new TypeReference(ident.Identifier, ident.TypeArguments);
+ }
+
+ MemberReferenceExpression member = expr as MemberReferenceExpression;
+ if (member != null) {
+ TypeReference targetType = GetTypeReferenceFromExpression(member.TargetObject);
+ if (targetType != null) {
+ if (targetType.GenericTypes.Count == 0 && targetType.IsArrayType == false) {
+ TypeReference tr = new TypeReference(targetType.Type + "." + member.MemberName, member.TypeArguments);
+ tr.IsGlobal = targetType.IsGlobal;
+ return tr;
+ } else {
+ return new InnerClassTypeReference(targetType, member.MemberName, member.TypeArguments);
+ }
+ }
+ }
+ return null;
+ }
+
+ bool IsMostNegativeIntegerWithoutTypeSuffix()
+ {
+ Token token = la;
+ if (token.kind == Tokens.Literal) {
+ return token.val == "2147483648" || token.val == "9223372036854775808";
+ } else {
+ return false;
+ }
+ }
+
+ bool LastExpressionIsUnaryMinus(System.Collections.ArrayList expressions)
+ {
+ if (expressions.Count == 0) return false;
+ UnaryOperatorExpression uoe = expressions[expressions.Count - 1] as UnaryOperatorExpression;
+ if (uoe != null) {
+ return uoe.Op == UnaryOperatorType.Minus;
+ } else {
+ return false;
+ }
+ }
+
+ bool StartOfQueryExpression()
+ {
+ if (la.kind == Tokens.From) {
+ Token p = Peek(1);
+ if (IsIdentifierToken(p) || Tokens.TypeKW[p.kind])
+ return true;
+ }
+ return false;
+ }
+
+ static bool IsIdentifierToken(Token tk)
+ {
+ return Tokens.IdentifierTokens[tk.kind];
+ }
+
+ /// <summary>
+ /// Adds a child item to a collection stored in the parent node.
+ /// Also set's the item's parent to <paramref name="parent"/>.
+ /// Does nothing if item is null.
+ /// </summary>
+ static void SafeAdd<T>(INode parent, List<T> list, T item) where T : class, INode
+ {
+ Debug.Assert(parent != null);
+ Debug.Assert((parent is INullable) ? !(parent as INullable).IsNull : true);
+ if (item != null) {
+ list.Add(item);
+ item.Parent = parent;
+ }
+ }
+ }
+}
diff --git a/main/contrib/NRefactory/Project/Src/Parser/CSharp/Parser.cs b/main/contrib/NRefactory/Project/Src/Parser/CSharp/Parser.cs
index 1e626b0097..f6459ff83d 100644
--- a/main/contrib/NRefactory/Project/Src/Parser/CSharp/Parser.cs
+++ b/main/contrib/NRefactory/Project/Src/Parser/CSharp/Parser.cs
@@ -8,31 +8,31 @@ 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
-{
+/*
+ Parser.frame file for NRefactory.
+ */
+using System;
+using System.Reflection;
+
+namespace ICSharpCode.NRefactory.Parser.CSharp {
+
+
+
+partial class Parser : AbstractParser
+{
const int maxT = 145;
-
- const bool T = true;
- const bool x = false;
-
+
+ const bool T = true;
+ const bool x = false;
+
#line 18 "cs.ATG"
-
-
-/*
-
-*/
-
+
+
+/*
+
+*/
+
void CS() {
#line 179 "cs.ATG"
@@ -955,39 +955,39 @@ templates);
}
void TypeParameterList(
-#line 2351 "cs.ATG"
+#line 2355 "cs.ATG"
List<TemplateDefinition> templates) {
-#line 2353 "cs.ATG"
+#line 2357 "cs.ATG"
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
Expect(23);
while (la.kind == 18) {
AttributeSection(
-#line 2357 "cs.ATG"
+#line 2361 "cs.ATG"
out section);
-#line 2357 "cs.ATG"
+#line 2361 "cs.ATG"
attributes.Add(section);
}
Identifier();
-#line 2358 "cs.ATG"
+#line 2362 "cs.ATG"
templates.Add(new TemplateDefinition(t.val, attributes));
while (la.kind == 14) {
lexer.NextToken();
while (la.kind == 18) {
AttributeSection(
-#line 2359 "cs.ATG"
+#line 2363 "cs.ATG"
out section);
-#line 2359 "cs.ATG"
+#line 2363 "cs.ATG"
attributes.Add(section);
}
Identifier();
-#line 2360 "cs.ATG"
+#line 2364 "cs.ATG"
templates.Add(new TemplateDefinition(t.val, attributes));
}
Expect(22);
@@ -1020,22 +1020,22 @@ out typeRef, false);
}
void TypeParameterConstraintsClause(
-#line 2364 "cs.ATG"
+#line 2368 "cs.ATG"
List<TemplateDefinition> templates) {
-#line 2365 "cs.ATG"
+#line 2369 "cs.ATG"
string name = ""; TypeReference type;
Expect(127);
Identifier();
-#line 2368 "cs.ATG"
+#line 2372 "cs.ATG"
name = t.val;
Expect(9);
TypeParameterConstraintsClauseBase(
-#line 2370 "cs.ATG"
+#line 2374 "cs.ATG"
out type);
-#line 2371 "cs.ATG"
+#line 2375 "cs.ATG"
TemplateDefinition td = null;
foreach (TemplateDefinition d in templates) {
if (d.Name == name) {
@@ -1048,10 +1048,10 @@ out type);
while (la.kind == 14) {
lexer.NextToken();
TypeParameterConstraintsClauseBase(
-#line 2380 "cs.ATG"
+#line 2384 "cs.ATG"
out type);
-#line 2381 "cs.ATG"
+#line 2385 "cs.ATG"
td = null;
foreach (TemplateDefinition d in templates) {
if (d.Name == name) {
@@ -1387,34 +1387,34 @@ out r, canBeUnbound);
}
void TypeName(
-#line 2292 "cs.ATG"
+#line 2296 "cs.ATG"
out TypeReference typeRef, bool canBeUnbound) {
-#line 2293 "cs.ATG"
+#line 2297 "cs.ATG"
List<TypeReference> typeArguments = null;
string alias = null;
string qualident;
Location startLocation = la.Location;
if (
-#line 2299 "cs.ATG"
+#line 2303 "cs.ATG"
IdentAndDoubleColon()) {
Identifier();
-#line 2300 "cs.ATG"
+#line 2304 "cs.ATG"
alias = t.val;
Expect(10);
}
Qualident(
-#line 2303 "cs.ATG"
+#line 2307 "cs.ATG"
out qualident);
if (la.kind == 23) {
TypeArgumentList(
-#line 2304 "cs.ATG"
+#line 2308 "cs.ATG"
out typeArguments, canBeUnbound);
}
-#line 2306 "cs.ATG"
+#line 2310 "cs.ATG"
if (alias == null) {
typeRef = new TypeReference(qualident, typeArguments);
} else if (alias == "global") {
@@ -1425,26 +1425,26 @@ out typeArguments, canBeUnbound);
}
while (
-#line 2315 "cs.ATG"
+#line 2319 "cs.ATG"
DotAndIdent()) {
Expect(15);
-#line 2316 "cs.ATG"
+#line 2320 "cs.ATG"
typeArguments = null;
Qualident(
-#line 2317 "cs.ATG"
+#line 2321 "cs.ATG"
out qualident);
if (la.kind == 23) {
TypeArgumentList(
-#line 2318 "cs.ATG"
+#line 2322 "cs.ATG"
out typeArguments, canBeUnbound);
}
-#line 2319 "cs.ATG"
+#line 2323 "cs.ATG"
typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments);
}
-#line 2321 "cs.ATG"
+#line 2325 "cs.ATG"
typeRef.StartLocation = startLocation;
}
@@ -2567,14 +2567,14 @@ out name);
}
void NullableQuestionMark(
-#line 2325 "cs.ATG"
+#line 2329 "cs.ATG"
ref TypeReference typeRef) {
-#line 2326 "cs.ATG"
+#line 2330 "cs.ATG"
List<TypeReference> typeArguments = new List<TypeReference>(1);
Expect(12);
-#line 2330 "cs.ATG"
+#line 2334 "cs.ATG"
if (typeRef != null) typeArguments.Add(typeRef);
typeRef = new TypeReference("System.Nullable", typeArguments) { IsKeyword = true };
@@ -4346,24 +4346,24 @@ out expr);
}
void ConditionalOrExpr(
-#line 2163 "cs.ATG"
+#line 2167 "cs.ATG"
ref Expression outExpr) {
-#line 2164 "cs.ATG"
+#line 2168 "cs.ATG"
Expression expr;
ConditionalAndExpr(
-#line 2166 "cs.ATG"
+#line 2170 "cs.ATG"
ref outExpr);
while (la.kind == 26) {
lexer.NextToken();
UnaryExpr(
-#line 2166 "cs.ATG"
+#line 2170 "cs.ATG"
out expr);
ConditionalAndExpr(
-#line 2166 "cs.ATG"
+#line 2170 "cs.ATG"
ref expr);
-#line 2166 "cs.ATG"
+#line 2170 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr);
}
}
@@ -4757,24 +4757,24 @@ out expr);
}
void QueryExpression(
-#line 2401 "cs.ATG"
+#line 2405 "cs.ATG"
out Expression outExpr) {
-#line 2402 "cs.ATG"
+#line 2406 "cs.ATG"
QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location;
QueryExpressionFromClause fromClause;
QueryExpressionFromClause(
-#line 2406 "cs.ATG"
+#line 2410 "cs.ATG"
out fromClause);
-#line 2406 "cs.ATG"
+#line 2410 "cs.ATG"
q.FromClause = fromClause;
QueryExpressionBody(
-#line 2407 "cs.ATG"
+#line 2411 "cs.ATG"
ref q);
-#line 2408 "cs.ATG"
+#line 2412 "cs.ATG"
q.EndLocation = t.EndLocation;
outExpr = q; /* set outExpr to q again if QueryExpressionBody changed it (can happen with 'into' clauses) */
@@ -4800,40 +4800,40 @@ lambda);
}
void TypeArgumentList(
-#line 2335 "cs.ATG"
+#line 2339 "cs.ATG"
out List<TypeReference> types, bool canBeUnbound) {
-#line 2337 "cs.ATG"
+#line 2341 "cs.ATG"
types = new List<TypeReference>();
TypeReference type = null;
Expect(23);
if (
-#line 2342 "cs.ATG"
+#line 2346 "cs.ATG"
canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma)) {
-#line 2343 "cs.ATG"
+#line 2347 "cs.ATG"
types.Add(TypeReference.Null);
while (la.kind == 14) {
lexer.NextToken();
-#line 2344 "cs.ATG"
+#line 2348 "cs.ATG"
types.Add(TypeReference.Null);
}
} else if (StartOf(10)) {
Type(
-#line 2345 "cs.ATG"
+#line 2349 "cs.ATG"
out type);
-#line 2345 "cs.ATG"
+#line 2349 "cs.ATG"
if (type != null) { types.Add(type); }
while (la.kind == 14) {
lexer.NextToken();
Type(
-#line 2346 "cs.ATG"
+#line 2350 "cs.ATG"
out type);
-#line 2346 "cs.ATG"
+#line 2350 "cs.ATG"
if (type != null) { types.Add(type); }
}
} else SynErr(211);
@@ -4851,7 +4851,7 @@ out Expression outExpr) {
outExpr = lambda;
Expect(20);
- if (StartOf(10)) {
+ if (StartOf(18)) {
LambdaExpressionParameter(
#line 2077 "cs.ATG"
out p);
@@ -5038,10 +5038,10 @@ out expr);
}
void AnonymousMethodExpr(
-#line 2130 "cs.ATG"
+#line 2134 "cs.ATG"
out Expression outExpr) {
-#line 2132 "cs.ATG"
+#line 2136 "cs.ATG"
AnonymousMethodExpression expr = new AnonymousMethodExpression();
expr.StartLocation = t.Location;
BlockStatement stmt;
@@ -5052,25 +5052,25 @@ out Expression outExpr) {
lexer.NextToken();
if (StartOf(11)) {
FormalParameterList(
-#line 2141 "cs.ATG"
+#line 2145 "cs.ATG"
p);
-#line 2141 "cs.ATG"
+#line 2145 "cs.ATG"
expr.Parameters = p;
}
Expect(21);
-#line 2143 "cs.ATG"
+#line 2147 "cs.ATG"
expr.HasParameterList = true;
}
BlockInsideExpression(
-#line 2145 "cs.ATG"
+#line 2149 "cs.ATG"
out stmt);
-#line 2145 "cs.ATG"
+#line 2149 "cs.ATG"
expr.Body = stmt;
-#line 2146 "cs.ATG"
+#line 2150 "cs.ATG"
expr.EndLocation = t.Location;
}
@@ -5136,287 +5136,301 @@ out ParameterDeclarationExpression p) {
#line 2102 "cs.ATG"
Location start = la.Location; p = null;
TypeReference type;
+ ParameterModifiers mod = ParameterModifiers.In;
if (
-#line 2106 "cs.ATG"
+#line 2107 "cs.ATG"
Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis) {
Identifier();
-#line 2108 "cs.ATG"
+#line 2109 "cs.ATG"
p = new ParameterDeclarationExpression(null, t.val);
p.StartLocation = start; p.EndLocation = t.EndLocation;
- } else if (StartOf(10)) {
+ } else if (StartOf(18)) {
+ if (la.kind == 93 || la.kind == 100) {
+ if (la.kind == 100) {
+ lexer.NextToken();
+
+#line 2112 "cs.ATG"
+ mod = ParameterModifiers.Ref;
+ } else {
+ lexer.NextToken();
+
+#line 2113 "cs.ATG"
+ mod = ParameterModifiers.Out;
+ }
+ }
Type(
-#line 2111 "cs.ATG"
+#line 2115 "cs.ATG"
out type);
Identifier();
-#line 2113 "cs.ATG"
- p = new ParameterDeclarationExpression(type, t.val);
+#line 2117 "cs.ATG"
+ p = new ParameterDeclarationExpression(type, t.val, mod);
p.StartLocation = start; p.EndLocation = t.EndLocation;
} else SynErr(214);
}
void LambdaExpressionBody(
-#line 2119 "cs.ATG"
+#line 2123 "cs.ATG"
LambdaExpression lambda) {
-#line 2120 "cs.ATG"
+#line 2124 "cs.ATG"
Expression expr; BlockStatement stmt;
if (la.kind == 16) {
BlockInsideExpression(
-#line 2123 "cs.ATG"
+#line 2127 "cs.ATG"
out stmt);
-#line 2123 "cs.ATG"
+#line 2127 "cs.ATG"
lambda.StatementBody = stmt;
} else if (StartOf(6)) {
Expr(
-#line 2124 "cs.ATG"
+#line 2128 "cs.ATG"
out expr);
-#line 2124 "cs.ATG"
+#line 2128 "cs.ATG"
lambda.ExpressionBody = expr;
} else SynErr(215);
-#line 2126 "cs.ATG"
+#line 2130 "cs.ATG"
lambda.EndLocation = t.EndLocation;
-#line 2127 "cs.ATG"
+#line 2131 "cs.ATG"
lambda.ExtendedEndLocation = la.Location;
}
void BlockInsideExpression(
-#line 2149 "cs.ATG"
+#line 2153 "cs.ATG"
out BlockStatement outStmt) {
-#line 2150 "cs.ATG"
+#line 2154 "cs.ATG"
Statement stmt = null; outStmt = null;
-#line 2154 "cs.ATG"
+#line 2158 "cs.ATG"
if (compilationUnit != null) {
Block(
-#line 2155 "cs.ATG"
+#line 2159 "cs.ATG"
out stmt);
-#line 2155 "cs.ATG"
+#line 2159 "cs.ATG"
outStmt = (BlockStatement)stmt;
-#line 2156 "cs.ATG"
+#line 2160 "cs.ATG"
} else {
Expect(16);
-#line 2158 "cs.ATG"
+#line 2162 "cs.ATG"
lexer.SkipCurrentBlock(0);
Expect(17);
-#line 2160 "cs.ATG"
+#line 2164 "cs.ATG"
}
}
void ConditionalAndExpr(
-#line 2169 "cs.ATG"
+#line 2173 "cs.ATG"
ref Expression outExpr) {
-#line 2170 "cs.ATG"
+#line 2174 "cs.ATG"
Expression expr;
InclusiveOrExpr(
-#line 2172 "cs.ATG"
+#line 2176 "cs.ATG"
ref outExpr);
while (la.kind == 25) {
lexer.NextToken();
UnaryExpr(
-#line 2172 "cs.ATG"
+#line 2176 "cs.ATG"
out expr);
InclusiveOrExpr(
-#line 2172 "cs.ATG"
+#line 2176 "cs.ATG"
ref expr);
-#line 2172 "cs.ATG"
+#line 2176 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr);
}
}
void InclusiveOrExpr(
-#line 2175 "cs.ATG"
+#line 2179 "cs.ATG"
ref Expression outExpr) {
-#line 2176 "cs.ATG"
+#line 2180 "cs.ATG"
Expression expr;
ExclusiveOrExpr(
-#line 2178 "cs.ATG"
+#line 2182 "cs.ATG"
ref outExpr);
while (la.kind == 29) {
lexer.NextToken();
UnaryExpr(
-#line 2178 "cs.ATG"
+#line 2182 "cs.ATG"
out expr);
ExclusiveOrExpr(
-#line 2178 "cs.ATG"
+#line 2182 "cs.ATG"
ref expr);
-#line 2178 "cs.ATG"
+#line 2182 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr);
}
}
void ExclusiveOrExpr(
-#line 2181 "cs.ATG"
+#line 2185 "cs.ATG"
ref Expression outExpr) {
-#line 2182 "cs.ATG"
+#line 2186 "cs.ATG"
Expression expr;
AndExpr(
-#line 2184 "cs.ATG"
+#line 2188 "cs.ATG"
ref outExpr);
while (la.kind == 30) {
lexer.NextToken();
UnaryExpr(
-#line 2184 "cs.ATG"
+#line 2188 "cs.ATG"
out expr);
AndExpr(
-#line 2184 "cs.ATG"
+#line 2188 "cs.ATG"
ref expr);
-#line 2184 "cs.ATG"
+#line 2188 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr);
}
}
void AndExpr(
-#line 2187 "cs.ATG"
+#line 2191 "cs.ATG"
ref Expression outExpr) {
-#line 2188 "cs.ATG"
+#line 2192 "cs.ATG"
Expression expr;
EqualityExpr(
-#line 2190 "cs.ATG"
+#line 2194 "cs.ATG"
ref outExpr);
while (la.kind == 28) {
lexer.NextToken();
UnaryExpr(
-#line 2190 "cs.ATG"
+#line 2194 "cs.ATG"
out expr);
EqualityExpr(
-#line 2190 "cs.ATG"
+#line 2194 "cs.ATG"
ref expr);
-#line 2190 "cs.ATG"
+#line 2194 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr);
}
}
void EqualityExpr(
-#line 2193 "cs.ATG"
+#line 2197 "cs.ATG"
ref Expression outExpr) {
-#line 2195 "cs.ATG"
+#line 2199 "cs.ATG"
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
RelationalExpr(
-#line 2199 "cs.ATG"
+#line 2203 "cs.ATG"
ref outExpr);
while (la.kind == 33 || la.kind == 34) {
if (la.kind == 34) {
lexer.NextToken();
-#line 2202 "cs.ATG"
+#line 2206 "cs.ATG"
op = BinaryOperatorType.InEquality;
} else {
lexer.NextToken();
-#line 2203 "cs.ATG"
+#line 2207 "cs.ATG"
op = BinaryOperatorType.Equality;
}
UnaryExpr(
-#line 2205 "cs.ATG"
+#line 2209 "cs.ATG"
out expr);
RelationalExpr(
-#line 2205 "cs.ATG"
+#line 2209 "cs.ATG"
ref expr);
-#line 2205 "cs.ATG"
+#line 2209 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, op, expr);
}
}
void RelationalExpr(
-#line 2209 "cs.ATG"
+#line 2213 "cs.ATG"
ref Expression outExpr) {
-#line 2211 "cs.ATG"
+#line 2215 "cs.ATG"
TypeReference type;
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
ShiftExpr(
-#line 2216 "cs.ATG"
+#line 2220 "cs.ATG"
ref outExpr);
while (StartOf(37)) {
if (StartOf(38)) {
if (la.kind == 23) {
lexer.NextToken();
-#line 2218 "cs.ATG"
+#line 2222 "cs.ATG"
op = BinaryOperatorType.LessThan;
} else if (la.kind == 22) {
lexer.NextToken();
-#line 2219 "cs.ATG"
+#line 2223 "cs.ATG"
op = BinaryOperatorType.GreaterThan;
} else if (la.kind == 36) {
lexer.NextToken();
-#line 2220 "cs.ATG"
+#line 2224 "cs.ATG"
op = BinaryOperatorType.LessThanOrEqual;
} else if (la.kind == 35) {
lexer.NextToken();
-#line 2221 "cs.ATG"
+#line 2225 "cs.ATG"
op = BinaryOperatorType.GreaterThanOrEqual;
} else SynErr(216);
UnaryExpr(
-#line 2223 "cs.ATG"
+#line 2227 "cs.ATG"
out expr);
ShiftExpr(
-#line 2224 "cs.ATG"
+#line 2228 "cs.ATG"
ref expr);
-#line 2225 "cs.ATG"
+#line 2229 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, op, expr);
} else {
if (la.kind == 85) {
lexer.NextToken();
TypeWithRestriction(
-#line 2228 "cs.ATG"
+#line 2232 "cs.ATG"
out type, false, false);
if (
-#line 2229 "cs.ATG"
+#line 2233 "cs.ATG"
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
NullableQuestionMark(
-#line 2230 "cs.ATG"
+#line 2234 "cs.ATG"
ref type);
}
-#line 2231 "cs.ATG"
+#line 2235 "cs.ATG"
outExpr = new TypeOfIsExpression(outExpr, type);
} else if (la.kind == 50) {
lexer.NextToken();
TypeWithRestriction(
-#line 2233 "cs.ATG"
+#line 2237 "cs.ATG"
out type, false, false);
if (
-#line 2234 "cs.ATG"
+#line 2238 "cs.ATG"
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
NullableQuestionMark(
-#line 2235 "cs.ATG"
+#line 2239 "cs.ATG"
ref type);
}
-#line 2236 "cs.ATG"
+#line 2240 "cs.ATG"
outExpr = new CastExpression(type, outExpr, CastType.TryCast);
} else SynErr(217);
}
@@ -5424,83 +5438,83 @@ ref type);
}
void ShiftExpr(
-#line 2241 "cs.ATG"
+#line 2245 "cs.ATG"
ref Expression outExpr) {
-#line 2243 "cs.ATG"
+#line 2247 "cs.ATG"
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
AdditiveExpr(
-#line 2247 "cs.ATG"
+#line 2251 "cs.ATG"
ref outExpr);
while (la.kind == 37 ||
-#line 2250 "cs.ATG"
+#line 2254 "cs.ATG"
IsShiftRight()) {
if (la.kind == 37) {
lexer.NextToken();
-#line 2249 "cs.ATG"
+#line 2253 "cs.ATG"
op = BinaryOperatorType.ShiftLeft;
} else {
Expect(22);
Expect(22);
-#line 2251 "cs.ATG"
+#line 2255 "cs.ATG"
op = BinaryOperatorType.ShiftRight;
}
UnaryExpr(
-#line 2254 "cs.ATG"
+#line 2258 "cs.ATG"
out expr);
AdditiveExpr(
-#line 2254 "cs.ATG"
+#line 2258 "cs.ATG"
ref expr);
-#line 2254 "cs.ATG"
+#line 2258 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, op, expr);
}
}
void AdditiveExpr(
-#line 2258 "cs.ATG"
+#line 2262 "cs.ATG"
ref Expression outExpr) {
-#line 2260 "cs.ATG"
+#line 2264 "cs.ATG"
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
MultiplicativeExpr(
-#line 2264 "cs.ATG"
+#line 2268 "cs.ATG"
ref outExpr);
while (la.kind == 4 || la.kind == 5) {
if (la.kind == 4) {
lexer.NextToken();
-#line 2267 "cs.ATG"
+#line 2271 "cs.ATG"
op = BinaryOperatorType.Add;
} else {
lexer.NextToken();
-#line 2268 "cs.ATG"
+#line 2272 "cs.ATG"
op = BinaryOperatorType.Subtract;
}
UnaryExpr(
-#line 2270 "cs.ATG"
+#line 2274 "cs.ATG"
out expr);
MultiplicativeExpr(
-#line 2270 "cs.ATG"
+#line 2274 "cs.ATG"
ref expr);
-#line 2270 "cs.ATG"
+#line 2274 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, op, expr);
}
}
void MultiplicativeExpr(
-#line 2274 "cs.ATG"
+#line 2278 "cs.ATG"
ref Expression outExpr) {
-#line 2276 "cs.ATG"
+#line 2280 "cs.ATG"
Expression expr;
BinaryOperatorType op = BinaryOperatorType.None;
@@ -5508,82 +5522,82 @@ ref Expression outExpr) {
if (la.kind == 6) {
lexer.NextToken();
-#line 2282 "cs.ATG"
+#line 2286 "cs.ATG"
op = BinaryOperatorType.Multiply;
} else if (la.kind == 7) {
lexer.NextToken();
-#line 2283 "cs.ATG"
+#line 2287 "cs.ATG"
op = BinaryOperatorType.Divide;
} else {
lexer.NextToken();
-#line 2284 "cs.ATG"
+#line 2288 "cs.ATG"
op = BinaryOperatorType.Modulus;
}
UnaryExpr(
-#line 2286 "cs.ATG"
+#line 2290 "cs.ATG"
out expr);
-#line 2286 "cs.ATG"
+#line 2290 "cs.ATG"
outExpr = new BinaryOperatorExpression(outExpr, op, expr);
}
}
void TypeParameterConstraintsClauseBase(
-#line 2392 "cs.ATG"
+#line 2396 "cs.ATG"
out TypeReference type) {
-#line 2393 "cs.ATG"
+#line 2397 "cs.ATG"
TypeReference t; type = null;
if (la.kind == 109) {
lexer.NextToken();
-#line 2395 "cs.ATG"
+#line 2399 "cs.ATG"
type = TypeReference.StructConstraint;
} else if (la.kind == 59) {
lexer.NextToken();
-#line 2396 "cs.ATG"
+#line 2400 "cs.ATG"
type = TypeReference.ClassConstraint;
} else if (la.kind == 89) {
lexer.NextToken();
Expect(20);
Expect(21);
-#line 2397 "cs.ATG"
+#line 2401 "cs.ATG"
type = TypeReference.NewConstraint;
} else if (StartOf(10)) {
Type(
-#line 2398 "cs.ATG"
+#line 2402 "cs.ATG"
out t);
-#line 2398 "cs.ATG"
+#line 2402 "cs.ATG"
type = t;
} else SynErr(218);
}
void QueryExpressionFromClause(
-#line 2413 "cs.ATG"
+#line 2417 "cs.ATG"
out QueryExpressionFromClause fc) {
-#line 2414 "cs.ATG"
+#line 2418 "cs.ATG"
fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location;
Expect(137);
QueryExpressionFromOrJoinClause(
-#line 2418 "cs.ATG"
+#line 2422 "cs.ATG"
fc);
-#line 2419 "cs.ATG"
+#line 2423 "cs.ATG"
fc.EndLocation = t.EndLocation;
}
void QueryExpressionBody(
-#line 2449 "cs.ATG"
+#line 2453 "cs.ATG"
ref QueryExpression q) {
-#line 2450 "cs.ATG"
+#line 2454 "cs.ATG"
QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause;
QueryExpressionLetClause letClause; QueryExpressionJoinClause joinClause;
QueryExpressionOrderClause orderClause;
@@ -5592,249 +5606,249 @@ ref QueryExpression q) {
while (StartOf(39)) {
if (la.kind == 137) {
QueryExpressionFromClause(
-#line 2456 "cs.ATG"
+#line 2460 "cs.ATG"
out fromClause);
-#line 2456 "cs.ATG"
+#line 2460 "cs.ATG"
SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, fromClause);
} else if (la.kind == 127) {
QueryExpressionWhereClause(
-#line 2457 "cs.ATG"
+#line 2461 "cs.ATG"
out whereClause);
-#line 2457 "cs.ATG"
+#line 2461 "cs.ATG"
SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, whereClause);
} else if (la.kind == 141) {
QueryExpressionLetClause(
-#line 2458 "cs.ATG"
+#line 2462 "cs.ATG"
out letClause);
-#line 2458 "cs.ATG"
+#line 2462 "cs.ATG"
SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, letClause);
} else if (la.kind == 142) {
QueryExpressionJoinClause(
-#line 2459 "cs.ATG"
+#line 2463 "cs.ATG"
out joinClause);
-#line 2459 "cs.ATG"
+#line 2463 "cs.ATG"
SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, joinClause);
} else {
QueryExpressionOrderByClause(
-#line 2460 "cs.ATG"
+#line 2464 "cs.ATG"
out orderClause);
-#line 2460 "cs.ATG"
+#line 2464 "cs.ATG"
SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, orderClause);
}
}
if (la.kind == 133) {
QueryExpressionSelectClause(
-#line 2462 "cs.ATG"
+#line 2466 "cs.ATG"
out selectClause);
-#line 2462 "cs.ATG"
+#line 2466 "cs.ATG"
q.SelectOrGroupClause = selectClause;
} else if (la.kind == 134) {
QueryExpressionGroupClause(
-#line 2463 "cs.ATG"
+#line 2467 "cs.ATG"
out groupClause);
-#line 2463 "cs.ATG"
+#line 2467 "cs.ATG"
q.SelectOrGroupClause = groupClause;
} else SynErr(219);
if (la.kind == 136) {
QueryExpressionIntoClause(
-#line 2465 "cs.ATG"
+#line 2469 "cs.ATG"
ref q);
}
}
void QueryExpressionFromOrJoinClause(
-#line 2439 "cs.ATG"
+#line 2443 "cs.ATG"
QueryExpressionFromOrJoinClause fjc) {
-#line 2440 "cs.ATG"
+#line 2444 "cs.ATG"
TypeReference type; Expression expr;
-#line 2442 "cs.ATG"
+#line 2446 "cs.ATG"
fjc.Type = null;
if (
-#line 2443 "cs.ATG"
+#line 2447 "cs.ATG"
IsLocalVarDecl()) {
Type(
-#line 2443 "cs.ATG"
+#line 2447 "cs.ATG"
out type);
-#line 2443 "cs.ATG"
+#line 2447 "cs.ATG"
fjc.Type = type;
}
Identifier();
-#line 2444 "cs.ATG"
+#line 2448 "cs.ATG"
fjc.Identifier = t.val;
Expect(81);
Expr(
-#line 2446 "cs.ATG"
+#line 2450 "cs.ATG"
out expr);
-#line 2446 "cs.ATG"
+#line 2450 "cs.ATG"
fjc.InExpression = expr;
}
void QueryExpressionJoinClause(
-#line 2422 "cs.ATG"
+#line 2426 "cs.ATG"
out QueryExpressionJoinClause jc) {
-#line 2423 "cs.ATG"
+#line 2427 "cs.ATG"
jc = new QueryExpressionJoinClause(); jc.StartLocation = la.Location;
Expression expr;
Expect(142);
QueryExpressionFromOrJoinClause(
-#line 2428 "cs.ATG"
+#line 2432 "cs.ATG"
jc);
Expect(143);
Expr(
-#line 2430 "cs.ATG"
+#line 2434 "cs.ATG"
out expr);
-#line 2430 "cs.ATG"
+#line 2434 "cs.ATG"
jc.OnExpression = expr;
Expect(144);
Expr(
-#line 2432 "cs.ATG"
+#line 2436 "cs.ATG"
out expr);
-#line 2432 "cs.ATG"
+#line 2436 "cs.ATG"
jc.EqualsExpression = expr;
if (la.kind == 136) {
lexer.NextToken();
Identifier();
-#line 2434 "cs.ATG"
+#line 2438 "cs.ATG"
jc.IntoIdentifier = t.val;
}
-#line 2436 "cs.ATG"
+#line 2440 "cs.ATG"
jc.EndLocation = t.EndLocation;
}
void QueryExpressionWhereClause(
-#line 2468 "cs.ATG"
+#line 2472 "cs.ATG"
out QueryExpressionWhereClause wc) {
-#line 2469 "cs.ATG"
+#line 2473 "cs.ATG"
Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location;
Expect(127);
Expr(
-#line 2472 "cs.ATG"
+#line 2476 "cs.ATG"
out expr);
-#line 2472 "cs.ATG"
+#line 2476 "cs.ATG"
wc.Condition = expr;
-#line 2473 "cs.ATG"
+#line 2477 "cs.ATG"
wc.EndLocation = t.EndLocation;
}
void QueryExpressionLetClause(
-#line 2476 "cs.ATG"
+#line 2480 "cs.ATG"
out QueryExpressionLetClause wc) {
-#line 2477 "cs.ATG"
+#line 2481 "cs.ATG"
Expression expr; wc = new QueryExpressionLetClause(); wc.StartLocation = la.Location;
Expect(141);
Identifier();
-#line 2480 "cs.ATG"
+#line 2484 "cs.ATG"
wc.Identifier = t.val;
Expect(3);
Expr(
-#line 2482 "cs.ATG"
+#line 2486 "cs.ATG"
out expr);
-#line 2482 "cs.ATG"
+#line 2486 "cs.ATG"
wc.Expression = expr;
-#line 2483 "cs.ATG"
+#line 2487 "cs.ATG"
wc.EndLocation = t.EndLocation;
}
void QueryExpressionOrderByClause(
-#line 2486 "cs.ATG"
+#line 2490 "cs.ATG"
out QueryExpressionOrderClause oc) {
-#line 2487 "cs.ATG"
+#line 2491 "cs.ATG"
QueryExpressionOrdering ordering; oc = new QueryExpressionOrderClause(); oc.StartLocation = la.Location;
Expect(140);
QueryExpressionOrdering(
-#line 2490 "cs.ATG"
+#line 2494 "cs.ATG"
out ordering);
-#line 2490 "cs.ATG"
+#line 2494 "cs.ATG"
SafeAdd(oc, oc.Orderings, ordering);
while (la.kind == 14) {
lexer.NextToken();
QueryExpressionOrdering(
-#line 2492 "cs.ATG"
+#line 2496 "cs.ATG"
out ordering);
-#line 2492 "cs.ATG"
+#line 2496 "cs.ATG"
SafeAdd(oc, oc.Orderings, ordering);
}
-#line 2494 "cs.ATG"
+#line 2498 "cs.ATG"
oc.EndLocation = t.EndLocation;
}
void QueryExpressionSelectClause(
-#line 2507 "cs.ATG"
+#line 2511 "cs.ATG"
out QueryExpressionSelectClause sc) {
-#line 2508 "cs.ATG"
+#line 2512 "cs.ATG"
Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location;
Expect(133);
Expr(
-#line 2511 "cs.ATG"
+#line 2515 "cs.ATG"
out expr);
-#line 2511 "cs.ATG"
+#line 2515 "cs.ATG"
sc.Projection = expr;
-#line 2512 "cs.ATG"
+#line 2516 "cs.ATG"
sc.EndLocation = t.EndLocation;
}
void QueryExpressionGroupClause(
-#line 2515 "cs.ATG"
+#line 2519 "cs.ATG"
out QueryExpressionGroupClause gc) {
-#line 2516 "cs.ATG"
+#line 2520 "cs.ATG"
Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location;
Expect(134);
Expr(
-#line 2519 "cs.ATG"
+#line 2523 "cs.ATG"
out expr);
-#line 2519 "cs.ATG"
+#line 2523 "cs.ATG"
gc.Projection = expr;
Expect(135);
Expr(
-#line 2521 "cs.ATG"
+#line 2525 "cs.ATG"
out expr);
-#line 2521 "cs.ATG"
+#line 2525 "cs.ATG"
gc.GroupBy = expr;
-#line 2522 "cs.ATG"
+#line 2526 "cs.ATG"
gc.EndLocation = t.EndLocation;
}
void QueryExpressionIntoClause(
-#line 2525 "cs.ATG"
+#line 2529 "cs.ATG"
ref QueryExpression q) {
-#line 2526 "cs.ATG"
+#line 2530 "cs.ATG"
QueryExpression firstQuery = q;
QueryExpression continuedQuery = new QueryExpression();
continuedQuery.StartLocation = q.StartLocation;
@@ -5849,58 +5863,58 @@ ref QueryExpression q) {
Expect(136);
Identifier();
-#line 2539 "cs.ATG"
+#line 2543 "cs.ATG"
continuedQuery.FromClause.Identifier = t.val;
-#line 2540 "cs.ATG"
+#line 2544 "cs.ATG"
continuedQuery.FromClause.EndLocation = t.EndLocation;
QueryExpressionBody(
-#line 2541 "cs.ATG"
+#line 2545 "cs.ATG"
ref q);
}
void QueryExpressionOrdering(
-#line 2497 "cs.ATG"
+#line 2501 "cs.ATG"
out QueryExpressionOrdering ordering) {
-#line 2498 "cs.ATG"
+#line 2502 "cs.ATG"
Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location;
Expr(
-#line 2500 "cs.ATG"
+#line 2504 "cs.ATG"
out expr);
-#line 2500 "cs.ATG"
+#line 2504 "cs.ATG"
ordering.Criteria = expr;
if (la.kind == 138 || la.kind == 139) {
if (la.kind == 138) {
lexer.NextToken();
-#line 2501 "cs.ATG"
+#line 2505 "cs.ATG"
ordering.Direction = QueryExpressionOrderingDirection.Ascending;
} else {
lexer.NextToken();
-#line 2502 "cs.ATG"
+#line 2506 "cs.ATG"
ordering.Direction = QueryExpressionOrderingDirection.Descending;
}
}
-#line 2504 "cs.ATG"
+#line 2508 "cs.ATG"
ordering.EndLocation = t.EndLocation;
}
-
-
- void ParseRoot()
- {
+
+
+ void ParseRoot()
+ {
CS();
-
- }
-
- protected override void SynErr(int line, int col, int errorNumber)
- {
- string s;
- switch (errorNumber) {
+
+ }
+
+ protected override void SynErr(int line, int col, int errorNumber)
+ {
+ string s;
+ switch (errorNumber) {
case 0: s = "EOF expected"; break;
case 1: s = "ident expected"; break;
case 2: s = "Literal expected"; break;
@@ -6121,18 +6135,18 @@ out expr);
case 217: s = "invalid RelationalExpr"; break;
case 218: s = "invalid TypeParameterConstraintsClauseBase"; break;
case 219: s = "invalid QueryExpressionBody"; break;
-
- default: s = "error " + errorNumber; break;
- }
- this.Errors.Error(line, col, s);
- }
-
- private bool StartOf(int s)
- {
- return set[s, lexer.LookAhead.kind];
- }
-
- static bool[,] set = {
+
+ default: s = "error " + errorNumber; break;
+ }
+ this.Errors.Error(line, col, s);
+ }
+
+ private bool StartOf(int s)
+ {
+ return set[s, lexer.LookAhead.kind];
+ }
+
+ static bool[,] set = {
{T,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,T,T,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,T,T,x, x,T,T,T, T,T,T,T, T,T,T,x, T,T,T,T, T,x,T,T, T,T,T,T, T,x,T,T, T,x,T,T, x,T,T,T, x,x,T,x, T,T,T,T, x,T,T,T, T,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, T,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
@@ -6173,8 +6187,8 @@ out expr);
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,T,x,x, T,T,T,x, x,x,x}
-
- };
-} // end Parser
-
+
+ };
+} // end Parser
+
} \ No newline at end of file
diff --git a/main/contrib/NRefactory/Project/Src/Parser/CSharp/cs.ATG b/main/contrib/NRefactory/Project/Src/Parser/CSharp/cs.ATG
index 0d349afa23..7385a427a9 100644
--- a/main/contrib/NRefactory/Project/Src/Parser/CSharp/cs.ATG
+++ b/main/contrib/NRefactory/Project/Src/Parser/CSharp/cs.ATG
@@ -1,2571 +1,2575 @@
-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;
-
-COMPILER CS /* AW 2002-12-30 renamed from CompilationUnit to CS */
-
-
-/*------------------------------------------------------------------------*
- *----- LEXER TOKEN LIST ------------------------------------------------*
- *------------------------------------------------------------------------*/
-
-/* START AUTOGENERATED TOKENS SECTION */
-TOKENS
- /* ----- terminal classes ----- */
- /* EOF is 0 */
- ident
- Literal
-
- /* ----- special character ----- */
- "="
- "+"
- "-"
- "*"
- "/"
- "%"
- ":"
- "::"
- ";"
- "?"
- "??"
- ","
- "."
- "{"
- "}"
- "["
- "]"
- "("
- ")"
- ">"
- "<"
- "!"
- "&&"
- "||"
- "~"
- "&"
- "|"
- "^"
- "++"
- "--"
- "=="
- "!="
- ">="
- "<="
- "<<"
- "+="
- "-="
- "*="
- "/="
- "%="
- "&="
- "|="
- "^="
- "<<="
- "->"
- "=>"
-
- /* ----- keywords ----- */
- "abstract"
- "as"
- "base"
- "bool"
- "break"
- "byte"
- "case"
- "catch"
- "char"
- "checked"
- "class"
- "const"
- "continue"
- "decimal"
- "default"
- "delegate"
- "do"
- "double"
- "else"
- "enum"
- "event"
- "explicit"
- "extern"
- "false"
- "finally"
- "fixed"
- "float"
- "for"
- "foreach"
- "goto"
- "if"
- "implicit"
- "in"
- "int"
- "interface"
- "internal"
- "is"
- "lock"
- "long"
- "namespace"
- "new"
- "null"
- "object"
- "operator"
- "out"
- "override"
- "params"
- "private"
- "protected"
- "public"
- "readonly"
- "ref"
- "return"
- "sbyte"
- "sealed"
- "short"
- "sizeof"
- "stackalloc"
- "static"
- "string"
- "struct"
- "switch"
- "this"
- "throw"
- "true"
- "try"
- "typeof"
- "uint"
- "ulong"
- "unchecked"
- "unsafe"
- "ushort"
- "using"
- "virtual"
- "void"
- "volatile"
- "while"
- "partial"
- "where"
- "get"
- "set"
- "add"
- "remove"
- "yield"
- "select"
- "group"
- "by"
- "into"
- "from"
- "ascending"
- "descending"
- "orderby"
- "let"
- "join"
- "on"
- "equals"
-/* END AUTOGENERATED TOKENS SECTION */
-
-/*------------------------------------------------------------------------*
- *----- PARSER -----------------------------------------------------------*
- *------------------------------------------------------------------------*/
-
-PRODUCTIONS
-
-/*--- compilation unit: */
-CS
-(. lexer.NextToken(); /* get the first token */ .)
-=
- { ExternAliasDirective }
- { UsingDirective }
- { IF (IsGlobalAttrTarget()) GlobalAttributeSection }
- { NamespaceMemberDecl }
- EOF
-.
-
-UsingDirective
-(.
- string qualident = null; TypeReference aliasedType = null;
-.)
-=
- "using" (. Location startPos = t.Location; .)
- Qualident<out qualident>
- [ "=" NonArrayType<out aliasedType> ]
- ";" (.
- 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);
- }
- .)
-.
-
-GlobalAttributeSection
-=
- "[" (. Location startPos = t.Location; .) Identifier
- (. if (t.val != "assembly" && t.val != "module") Error("global attribute target specifier (assembly or module) expected");
- string attributeTarget = t.val;
- List<ASTAttribute> attributes = new List<ASTAttribute>();
- ASTAttribute attribute;
- .)
- ":" Attribute<out attribute> (. attributes.Add(attribute); .)
- { IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .)}
- [ "," ]
- "]" (. AttributeSection section = new AttributeSection {
- AttributeTarget = attributeTarget,
- Attributes = attributes,
- StartLocation = startPos,
- EndLocation = t.EndLocation
- };
- compilationUnit.AddChild(section);
- .)
-.
-
-Attribute<out ASTAttribute attribute>
-(. string qualident;
- string alias = null;
-.)
-=
- (. Location startPos = la.Location; .)
- [ IF (IdentAndDoubleColon())
- Identifier (. alias = t.val; .)
- "::"
- ]
- Qualident<out qualident>
- (. List<Expression> positional = new List<Expression>();
- List<NamedArgumentExpression> named = new List<NamedArgumentExpression>();
- string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident;
- .)
- [ AttributeArguments<positional, named> ]
- (. attribute = new ASTAttribute(name, positional, named);
- attribute.StartLocation = startPos;
- attribute.EndLocation = t.EndLocation;
- .)
-.
-
-AttributeArguments<List<Expression> positional, List<NamedArgumentExpression> named>
-(.
- bool nameFound = false;
- string name = "";
- Expression expr;
-.)
-=
- "("
- [
- [
- IF (IsAssignment()) (. nameFound = true; .)
- Identifier (. name = t.val; .)
- "="
- ] Expr<out expr> (. if (expr != null) {if(name == "") positional.Add(expr);
- else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
- }
- .)
-
- {
- ","
- (
- IF (IsAssignment()) (. nameFound = true; .)
- Identifier (. name = t.val; .)
- "="
- | /*Empty*/ (. if (nameFound) Error("no positional argument after named argument"); .)
- ) Expr<out expr> (. if (expr != null) { if(name == "") positional.Add(expr);
- else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
- }
- .)
- }
- ]
- ")"
-.
-
-AttributeSection<out AttributeSection section>
-(.
- string attributeTarget = "";
- List<ASTAttribute> attributes = new List<ASTAttribute>();
- ASTAttribute attribute;
-
-.)
-=
- "[" (. Location startPos = t.Location; .) /*--- attribute target specifier: */
- [ IF (IsLocalAttrTarget())
- ( "event" (. attributeTarget = "event";.)
- | "return" (. attributeTarget = "return";.)
- | Identifier (. if (t.val != "field" && t.val != "method" &&
- t.val != "param" &&
- t.val != "property" && t.val != "type")
- Error("attribute target specifier (field, event, method, param, property, return or type) expected");
- attributeTarget = t.val;
- .)
- ) ":"
- ]
- /*--- attribute list: */
- Attribute<out attribute> (. attributes.Add(attribute); .)
- { IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .)}
- [ "," ]
- "]" (. section = new AttributeSection {
- AttributeTarget = attributeTarget,
- Attributes = attributes,
- StartLocation = startPos,
- EndLocation = t.EndLocation
- };
- .)
-.
-
-NamespaceMemberDecl
-(.
- AttributeSection section;
- List<AttributeSection> attributes = new List<AttributeSection>();
- ModifierList m = new ModifierList();
- string qualident;
-.)
-= /*--- namespace declaration: */
- "namespace" (. Location startPos = t.Location; .)
- Qualident<out qualident> (. INode node = new NamespaceDeclaration(qualident);
- node.StartLocation = startPos;
- compilationUnit.AddChild(node);
- compilationUnit.BlockStart(node);
- .)
- "{"
- { ExternAliasDirective }
- { UsingDirective }
- { NamespaceMemberDecl }
- "}"
- [ ";" ] (. node.EndLocation = t.EndLocation;
- compilationUnit.BlockEnd();
- .)
- /*--- type declaration: */
-| { AttributeSection<out section> (. attributes.Add(section); .) }
- { TypeModifier<m> }
- TypeDecl<m, attributes>
-.
-
-ExternAliasDirective
-(. ExternAliasDirective ead = new ExternAliasDirective { StartLocation = la.Location }; .)
-=
- "extern"
- Identifier (. if (t.val != "alias") Error("Expected 'extern alias'."); .)
- Identifier (. ead.Name = t.val; .)
- ";" (. ead.EndLocation = t.EndLocation; .)
- (. compilationUnit.AddChild(ead); .)
-.
-
-TypeDecl<ModifierList m, List<AttributeSection> attributes>
-(.
- TypeReference type;
- List<TypeReference> names;
- List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
- string name;
- List<TemplateDefinition> templates;
-.)
-= /*--- class declaration: */ (. m.Check(Modifiers.Classes); .)
- "class" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
- templates = newType.Templates;
- compilationUnit.AddChild(newType);
- compilationUnit.BlockStart(newType);
- newType.StartLocation = m.GetDeclarationLocation(t.Location);
-
- newType.Type = Types.Class;
- .)
- Identifier (. newType.Name = t.val; .)
-
- /* .NET 2.0 */
- [ TypeParameterList<templates> ]
-
- [ ClassBase<out names> (. newType.BaseTypes = names; .) ]
-
- /* .NET 2.0 */
- { TypeParameterConstraintsClause<templates> }
-
- (. newType.BodyStartLocation = t.EndLocation; .)
- "{"
- ClassBody
- "}"
- [ ";" ] (. newType.EndLocation = t.Location;
- compilationUnit.BlockEnd();
- .)
-| /*--- struct declaration: */ (. m.Check(Modifiers.StructsInterfacesEnumsDelegates); .)
- ( "struct" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
- templates = newType.Templates;
- newType.StartLocation = m.GetDeclarationLocation(t.Location);
- compilationUnit.AddChild(newType);
- compilationUnit.BlockStart(newType);
- newType.Type = Types.Struct;
- .)
- Identifier (. newType.Name = t.val; .)
-
- /* .NET 2.0 */
- [ TypeParameterList<templates> ]
-
- [ StructInterfaces<out names> (. newType.BaseTypes = names; .) ]
-
- /* .NET 2.0 */
- { TypeParameterConstraintsClause<templates> }
-
-
- (. newType.BodyStartLocation = t.EndLocation; .)
- StructBody
- [ ";" ] (. newType.EndLocation = t.Location;
- compilationUnit.BlockEnd();
- .)
-| /*--- interface declaration: */
- "interface" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
- templates = newType.Templates;
- compilationUnit.AddChild(newType);
- compilationUnit.BlockStart(newType);
- newType.StartLocation = m.GetDeclarationLocation(t.Location);
- newType.Type = Types.Interface;
- .)
- Identifier (. newType.Name = t.val; .)
-
- /* .NET 2.0 */
- [ TypeParameterList<templates> ]
-
- [ InterfaceBase<out names> (. newType.BaseTypes = names; .) ]
-
- /* .NET 2.0 */
- { TypeParameterConstraintsClause<templates> }
-
- (. newType.BodyStartLocation = t.EndLocation; .)
- InterfaceBody
- [ ";" ] (. newType.EndLocation = t.Location;
- compilationUnit.BlockEnd();
- .)
-| /*--- enumeration declaration: */
- "enum" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
- compilationUnit.AddChild(newType);
- compilationUnit.BlockStart(newType);
- newType.StartLocation = m.GetDeclarationLocation(t.Location);
- newType.Type = Types.Enum;
- .)
- Identifier (. newType.Name = t.val; .)
- [ ":" IntegralType<out name> (. newType.BaseTypes.Add(new TypeReference(name, true)); .)
- ]
- (. newType.BodyStartLocation = t.EndLocation; .)
- EnumBody
- [ ";" ] (. newType.EndLocation = t.Location;
- compilationUnit.BlockEnd();
- .)
-| /*--- delegate declaration: */
- "delegate" (. DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
- templates = delegateDeclr.Templates;
- delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
- .)
- ( IF (NotVoidPointer()) "void" (. delegateDeclr.ReturnType = new TypeReference("System.Void", true); .)
- | Type<out type> (. delegateDeclr.ReturnType = type; .)
- )
- Identifier (. delegateDeclr.Name = t.val; .)
-
- /* .NET 2.0 */
- [ TypeParameterList<templates> ]
-
- "(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .)
- ] ")"
-
- /* .NET 2.0 */
- { TypeParameterConstraintsClause<templates> }
-
- ";" (. delegateDeclr.EndLocation = t.Location;
- compilationUnit.AddChild(delegateDeclr);
- .)
- )
-.
-
-Qualident<out string qualident>
-=
- Identifier (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .)
- { IF (DotAndIdent()) "." Identifier (. qualidentBuilder.Append('.');
- qualidentBuilder.Append(t.val);
- .)
- } (. qualident = qualidentBuilder.ToString(); .)
-.
-
-ClassBase<out List<TypeReference> names>
-(.
- TypeReference typeRef;
- names = new List<TypeReference>();
-.)
-=
- ":" ClassType<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
- { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
-.
-
-ClassBody
-(. AttributeSection section; .)
-=
- { (.List<AttributeSection> attributes = new List<AttributeSection>();
- ModifierList m = new ModifierList();
- .)
- SYNC
- { AttributeSection<out section> (. attributes.Add(section); .) }
- MemberModifiers<m>
- ClassMemberDecl<m, attributes>
- }
-.
-
-StructInterfaces<out List<TypeReference> names>
-(.
- TypeReference typeRef;
- names = new List<TypeReference>();
-.)
-=
- ":" TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
- { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
-.
-
-StructBody
-(. AttributeSection section; .)
-=
- "{"
- { (.List<AttributeSection> attributes = new List<AttributeSection>();
- ModifierList m = new ModifierList();
- .)
- { AttributeSection<out section> (. attributes.Add(section); .) }
- MemberModifiers<m>
- StructMemberDecl<m, attributes>
- }
- "}"
-.
-
-InterfaceBase<out List<TypeReference> names>
-(.
- TypeReference typeRef;
- names = new List<TypeReference>();
-.)
-=
- ":" TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
- { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
-.
-
-InterfaceBody
-= "{"
- { SYNC InterfaceMemberDecl }
- "}"
-.
-
-EnumBody (. FieldDeclaration f; .)
-=
- "{"
- [ EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
- { IF (NotFinalComma()) ","
- EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
- }
- [","] ]
- "}"
-.
-
-Type<out TypeReference type>
-=
- TypeWithRestriction<out type, true, false>
-.
-
-TypeWithRestriction<out TypeReference type, bool allowNullable, bool canBeUnbound>
-(.
- Location startPos = la.Location;
- string name;
- int pointer = 0;
- type = null;
-.)
-=
- ( ClassType<out type, canBeUnbound>
- | SimpleType<out name> (. type = new TypeReference(name, true); .)
- | "void" "*" (. pointer = 1; type = new TypeReference("System.Void", true); .)
- ) (. List<int> r = new List<int>(); .)
-
- [ IF (allowNullable && la.kind == Tokens.Question) NullableQuestionMark<ref type> ]
-
- { IF (IsPointerOrDims()) (. int i = 0; .)
- ( "*" (. ++pointer; .)
- | "[" { "," (. ++i; .) } "]" (. r.Add(i); .)
- )
- }
- (. if (type != null) {
- type.RankSpecifier = r.ToArray();
- type.PointerNestingLevel = pointer;
- type.EndLocation = t.EndLocation;
- type.StartLocation = startPos;
- }
- .)
-.
-
-
-NonArrayType<out TypeReference type>
-(.
- Location startPos = la.Location;
- string name;
- int pointer = 0;
- type = null;
-.)
-=
- ( ClassType<out type, false>
- | SimpleType<out name> (. type = new TypeReference(name, true); .)
- | "void" "*" (. pointer = 1; type = new TypeReference("System.Void", true); .)
- )
-
- [ NullableQuestionMark<ref type> ]
-
- { IF (IsPointer())
- "*" (. ++pointer; .)
- }
- (.if (type != null) {
- type.PointerNestingLevel = pointer;
- type.EndLocation = t.EndLocation;
- type.StartLocation = startPos;
- }
- .)
-.
-
-SimpleType<out string name>
-(. name = String.Empty; .)
-=
- IntegralType<out name>
- | "float" (. name = "System.Single"; .)
- | "double" (. name = "System.Double"; .)
- | "decimal" (. name = "System.Decimal"; .)
- | "bool" (. name = "System.Boolean"; .)
-.
-
-
-FormalParameterList<List<ParameterDeclarationExpression> parameter>
-(.
-
- ParameterDeclarationExpression p;
- AttributeSection section;
- List<AttributeSection> attributes = new List<AttributeSection>();
-.)
-=
- { AttributeSection<out section> (.attributes.Add(section); .) }
- (
- FixedParameter<out p> (. bool paramsFound = false;
- p.Attributes = attributes;
- parameter.Add(p);
- .)
- {
- "," (. attributes = new List<AttributeSection>(); if (paramsFound) Error("params array must be at end of parameter list"); .)
- { AttributeSection<out section> (.attributes.Add(section); .) }
- (
- FixedParameter<out p> (. p.Attributes = attributes; parameter.Add(p); .)
- | ParameterArray<out p> (. paramsFound = true; p.Attributes = attributes; parameter.Add(p); .)
- )
- }
- | ParameterArray<out p> (. p.Attributes = attributes; parameter.Add(p); .)
- )
-.
-
-FixedParameter<out ParameterDeclarationExpression p>
-(.
- TypeReference type;
- ParameterModifiers mod = ParameterModifiers.In;
- Location start = la.Location;
-.)
-=
- [
- "ref" (. mod = ParameterModifiers.Ref; .)
- | "out" (. mod = ParameterModifiers.Out; .)
- ]
- Type<out type> Identifier (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .)
-.
-
-ParameterArray<out ParameterDeclarationExpression p>
-(. TypeReference type; .)
-=
- "params" Type<out type> Identifier (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .)
-.
-
-AccessorModifiers<out ModifierList m>
-(. m = new ModifierList(); .)
-=
- "private" (. m.Add(Modifiers.Private, t.Location); .)
- | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
- ["internal" (. m.Add(Modifiers.Internal, t.Location); .)]
- | "internal" (. m.Add(Modifiers.Internal, t.Location); .)
- ["protected" (. m.Add(Modifiers.Protected, t.Location); .)]
-.
-
-TypeModifier<ModifierList m>
-=
- "new" (. m.Add(Modifiers.New, t.Location); .)
- | "public" (. m.Add(Modifiers.Public, t.Location); .)
- | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
- | "internal" (. m.Add(Modifiers.Internal, t.Location); .)
- | "private" (. m.Add(Modifiers.Private, t.Location); .)
- | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .)
- | "abstract" (. m.Add(Modifiers.Abstract, t.Location); .)
- | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .)
- | "static" (. m.Add(Modifiers.Static, t.Location); .)
- | "partial" (. m.Add(Modifiers.Partial, t.Location); .)
-.
-
-ClassType<out TypeReference typeRef, bool canBeUnbound>
-(. TypeReference r; typeRef = null; .)
-=
- TypeName<out r, canBeUnbound> (. typeRef = r; .)
- | "object" (. typeRef = new TypeReference("System.Object", true); typeRef.StartLocation = t.Location; .)
- | "string" (. typeRef = new TypeReference("System.String", true); typeRef.StartLocation = t.Location; .)
-.
-
-IntegralType<out string name> (. name = ""; .)
-=
- "sbyte" (. name = "System.SByte"; .)
- | "byte" (. name = "System.Byte"; .)
- | "short" (. name = "System.Int16"; .)
- | "ushort" (. name = "System.UInt16"; .)
- | "int" (. name = "System.Int32"; .)
- | "uint" (. name = "System.UInt32"; .)
- | "long" (. name = "System.Int64"; .)
- | "ulong" (. name = "System.UInt64"; .)
- | "char" (. name = "System.Char"; .)
-.
-
-MemberModifiers<ModifierList m>
-=
- {
- "abstract" (. m.Add(Modifiers.Abstract, t.Location); .)
- | "extern" (. m.Add(Modifiers.Extern, t.Location); .)
- | "internal" (. m.Add(Modifiers.Internal, t.Location); .)
- | "new" (. m.Add(Modifiers.New, t.Location); .)
- | "override" (. m.Add(Modifiers.Override, t.Location); .)
- | "private" (. m.Add(Modifiers.Private, t.Location); .)
- | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
- | "public" (. m.Add(Modifiers.Public, t.Location); .)
- | "readonly" (. m.Add(Modifiers.ReadOnly, t.Location); .)
- | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .)
- | "static" (. m.Add(Modifiers.Static, t.Location); .)
- | "fixed" (. m.Add(Modifiers.Fixed, t.Location); .)
- | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .)
- | "virtual" (. m.Add(Modifiers.Virtual, t.Location); .)
- | "volatile" (. m.Add(Modifiers.Volatile, t.Location); .)
- | "partial" (. m.Add(Modifiers.Partial, t.Location); .)
- }
-.
-
-StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
-(.
- string qualident = null;
- TypeReference type;
- Expression expr;
- List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
- Statement stmt = null;
- List<TemplateDefinition> templates = new List<TemplateDefinition>();
- TypeReference explicitInterface = null;
- bool isExtensionMethod = false;
-.)
-=
- /*--- constant declaration: */ (. m.Check(Modifiers.Constants); .)
- "const" (.Location startPos = t.Location; .)
- Type<out type> Identifier (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const);
- fd.StartLocation = m.GetDeclarationLocation(startPos);
- VariableDeclaration f = new VariableDeclaration(t.val);
- f.StartLocation = t.Location;
- f.TypeReference = type;
- SafeAdd(fd, fd.Fields, f);
- .)
- "=" Expr<out expr> (. f.Initializer = expr; .)
- { "," Identifier (. f = new VariableDeclaration(t.val);
- f.StartLocation = t.Location;
- f.TypeReference = type;
- SafeAdd(fd, fd.Fields, f);
- .)
- "=" Expr<out expr> (. f.EndLocation = t.EndLocation; f.Initializer = expr; .)
- } ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .)
-
-
-| /*--- void method (procedure) declaration: */
- IF (NotVoidPointer()) (. m.Check(Modifiers.PropertysEventsMethods); .)
- "void" (. Location startPos = t.Location; .)
- ( IF (IsExplicitInterfaceImplementation())
- TypeName<out explicitInterface, false>
- (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
- qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
- } .)
- | Identifier (. qualident = t.val; .)
- )
- /* .NET 2.0 */
- [ TypeParameterList<templates> ]
-
- "("
- [ "this" (. isExtensionMethod = true; /* C# 3.0 */ .) ]
- [ FormalParameterList<p> ] ")"
- (. MethodDeclaration methodDeclaration = new MethodDeclaration {
- Name = qualident,
- Modifier = m.Modifier,
- TypeReference = new TypeReference("System.Void", true),
- Parameters = p,
- Attributes = attributes,
- StartLocation = m.GetDeclarationLocation(startPos),
- EndLocation = t.EndLocation,
- Templates = templates,
- IsExtensionMethod = isExtensionMethod
- };
- if (explicitInterface != null)
- SafeAdd(methodDeclaration, methodDeclaration.InterfaceImplementations, new InterfaceImplementation(explicitInterface, qualident));
- compilationUnit.AddChild(methodDeclaration);
- compilationUnit.BlockStart(methodDeclaration);
- .)
-
- /* .NET 2.0 */
- { TypeParameterConstraintsClause<templates> }
-
- ( Block<out stmt> | ";" ) (. compilationUnit.BlockEnd();
- methodDeclaration.Body = (BlockStatement)stmt;
- .)
-
-| /*--- event declaration: */ (. m.Check(Modifiers.PropertysEventsMethods); .)
- "event"
- (. EventDeclaration eventDecl = new EventDeclaration {
- Modifier = m.Modifier,
- Attributes = attributes,
- StartLocation = t.Location
- };
- compilationUnit.AddChild(eventDecl);
- compilationUnit.BlockStart(eventDecl);
- EventAddRegion addBlock = null;
- EventRemoveRegion removeBlock = null;
- .)
- Type<out type> (. eventDecl.TypeReference = type; .)
- ( IF (IsExplicitInterfaceImplementation())
- TypeName<out explicitInterface, false>
- (. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); .)
- (. eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); .)
-
- | Identifier (. qualident = t.val; .)
- )
- (. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .)
- [ "=" Expr<out expr> (. eventDecl.Initializer = expr; .) ]
- [ "{" (. eventDecl.BodyStart = t.Location; .)
- EventAccessorDecls<out addBlock, out removeBlock>
- "}" (. eventDecl.BodyEnd = t.EndLocation; .)
- ]
- [ ";" ]
- (. compilationUnit.BlockEnd();
- eventDecl.AddRegion = addBlock;
- eventDecl.RemoveRegion = removeBlock;
- .)
-
-| /*--- constructor or static contructor declaration: */
- IF (IdentAndLPar()) (. m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); .)
- Identifier (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .)
- FormalParameterList<p>
- ]
- ")" (.ConstructorInitializer init = null; .)
- [ (. m.Check(Modifiers.Constructors); .)
- ConstructorInitializer<out init>
- ] (.
- ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes);
- cd.StartLocation = startPos;
- cd.EndLocation = t.EndLocation;
- .)
-
- ( Block<out stmt> | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .)
-
-
-| /*--- conversion operator declaration: */ (. m.Check(Modifiers.Operators);
- if (m.isNone) Error("at least one modifier must be set");
- bool isImplicit = true;
- Location startPos = Location.Empty;
- .)
- ( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) )
- "operator" Type<out type> (. TypeReference operatorType = type; .)
- "(" Type<out type> Identifier (. string varName = t.val; .) ")"
- (. Location endPos = t.Location; .)
- ( Block<out stmt> | ";" (. stmt = null; .) )
- (.
-
- List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
- parameters.Add(new ParameterDeclarationExpression(type, varName));
- OperatorDeclaration operatorDeclaration = new OperatorDeclaration {
- Modifier = m.Modifier,
- Attributes = attributes,
- Parameters = parameters,
- TypeReference = operatorType,
- ConversionType = isImplicit ? ConversionType.Implicit : ConversionType.Explicit,
- Body = (BlockStatement)stmt,
- StartLocation = m.GetDeclarationLocation(startPos),
- EndLocation = endPos
- };
- compilationUnit.AddChild(operatorDeclaration);
- .)
-
-
-| /*--- inner type declaration: */
- TypeDecl<m, attributes>
-
-| Type<out type> (. Location startPos = t.Location; .)
- (
- /*--- operator declaration: */ (. OverloadableOperatorType op;
- m.Check(Modifiers.Operators);
- if (m.isNone) Error("at least one modifier must be set");
- .)
- "operator" OverloadableOperator<out op> (. TypeReference firstType, secondType = null; string secondName = null; .)
- "(" Type<out firstType> Identifier (. string firstName = t.val; .)
- ( "," Type<out secondType> Identifier (. secondName = t.val; .) /* (. if (Tokens.OverloadableUnaryOp[op.kind] && !Tokens.OverloadableBinaryOp[op.kind])
- Error("too many operands for unary operator");
- .)*/
- | /* empty */ /*(. if (Tokens.OverloadableBinaryOp[op.kind]){
- Error("too few operands for binary operator");
- }
- .)*/
- )
- (. Location endPos = t.Location; .)
- ")" ( Block<out stmt> | ";" )
- (.
- OperatorDeclaration operatorDeclaration = new OperatorDeclaration {
- Modifier = m.Modifier,
- Attributes = attributes,
- TypeReference = type,
- OverloadableOperator = op,
- Body = (BlockStatement)stmt,
- StartLocation = m.GetDeclarationLocation(startPos),
- EndLocation = endPos
- };
- SafeAdd(operatorDeclaration, operatorDeclaration.Parameters, new ParameterDeclarationExpression(firstType, firstName));
- if (secondType != null) {
- SafeAdd(operatorDeclaration, operatorDeclaration.Parameters, new ParameterDeclarationExpression(secondType, secondName));
- }
- compilationUnit.AddChild(operatorDeclaration);
- .)
-
- /*--- field declaration: */
- | IF (IsVarDecl())
- (. m.Check(Modifiers.Fields);
- FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
- fd.StartLocation = m.GetDeclarationLocation(startPos);
- .)
- ( IF (m.Contains(Modifiers.Fixed))
- VariableDeclarator<fd>
- "["
- Expr<out expr> (. if (fd.Fields.Count > 0)
- fd.Fields[fd.Fields.Count-1].FixedArrayInitialization = expr; .)
- "]"
- { ","
- VariableDeclarator<fd>
- "["
- Expr<out expr> (. if (fd.Fields.Count > 0)
- fd.Fields[fd.Fields.Count-1].FixedArrayInitialization = expr; .)
- "]"
- }
- | /* non-fixed field */
- VariableDeclarator<fd>
- { "," VariableDeclarator<fd> }
- )
- ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .)
-
- /*--- unqualified indexer declaration (without interface name): */
- | (. m.Check(Modifiers.Indexers); .)
- "this" "[" FormalParameterList<p> "]" (. Location endLocation = t.EndLocation; .) "{" (.
- IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
- indexer.StartLocation = startPos;
- indexer.EndLocation = endLocation;
- indexer.BodyStart = t.Location;
- PropertyGetRegion getRegion;
- PropertySetRegion setRegion;
- .)
- AccessorDecls<out getRegion, out setRegion> "}" (.
- indexer.BodyEnd = t.EndLocation;
- indexer.GetRegion = getRegion;
- indexer.SetRegion = setRegion;
- compilationUnit.AddChild(indexer);
- .)
- | IF (IsIdentifierToken(la))
- ( IF (IsExplicitInterfaceImplementation())
- TypeName<out explicitInterface, false>
- (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
- qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
- } .)
- | Identifier (. qualident = t.val; .)
- )
- (. Location qualIdentEndLocation = t.EndLocation; .)
-
- (
- /*--- "not void" method (function) declaration: */
- ( (. m.Check(Modifiers.PropertysEventsMethods); .)
- /* .NET 2.0 */
- [ TypeParameterList<templates> ]
- "("
- [ "this" (. isExtensionMethod = true; .) ]
- [ FormalParameterList<p> ] ")"
- (.
- MethodDeclaration methodDeclaration = new MethodDeclaration {
- Name = qualident,
- Modifier = m.Modifier,
- TypeReference = type,
- Parameters = p,
- Attributes = attributes
- };
- if (explicitInterface != null)
- methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
- methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
- methodDeclaration.EndLocation = t.EndLocation;
- methodDeclaration.IsExtensionMethod = isExtensionMethod;
- methodDeclaration.Templates = templates;
- compilationUnit.AddChild(methodDeclaration);
- .)
- { TypeParameterConstraintsClause<templates> }
- ( Block<out stmt> | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .)
-
- /*--- property declaration: */
- | "{" (. PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes);
- if (explicitInterface != null)
- pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
- pDecl.StartLocation = m.GetDeclarationLocation(startPos);
- pDecl.EndLocation = qualIdentEndLocation;
- pDecl.BodyStart = t.Location;
- PropertyGetRegion getRegion;
- PropertySetRegion setRegion;
- .)
- AccessorDecls<out getRegion, out setRegion>
- "}" (.
- pDecl.GetRegion = getRegion;
- pDecl.SetRegion = setRegion;
- pDecl.BodyEnd = t.EndLocation;
- compilationUnit.AddChild(pDecl);
- .)
- )
-
- /*--- qualified indexer declaration (with interface name): */
- | (. m.Check(Modifiers.Indexers); .)
- "." "this" "[" FormalParameterList<p> "]" (.
- IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
- indexer.StartLocation = m.GetDeclarationLocation(startPos);
- indexer.EndLocation = t.EndLocation;
- if (explicitInterface != null)
- SafeAdd(indexer, indexer.InterfaceImplementations, new InterfaceImplementation(explicitInterface, "this"));
- PropertyGetRegion getRegion;
- PropertySetRegion setRegion;
- .)
- "{" (. Location bodyStart = t.Location; .)
- AccessorDecls<out getRegion, out setRegion>
- "}" (. indexer.BodyStart = bodyStart;
- indexer.BodyEnd = t.EndLocation;
- indexer.GetRegion = getRegion;
- indexer.SetRegion = setRegion;
- compilationUnit.AddChild(indexer);
- .)
- )
- )
-.
-
-ClassMemberDecl<ModifierList m, List<AttributeSection> attributes>
-(. Statement stmt = null; .)
-=
- StructMemberDecl<m, attributes>
- | /*--- destructor declaration: */ (. m.Check(Modifiers.Destructors); Location startPos = la.Location; .)
- "~" Identifier (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes);
- d.Modifier = m.Modifier;
- d.StartLocation = m.GetDeclarationLocation(startPos);
- .)
- "(" ")" (. d.EndLocation = t.EndLocation; .) ( Block<out stmt> | ";" ) (.
- d.Body = (BlockStatement)stmt;
- compilationUnit.AddChild(d);
- .)
-.
-
-InterfaceMemberDecl
-(.
- TypeReference type;
-
- AttributeSection section;
- Modifiers mod = Modifiers.None;
- List<AttributeSection> attributes = new List<AttributeSection>();
- List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
- string name;
- PropertyGetRegion getBlock;
- PropertySetRegion setBlock;
- Location startLocation = new Location(-1, -1);
- List<TemplateDefinition> templates = new List<TemplateDefinition>();
-.)
-=
- { AttributeSection<out section> (. attributes.Add(section); .)}
- [ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ]
- (
- /*--- interface void method (procedure) declaration: */
- IF (NotVoidPointer()) "void" (. if (startLocation.IsEmpty) startLocation = t.Location; .)
- Identifier (. name = t.val; .)
- [ TypeParameterList<templates> ]
- "(" [ FormalParameterList<parameters> ] ")"
- { TypeParameterConstraintsClause<templates> }
- ";"
- (. MethodDeclaration md = new MethodDeclaration {
- Name = name, Modifier = mod, TypeReference = new TypeReference("System.Void", true),
- Parameters = parameters, Attributes = attributes, Templates = templates,
- StartLocation = startLocation, EndLocation = t.EndLocation
- };
- compilationUnit.AddChild(md);
- .)
- | (
- Type<out type> (. if (startLocation.IsEmpty) startLocation = t.Location; .)
- (
- Identifier (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .)
- (
- /*--- interface "not void" method (function) declaration: */
- /* .NET 2.0 */
- [ TypeParameterList<templates> ]
- "(" [ FormalParameterList<parameters> ] ")"
- /* .NET 2.0 */
- { TypeParameterConstraintsClause<templates> }
- ";" (. MethodDeclaration md = new MethodDeclaration {
- Name = name, Modifier = mod, TypeReference = type,
- Parameters = parameters, Attributes = attributes, Templates = templates,
- StartLocation = startLocation, EndLocation = t.EndLocation
- };
- compilationUnit.AddChild(md);
- .)
- /*--- interface property declaration: */
- |
- (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes);
- compilationUnit.AddChild(pd); .)
- "{"
- (. Location bodyStart = t.Location;.)
- InterfaceAccessors<out getBlock, out setBlock>
- "}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .)
- )
- /*--- interface indexer declaration: */
- | "this" "[" FormalParameterList<parameters> "]"
- (. Location bracketEndLocation = t.EndLocation; .)
- (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes);
- compilationUnit.AddChild(id); .)
- "{" (. Location bodyStart = t.Location;.)
- InterfaceAccessors<out getBlock, out setBlock>
- "}"
- (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.)
- )
- /*--- interface event declaration: */
- | "event" (. if (startLocation.IsEmpty) startLocation = t.Location; .)
- Type<out type> Identifier
- (. EventDeclaration ed = new EventDeclaration {
- TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes
- };
- compilationUnit.AddChild(ed);
- .)
- ";"
- (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .)
- )
- )
-.
-
-EnumMemberDecl<out FieldDeclaration f>
-(.
- Expression expr = null;
- List<AttributeSection> attributes = new List<AttributeSection>();
- AttributeSection section = null;
- VariableDeclaration varDecl = null;
-.)
-=
- { AttributeSection<out section> (. attributes.Add(section); .) }
- Identifier (. f = new FieldDeclaration(attributes);
- varDecl = new VariableDeclaration(t.val);
- f.Fields.Add(varDecl);
- f.StartLocation = t.Location;
- f.EndLocation = t.EndLocation;
- .)
- [ "=" Expr<out expr> (. varDecl.Initializer = expr; .) ]
-.
-
-
-AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
-(.
- List<AttributeSection> attributes = new List<AttributeSection>();
- AttributeSection section;
- getBlock = null;
- setBlock = null;
- ModifierList modifiers = null;
-.)
-=
- { AttributeSection<out section> (. attributes.Add(section); .) }
- [ AccessorModifiers<out modifiers> ]
- (
- GetAccessorDecl<out getBlock, attributes>
- (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .)
- [ (. attributes = new List<AttributeSection>(); modifiers = null; .)
- { AttributeSection<out section> (. attributes.Add(section); .) }
- [ AccessorModifiers<out modifiers> ]
- SetAccessorDecl<out setBlock, attributes>
- (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .)
- ]
- |
- SetAccessorDecl<out setBlock, attributes>
- (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .)
- [ (. attributes = new List<AttributeSection>(); modifiers = null; .)
- { AttributeSection<out section> (. attributes.Add(section); .) }
- [ AccessorModifiers<out modifiers> ]
- GetAccessorDecl<out getBlock, attributes>
- (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .)
- ]
- | Identifier (. Error("get or set accessor declaration expected"); .)
- )
-.
-
-GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
-(. Statement stmt = null; .)
-=
- "get"
- (. Location startLocation = t.Location; .)
- ( Block<out stmt> | ";" )
- (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
- (. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
-.
-
-SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attributes>
-(. Statement stmt = null; .)
-=
- "set"
- (. Location startLocation = t.Location; .)
- ( Block<out stmt> | ";" )
- (. setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); .)
- (. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .)
-.
-
-EventAccessorDecls<out EventAddRegion addBlock, out EventRemoveRegion removeBlock>
-(. AttributeSection section;
- List<AttributeSection> attributes = new List<AttributeSection>();
- Statement stmt;
- addBlock = null;
- removeBlock = null;
-.)
-=
- { AttributeSection<out section> (. attributes.Add(section); .) }
- (
- (. addBlock = new EventAddRegion(attributes); .)
- AddAccessorDecl<out stmt> (. attributes = new List<AttributeSection>(); addBlock.Block = (BlockStatement)stmt; .)
- { AttributeSection<out section> (. attributes.Add(section); .)}
- RemoveAccessorDecl<out stmt> (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; .)
- |
- RemoveAccessorDecl <out stmt> (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new List<AttributeSection>(); .)
- { AttributeSection<out section> (. attributes.Add(section); .) }
- AddAccessorDecl<out stmt> (. addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; .)
- )
-.
-
-InterfaceAccessors<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
-(.
- AttributeSection section;
- List<AttributeSection> attributes = new List<AttributeSection>();
- getBlock = null; setBlock = null;
- PropertyGetSetRegion lastBlock = null;
-.)
-=
- { AttributeSection<out section> (. attributes.Add(section); .) }
- (. Location startLocation = la.Location; .)
- (
- "get" (. getBlock = new PropertyGetRegion(null, attributes); .)
- | "set" (. setBlock = new PropertySetRegion(null, attributes); .)
- )
- ";"
- (. if (getBlock != null) { getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; }
- if (setBlock != null) { setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; }
- attributes = new List<AttributeSection>(); .)
- [
- { AttributeSection<out section> (. attributes.Add(section); .) }
- (. startLocation = la.Location; .)
- (
- "get" (. if (getBlock != null) Error("get already declared");
- else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; }
- .)
- | "set" (. if (setBlock != null) Error("set already declared");
- else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; }
- .)
- )
- ";"
- (. if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } .)
- ]
-.
-
-VariableDeclarator<FieldDeclaration parentFieldDeclaration>
-(. Expression expr = null; .)
-=
- Identifier (. VariableDeclaration f = new VariableDeclaration(t.val); f.StartLocation = t.Location; .)
- [ "=" VariableInitializer<out expr> (. f.Initializer = expr; .) ]
- (. f.EndLocation = t.EndLocation; SafeAdd(parentFieldDeclaration, parentFieldDeclaration.Fields, f); .)
-.
-
-Block<out Statement stmt> /* not BlockStatement because of EmbeddedStatement */
-=
- "{" (. BlockStatement blockStmt = new BlockStatement();
- blockStmt.StartLocation = t.Location;
- compilationUnit.BlockStart(blockStmt);
- if (!ParseMethodBodies) lexer.SkipCurrentBlock(0);
- .)
- { Statement }
- SYNC "}"
- (.
- stmt = blockStmt;
- blockStmt.EndLocation = t.EndLocation;
- compilationUnit.BlockEnd();
- .)
-.
-
-AddAccessorDecl<out Statement stmt>
-(.stmt = null;.)
-=
- "add"
- Block<out stmt>
-.
-
-RemoveAccessorDecl<out Statement stmt>
-(.stmt = null;.)
-=
- "remove"
- Block<out stmt>
-.
-
-ConstructorInitializer<out ConstructorInitializer ci>
-(. Expression expr; ci = new ConstructorInitializer(); .)
-=
- ":"
- (
- "base" (. ci.ConstructorInitializerType = ConstructorInitializerType.Base; .)
- | "this" (. ci.ConstructorInitializerType = ConstructorInitializerType.This; .)
- )
- "("
- [ Argument<out expr> (. SafeAdd(ci, ci.Arguments, expr); .)
- { "," Argument<out expr> (. SafeAdd(ci, ci.Arguments, expr); .) }
- ]
- ")"
-.
-
-VariableInitializer<out Expression initializerExpression>
-(. TypeReference type = null; Expression expr = null; initializerExpression = null; .)
-=
- Expr<out initializerExpression>
- | CollectionInitializer<out initializerExpression>
- | "stackalloc" Type<out type> "[" Expr<out expr> "]" (. initializerExpression = new StackAllocExpression(type, expr); .)
-.
-
-OverloadableOperator<out OverloadableOperatorType op>
-(. op = OverloadableOperatorType.None; .)
-=
- "+" (. op = OverloadableOperatorType.Add; .)
- | "-" (. op = OverloadableOperatorType.Subtract; .)
-
- | "!" (. op = OverloadableOperatorType.Not; .)
- | "~" (. op = OverloadableOperatorType.BitNot; .)
-
- | "++" (. op = OverloadableOperatorType.Increment; .)
- | "--" (. op = OverloadableOperatorType.Decrement; .)
-
- | "true" (. op = OverloadableOperatorType.IsTrue; .)
- | "false" (. op = OverloadableOperatorType.IsFalse; .)
-
- | "*" (. op = OverloadableOperatorType.Multiply; .)
- | "/" (. op = OverloadableOperatorType.Divide; .)
- | "%" (. op = OverloadableOperatorType.Modulus; .)
-
- | "&" (. op = OverloadableOperatorType.BitwiseAnd; .)
- | "|" (. op = OverloadableOperatorType.BitwiseOr; .)
- | "^" (. op = OverloadableOperatorType.ExclusiveOr; .)
-
- | "<<" (. op = OverloadableOperatorType.ShiftLeft; .)
- | "==" (. op = OverloadableOperatorType.Equality; .)
- | "!=" (. op = OverloadableOperatorType.InEquality; .)
- | "<" (. op = OverloadableOperatorType.LessThan; .)
- | ">=" (. op = OverloadableOperatorType.GreaterThanOrEqual; .)
- | "<=" (. op = OverloadableOperatorType.LessThanOrEqual; .)
- | ">" (. op = OverloadableOperatorType.GreaterThan; .) [ ">" (. op = OverloadableOperatorType.ShiftRight; .) ]
-.
-
-Argument<out Expression argumentexpr>
-(.
- Expression expr;
- FieldDirection fd = FieldDirection.None;
-.)
-=
- [
- "ref" (. fd = FieldDirection.Ref; .)
- | "out" (. fd = FieldDirection.Out; .)
- ]
- Expr<out expr>
- (. argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; .)
-.
-
-AssignmentOperator<out AssignmentOperatorType op>
-(. op = AssignmentOperatorType.None; .)
-=
- "=" (. op = AssignmentOperatorType.Assign; .)
- | "+=" (. op = AssignmentOperatorType.Add; .)
- | "-=" (. op = AssignmentOperatorType.Subtract; .)
- | "*=" (. op = AssignmentOperatorType.Multiply; .)
- | "/=" (. op = AssignmentOperatorType.Divide; .)
- | "%=" (. op = AssignmentOperatorType.Modulus; .)
- | "&=" (. op = AssignmentOperatorType.BitwiseAnd; .)
- | "|=" (. op = AssignmentOperatorType.BitwiseOr; .)
- | "^=" (. op = AssignmentOperatorType.ExclusiveOr; .)
- | "<<=" (. op = AssignmentOperatorType.ShiftLeft; .)
- | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual)
- ">" ">=" (. op = AssignmentOperatorType.ShiftRight; .)
-.
-
-CollectionInitializer<out Expression outExpr>
-(.
- Expression expr = null;
- CollectionInitializerExpression initializer = new CollectionInitializerExpression();
-.)
-=
- "{" (. initializer.StartLocation = t.Location; .)
- [ VariableInitializer<out expr>
- (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
- { IF (NotFinalComma())
- "," VariableInitializer<out expr>
- (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
- }
- [ "," ]
- ]
- "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .)
-.
-
-CollectionOrObjectInitializer<out Expression outExpr>
-(.
- Expression expr = null;
- CollectionInitializerExpression initializer = new CollectionInitializerExpression();
-.)
-=
- "{" (. initializer.StartLocation = t.Location; .)
- [ ObjectPropertyInitializerOrVariableInitializer<out expr>
- (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
- { IF (NotFinalComma())
- "," ObjectPropertyInitializerOrVariableInitializer<out expr>
- (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
- }
- [ "," ]
- ]
- "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .)
-.
-
-ObjectPropertyInitializerOrVariableInitializer<out Expression expr>
-(. expr = null; .)
-=
-( IF (IdentAndAsgn())
- Identifier
- (. NamedArgumentExpression nae = new NamedArgumentExpression(t.val, null);
- nae.StartLocation = t.Location;
- Expression r = null; .)
- "="
- ( CollectionOrObjectInitializer<out r>
- | VariableInitializer <out r> )
- (. nae.Expression = r; nae.EndLocation = t.EndLocation; expr = nae; .)
-
-| VariableInitializer <out expr>
-)
-.
-
-LocalVariableDecl<out Statement stmt>
-(.
- TypeReference type;
- VariableDeclaration var = null;
- LocalVariableDeclaration localVariableDeclaration;
- Location startPos = la.Location;
-.)
-=
- Type<out type> (. localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = startPos; .)
- LocalVariableDeclarator<out var> (. SafeAdd(localVariableDeclaration, localVariableDeclaration.Variables, var); .)
- { "," LocalVariableDeclarator<out var> (. SafeAdd(localVariableDeclaration, localVariableDeclaration.Variables, var); .) }
- (. stmt = localVariableDeclaration; stmt.EndLocation = t.EndLocation; .)
-.
-
-LocalVariableDeclarator<out VariableDeclaration var>
-(. Expression expr = null; .)
-=
- Identifier (. var = new VariableDeclaration(t.val); var.StartLocation = t.Location; .)
- [ "=" VariableInitializer<out expr> (. var.Initializer = expr; .) ]
- (. var.EndLocation = t.EndLocation; .)
-.
-
-Statement
-(.
- TypeReference type;
- Expression expr;
- Statement stmt = null;
- Location startPos = la.Location;
-.)
-=
- SYNC
- (
- /*--- labeled statement: */
- IF (IsLabel()) Identifier (. compilationUnit.AddChild(new LabelStatement(t.val)); .)
- ":" Statement
- /*--- local constant declaration: */
- | "const" Type<out type> (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; .)
- Identifier (. ident = t.val; Location varStart = t.Location; .)
- "=" Expr<out expr>
- (.
- SafeAdd(var, var.Variables, new VariableDeclaration(ident, expr) {
- StartLocation = varStart,
- EndLocation = t.EndLocation,
- TypeReference = type
- });
- .)
- { "," Identifier (. ident = t.val; .) "=" Expr<out expr>
- (.
- SafeAdd(var, var.Variables, new VariableDeclaration(ident, expr) {
- StartLocation = varStart,
- EndLocation = t.EndLocation,
- TypeReference = type
- });
- .) }
- ";" (. var.EndLocation = t.EndLocation; compilationUnit.AddChild(var); .)
-
- /*--- local variable declaration: */
- | IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> ";" (. compilationUnit.AddChild(stmt); .)
-
- | EmbeddedStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
- /* LL(1) confict: LocalVariableDecl *
- * <-> StatementExpr *
- * ident {"." ident} { "[" Expr ... */
- )
- (.
- if (stmt != null) {
- stmt.StartLocation = startPos;
- stmt.EndLocation = t.EndLocation;
- }
- .)
-.
-
-EmbeddedStatement<out Statement statement>
-(.
- TypeReference type = null;
- Expression expr = null;
- Statement embeddedStatement = null;
- statement = null;
-.)
-=
- (. Location startLocation = la.Location; .)
- (
- Block<out statement>
-
- /*--- empty statement: */
- | ";" (. statement = new EmptyStatement(); .)
-
- /*--- checked / unchecked statement: */
- | IF (UnCheckedAndLBrace()) (. Statement block; bool isChecked = true; .)
- ("checked" | "unchecked" (. isChecked = false;.) )
- Block<out block> (. statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); .)
-
- /*--- selection statements (if, switch): */
- | IfStatement<out statement>
-
- | "switch" (. List<SwitchSection> switchSections = new List<SwitchSection>(); .)
- "(" Expr<out expr> ")"
- "{" SwitchSections<switchSections>
- "}"
- (. statement = new SwitchStatement(expr, switchSections); .)
-
- /*--- iteration statements (while, do, for, foreach): */
- | "while" "(" Expr<out expr> ")"
- EmbeddedStatement<out embeddedStatement>
- (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);.)
-
- | "do" EmbeddedStatement<out embeddedStatement> "while"
- "(" Expr<out expr> ")" ";"
- (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); .)
-
- | "for" (. List<Statement> initializer = null; List<Statement> iterator = null; .)
- "(" [ ForInitializer<out initializer> ] ";"
- [ Expr<out expr> ] ";"
- [ ForIterator<out iterator> ] ")"
- EmbeddedStatement<out embeddedStatement>
- (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .)
-
- | "foreach" "(" Type<out type> Identifier (. string varName = t.val; .)
- "in" Expr<out expr> ")"
- EmbeddedStatement<out embeddedStatement>
- (. statement = new ForeachStatement(type, varName , expr, embeddedStatement); .)
-
- /*--- jump statements (break, contine, goto, return, throw): */
- | "break" ";" (. statement = new BreakStatement(); .)
- | "continue" ";" (. statement = new ContinueStatement(); .)
- | GotoStatement<out statement>
-
- | IF (IsYieldStatement()) "yield"
- ( "return" Expr<out expr> (. statement = new YieldStatement(new ReturnStatement(expr)); .)
- | "break" (. statement = new YieldStatement(new BreakStatement()); .) )
- ";"
-
- | "return" [ Expr<out expr> ] ";" (. statement = new ReturnStatement(expr); .)
- | "throw" [ Expr<out expr> ] ";" (. statement = new ThrowStatement(expr); .)
-
- /*--- expression statement: */
- | StatementExpr<out statement> SYNC ";"
-
- /*--- try statement: */
- | TryStatement<out statement>
-
- /*--- lock satement: */
- | "lock" "(" Expr<out expr> ")"
- EmbeddedStatement<out embeddedStatement> (. statement = new LockStatement(expr, embeddedStatement); .)
-
- /*--- using statement: */
- | (.Statement resourceAcquisitionStmt = null; .)
- "using" "("
- ResourceAcquisition<out resourceAcquisitionStmt> ")"
- EmbeddedStatement<out embeddedStatement> (. statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); .)
-
- /*--- unsafe statement: */
- | "unsafe" Block<out embeddedStatement> (. statement = new UnsafeStatement(embeddedStatement); .)
- /*--- fixed statement: */
- | (. Statement pointerDeclarationStmt = null; .)
- "fixed" "("
- ResourceAcquisition<out pointerDeclarationStmt> ")"
- EmbeddedStatement<out embeddedStatement> (. statement = new FixedStatement(pointerDeclarationStmt, embeddedStatement); .)
- )
- (. if (statement != null) {
- statement.StartLocation = startLocation;
- statement.EndLocation = t.EndLocation;
- }
- .)
-.
-
-IfStatement<out Statement statement>
-(.
- Expression expr = null;
- Statement embeddedStatement = null;
- statement = null;
-.)
-=
- "if"
- "(" Expr<out expr> ")"
- EmbeddedStatement<out embeddedStatement>
- (. Statement elseStatement = null; .)
- [ "else" EmbeddedStatement<out elseStatement> ]
- (. statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); .)
- (. if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) {
- /* else if-section (otherwise we would have a BlockStatment) */
- (statement as IfElseStatement).ElseIfSections.Add(
- new ElseIfSection((elseStatement as IfElseStatement).Condition,
- (elseStatement as IfElseStatement).TrueStatement[0]));
- (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections);
- (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement;
- }
- .)
-.
-
-ForInitializer<out List<Statement> initializer>
-(.
- Statement stmt;
- initializer = new List<Statement>();
-.)
-=
- IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> (. initializer.Add(stmt);.)
- | StatementExpr<out stmt> (.initializer.Add(stmt);.) { "," StatementExpr<out stmt> (. initializer.Add(stmt);.) }
-.
-
-ForIterator<out List<Statement> iterator>
-(.
- Statement stmt;
- iterator = new List<Statement>();
-.)
-=
- StatementExpr<out stmt> (. iterator.Add(stmt);.) { "," StatementExpr<out stmt> (. iterator.Add(stmt); .) }
-.
-
-SwitchSections<List<SwitchSection> switchSections>
-(.
- SwitchSection switchSection = new SwitchSection();
- CaseLabel label;
-.)
-=
- SwitchLabel<out label> (. SafeAdd(switchSection, switchSection.SwitchLabels, label); .)
- (. compilationUnit.BlockStart(switchSection); .)
- {
- ( SwitchLabel<out label>
- (. if (label != null) {
- if (switchSection.Children.Count > 0) {
- // open new section
- compilationUnit.BlockEnd(); switchSections.Add(switchSection);
- switchSection = new SwitchSection();
- compilationUnit.BlockStart(switchSection);
- }
- SafeAdd(switchSection, switchSection.SwitchLabels, label);
- }
- .)
- | Statement)
- }
- (. compilationUnit.BlockEnd(); switchSections.Add(switchSection); .)
-.
-
-SwitchLabel<out CaseLabel label>
- (. Expression expr = null; label = null; .)
-=
- "case" Expr<out expr> ":" (. label = new CaseLabel(expr); .)
- | "default" ":" (. label = new CaseLabel(); .)
-.
-
-TryStatement<out Statement tryStatement>
-(.
- Statement blockStmt = null, finallyStmt = null;
- List<CatchClause> catchClauses = null;
-.)
-=
- "try" Block<out blockStmt>
- (
- CatchClauses<out catchClauses> [ "finally" Block<out finallyStmt> ]
- | "finally" Block<out finallyStmt>
- )
- (.
- tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
- if (catchClauses != null) {
- foreach (CatchClause cc in catchClauses) cc.Parent = tryStatement;
- }
- .)
-.
-
-CatchClauses<out List<CatchClause> catchClauses>
-(.
- catchClauses = new List<CatchClause>();
-.)
-=
- "catch" (. string identifier;
- Statement stmt;
- TypeReference typeRef;
- .)
- /*--- general catch clause (as only catch clause) */
- (
- Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .)
- /*--- specific catch clause */
- | "(" ClassType<out typeRef, false> (. identifier = null; .)
- [ Identifier (. identifier = t.val; .) ]
- ")" Block<out stmt>
- (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .)
- { IF (IsTypedCatch()) "catch" "(" ClassType<out typeRef, false> (. identifier = null; .)
- [ Identifier (. identifier = t.val; .) ]
- ")" Block<out stmt>
- (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) }
- /*--- general catch clause (after specific catch clauses, optional) */
- [ "catch" Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) ]
- )
-.
-
-GotoStatement<out Statement stmt>
-(. Expression expr; stmt = null; .)
-=
- "goto"
- (
- Identifier (. stmt = new GotoStatement(t.val); .) ";"
- | "case" Expr<out expr> ";" (. stmt = new GotoCaseStatement(expr); .)
- | "default" ";" (. stmt = new GotoCaseStatement(null); .)
- )
-.
-
-ResourceAcquisition<out Statement stmt>
-(.
- stmt = null;
- Expression expr;
-.)
-=
- (
- IF (IsLocalVarDecl()) LocalVariableDecl<out stmt>
- | Expr<out expr> /* LL(1) conflict resoltion: *
- * check if next is Qualident followed by ident *
- * ==> LocalVariableDecl *
- * new problem: first set of ResourceAcquisition changes */
- (. stmt = new ExpressionStatement(expr); .)
- )
-.
-
-StatementExpr<out Statement stmt>
-(. Expression expr; .)
-=
- Expr<out expr>
- /* The grammar allows only assignments or method invocations here, */
- /* but we don't enforce that here */
- (. stmt = new ExpressionStatement(expr); .)
-.
-
-Expr<out Expression expr>
-(. expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; .)
-=
- (. Location startLocation = la.Location; .)
- UnaryExpr<out expr>
- /*--- conditional expression: */
- (
- ( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
- | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual)
- ( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
- | (
- ConditionalOrExpr<ref expr>
- [ "??" Expr<out expr1> (. expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); .) ]
- [ "?" Expr<out expr1> ":" Expr<out expr2> (. expr = new ConditionalExpression(expr, expr1, expr2); .) ]
- )
- )
- (. if (expr != null) {
- expr.StartLocation = startLocation;
- expr.EndLocation = t.EndLocation;
- }
- .)
-.
-
-
-UnaryExpr<out Expression uExpr>
-(.
- TypeReference type = null;
- Expression expr = null;
- ArrayList expressions = new ArrayList();
- uExpr = null;
-.)
-=
- {
- /* IF (Tokens.UnaryOp[la.kind] || IsTypeCast()) */
- (
- "+" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); .)
- | "-" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); .)
- | "!" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); .)
- | "~" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); .)
- | "*" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Dereference)); .)
- | "++" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); .)
- | "--" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); .)
- | "&" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.AddressOf)); .)
-
- /*--- cast expression: */
- /* Problem: "(" Type ")" from here and *
- * "(" Expr ")" from PrimaryExpr *
- * Solution: (in IsTypeCast()) */
- | IF (IsTypeCast()) "(" Type<out type> ")" (. expressions.Add(new CastExpression(type)); .)
- )
- }
-
- /* special rule (2.4.4.2) to allow writing int.MinValue and long.MinValue */
- ( IF (LastExpressionIsUnaryMinus(expressions) && IsMostNegativeIntegerWithoutTypeSuffix())
- Literal
- (.
- expressions.RemoveAt(expressions.Count - 1);
- if (t.literalValue is uint) {
- expr = new PrimitiveExpression(int.MinValue, int.MinValue.ToString());
- } else if (t.literalValue is ulong) {
- expr = new PrimitiveExpression(long.MinValue, long.MinValue.ToString());
- } else {
- throw new Exception("t.literalValue must be uint or ulong");
- }
- .)
- | PrimaryExpr<out expr>
- )
- (. for (int i = 0; i < expressions.Count; ++i) {
- Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr;
- if (expressions[i] is CastExpression) {
- ((CastExpression)expressions[i]).Expression = nextExpression;
- } else {
- ((UnaryOperatorExpression)expressions[i]).Expression = nextExpression;
- }
- }
- if (expressions.Count > 0) {
- uExpr = (Expression)expressions[0];
- } else {
- uExpr = expr;
- }
- .)
-.
-
-
-PrimaryExpr<out Expression pexpr>
-(.
- TypeReference type = null;
- Expression expr;
- pexpr = null;
-.)
-=
- (. Location startLocation = la.Location; .)
- (
- "true" (.pexpr = new PrimitiveExpression(true, "true"); .)
- | "false" (.pexpr = new PrimitiveExpression(false, "false"); .)
- | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */
- | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; .)
- | IF (StartOfQueryExpression())
- QueryExpression<out pexpr>
- | IF (IdentAndDoubleColon())
- Identifier (. type = new TypeReference(t.val); .)
- "::" (. pexpr = new TypeReferenceExpression(type); .)
- Identifier (. if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val ?? "?"; } else type.Type += "." + (t.val ?? "?"); .)
-
- /*--- simple name (IdentifierExpression): */
- | Identifier
- (. pexpr = new IdentifierExpression(t.val); .)
-
- [ ShortedLambdaExpression<(IdentifierExpression)pexpr, out pexpr>
- | IF (IsGenericInSimpleNameOrMemberAccess())
- (. List<TypeReference> typeList; .)
- TypeArgumentList<out typeList, false>
- (. ((IdentifierExpression)pexpr).TypeArguments = typeList; .)
- ]
- | IF (IsLambdaExpression()) /* Lambda expression */
- LambdaExpression<out pexpr>
-
- /*--- parenthesized expression: */
- | "(" Expr<out expr> ")" (. pexpr = new ParenthesizedExpression(expr); .)
-
- | /*--- predefined type member access: */
- (. string val = null; .)
- ( "bool" (. val = "System.Boolean"; .)
- | "byte" (. val = "System.Byte"; .)
- | "char" (. val = "System.Char"; .)
- | "decimal" (. val = "System.Decimal"; .)
- | "double" (. val = "System.Double"; .)
- | "float" (. val = "System.Single"; .)
- | "int" (. val = "System.Int32"; .)
- | "long" (. val = "System.Int64"; .)
- | "object" (. val = "System.Object"; .)
- | "sbyte" (. val = "System.SByte"; .)
- | "short" (. val = "System.Int16"; .)
- | "string" (. val = "System.String"; .)
- | "uint" (. val = "System.UInt32"; .)
- | "ulong" (. val = "System.UInt64"; .)
- | "ushort" (. val = "System.UInt16"; .)
- | "void" (. val = "System.Void"; .)
- )
- (. pexpr = new TypeReferenceExpression(new TypeReference(val, true)) { StartLocation = t.Location, EndLocation = t.EndLocation }; .)
-
- /*--- this access: */
- | "this" (. pexpr = new ThisReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .)
- /*--- base access: */
- | "base" (. pexpr = new BaseReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .)
-
- /* new ... - ObjectCreationExpression or ArrayCreateExpression */
- | NewExpression<out pexpr>
-
- | "typeof" "("
- (
- IF (NotVoidPointer()) "void" (. type = new TypeReference("System.Void", true); .)
- | TypeWithRestriction<out type, true, true>
- )
- ")" (. pexpr = new TypeOfExpression(type); .)
-
- | "default" "(" Type<out type> ")" (. pexpr = new DefaultValueExpression(type); .)
- | "sizeof" "(" Type<out type> ")" (. pexpr = new SizeOfExpression(type); .)
- | "checked" "(" Expr<out expr> ")" (. pexpr = new CheckedExpression(expr); .)
- | "unchecked" "(" Expr<out expr> ")" (. pexpr = new UncheckedExpression(expr); .)
- | "delegate" AnonymousMethodExpr<out expr> (. pexpr = expr; .)
- )
- (. if (pexpr != null) {
- if (pexpr.StartLocation.IsEmpty)
- pexpr.StartLocation = startLocation;
- if (pexpr.EndLocation.IsEmpty)
- pexpr.EndLocation = t.EndLocation;
- }
- .)
- {
- (. startLocation = la.Location; .)
- (
- "++" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); .)
- | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .)
- )
- /*--- member access */
- | PointerMemberAccess<out pexpr, pexpr>
- | MemberAccess<out pexpr, pexpr>
-
- /*--- invocation expression: */
- | "("
- (. List<Expression> parameters = new List<Expression>(); .)
- (. pexpr = new InvocationExpression(pexpr, parameters); .)
- [ Argument<out expr> (. SafeAdd(pexpr, parameters, expr); .)
- { "," Argument<out expr> (. SafeAdd(pexpr, parameters, expr); .)
- }
- ]
- ")"
- /*--- element access */
- | (. /*if (isArrayCreation) Error("element access not allow on array creation");*/
- List<Expression> indices = new List<Expression>();
- pexpr = new IndexerExpression(pexpr, indices);
- .)
- "[" Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
- { "," Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
- } "]"
-
- (. if (pexpr != null) {
- pexpr.StartLocation = startLocation;
- pexpr.EndLocation = t.EndLocation;
- }
- .)
- }
-.
-
-MemberAccess<out Expression expr, Expression target>
-(. List<TypeReference> typeList; .)
-=
- (. if (ShouldConvertTargetExpressionToTypeReference(target)) {
- TypeReference type = GetTypeReferenceFromExpression(target);
- if (type != null) {
- target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation };
- }
- }
- .)
- "."
- Identifier
- (. expr = new MemberReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; .)
- [ IF (IsGenericInSimpleNameOrMemberAccess())
- TypeArgumentList<out typeList, false>
- (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .)
- ]
-.
-
-PointerMemberAccess<out Expression expr, Expression target>
-(. List<TypeReference> typeList; .)
-=
- "->"
- Identifier
- (. expr = new PointerReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; .)
- [ IF (IsGenericInSimpleNameOrMemberAccess())
- TypeArgumentList<out typeList, false>
- (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .)
- ]
-.
-
-NewExpression<out Expression pexpr>
-(. pexpr = null;
- List<Expression> parameters = new List<Expression>();
- TypeReference type = null;
- Expression expr;
-.)
-=
- "new"
- [ NonArrayType<out type> ] /* optional since .NET 3.0 */
-
- /*--- delegate / object creation expression: */
- /* Note: a delegate creation expression allow only a single Expr */
- /* not an argument list, but this is not distinguished here */
- (
- ( (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .)
- "(" (. if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); .)
- [ Argument<out expr> (. SafeAdd(oce, parameters, expr); .)
- { "," Argument<out expr> (. SafeAdd(oce, parameters, expr); .) }
- ]
- ")" (. pexpr = oce; .)
- [ CollectionOrObjectInitializer<out expr> (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) ]
- | (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .)
- CollectionOrObjectInitializer<out expr> (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .)
- (. pexpr = oce; .)
- )
-
- /*--- array creation expression: */
- | "["
- (. ArrayCreateExpression ace = new ArrayCreateExpression(type);
- /* we must not change RankSpecifier on the null type reference*/
- if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); }
- pexpr = ace;
- int dims = 0; List<int> ranks = new List<int>();
- .)
- (
- { "," (. dims += 1; .) }
- "]" (. ranks.Add(dims); dims = 0; .)
- { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) }
- (. ace.CreateType.RankSpecifier = ranks.ToArray(); .)
- CollectionInitializer<out expr> (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .)
- | Expr<out expr> (. if (expr != null) parameters.Add(expr); .)
- { "," (. dims += 1; .)
- Expr<out expr> (. if (expr != null) parameters.Add(expr); .)
- }
- "]" (. ranks.Add(dims); ace.Arguments = parameters; dims = 0; .)
- { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) }
- (. ace.CreateType.RankSpecifier = ranks.ToArray(); .)
- [ CollectionInitializer<out expr> (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) ]
- )
- )
-.
-
-/* Lambda expression with parameter list */
-LambdaExpression<out Expression outExpr>
-(.
- LambdaExpression lambda = new LambdaExpression();
- lambda.StartLocation = la.Location;
- ParameterDeclarationExpression p;
- outExpr = lambda;
-.)
-=
- "("
- [
- LambdaExpressionParameter<out p> (. SafeAdd(lambda, lambda.Parameters, p); .)
- { ","
- LambdaExpressionParameter<out p> (. SafeAdd(lambda, lambda.Parameters, p); .)
- }
- ]
- ")"
- "=>"
- LambdaExpressionBody<lambda>
-.
-
-ShortedLambdaExpression<IdentifierExpression ident, out Expression pexpr>
-(. LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; .)
-=
- "=>"
- /* not an IdentifierExpression, but a short lambda expression*/
- (.
- lambda.StartLocation = ident.StartLocation;
- SafeAdd(lambda, lambda.Parameters, new ParameterDeclarationExpression(null, ident.Identifier));
- lambda.Parameters[0].StartLocation = ident.StartLocation;
- lambda.Parameters[0].EndLocation = ident.EndLocation;
- .)
- LambdaExpressionBody<lambda>
-.
-
-LambdaExpressionParameter<out ParameterDeclarationExpression p>
-(. Location start = la.Location; p = null;
- TypeReference type;
-.)
-=
- ( IF (Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis)
- Identifier
- (. p = new ParameterDeclarationExpression(null, t.val);
- p.StartLocation = start; p.EndLocation = t.EndLocation;
- .)
- | Type<out type>
- Identifier
- (. p = new ParameterDeclarationExpression(type, t.val);
- p.StartLocation = start; p.EndLocation = t.EndLocation;
- .)
- )
-.
-
-LambdaExpressionBody<LambdaExpression lambda>
-(. Expression expr; BlockStatement stmt; .)
-=
- (
- BlockInsideExpression<out stmt> (. lambda.StatementBody = stmt; .)
- | Expr<out expr> (. lambda.ExpressionBody = expr; .)
- )
- (. lambda.EndLocation = t.EndLocation; .)
- (. lambda.ExtendedEndLocation = la.Location; .)
-.
-
-AnonymousMethodExpr<out Expression outExpr>
-(.
- AnonymousMethodExpression expr = new AnonymousMethodExpression();
- expr.StartLocation = t.Location;
- BlockStatement stmt;
- List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
- outExpr = expr;
-.)
-=
- [
- "("
- [ FormalParameterList<p> (. expr.Parameters = p; .) ]
- ")"
- (. expr.HasParameterList = true; .)
- ]
- BlockInsideExpression<out stmt> (. expr.Body = stmt; .)
- (. expr.EndLocation = t.Location; .)
-.
-
-BlockInsideExpression<out BlockStatement outStmt>
-(. Statement stmt = null; outStmt = null; .)
-=
- /*--- ParseExpression doesn't set a compilation unit, */
- /*--- so we can't use block then -> skip body of anonymous method */
- (. if (compilationUnit != null) { .)
- Block<out stmt> (. outStmt = (BlockStatement)stmt; .)
- (. } else { .)
- "{"
- (. lexer.SkipCurrentBlock(0); .)
- "}"
- (. } .)
-.
-
-ConditionalOrExpr<ref Expression outExpr>
-(. Expression expr; .)
-=
- ConditionalAndExpr<ref outExpr> { "||" UnaryExpr<out expr> ConditionalAndExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); .) }
-.
-
-ConditionalAndExpr<ref Expression outExpr>
-(. Expression expr; .)
-=
- InclusiveOrExpr<ref outExpr> { "&&" UnaryExpr<out expr> InclusiveOrExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); .) }
-.
-
-InclusiveOrExpr<ref Expression outExpr>
-(. Expression expr; .)
-=
- ExclusiveOrExpr<ref outExpr> { "|" UnaryExpr<out expr> ExclusiveOrExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); .) }
-.
-
-ExclusiveOrExpr<ref Expression outExpr>
-(. Expression expr; .)
-=
- AndExpr<ref outExpr> { "^" UnaryExpr<out expr> AndExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); .) }
-.
-
-AndExpr<ref Expression outExpr>
-(. Expression expr; .)
-=
- EqualityExpr<ref outExpr> { "&" UnaryExpr<out expr> EqualityExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); .) }
-.
-
-EqualityExpr<ref Expression outExpr>
-(.
- Expression expr;
- BinaryOperatorType op = BinaryOperatorType.None;
-.)
-=
- RelationalExpr<ref outExpr>
- {
- (
- "!=" (. op = BinaryOperatorType.InEquality; .)
- | "==" (. op = BinaryOperatorType.Equality; .)
- )
- UnaryExpr<out expr> RelationalExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
- }
-.
-
-RelationalExpr<ref Expression outExpr>
-(.
- TypeReference type;
- Expression expr;
- BinaryOperatorType op = BinaryOperatorType.None;
-.)
-=
- ShiftExpr<ref outExpr>
- {
- ( "<" (. op = BinaryOperatorType.LessThan; .)
- | ">" (. op = BinaryOperatorType.GreaterThan; .)
- | "<=" (. op = BinaryOperatorType.LessThanOrEqual; .)
- | ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .)
- )
- UnaryExpr<out expr>
- ShiftExpr<ref expr>
- (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
- |
- ( "is"
- TypeWithRestriction<out type, false, false>
- [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind))
- NullableQuestionMark<ref type> ]
- (. outExpr = new TypeOfIsExpression(outExpr, type); .)
- | "as"
- TypeWithRestriction<out type, false, false>
- [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind))
- NullableQuestionMark<ref type> ]
- (. outExpr = new CastExpression(type, outExpr, CastType.TryCast); .)
- )
- }
-.
-
-ShiftExpr<ref Expression outExpr>
-(.
- Expression expr;
- BinaryOperatorType op = BinaryOperatorType.None;
-.)
-=
- AdditiveExpr<ref outExpr>
- {
- ( "<<" (. op = BinaryOperatorType.ShiftLeft; .)
- | IF (IsShiftRight()) (
- ">" ">" (. op = BinaryOperatorType.ShiftRight; .)
- )
- )
- UnaryExpr<out expr> AdditiveExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
- }
-.
-
-AdditiveExpr<ref Expression outExpr>
-(.
- Expression expr;
- BinaryOperatorType op = BinaryOperatorType.None;
-.)
-=
- MultiplicativeExpr<ref outExpr>
- {
- (
- "+" (. op = BinaryOperatorType.Add; .)
- | "-" (. op = BinaryOperatorType.Subtract; .)
- )
- UnaryExpr<out expr> MultiplicativeExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
- }
-.
-
-MultiplicativeExpr<ref Expression outExpr>
-(.
- Expression expr;
- BinaryOperatorType op = BinaryOperatorType.None;
-.)
-=
- {
- (
- "*" (. op = BinaryOperatorType.Multiply; .)
- | "/" (. op = BinaryOperatorType.Divide; .)
- | "%" (. op = BinaryOperatorType.Modulus; .)
- )
- UnaryExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
- }
-.
-
-/* .NET 2.0 rules */
-
-TypeName<out TypeReference typeRef, bool canBeUnbound>
-(. List<TypeReference> typeArguments = null;
- string alias = null;
- string qualident;
- Location startLocation = la.Location;
-.)
-=
- [ IF (IdentAndDoubleColon())
- Identifier (. alias = t.val; .)
- "::"
- ]
- Qualident<out qualident>
- [TypeArgumentList<out typeArguments, canBeUnbound>]
- (.
- if (alias == null) {
- typeRef = new TypeReference(qualident, typeArguments);
- } else if (alias == "global") {
- typeRef = new TypeReference(qualident, typeArguments);
- typeRef.IsGlobal = true;
- } else {
- typeRef = new TypeReference(alias + "." + qualident, typeArguments);
- }
- .)
- { IF (DotAndIdent())
- "." (. typeArguments = null; .)
- Qualident<out qualident>
- [TypeArgumentList<out typeArguments, canBeUnbound>]
- (. typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments); .)
- }
- (. typeRef.StartLocation = startLocation; .)
-.
-
-
-NullableQuestionMark<ref TypeReference typeRef>
-(. List<TypeReference> typeArguments = new List<TypeReference>(1); .)
-=
- "?"
- (.
- if (typeRef != null) typeArguments.Add(typeRef);
- typeRef = new TypeReference("System.Nullable", typeArguments) { IsKeyword = true };
- .)
-.
-
-TypeArgumentList<out List<TypeReference> types, bool canBeUnbound>
-(.
- types = new List<TypeReference>();
- TypeReference type = null;
-.)
-=
- "<"
- ( IF (canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma))
- (. types.Add(TypeReference.Null); .)
- { "," (. types.Add(TypeReference.Null); .) }
- | Type<out type> (. if (type != null) { types.Add(type); } .)
- { "," Type<out type> (. if (type != null) { types.Add(type); } .) }
- )
- ">"
-.
-
-TypeParameterList<List<TemplateDefinition> templates>
-(.
- AttributeSection section;
- List<AttributeSection> attributes = new List<AttributeSection>();
-.)
-=
- "<" { AttributeSection<out section> (. attributes.Add(section); .) }
- Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)
- { "," { AttributeSection<out section> (. attributes.Add(section); .) }
- Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)}
- ">"
-.
-
-TypeParameterConstraintsClause<List<TemplateDefinition> templates>
-(. string name = ""; TypeReference type; .)
-=
- "where"
- Identifier (. name = t.val; .)
- ":"
- TypeParameterConstraintsClauseBase<out type> (.
- TemplateDefinition td = null;
- foreach (TemplateDefinition d in templates) {
- if (d.Name == name) {
- td = d;
- break;
- }
- }
- if ( td != null && type != null) { td.Bases.Add(type); }
- .)
- { "," TypeParameterConstraintsClauseBase<out type> (.
- td = null;
- foreach (TemplateDefinition d in templates) {
- if (d.Name == name) {
- td = d;
- break;
- }
- }
- if ( td != null && type != null) { td.Bases.Add(type); }
- .) }
-.
-
-TypeParameterConstraintsClauseBase<out TypeReference type>
-(. TypeReference t; type = null; .)
-=
- "struct" (. type = TypeReference.StructConstraint; .)
- | "class" (. type = TypeReference.ClassConstraint; .)
- | "new" "(" ")" (. type = TypeReference.NewConstraint; .)
- | Type<out t> (. type = t; .)
-.
-
-QueryExpression<out Expression outExpr>
-(. QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location;
- QueryExpressionFromClause fromClause;
-.)
-=
- QueryExpressionFromClause<out fromClause> (. q.FromClause = fromClause; .)
- QueryExpressionBody<ref q>
- (. q.EndLocation = t.EndLocation;
- outExpr = q; /* set outExpr to q again if QueryExpressionBody changed it (can happen with 'into' clauses) */
- .)
-.
-
-QueryExpressionFromClause<out QueryExpressionFromClause fc>
-(. fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location;
-.)
-=
- "from"
- QueryExpressionFromOrJoinClause<fc>
- (. fc.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionJoinClause<out QueryExpressionJoinClause jc>
-(. jc = new QueryExpressionJoinClause(); jc.StartLocation = la.Location;
- Expression expr;
-.)
-=
- "join"
- QueryExpressionFromOrJoinClause<jc>
- "on"
- Expr<out expr> (. jc.OnExpression = expr; .)
- "equals"
- Expr<out expr> (. jc.EqualsExpression = expr; .)
- [ "into"
- Identifier (. jc.IntoIdentifier = t.val; .)
- ]
- (. jc.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionFromOrJoinClause<QueryExpressionFromOrJoinClause fjc>
-(. TypeReference type; Expression expr; .)
-=
- (. fjc.Type = null; .)
- [ IF (IsLocalVarDecl()) Type<out type> (. fjc.Type = type; .) ]
- Identifier (. fjc.Identifier = t.val; .)
- "in"
- Expr<out expr> (. fjc.InExpression = expr; .)
-.
-
-QueryExpressionBody<ref QueryExpression q>
-(. QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause;
- QueryExpressionLetClause letClause; QueryExpressionJoinClause joinClause;
- QueryExpressionOrderClause orderClause;
- QueryExpressionSelectClause selectClause; QueryExpressionGroupClause groupClause;
-.)
-=
- { ( QueryExpressionFromClause<out fromClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, fromClause); .)
- | QueryExpressionWhereClause<out whereClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, whereClause); .)
- | QueryExpressionLetClause<out letClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, letClause); .)
- | QueryExpressionJoinClause<out joinClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, joinClause); .)
- | QueryExpressionOrderByClause<out orderClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, orderClause); .)
- ) }
- ( QueryExpressionSelectClause<out selectClause> (. q.SelectOrGroupClause = selectClause; .)
- | QueryExpressionGroupClause<out groupClause> (. q.SelectOrGroupClause = groupClause; .)
- )
- [ QueryExpressionIntoClause<ref q> ]
-.
-
-QueryExpressionWhereClause<out QueryExpressionWhereClause wc>
-(. Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location; .)
-=
- "where"
- Expr<out expr> (. wc.Condition = expr; .)
- (. wc.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionLetClause<out QueryExpressionLetClause wc>
-(. Expression expr; wc = new QueryExpressionLetClause(); wc.StartLocation = la.Location; .)
-=
- "let"
- Identifier (. wc.Identifier = t.val; .)
- "="
- Expr<out expr> (. wc.Expression = expr; .)
- (. wc.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionOrderByClause<out QueryExpressionOrderClause oc>
-(. QueryExpressionOrdering ordering; oc = new QueryExpressionOrderClause(); oc.StartLocation = la.Location; .)
-=
- "orderby"
- QueryExpressionOrdering<out ordering> (. SafeAdd(oc, oc.Orderings, ordering); .)
- { ","
- QueryExpressionOrdering<out ordering> (. SafeAdd(oc, oc.Orderings, ordering); .)
- }
- (. oc.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionOrdering<out QueryExpressionOrdering ordering>
-(. Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location; .)
-=
- Expr<out expr> (. ordering.Criteria = expr; .)
- [ "ascending" (. ordering.Direction = QueryExpressionOrderingDirection.Ascending; .)
- | "descending" (. ordering.Direction = QueryExpressionOrderingDirection.Descending; .)
- ]
- (. ordering.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionSelectClause<out QueryExpressionSelectClause sc>
-(. Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location; .)
-=
- "select"
- Expr<out expr> (. sc.Projection = expr; .)
- (. sc.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionGroupClause<out QueryExpressionGroupClause gc>
-(. Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; .)
-=
- "group"
- Expr<out expr> (. gc.Projection = expr; .)
- "by"
- Expr<out expr> (. gc.GroupBy = expr; .)
- (. gc.EndLocation = t.EndLocation; .)
-.
-
-QueryExpressionIntoClause<ref QueryExpression q>
-(. QueryExpression firstQuery = q;
- QueryExpression continuedQuery = new QueryExpression();
- continuedQuery.StartLocation = q.StartLocation;
- firstQuery.EndLocation = la.Location;
- continuedQuery.FromClause = new QueryExpressionFromClause();
- continuedQuery.FromClause.StartLocation = la.Location;
- // nest firstQuery inside continuedQuery.
- continuedQuery.FromClause.InExpression = firstQuery;
- continuedQuery.IsQueryContinuation = true;
- q = continuedQuery;
-.)
-=
- "into"
- Identifier (. continuedQuery.FromClause.Identifier = t.val; .)
- (. continuedQuery.FromClause.EndLocation = t.EndLocation; .)
- QueryExpressionBody<ref q>
-.
-
-/* allow usage of context sensitive keywords as identifiers */
-Identifier
-=
-/* when updating this list, ensure you also change KeywordList.IdentifierTokens*/
- ident
-| "partial"
-| "where"
-| "get"
-| "set"
-| "add"
-| "remove"
-| "yield"
-| "select"
-| "group"
-| "by"
-| "into"
-| "from"
-| "ascending"
-| "descending"
-| "orderby"
-| "let"
-| "join"
-| "on"
-| "equals"
-.
-
-
-END CS.
+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;
+
+COMPILER CS /* AW 2002-12-30 renamed from CompilationUnit to CS */
+
+
+/*------------------------------------------------------------------------*
+ *----- LEXER TOKEN LIST ------------------------------------------------*
+ *------------------------------------------------------------------------*/
+
+/* START AUTOGENERATED TOKENS SECTION */
+TOKENS
+ /* ----- terminal classes ----- */
+ /* EOF is 0 */
+ ident
+ Literal
+
+ /* ----- special character ----- */
+ "="
+ "+"
+ "-"
+ "*"
+ "/"
+ "%"
+ ":"
+ "::"
+ ";"
+ "?"
+ "??"
+ ","
+ "."
+ "{"
+ "}"
+ "["
+ "]"
+ "("
+ ")"
+ ">"
+ "<"
+ "!"
+ "&&"
+ "||"
+ "~"
+ "&"
+ "|"
+ "^"
+ "++"
+ "--"
+ "=="
+ "!="
+ ">="
+ "<="
+ "<<"
+ "+="
+ "-="
+ "*="
+ "/="
+ "%="
+ "&="
+ "|="
+ "^="
+ "<<="
+ "->"
+ "=>"
+
+ /* ----- keywords ----- */
+ "abstract"
+ "as"
+ "base"
+ "bool"
+ "break"
+ "byte"
+ "case"
+ "catch"
+ "char"
+ "checked"
+ "class"
+ "const"
+ "continue"
+ "decimal"
+ "default"
+ "delegate"
+ "do"
+ "double"
+ "else"
+ "enum"
+ "event"
+ "explicit"
+ "extern"
+ "false"
+ "finally"
+ "fixed"
+ "float"
+ "for"
+ "foreach"
+ "goto"
+ "if"
+ "implicit"
+ "in"
+ "int"
+ "interface"
+ "internal"
+ "is"
+ "lock"
+ "long"
+ "namespace"
+ "new"
+ "null"
+ "object"
+ "operator"
+ "out"
+ "override"
+ "params"
+ "private"
+ "protected"
+ "public"
+ "readonly"
+ "ref"
+ "return"
+ "sbyte"
+ "sealed"
+ "short"
+ "sizeof"
+ "stackalloc"
+ "static"
+ "string"
+ "struct"
+ "switch"
+ "this"
+ "throw"
+ "true"
+ "try"
+ "typeof"
+ "uint"
+ "ulong"
+ "unchecked"
+ "unsafe"
+ "ushort"
+ "using"
+ "virtual"
+ "void"
+ "volatile"
+ "while"
+ "partial"
+ "where"
+ "get"
+ "set"
+ "add"
+ "remove"
+ "yield"
+ "select"
+ "group"
+ "by"
+ "into"
+ "from"
+ "ascending"
+ "descending"
+ "orderby"
+ "let"
+ "join"
+ "on"
+ "equals"
+/* END AUTOGENERATED TOKENS SECTION */
+
+/*------------------------------------------------------------------------*
+ *----- PARSER -----------------------------------------------------------*
+ *------------------------------------------------------------------------*/
+
+PRODUCTIONS
+
+/*--- compilation unit: */
+CS
+(. lexer.NextToken(); /* get the first token */ .)
+=
+ { ExternAliasDirective }
+ { UsingDirective }
+ { IF (IsGlobalAttrTarget()) GlobalAttributeSection }
+ { NamespaceMemberDecl }
+ EOF
+.
+
+UsingDirective
+(.
+ string qualident = null; TypeReference aliasedType = null;
+.)
+=
+ "using" (. Location startPos = t.Location; .)
+ Qualident<out qualident>
+ [ "=" NonArrayType<out aliasedType> ]
+ ";" (.
+ 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);
+ }
+ .)
+.
+
+GlobalAttributeSection
+=
+ "[" (. Location startPos = t.Location; .) Identifier
+ (. if (t.val != "assembly" && t.val != "module") Error("global attribute target specifier (assembly or module) expected");
+ string attributeTarget = t.val;
+ List<ASTAttribute> attributes = new List<ASTAttribute>();
+ ASTAttribute attribute;
+ .)
+ ":" Attribute<out attribute> (. attributes.Add(attribute); .)
+ { IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .)}
+ [ "," ]
+ "]" (. AttributeSection section = new AttributeSection {
+ AttributeTarget = attributeTarget,
+ Attributes = attributes,
+ StartLocation = startPos,
+ EndLocation = t.EndLocation
+ };
+ compilationUnit.AddChild(section);
+ .)
+.
+
+Attribute<out ASTAttribute attribute>
+(. string qualident;
+ string alias = null;
+.)
+=
+ (. Location startPos = la.Location; .)
+ [ IF (IdentAndDoubleColon())
+ Identifier (. alias = t.val; .)
+ "::"
+ ]
+ Qualident<out qualident>
+ (. List<Expression> positional = new List<Expression>();
+ List<NamedArgumentExpression> named = new List<NamedArgumentExpression>();
+ string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident;
+ .)
+ [ AttributeArguments<positional, named> ]
+ (. attribute = new ASTAttribute(name, positional, named);
+ attribute.StartLocation = startPos;
+ attribute.EndLocation = t.EndLocation;
+ .)
+.
+
+AttributeArguments<List<Expression> positional, List<NamedArgumentExpression> named>
+(.
+ bool nameFound = false;
+ string name = "";
+ Expression expr;
+.)
+=
+ "("
+ [
+ [
+ IF (IsAssignment()) (. nameFound = true; .)
+ Identifier (. name = t.val; .)
+ "="
+ ] Expr<out expr> (. if (expr != null) {if(name == "") positional.Add(expr);
+ else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
+ }
+ .)
+
+ {
+ ","
+ (
+ IF (IsAssignment()) (. nameFound = true; .)
+ Identifier (. name = t.val; .)
+ "="
+ | /*Empty*/ (. if (nameFound) Error("no positional argument after named argument"); .)
+ ) Expr<out expr> (. if (expr != null) { if(name == "") positional.Add(expr);
+ else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; }
+ }
+ .)
+ }
+ ]
+ ")"
+.
+
+AttributeSection<out AttributeSection section>
+(.
+ string attributeTarget = "";
+ List<ASTAttribute> attributes = new List<ASTAttribute>();
+ ASTAttribute attribute;
+
+.)
+=
+ "[" (. Location startPos = t.Location; .) /*--- attribute target specifier: */
+ [ IF (IsLocalAttrTarget())
+ ( "event" (. attributeTarget = "event";.)
+ | "return" (. attributeTarget = "return";.)
+ | Identifier (. if (t.val != "field" && t.val != "method" &&
+ t.val != "param" &&
+ t.val != "property" && t.val != "type")
+ Error("attribute target specifier (field, event, method, param, property, return or type) expected");
+ attributeTarget = t.val;
+ .)
+ ) ":"
+ ]
+ /*--- attribute list: */
+ Attribute<out attribute> (. attributes.Add(attribute); .)
+ { IF (NotFinalComma()) "," Attribute<out attribute> (. attributes.Add(attribute); .)}
+ [ "," ]
+ "]" (. section = new AttributeSection {
+ AttributeTarget = attributeTarget,
+ Attributes = attributes,
+ StartLocation = startPos,
+ EndLocation = t.EndLocation
+ };
+ .)
+.
+
+NamespaceMemberDecl
+(.
+ AttributeSection section;
+ List<AttributeSection> attributes = new List<AttributeSection>();
+ ModifierList m = new ModifierList();
+ string qualident;
+.)
+= /*--- namespace declaration: */
+ "namespace" (. Location startPos = t.Location; .)
+ Qualident<out qualident> (. INode node = new NamespaceDeclaration(qualident);
+ node.StartLocation = startPos;
+ compilationUnit.AddChild(node);
+ compilationUnit.BlockStart(node);
+ .)
+ "{"
+ { ExternAliasDirective }
+ { UsingDirective }
+ { NamespaceMemberDecl }
+ "}"
+ [ ";" ] (. node.EndLocation = t.EndLocation;
+ compilationUnit.BlockEnd();
+ .)
+ /*--- type declaration: */
+| { AttributeSection<out section> (. attributes.Add(section); .) }
+ { TypeModifier<m> }
+ TypeDecl<m, attributes>
+.
+
+ExternAliasDirective
+(. ExternAliasDirective ead = new ExternAliasDirective { StartLocation = la.Location }; .)
+=
+ "extern"
+ Identifier (. if (t.val != "alias") Error("Expected 'extern alias'."); .)
+ Identifier (. ead.Name = t.val; .)
+ ";" (. ead.EndLocation = t.EndLocation; .)
+ (. compilationUnit.AddChild(ead); .)
+.
+
+TypeDecl<ModifierList m, List<AttributeSection> attributes>
+(.
+ TypeReference type;
+ List<TypeReference> names;
+ List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
+ string name;
+ List<TemplateDefinition> templates;
+.)
+= /*--- class declaration: */ (. m.Check(Modifiers.Classes); .)
+ "class" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
+ templates = newType.Templates;
+ compilationUnit.AddChild(newType);
+ compilationUnit.BlockStart(newType);
+ newType.StartLocation = m.GetDeclarationLocation(t.Location);
+
+ newType.Type = Types.Class;
+ .)
+ Identifier (. newType.Name = t.val; .)
+
+ /* .NET 2.0 */
+ [ TypeParameterList<templates> ]
+
+ [ ClassBase<out names> (. newType.BaseTypes = names; .) ]
+
+ /* .NET 2.0 */
+ { TypeParameterConstraintsClause<templates> }
+
+ (. newType.BodyStartLocation = t.EndLocation; .)
+ "{"
+ ClassBody
+ "}"
+ [ ";" ] (. newType.EndLocation = t.Location;
+ compilationUnit.BlockEnd();
+ .)
+| /*--- struct declaration: */ (. m.Check(Modifiers.StructsInterfacesEnumsDelegates); .)
+ ( "struct" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
+ templates = newType.Templates;
+ newType.StartLocation = m.GetDeclarationLocation(t.Location);
+ compilationUnit.AddChild(newType);
+ compilationUnit.BlockStart(newType);
+ newType.Type = Types.Struct;
+ .)
+ Identifier (. newType.Name = t.val; .)
+
+ /* .NET 2.0 */
+ [ TypeParameterList<templates> ]
+
+ [ StructInterfaces<out names> (. newType.BaseTypes = names; .) ]
+
+ /* .NET 2.0 */
+ { TypeParameterConstraintsClause<templates> }
+
+
+ (. newType.BodyStartLocation = t.EndLocation; .)
+ StructBody
+ [ ";" ] (. newType.EndLocation = t.Location;
+ compilationUnit.BlockEnd();
+ .)
+| /*--- interface declaration: */
+ "interface" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
+ templates = newType.Templates;
+ compilationUnit.AddChild(newType);
+ compilationUnit.BlockStart(newType);
+ newType.StartLocation = m.GetDeclarationLocation(t.Location);
+ newType.Type = Types.Interface;
+ .)
+ Identifier (. newType.Name = t.val; .)
+
+ /* .NET 2.0 */
+ [ TypeParameterList<templates> ]
+
+ [ InterfaceBase<out names> (. newType.BaseTypes = names; .) ]
+
+ /* .NET 2.0 */
+ { TypeParameterConstraintsClause<templates> }
+
+ (. newType.BodyStartLocation = t.EndLocation; .)
+ InterfaceBody
+ [ ";" ] (. newType.EndLocation = t.Location;
+ compilationUnit.BlockEnd();
+ .)
+| /*--- enumeration declaration: */
+ "enum" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
+ compilationUnit.AddChild(newType);
+ compilationUnit.BlockStart(newType);
+ newType.StartLocation = m.GetDeclarationLocation(t.Location);
+ newType.Type = Types.Enum;
+ .)
+ Identifier (. newType.Name = t.val; .)
+ [ ":" IntegralType<out name> (. newType.BaseTypes.Add(new TypeReference(name, true)); .)
+ ]
+ (. newType.BodyStartLocation = t.EndLocation; .)
+ EnumBody
+ [ ";" ] (. newType.EndLocation = t.Location;
+ compilationUnit.BlockEnd();
+ .)
+| /*--- delegate declaration: */
+ "delegate" (. DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
+ templates = delegateDeclr.Templates;
+ delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
+ .)
+ ( IF (NotVoidPointer()) "void" (. delegateDeclr.ReturnType = new TypeReference("System.Void", true); .)
+ | Type<out type> (. delegateDeclr.ReturnType = type; .)
+ )
+ Identifier (. delegateDeclr.Name = t.val; .)
+
+ /* .NET 2.0 */
+ [ TypeParameterList<templates> ]
+
+ "(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .)
+ ] ")"
+
+ /* .NET 2.0 */
+ { TypeParameterConstraintsClause<templates> }
+
+ ";" (. delegateDeclr.EndLocation = t.Location;
+ compilationUnit.AddChild(delegateDeclr);
+ .)
+ )
+.
+
+Qualident<out string qualident>
+=
+ Identifier (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .)
+ { IF (DotAndIdent()) "." Identifier (. qualidentBuilder.Append('.');
+ qualidentBuilder.Append(t.val);
+ .)
+ } (. qualident = qualidentBuilder.ToString(); .)
+.
+
+ClassBase<out List<TypeReference> names>
+(.
+ TypeReference typeRef;
+ names = new List<TypeReference>();
+.)
+=
+ ":" ClassType<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
+ { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
+.
+
+ClassBody
+(. AttributeSection section; .)
+=
+ { (.List<AttributeSection> attributes = new List<AttributeSection>();
+ ModifierList m = new ModifierList();
+ .)
+ SYNC
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ MemberModifiers<m>
+ ClassMemberDecl<m, attributes>
+ }
+.
+
+StructInterfaces<out List<TypeReference> names>
+(.
+ TypeReference typeRef;
+ names = new List<TypeReference>();
+.)
+=
+ ":" TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
+ { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
+.
+
+StructBody
+(. AttributeSection section; .)
+=
+ "{"
+ { (.List<AttributeSection> attributes = new List<AttributeSection>();
+ ModifierList m = new ModifierList();
+ .)
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ MemberModifiers<m>
+ StructMemberDecl<m, attributes>
+ }
+ "}"
+.
+
+InterfaceBase<out List<TypeReference> names>
+(.
+ TypeReference typeRef;
+ names = new List<TypeReference>();
+.)
+=
+ ":" TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
+ { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
+.
+
+InterfaceBody
+= "{"
+ { SYNC InterfaceMemberDecl }
+ "}"
+.
+
+EnumBody (. FieldDeclaration f; .)
+=
+ "{"
+ [ EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
+ { IF (NotFinalComma()) ","
+ EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
+ }
+ [","] ]
+ "}"
+.
+
+Type<out TypeReference type>
+=
+ TypeWithRestriction<out type, true, false>
+.
+
+TypeWithRestriction<out TypeReference type, bool allowNullable, bool canBeUnbound>
+(.
+ Location startPos = la.Location;
+ string name;
+ int pointer = 0;
+ type = null;
+.)
+=
+ ( ClassType<out type, canBeUnbound>
+ | SimpleType<out name> (. type = new TypeReference(name, true); .)
+ | "void" "*" (. pointer = 1; type = new TypeReference("System.Void", true); .)
+ ) (. List<int> r = new List<int>(); .)
+
+ [ IF (allowNullable && la.kind == Tokens.Question) NullableQuestionMark<ref type> ]
+
+ { IF (IsPointerOrDims()) (. int i = 0; .)
+ ( "*" (. ++pointer; .)
+ | "[" { "," (. ++i; .) } "]" (. r.Add(i); .)
+ )
+ }
+ (. if (type != null) {
+ type.RankSpecifier = r.ToArray();
+ type.PointerNestingLevel = pointer;
+ type.EndLocation = t.EndLocation;
+ type.StartLocation = startPos;
+ }
+ .)
+.
+
+
+NonArrayType<out TypeReference type>
+(.
+ Location startPos = la.Location;
+ string name;
+ int pointer = 0;
+ type = null;
+.)
+=
+ ( ClassType<out type, false>
+ | SimpleType<out name> (. type = new TypeReference(name, true); .)
+ | "void" "*" (. pointer = 1; type = new TypeReference("System.Void", true); .)
+ )
+
+ [ NullableQuestionMark<ref type> ]
+
+ { IF (IsPointer())
+ "*" (. ++pointer; .)
+ }
+ (.if (type != null) {
+ type.PointerNestingLevel = pointer;
+ type.EndLocation = t.EndLocation;
+ type.StartLocation = startPos;
+ }
+ .)
+.
+
+SimpleType<out string name>
+(. name = String.Empty; .)
+=
+ IntegralType<out name>
+ | "float" (. name = "System.Single"; .)
+ | "double" (. name = "System.Double"; .)
+ | "decimal" (. name = "System.Decimal"; .)
+ | "bool" (. name = "System.Boolean"; .)
+.
+
+
+FormalParameterList<List<ParameterDeclarationExpression> parameter>
+(.
+
+ ParameterDeclarationExpression p;
+ AttributeSection section;
+ List<AttributeSection> attributes = new List<AttributeSection>();
+.)
+=
+ { AttributeSection<out section> (.attributes.Add(section); .) }
+ (
+ FixedParameter<out p> (. bool paramsFound = false;
+ p.Attributes = attributes;
+ parameter.Add(p);
+ .)
+ {
+ "," (. attributes = new List<AttributeSection>(); if (paramsFound) Error("params array must be at end of parameter list"); .)
+ { AttributeSection<out section> (.attributes.Add(section); .) }
+ (
+ FixedParameter<out p> (. p.Attributes = attributes; parameter.Add(p); .)
+ | ParameterArray<out p> (. paramsFound = true; p.Attributes = attributes; parameter.Add(p); .)
+ )
+ }
+ | ParameterArray<out p> (. p.Attributes = attributes; parameter.Add(p); .)
+ )
+.
+
+FixedParameter<out ParameterDeclarationExpression p>
+(.
+ TypeReference type;
+ ParameterModifiers mod = ParameterModifiers.In;
+ Location start = la.Location;
+.)
+=
+ [
+ "ref" (. mod = ParameterModifiers.Ref; .)
+ | "out" (. mod = ParameterModifiers.Out; .)
+ ]
+ Type<out type> Identifier (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .)
+.
+
+ParameterArray<out ParameterDeclarationExpression p>
+(. TypeReference type; .)
+=
+ "params" Type<out type> Identifier (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .)
+.
+
+AccessorModifiers<out ModifierList m>
+(. m = new ModifierList(); .)
+=
+ "private" (. m.Add(Modifiers.Private, t.Location); .)
+ | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
+ ["internal" (. m.Add(Modifiers.Internal, t.Location); .)]
+ | "internal" (. m.Add(Modifiers.Internal, t.Location); .)
+ ["protected" (. m.Add(Modifiers.Protected, t.Location); .)]
+.
+
+TypeModifier<ModifierList m>
+=
+ "new" (. m.Add(Modifiers.New, t.Location); .)
+ | "public" (. m.Add(Modifiers.Public, t.Location); .)
+ | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
+ | "internal" (. m.Add(Modifiers.Internal, t.Location); .)
+ | "private" (. m.Add(Modifiers.Private, t.Location); .)
+ | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .)
+ | "abstract" (. m.Add(Modifiers.Abstract, t.Location); .)
+ | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .)
+ | "static" (. m.Add(Modifiers.Static, t.Location); .)
+ | "partial" (. m.Add(Modifiers.Partial, t.Location); .)
+.
+
+ClassType<out TypeReference typeRef, bool canBeUnbound>
+(. TypeReference r; typeRef = null; .)
+=
+ TypeName<out r, canBeUnbound> (. typeRef = r; .)
+ | "object" (. typeRef = new TypeReference("System.Object", true); typeRef.StartLocation = t.Location; .)
+ | "string" (. typeRef = new TypeReference("System.String", true); typeRef.StartLocation = t.Location; .)
+.
+
+IntegralType<out string name> (. name = ""; .)
+=
+ "sbyte" (. name = "System.SByte"; .)
+ | "byte" (. name = "System.Byte"; .)
+ | "short" (. name = "System.Int16"; .)
+ | "ushort" (. name = "System.UInt16"; .)
+ | "int" (. name = "System.Int32"; .)
+ | "uint" (. name = "System.UInt32"; .)
+ | "long" (. name = "System.Int64"; .)
+ | "ulong" (. name = "System.UInt64"; .)
+ | "char" (. name = "System.Char"; .)
+.
+
+MemberModifiers<ModifierList m>
+=
+ {
+ "abstract" (. m.Add(Modifiers.Abstract, t.Location); .)
+ | "extern" (. m.Add(Modifiers.Extern, t.Location); .)
+ | "internal" (. m.Add(Modifiers.Internal, t.Location); .)
+ | "new" (. m.Add(Modifiers.New, t.Location); .)
+ | "override" (. m.Add(Modifiers.Override, t.Location); .)
+ | "private" (. m.Add(Modifiers.Private, t.Location); .)
+ | "protected" (. m.Add(Modifiers.Protected, t.Location); .)
+ | "public" (. m.Add(Modifiers.Public, t.Location); .)
+ | "readonly" (. m.Add(Modifiers.ReadOnly, t.Location); .)
+ | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .)
+ | "static" (. m.Add(Modifiers.Static, t.Location); .)
+ | "fixed" (. m.Add(Modifiers.Fixed, t.Location); .)
+ | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .)
+ | "virtual" (. m.Add(Modifiers.Virtual, t.Location); .)
+ | "volatile" (. m.Add(Modifiers.Volatile, t.Location); .)
+ | "partial" (. m.Add(Modifiers.Partial, t.Location); .)
+ }
+.
+
+StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
+(.
+ string qualident = null;
+ TypeReference type;
+ Expression expr;
+ List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
+ Statement stmt = null;
+ List<TemplateDefinition> templates = new List<TemplateDefinition>();
+ TypeReference explicitInterface = null;
+ bool isExtensionMethod = false;
+.)
+=
+ /*--- constant declaration: */ (. m.Check(Modifiers.Constants); .)
+ "const" (.Location startPos = t.Location; .)
+ Type<out type> Identifier (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const);
+ fd.StartLocation = m.GetDeclarationLocation(startPos);
+ VariableDeclaration f = new VariableDeclaration(t.val);
+ f.StartLocation = t.Location;
+ f.TypeReference = type;
+ SafeAdd(fd, fd.Fields, f);
+ .)
+ "=" Expr<out expr> (. f.Initializer = expr; .)
+ { "," Identifier (. f = new VariableDeclaration(t.val);
+ f.StartLocation = t.Location;
+ f.TypeReference = type;
+ SafeAdd(fd, fd.Fields, f);
+ .)
+ "=" Expr<out expr> (. f.EndLocation = t.EndLocation; f.Initializer = expr; .)
+ } ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .)
+
+
+| /*--- void method (procedure) declaration: */
+ IF (NotVoidPointer()) (. m.Check(Modifiers.PropertysEventsMethods); .)
+ "void" (. Location startPos = t.Location; .)
+ ( IF (IsExplicitInterfaceImplementation())
+ TypeName<out explicitInterface, false>
+ (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
+ qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
+ } .)
+ | Identifier (. qualident = t.val; .)
+ )
+ /* .NET 2.0 */
+ [ TypeParameterList<templates> ]
+
+ "("
+ [ "this" (. isExtensionMethod = true; /* C# 3.0 */ .) ]
+ [ FormalParameterList<p> ] ")"
+ (. MethodDeclaration methodDeclaration = new MethodDeclaration {
+ Name = qualident,
+ Modifier = m.Modifier,
+ TypeReference = new TypeReference("System.Void", true),
+ Parameters = p,
+ Attributes = attributes,
+ StartLocation = m.GetDeclarationLocation(startPos),
+ EndLocation = t.EndLocation,
+ Templates = templates,
+ IsExtensionMethod = isExtensionMethod
+ };
+ if (explicitInterface != null)
+ SafeAdd(methodDeclaration, methodDeclaration.InterfaceImplementations, new InterfaceImplementation(explicitInterface, qualident));
+ compilationUnit.AddChild(methodDeclaration);
+ compilationUnit.BlockStart(methodDeclaration);
+ .)
+
+ /* .NET 2.0 */
+ { TypeParameterConstraintsClause<templates> }
+
+ ( Block<out stmt> | ";" ) (. compilationUnit.BlockEnd();
+ methodDeclaration.Body = (BlockStatement)stmt;
+ .)
+
+| /*--- event declaration: */ (. m.Check(Modifiers.PropertysEventsMethods); .)
+ "event"
+ (. EventDeclaration eventDecl = new EventDeclaration {
+ Modifier = m.Modifier,
+ Attributes = attributes,
+ StartLocation = t.Location
+ };
+ compilationUnit.AddChild(eventDecl);
+ compilationUnit.BlockStart(eventDecl);
+ EventAddRegion addBlock = null;
+ EventRemoveRegion removeBlock = null;
+ .)
+ Type<out type> (. eventDecl.TypeReference = type; .)
+ ( IF (IsExplicitInterfaceImplementation())
+ TypeName<out explicitInterface, false>
+ (. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); .)
+ (. eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); .)
+
+ | Identifier (. qualident = t.val; .)
+ )
+ (. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .)
+ [ "=" Expr<out expr> (. eventDecl.Initializer = expr; .) ]
+ [ "{" (. eventDecl.BodyStart = t.Location; .)
+ EventAccessorDecls<out addBlock, out removeBlock>
+ "}" (. eventDecl.BodyEnd = t.EndLocation; .)
+ ]
+ [ ";" ]
+ (. compilationUnit.BlockEnd();
+ eventDecl.AddRegion = addBlock;
+ eventDecl.RemoveRegion = removeBlock;
+ .)
+
+| /*--- constructor or static contructor declaration: */
+ IF (IdentAndLPar()) (. m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); .)
+ Identifier (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .)
+ FormalParameterList<p>
+ ]
+ ")" (.ConstructorInitializer init = null; .)
+ [ (. m.Check(Modifiers.Constructors); .)
+ ConstructorInitializer<out init>
+ ] (.
+ ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes);
+ cd.StartLocation = startPos;
+ cd.EndLocation = t.EndLocation;
+ .)
+
+ ( Block<out stmt> | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .)
+
+
+| /*--- conversion operator declaration: */ (. m.Check(Modifiers.Operators);
+ if (m.isNone) Error("at least one modifier must be set");
+ bool isImplicit = true;
+ Location startPos = Location.Empty;
+ .)
+ ( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) )
+ "operator" Type<out type> (. TypeReference operatorType = type; .)
+ "(" Type<out type> Identifier (. string varName = t.val; .) ")"
+ (. Location endPos = t.Location; .)
+ ( Block<out stmt> | ";" (. stmt = null; .) )
+ (.
+
+ List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
+ parameters.Add(new ParameterDeclarationExpression(type, varName));
+ OperatorDeclaration operatorDeclaration = new OperatorDeclaration {
+ Modifier = m.Modifier,
+ Attributes = attributes,
+ Parameters = parameters,
+ TypeReference = operatorType,
+ ConversionType = isImplicit ? ConversionType.Implicit : ConversionType.Explicit,
+ Body = (BlockStatement)stmt,
+ StartLocation = m.GetDeclarationLocation(startPos),
+ EndLocation = endPos
+ };
+ compilationUnit.AddChild(operatorDeclaration);
+ .)
+
+
+| /*--- inner type declaration: */
+ TypeDecl<m, attributes>
+
+| Type<out type> (. Location startPos = t.Location; .)
+ (
+ /*--- operator declaration: */ (. OverloadableOperatorType op;
+ m.Check(Modifiers.Operators);
+ if (m.isNone) Error("at least one modifier must be set");
+ .)
+ "operator" OverloadableOperator<out op> (. TypeReference firstType, secondType = null; string secondName = null; .)
+ "(" Type<out firstType> Identifier (. string firstName = t.val; .)
+ ( "," Type<out secondType> Identifier (. secondName = t.val; .) /* (. if (Tokens.OverloadableUnaryOp[op.kind] && !Tokens.OverloadableBinaryOp[op.kind])
+ Error("too many operands for unary operator");
+ .)*/
+ | /* empty */ /*(. if (Tokens.OverloadableBinaryOp[op.kind]){
+ Error("too few operands for binary operator");
+ }
+ .)*/
+ )
+ (. Location endPos = t.Location; .)
+ ")" ( Block<out stmt> | ";" )
+ (.
+ OperatorDeclaration operatorDeclaration = new OperatorDeclaration {
+ Modifier = m.Modifier,
+ Attributes = attributes,
+ TypeReference = type,
+ OverloadableOperator = op,
+ Body = (BlockStatement)stmt,
+ StartLocation = m.GetDeclarationLocation(startPos),
+ EndLocation = endPos
+ };
+ SafeAdd(operatorDeclaration, operatorDeclaration.Parameters, new ParameterDeclarationExpression(firstType, firstName));
+ if (secondType != null) {
+ SafeAdd(operatorDeclaration, operatorDeclaration.Parameters, new ParameterDeclarationExpression(secondType, secondName));
+ }
+ compilationUnit.AddChild(operatorDeclaration);
+ .)
+
+ /*--- field declaration: */
+ | IF (IsVarDecl())
+ (. m.Check(Modifiers.Fields);
+ FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
+ fd.StartLocation = m.GetDeclarationLocation(startPos);
+ .)
+ ( IF (m.Contains(Modifiers.Fixed))
+ VariableDeclarator<fd>
+ "["
+ Expr<out expr> (. if (fd.Fields.Count > 0)
+ fd.Fields[fd.Fields.Count-1].FixedArrayInitialization = expr; .)
+ "]"
+ { ","
+ VariableDeclarator<fd>
+ "["
+ Expr<out expr> (. if (fd.Fields.Count > 0)
+ fd.Fields[fd.Fields.Count-1].FixedArrayInitialization = expr; .)
+ "]"
+ }
+ | /* non-fixed field */
+ VariableDeclarator<fd>
+ { "," VariableDeclarator<fd> }
+ )
+ ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .)
+
+ /*--- unqualified indexer declaration (without interface name): */
+ | (. m.Check(Modifiers.Indexers); .)
+ "this" "[" FormalParameterList<p> "]" (. Location endLocation = t.EndLocation; .) "{" (.
+ IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
+ indexer.StartLocation = startPos;
+ indexer.EndLocation = endLocation;
+ indexer.BodyStart = t.Location;
+ PropertyGetRegion getRegion;
+ PropertySetRegion setRegion;
+ .)
+ AccessorDecls<out getRegion, out setRegion> "}" (.
+ indexer.BodyEnd = t.EndLocation;
+ indexer.GetRegion = getRegion;
+ indexer.SetRegion = setRegion;
+ compilationUnit.AddChild(indexer);
+ .)
+ | IF (IsIdentifierToken(la))
+ ( IF (IsExplicitInterfaceImplementation())
+ TypeName<out explicitInterface, false>
+ (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
+ qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
+ } .)
+ | Identifier (. qualident = t.val; .)
+ )
+ (. Location qualIdentEndLocation = t.EndLocation; .)
+
+ (
+ /*--- "not void" method (function) declaration: */
+ ( (. m.Check(Modifiers.PropertysEventsMethods); .)
+ /* .NET 2.0 */
+ [ TypeParameterList<templates> ]
+ "("
+ [ "this" (. isExtensionMethod = true; .) ]
+ [ FormalParameterList<p> ] ")"
+ (.
+ MethodDeclaration methodDeclaration = new MethodDeclaration {
+ Name = qualident,
+ Modifier = m.Modifier,
+ TypeReference = type,
+ Parameters = p,
+ Attributes = attributes
+ };
+ if (explicitInterface != null)
+ methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
+ methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
+ methodDeclaration.EndLocation = t.EndLocation;
+ methodDeclaration.IsExtensionMethod = isExtensionMethod;
+ methodDeclaration.Templates = templates;
+ compilationUnit.AddChild(methodDeclaration);
+ .)
+ { TypeParameterConstraintsClause<templates> }
+ ( Block<out stmt> | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .)
+
+ /*--- property declaration: */
+ | "{" (. PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes);
+ if (explicitInterface != null)
+ pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
+ pDecl.StartLocation = m.GetDeclarationLocation(startPos);
+ pDecl.EndLocation = qualIdentEndLocation;
+ pDecl.BodyStart = t.Location;
+ PropertyGetRegion getRegion;
+ PropertySetRegion setRegion;
+ .)
+ AccessorDecls<out getRegion, out setRegion>
+ "}" (.
+ pDecl.GetRegion = getRegion;
+ pDecl.SetRegion = setRegion;
+ pDecl.BodyEnd = t.EndLocation;
+ compilationUnit.AddChild(pDecl);
+ .)
+ )
+
+ /*--- qualified indexer declaration (with interface name): */
+ | (. m.Check(Modifiers.Indexers); .)
+ "." "this" "[" FormalParameterList<p> "]" (.
+ IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
+ indexer.StartLocation = m.GetDeclarationLocation(startPos);
+ indexer.EndLocation = t.EndLocation;
+ if (explicitInterface != null)
+ SafeAdd(indexer, indexer.InterfaceImplementations, new InterfaceImplementation(explicitInterface, "this"));
+ PropertyGetRegion getRegion;
+ PropertySetRegion setRegion;
+ .)
+ "{" (. Location bodyStart = t.Location; .)
+ AccessorDecls<out getRegion, out setRegion>
+ "}" (. indexer.BodyStart = bodyStart;
+ indexer.BodyEnd = t.EndLocation;
+ indexer.GetRegion = getRegion;
+ indexer.SetRegion = setRegion;
+ compilationUnit.AddChild(indexer);
+ .)
+ )
+ )
+.
+
+ClassMemberDecl<ModifierList m, List<AttributeSection> attributes>
+(. Statement stmt = null; .)
+=
+ StructMemberDecl<m, attributes>
+ | /*--- destructor declaration: */ (. m.Check(Modifiers.Destructors); Location startPos = la.Location; .)
+ "~" Identifier (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes);
+ d.Modifier = m.Modifier;
+ d.StartLocation = m.GetDeclarationLocation(startPos);
+ .)
+ "(" ")" (. d.EndLocation = t.EndLocation; .) ( Block<out stmt> | ";" ) (.
+ d.Body = (BlockStatement)stmt;
+ compilationUnit.AddChild(d);
+ .)
+.
+
+InterfaceMemberDecl
+(.
+ TypeReference type;
+
+ AttributeSection section;
+ Modifiers mod = Modifiers.None;
+ List<AttributeSection> attributes = new List<AttributeSection>();
+ List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
+ string name;
+ PropertyGetRegion getBlock;
+ PropertySetRegion setBlock;
+ Location startLocation = new Location(-1, -1);
+ List<TemplateDefinition> templates = new List<TemplateDefinition>();
+.)
+=
+ { AttributeSection<out section> (. attributes.Add(section); .)}
+ [ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ]
+ (
+ /*--- interface void method (procedure) declaration: */
+ IF (NotVoidPointer()) "void" (. if (startLocation.IsEmpty) startLocation = t.Location; .)
+ Identifier (. name = t.val; .)
+ [ TypeParameterList<templates> ]
+ "(" [ FormalParameterList<parameters> ] ")"
+ { TypeParameterConstraintsClause<templates> }
+ ";"
+ (. MethodDeclaration md = new MethodDeclaration {
+ Name = name, Modifier = mod, TypeReference = new TypeReference("System.Void", true),
+ Parameters = parameters, Attributes = attributes, Templates = templates,
+ StartLocation = startLocation, EndLocation = t.EndLocation
+ };
+ compilationUnit.AddChild(md);
+ .)
+ | (
+ Type<out type> (. if (startLocation.IsEmpty) startLocation = t.Location; .)
+ (
+ Identifier (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .)
+ (
+ /*--- interface "not void" method (function) declaration: */
+ /* .NET 2.0 */
+ [ TypeParameterList<templates> ]
+ "(" [ FormalParameterList<parameters> ] ")"
+ /* .NET 2.0 */
+ { TypeParameterConstraintsClause<templates> }
+ ";" (. MethodDeclaration md = new MethodDeclaration {
+ Name = name, Modifier = mod, TypeReference = type,
+ Parameters = parameters, Attributes = attributes, Templates = templates,
+ StartLocation = startLocation, EndLocation = t.EndLocation
+ };
+ compilationUnit.AddChild(md);
+ .)
+ /*--- interface property declaration: */
+ |
+ (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes);
+ compilationUnit.AddChild(pd); .)
+ "{"
+ (. Location bodyStart = t.Location;.)
+ InterfaceAccessors<out getBlock, out setBlock>
+ "}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .)
+ )
+ /*--- interface indexer declaration: */
+ | "this" "[" FormalParameterList<parameters> "]"
+ (. Location bracketEndLocation = t.EndLocation; .)
+ (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes);
+ compilationUnit.AddChild(id); .)
+ "{" (. Location bodyStart = t.Location;.)
+ InterfaceAccessors<out getBlock, out setBlock>
+ "}"
+ (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.)
+ )
+ /*--- interface event declaration: */
+ | "event" (. if (startLocation.IsEmpty) startLocation = t.Location; .)
+ Type<out type> Identifier
+ (. EventDeclaration ed = new EventDeclaration {
+ TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes
+ };
+ compilationUnit.AddChild(ed);
+ .)
+ ";"
+ (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .)
+ )
+ )
+.
+
+EnumMemberDecl<out FieldDeclaration f>
+(.
+ Expression expr = null;
+ List<AttributeSection> attributes = new List<AttributeSection>();
+ AttributeSection section = null;
+ VariableDeclaration varDecl = null;
+.)
+=
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ Identifier (. f = new FieldDeclaration(attributes);
+ varDecl = new VariableDeclaration(t.val);
+ f.Fields.Add(varDecl);
+ f.StartLocation = t.Location;
+ f.EndLocation = t.EndLocation;
+ .)
+ [ "=" Expr<out expr> (. varDecl.Initializer = expr; .) ]
+.
+
+
+AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
+(.
+ List<AttributeSection> attributes = new List<AttributeSection>();
+ AttributeSection section;
+ getBlock = null;
+ setBlock = null;
+ ModifierList modifiers = null;
+.)
+=
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ [ AccessorModifiers<out modifiers> ]
+ (
+ GetAccessorDecl<out getBlock, attributes>
+ (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .)
+ [ (. attributes = new List<AttributeSection>(); modifiers = null; .)
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ [ AccessorModifiers<out modifiers> ]
+ SetAccessorDecl<out setBlock, attributes>
+ (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .)
+ ]
+ |
+ SetAccessorDecl<out setBlock, attributes>
+ (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .)
+ [ (. attributes = new List<AttributeSection>(); modifiers = null; .)
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ [ AccessorModifiers<out modifiers> ]
+ GetAccessorDecl<out getBlock, attributes>
+ (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .)
+ ]
+ | Identifier (. Error("get or set accessor declaration expected"); .)
+ )
+.
+
+GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
+(. Statement stmt = null; .)
+=
+ "get"
+ (. Location startLocation = t.Location; .)
+ ( Block<out stmt> | ";" )
+ (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
+ (. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
+.
+
+SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attributes>
+(. Statement stmt = null; .)
+=
+ "set"
+ (. Location startLocation = t.Location; .)
+ ( Block<out stmt> | ";" )
+ (. setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); .)
+ (. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .)
+.
+
+EventAccessorDecls<out EventAddRegion addBlock, out EventRemoveRegion removeBlock>
+(. AttributeSection section;
+ List<AttributeSection> attributes = new List<AttributeSection>();
+ Statement stmt;
+ addBlock = null;
+ removeBlock = null;
+.)
+=
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ (
+ (. addBlock = new EventAddRegion(attributes); .)
+ AddAccessorDecl<out stmt> (. attributes = new List<AttributeSection>(); addBlock.Block = (BlockStatement)stmt; .)
+ { AttributeSection<out section> (. attributes.Add(section); .)}
+ RemoveAccessorDecl<out stmt> (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; .)
+ |
+ RemoveAccessorDecl <out stmt> (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new List<AttributeSection>(); .)
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ AddAccessorDecl<out stmt> (. addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; .)
+ )
+.
+
+InterfaceAccessors<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
+(.
+ AttributeSection section;
+ List<AttributeSection> attributes = new List<AttributeSection>();
+ getBlock = null; setBlock = null;
+ PropertyGetSetRegion lastBlock = null;
+.)
+=
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ (. Location startLocation = la.Location; .)
+ (
+ "get" (. getBlock = new PropertyGetRegion(null, attributes); .)
+ | "set" (. setBlock = new PropertySetRegion(null, attributes); .)
+ )
+ ";"
+ (. if (getBlock != null) { getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; }
+ if (setBlock != null) { setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; }
+ attributes = new List<AttributeSection>(); .)
+ [
+ { AttributeSection<out section> (. attributes.Add(section); .) }
+ (. startLocation = la.Location; .)
+ (
+ "get" (. if (getBlock != null) Error("get already declared");
+ else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; }
+ .)
+ | "set" (. if (setBlock != null) Error("set already declared");
+ else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; }
+ .)
+ )
+ ";"
+ (. if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } .)
+ ]
+.
+
+VariableDeclarator<FieldDeclaration parentFieldDeclaration>
+(. Expression expr = null; .)
+=
+ Identifier (. VariableDeclaration f = new VariableDeclaration(t.val); f.StartLocation = t.Location; .)
+ [ "=" VariableInitializer<out expr> (. f.Initializer = expr; .) ]
+ (. f.EndLocation = t.EndLocation; SafeAdd(parentFieldDeclaration, parentFieldDeclaration.Fields, f); .)
+.
+
+Block<out Statement stmt> /* not BlockStatement because of EmbeddedStatement */
+=
+ "{" (. BlockStatement blockStmt = new BlockStatement();
+ blockStmt.StartLocation = t.Location;
+ compilationUnit.BlockStart(blockStmt);
+ if (!ParseMethodBodies) lexer.SkipCurrentBlock(0);
+ .)
+ { Statement }
+ SYNC "}"
+ (.
+ stmt = blockStmt;
+ blockStmt.EndLocation = t.EndLocation;
+ compilationUnit.BlockEnd();
+ .)
+.
+
+AddAccessorDecl<out Statement stmt>
+(.stmt = null;.)
+=
+ "add"
+ Block<out stmt>
+.
+
+RemoveAccessorDecl<out Statement stmt>
+(.stmt = null;.)
+=
+ "remove"
+ Block<out stmt>
+.
+
+ConstructorInitializer<out ConstructorInitializer ci>
+(. Expression expr; ci = new ConstructorInitializer(); .)
+=
+ ":"
+ (
+ "base" (. ci.ConstructorInitializerType = ConstructorInitializerType.Base; .)
+ | "this" (. ci.ConstructorInitializerType = ConstructorInitializerType.This; .)
+ )
+ "("
+ [ Argument<out expr> (. SafeAdd(ci, ci.Arguments, expr); .)
+ { "," Argument<out expr> (. SafeAdd(ci, ci.Arguments, expr); .) }
+ ]
+ ")"
+.
+
+VariableInitializer<out Expression initializerExpression>
+(. TypeReference type = null; Expression expr = null; initializerExpression = null; .)
+=
+ Expr<out initializerExpression>
+ | CollectionInitializer<out initializerExpression>
+ | "stackalloc" Type<out type> "[" Expr<out expr> "]" (. initializerExpression = new StackAllocExpression(type, expr); .)
+.
+
+OverloadableOperator<out OverloadableOperatorType op>
+(. op = OverloadableOperatorType.None; .)
+=
+ "+" (. op = OverloadableOperatorType.Add; .)
+ | "-" (. op = OverloadableOperatorType.Subtract; .)
+
+ | "!" (. op = OverloadableOperatorType.Not; .)
+ | "~" (. op = OverloadableOperatorType.BitNot; .)
+
+ | "++" (. op = OverloadableOperatorType.Increment; .)
+ | "--" (. op = OverloadableOperatorType.Decrement; .)
+
+ | "true" (. op = OverloadableOperatorType.IsTrue; .)
+ | "false" (. op = OverloadableOperatorType.IsFalse; .)
+
+ | "*" (. op = OverloadableOperatorType.Multiply; .)
+ | "/" (. op = OverloadableOperatorType.Divide; .)
+ | "%" (. op = OverloadableOperatorType.Modulus; .)
+
+ | "&" (. op = OverloadableOperatorType.BitwiseAnd; .)
+ | "|" (. op = OverloadableOperatorType.BitwiseOr; .)
+ | "^" (. op = OverloadableOperatorType.ExclusiveOr; .)
+
+ | "<<" (. op = OverloadableOperatorType.ShiftLeft; .)
+ | "==" (. op = OverloadableOperatorType.Equality; .)
+ | "!=" (. op = OverloadableOperatorType.InEquality; .)
+ | "<" (. op = OverloadableOperatorType.LessThan; .)
+ | ">=" (. op = OverloadableOperatorType.GreaterThanOrEqual; .)
+ | "<=" (. op = OverloadableOperatorType.LessThanOrEqual; .)
+ | ">" (. op = OverloadableOperatorType.GreaterThan; .) [ ">" (. op = OverloadableOperatorType.ShiftRight; .) ]
+.
+
+Argument<out Expression argumentexpr>
+(.
+ Expression expr;
+ FieldDirection fd = FieldDirection.None;
+.)
+=
+ [
+ "ref" (. fd = FieldDirection.Ref; .)
+ | "out" (. fd = FieldDirection.Out; .)
+ ]
+ Expr<out expr>
+ (. argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; .)
+.
+
+AssignmentOperator<out AssignmentOperatorType op>
+(. op = AssignmentOperatorType.None; .)
+=
+ "=" (. op = AssignmentOperatorType.Assign; .)
+ | "+=" (. op = AssignmentOperatorType.Add; .)
+ | "-=" (. op = AssignmentOperatorType.Subtract; .)
+ | "*=" (. op = AssignmentOperatorType.Multiply; .)
+ | "/=" (. op = AssignmentOperatorType.Divide; .)
+ | "%=" (. op = AssignmentOperatorType.Modulus; .)
+ | "&=" (. op = AssignmentOperatorType.BitwiseAnd; .)
+ | "|=" (. op = AssignmentOperatorType.BitwiseOr; .)
+ | "^=" (. op = AssignmentOperatorType.ExclusiveOr; .)
+ | "<<=" (. op = AssignmentOperatorType.ShiftLeft; .)
+ | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual)
+ ">" ">=" (. op = AssignmentOperatorType.ShiftRight; .)
+.
+
+CollectionInitializer<out Expression outExpr>
+(.
+ Expression expr = null;
+ CollectionInitializerExpression initializer = new CollectionInitializerExpression();
+.)
+=
+ "{" (. initializer.StartLocation = t.Location; .)
+ [ VariableInitializer<out expr>
+ (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
+ { IF (NotFinalComma())
+ "," VariableInitializer<out expr>
+ (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
+ }
+ [ "," ]
+ ]
+ "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .)
+.
+
+CollectionOrObjectInitializer<out Expression outExpr>
+(.
+ Expression expr = null;
+ CollectionInitializerExpression initializer = new CollectionInitializerExpression();
+.)
+=
+ "{" (. initializer.StartLocation = t.Location; .)
+ [ ObjectPropertyInitializerOrVariableInitializer<out expr>
+ (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
+ { IF (NotFinalComma())
+ "," ObjectPropertyInitializerOrVariableInitializer<out expr>
+ (. SafeAdd(initializer, initializer.CreateExpressions, expr); .)
+ }
+ [ "," ]
+ ]
+ "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .)
+.
+
+ObjectPropertyInitializerOrVariableInitializer<out Expression expr>
+(. expr = null; .)
+=
+( IF (IdentAndAsgn())
+ Identifier
+ (. NamedArgumentExpression nae = new NamedArgumentExpression(t.val, null);
+ nae.StartLocation = t.Location;
+ Expression r = null; .)
+ "="
+ ( CollectionOrObjectInitializer<out r>
+ | VariableInitializer <out r> )
+ (. nae.Expression = r; nae.EndLocation = t.EndLocation; expr = nae; .)
+
+| VariableInitializer <out expr>
+)
+.
+
+LocalVariableDecl<out Statement stmt>
+(.
+ TypeReference type;
+ VariableDeclaration var = null;
+ LocalVariableDeclaration localVariableDeclaration;
+ Location startPos = la.Location;
+.)
+=
+ Type<out type> (. localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = startPos; .)
+ LocalVariableDeclarator<out var> (. SafeAdd(localVariableDeclaration, localVariableDeclaration.Variables, var); .)
+ { "," LocalVariableDeclarator<out var> (. SafeAdd(localVariableDeclaration, localVariableDeclaration.Variables, var); .) }
+ (. stmt = localVariableDeclaration; stmt.EndLocation = t.EndLocation; .)
+.
+
+LocalVariableDeclarator<out VariableDeclaration var>
+(. Expression expr = null; .)
+=
+ Identifier (. var = new VariableDeclaration(t.val); var.StartLocation = t.Location; .)
+ [ "=" VariableInitializer<out expr> (. var.Initializer = expr; .) ]
+ (. var.EndLocation = t.EndLocation; .)
+.
+
+Statement
+(.
+ TypeReference type;
+ Expression expr;
+ Statement stmt = null;
+ Location startPos = la.Location;
+.)
+=
+ SYNC
+ (
+ /*--- labeled statement: */
+ IF (IsLabel()) Identifier (. compilationUnit.AddChild(new LabelStatement(t.val)); .)
+ ":" Statement
+ /*--- local constant declaration: */
+ | "const" Type<out type> (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; .)
+ Identifier (. ident = t.val; Location varStart = t.Location; .)
+ "=" Expr<out expr>
+ (.
+ SafeAdd(var, var.Variables, new VariableDeclaration(ident, expr) {
+ StartLocation = varStart,
+ EndLocation = t.EndLocation,
+ TypeReference = type
+ });
+ .)
+ { "," Identifier (. ident = t.val; .) "=" Expr<out expr>
+ (.
+ SafeAdd(var, var.Variables, new VariableDeclaration(ident, expr) {
+ StartLocation = varStart,
+ EndLocation = t.EndLocation,
+ TypeReference = type
+ });
+ .) }
+ ";" (. var.EndLocation = t.EndLocation; compilationUnit.AddChild(var); .)
+
+ /*--- local variable declaration: */
+ | IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> ";" (. compilationUnit.AddChild(stmt); .)
+
+ | EmbeddedStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
+ /* LL(1) confict: LocalVariableDecl *
+ * <-> StatementExpr *
+ * ident {"." ident} { "[" Expr ... */
+ )
+ (.
+ if (stmt != null) {
+ stmt.StartLocation = startPos;
+ stmt.EndLocation = t.EndLocation;
+ }
+ .)
+.
+
+EmbeddedStatement<out Statement statement>
+(.
+ TypeReference type = null;
+ Expression expr = null;
+ Statement embeddedStatement = null;
+ statement = null;
+.)
+=
+ (. Location startLocation = la.Location; .)
+ (
+ Block<out statement>
+
+ /*--- empty statement: */
+ | ";" (. statement = new EmptyStatement(); .)
+
+ /*--- checked / unchecked statement: */
+ | IF (UnCheckedAndLBrace()) (. Statement block; bool isChecked = true; .)
+ ("checked" | "unchecked" (. isChecked = false;.) )
+ Block<out block> (. statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); .)
+
+ /*--- selection statements (if, switch): */
+ | IfStatement<out statement>
+
+ | "switch" (. List<SwitchSection> switchSections = new List<SwitchSection>(); .)
+ "(" Expr<out expr> ")"
+ "{" SwitchSections<switchSections>
+ "}"
+ (. statement = new SwitchStatement(expr, switchSections); .)
+
+ /*--- iteration statements (while, do, for, foreach): */
+ | "while" "(" Expr<out expr> ")"
+ EmbeddedStatement<out embeddedStatement>
+ (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);.)
+
+ | "do" EmbeddedStatement<out embeddedStatement> "while"
+ "(" Expr<out expr> ")" ";"
+ (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); .)
+
+ | "for" (. List<Statement> initializer = null; List<Statement> iterator = null; .)
+ "(" [ ForInitializer<out initializer> ] ";"
+ [ Expr<out expr> ] ";"
+ [ ForIterator<out iterator> ] ")"
+ EmbeddedStatement<out embeddedStatement>
+ (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .)
+
+ | "foreach" "(" Type<out type> Identifier (. string varName = t.val; .)
+ "in" Expr<out expr> ")"
+ EmbeddedStatement<out embeddedStatement>
+ (. statement = new ForeachStatement(type, varName , expr, embeddedStatement); .)
+
+ /*--- jump statements (break, contine, goto, return, throw): */
+ | "break" ";" (. statement = new BreakStatement(); .)
+ | "continue" ";" (. statement = new ContinueStatement(); .)
+ | GotoStatement<out statement>
+
+ | IF (IsYieldStatement()) "yield"
+ ( "return" Expr<out expr> (. statement = new YieldStatement(new ReturnStatement(expr)); .)
+ | "break" (. statement = new YieldStatement(new BreakStatement()); .) )
+ ";"
+
+ | "return" [ Expr<out expr> ] ";" (. statement = new ReturnStatement(expr); .)
+ | "throw" [ Expr<out expr> ] ";" (. statement = new ThrowStatement(expr); .)
+
+ /*--- expression statement: */
+ | StatementExpr<out statement> SYNC ";"
+
+ /*--- try statement: */
+ | TryStatement<out statement>
+
+ /*--- lock satement: */
+ | "lock" "(" Expr<out expr> ")"
+ EmbeddedStatement<out embeddedStatement> (. statement = new LockStatement(expr, embeddedStatement); .)
+
+ /*--- using statement: */
+ | (.Statement resourceAcquisitionStmt = null; .)
+ "using" "("
+ ResourceAcquisition<out resourceAcquisitionStmt> ")"
+ EmbeddedStatement<out embeddedStatement> (. statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); .)
+
+ /*--- unsafe statement: */
+ | "unsafe" Block<out embeddedStatement> (. statement = new UnsafeStatement(embeddedStatement); .)
+ /*--- fixed statement: */
+ | (. Statement pointerDeclarationStmt = null; .)
+ "fixed" "("
+ ResourceAcquisition<out pointerDeclarationStmt> ")"
+ EmbeddedStatement<out embeddedStatement> (. statement = new FixedStatement(pointerDeclarationStmt, embeddedStatement); .)
+ )
+ (. if (statement != null) {
+ statement.StartLocation = startLocation;
+ statement.EndLocation = t.EndLocation;
+ }
+ .)
+.
+
+IfStatement<out Statement statement>
+(.
+ Expression expr = null;
+ Statement embeddedStatement = null;
+ statement = null;
+.)
+=
+ "if"
+ "(" Expr<out expr> ")"
+ EmbeddedStatement<out embeddedStatement>
+ (. Statement elseStatement = null; .)
+ [ "else" EmbeddedStatement<out elseStatement> ]
+ (. statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); .)
+ (. if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) {
+ /* else if-section (otherwise we would have a BlockStatment) */
+ (statement as IfElseStatement).ElseIfSections.Add(
+ new ElseIfSection((elseStatement as IfElseStatement).Condition,
+ (elseStatement as IfElseStatement).TrueStatement[0]));
+ (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections);
+ (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement;
+ }
+ .)
+.
+
+ForInitializer<out List<Statement> initializer>
+(.
+ Statement stmt;
+ initializer = new List<Statement>();
+.)
+=
+ IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> (. initializer.Add(stmt);.)
+ | StatementExpr<out stmt> (.initializer.Add(stmt);.) { "," StatementExpr<out stmt> (. initializer.Add(stmt);.) }
+.
+
+ForIterator<out List<Statement> iterator>
+(.
+ Statement stmt;
+ iterator = new List<Statement>();
+.)
+=
+ StatementExpr<out stmt> (. iterator.Add(stmt);.) { "," StatementExpr<out stmt> (. iterator.Add(stmt); .) }
+.
+
+SwitchSections<List<SwitchSection> switchSections>
+(.
+ SwitchSection switchSection = new SwitchSection();
+ CaseLabel label;
+.)
+=
+ SwitchLabel<out label> (. SafeAdd(switchSection, switchSection.SwitchLabels, label); .)
+ (. compilationUnit.BlockStart(switchSection); .)
+ {
+ ( SwitchLabel<out label>
+ (. if (label != null) {
+ if (switchSection.Children.Count > 0) {
+ // open new section
+ compilationUnit.BlockEnd(); switchSections.Add(switchSection);
+ switchSection = new SwitchSection();
+ compilationUnit.BlockStart(switchSection);
+ }
+ SafeAdd(switchSection, switchSection.SwitchLabels, label);
+ }
+ .)
+ | Statement)
+ }
+ (. compilationUnit.BlockEnd(); switchSections.Add(switchSection); .)
+.
+
+SwitchLabel<out CaseLabel label>
+ (. Expression expr = null; label = null; .)
+=
+ "case" Expr<out expr> ":" (. label = new CaseLabel(expr); .)
+ | "default" ":" (. label = new CaseLabel(); .)
+.
+
+TryStatement<out Statement tryStatement>
+(.
+ Statement blockStmt = null, finallyStmt = null;
+ List<CatchClause> catchClauses = null;
+.)
+=
+ "try" Block<out blockStmt>
+ (
+ CatchClauses<out catchClauses> [ "finally" Block<out finallyStmt> ]
+ | "finally" Block<out finallyStmt>
+ )
+ (.
+ tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
+ if (catchClauses != null) {
+ foreach (CatchClause cc in catchClauses) cc.Parent = tryStatement;
+ }
+ .)
+.
+
+CatchClauses<out List<CatchClause> catchClauses>
+(.
+ catchClauses = new List<CatchClause>();
+.)
+=
+ "catch" (. string identifier;
+ Statement stmt;
+ TypeReference typeRef;
+ .)
+ /*--- general catch clause (as only catch clause) */
+ (
+ Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .)
+ /*--- specific catch clause */
+ | "(" ClassType<out typeRef, false> (. identifier = null; .)
+ [ Identifier (. identifier = t.val; .) ]
+ ")" Block<out stmt>
+ (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .)
+ { IF (IsTypedCatch()) "catch" "(" ClassType<out typeRef, false> (. identifier = null; .)
+ [ Identifier (. identifier = t.val; .) ]
+ ")" Block<out stmt>
+ (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) }
+ /*--- general catch clause (after specific catch clauses, optional) */
+ [ "catch" Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) ]
+ )
+.
+
+GotoStatement<out Statement stmt>
+(. Expression expr; stmt = null; .)
+=
+ "goto"
+ (
+ Identifier (. stmt = new GotoStatement(t.val); .) ";"
+ | "case" Expr<out expr> ";" (. stmt = new GotoCaseStatement(expr); .)
+ | "default" ";" (. stmt = new GotoCaseStatement(null); .)
+ )
+.
+
+ResourceAcquisition<out Statement stmt>
+(.
+ stmt = null;
+ Expression expr;
+.)
+=
+ (
+ IF (IsLocalVarDecl()) LocalVariableDecl<out stmt>
+ | Expr<out expr> /* LL(1) conflict resoltion: *
+ * check if next is Qualident followed by ident *
+ * ==> LocalVariableDecl *
+ * new problem: first set of ResourceAcquisition changes */
+ (. stmt = new ExpressionStatement(expr); .)
+ )
+.
+
+StatementExpr<out Statement stmt>
+(. Expression expr; .)
+=
+ Expr<out expr>
+ /* The grammar allows only assignments or method invocations here, */
+ /* but we don't enforce that here */
+ (. stmt = new ExpressionStatement(expr); .)
+.
+
+Expr<out Expression expr>
+(. expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; .)
+=
+ (. Location startLocation = la.Location; .)
+ UnaryExpr<out expr>
+ /*--- conditional expression: */
+ (
+ ( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
+ | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual)
+ ( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
+ | (
+ ConditionalOrExpr<ref expr>
+ [ "??" Expr<out expr1> (. expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); .) ]
+ [ "?" Expr<out expr1> ":" Expr<out expr2> (. expr = new ConditionalExpression(expr, expr1, expr2); .) ]
+ )
+ )
+ (. if (expr != null) {
+ expr.StartLocation = startLocation;
+ expr.EndLocation = t.EndLocation;
+ }
+ .)
+.
+
+
+UnaryExpr<out Expression uExpr>
+(.
+ TypeReference type = null;
+ Expression expr = null;
+ ArrayList expressions = new ArrayList();
+ uExpr = null;
+.)
+=
+ {
+ /* IF (Tokens.UnaryOp[la.kind] || IsTypeCast()) */
+ (
+ "+" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); .)
+ | "-" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); .)
+ | "!" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); .)
+ | "~" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); .)
+ | "*" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Dereference)); .)
+ | "++" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); .)
+ | "--" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); .)
+ | "&" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.AddressOf)); .)
+
+ /*--- cast expression: */
+ /* Problem: "(" Type ")" from here and *
+ * "(" Expr ")" from PrimaryExpr *
+ * Solution: (in IsTypeCast()) */
+ | IF (IsTypeCast()) "(" Type<out type> ")" (. expressions.Add(new CastExpression(type)); .)
+ )
+ }
+
+ /* special rule (2.4.4.2) to allow writing int.MinValue and long.MinValue */
+ ( IF (LastExpressionIsUnaryMinus(expressions) && IsMostNegativeIntegerWithoutTypeSuffix())
+ Literal
+ (.
+ expressions.RemoveAt(expressions.Count - 1);
+ if (t.literalValue is uint) {
+ expr = new PrimitiveExpression(int.MinValue, int.MinValue.ToString());
+ } else if (t.literalValue is ulong) {
+ expr = new PrimitiveExpression(long.MinValue, long.MinValue.ToString());
+ } else {
+ throw new Exception("t.literalValue must be uint or ulong");
+ }
+ .)
+ | PrimaryExpr<out expr>
+ )
+ (. for (int i = 0; i < expressions.Count; ++i) {
+ Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr;
+ if (expressions[i] is CastExpression) {
+ ((CastExpression)expressions[i]).Expression = nextExpression;
+ } else {
+ ((UnaryOperatorExpression)expressions[i]).Expression = nextExpression;
+ }
+ }
+ if (expressions.Count > 0) {
+ uExpr = (Expression)expressions[0];
+ } else {
+ uExpr = expr;
+ }
+ .)
+.
+
+
+PrimaryExpr<out Expression pexpr>
+(.
+ TypeReference type = null;
+ Expression expr;
+ pexpr = null;
+.)
+=
+ (. Location startLocation = la.Location; .)
+ (
+ "true" (.pexpr = new PrimitiveExpression(true, "true"); .)
+ | "false" (.pexpr = new PrimitiveExpression(false, "false"); .)
+ | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */
+ | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; .)
+ | IF (StartOfQueryExpression())
+ QueryExpression<out pexpr>
+ | IF (IdentAndDoubleColon())
+ Identifier (. type = new TypeReference(t.val); .)
+ "::" (. pexpr = new TypeReferenceExpression(type); .)
+ Identifier (. if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val ?? "?"; } else type.Type += "." + (t.val ?? "?"); .)
+
+ /*--- simple name (IdentifierExpression): */
+ | Identifier
+ (. pexpr = new IdentifierExpression(t.val); .)
+
+ [ ShortedLambdaExpression<(IdentifierExpression)pexpr, out pexpr>
+ | IF (IsGenericInSimpleNameOrMemberAccess())
+ (. List<TypeReference> typeList; .)
+ TypeArgumentList<out typeList, false>
+ (. ((IdentifierExpression)pexpr).TypeArguments = typeList; .)
+ ]
+ | IF (IsLambdaExpression()) /* Lambda expression */
+ LambdaExpression<out pexpr>
+
+ /*--- parenthesized expression: */
+ | "(" Expr<out expr> ")" (. pexpr = new ParenthesizedExpression(expr); .)
+
+ | /*--- predefined type member access: */
+ (. string val = null; .)
+ ( "bool" (. val = "System.Boolean"; .)
+ | "byte" (. val = "System.Byte"; .)
+ | "char" (. val = "System.Char"; .)
+ | "decimal" (. val = "System.Decimal"; .)
+ | "double" (. val = "System.Double"; .)
+ | "float" (. val = "System.Single"; .)
+ | "int" (. val = "System.Int32"; .)
+ | "long" (. val = "System.Int64"; .)
+ | "object" (. val = "System.Object"; .)
+ | "sbyte" (. val = "System.SByte"; .)
+ | "short" (. val = "System.Int16"; .)
+ | "string" (. val = "System.String"; .)
+ | "uint" (. val = "System.UInt32"; .)
+ | "ulong" (. val = "System.UInt64"; .)
+ | "ushort" (. val = "System.UInt16"; .)
+ | "void" (. val = "System.Void"; .)
+ )
+ (. pexpr = new TypeReferenceExpression(new TypeReference(val, true)) { StartLocation = t.Location, EndLocation = t.EndLocation }; .)
+
+ /*--- this access: */
+ | "this" (. pexpr = new ThisReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .)
+ /*--- base access: */
+ | "base" (. pexpr = new BaseReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .)
+
+ /* new ... - ObjectCreationExpression or ArrayCreateExpression */
+ | NewExpression<out pexpr>
+
+ | "typeof" "("
+ (
+ IF (NotVoidPointer()) "void" (. type = new TypeReference("System.Void", true); .)
+ | TypeWithRestriction<out type, true, true>
+ )
+ ")" (. pexpr = new TypeOfExpression(type); .)
+
+ | "default" "(" Type<out type> ")" (. pexpr = new DefaultValueExpression(type); .)
+ | "sizeof" "(" Type<out type> ")" (. pexpr = new SizeOfExpression(type); .)
+ | "checked" "(" Expr<out expr> ")" (. pexpr = new CheckedExpression(expr); .)
+ | "unchecked" "(" Expr<out expr> ")" (. pexpr = new UncheckedExpression(expr); .)
+ | "delegate" AnonymousMethodExpr<out expr> (. pexpr = expr; .)
+ )
+ (. if (pexpr != null) {
+ if (pexpr.StartLocation.IsEmpty)
+ pexpr.StartLocation = startLocation;
+ if (pexpr.EndLocation.IsEmpty)
+ pexpr.EndLocation = t.EndLocation;
+ }
+ .)
+ {
+ (. startLocation = la.Location; .)
+ (
+ "++" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); .)
+ | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .)
+ )
+ /*--- member access */
+ | PointerMemberAccess<out pexpr, pexpr>
+ | MemberAccess<out pexpr, pexpr>
+
+ /*--- invocation expression: */
+ | "("
+ (. List<Expression> parameters = new List<Expression>(); .)
+ (. pexpr = new InvocationExpression(pexpr, parameters); .)
+ [ Argument<out expr> (. SafeAdd(pexpr, parameters, expr); .)
+ { "," Argument<out expr> (. SafeAdd(pexpr, parameters, expr); .)
+ }
+ ]
+ ")"
+ /*--- element access */
+ | (. /*if (isArrayCreation) Error("element access not allow on array creation");*/
+ List<Expression> indices = new List<Expression>();
+ pexpr = new IndexerExpression(pexpr, indices);
+ .)
+ "[" Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
+ { "," Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
+ } "]"
+
+ (. if (pexpr != null) {
+ pexpr.StartLocation = startLocation;
+ pexpr.EndLocation = t.EndLocation;
+ }
+ .)
+ }
+.
+
+MemberAccess<out Expression expr, Expression target>
+(. List<TypeReference> typeList; .)
+=
+ (. if (ShouldConvertTargetExpressionToTypeReference(target)) {
+ TypeReference type = GetTypeReferenceFromExpression(target);
+ if (type != null) {
+ target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation };
+ }
+ }
+ .)
+ "."
+ Identifier
+ (. expr = new MemberReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; .)
+ [ IF (IsGenericInSimpleNameOrMemberAccess())
+ TypeArgumentList<out typeList, false>
+ (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .)
+ ]
+.
+
+PointerMemberAccess<out Expression expr, Expression target>
+(. List<TypeReference> typeList; .)
+=
+ "->"
+ Identifier
+ (. expr = new PointerReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; .)
+ [ IF (IsGenericInSimpleNameOrMemberAccess())
+ TypeArgumentList<out typeList, false>
+ (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .)
+ ]
+.
+
+NewExpression<out Expression pexpr>
+(. pexpr = null;
+ List<Expression> parameters = new List<Expression>();
+ TypeReference type = null;
+ Expression expr;
+.)
+=
+ "new"
+ [ NonArrayType<out type> ] /* optional since .NET 3.0 */
+
+ /*--- delegate / object creation expression: */
+ /* Note: a delegate creation expression allow only a single Expr */
+ /* not an argument list, but this is not distinguished here */
+ (
+ ( (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .)
+ "(" (. if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); .)
+ [ Argument<out expr> (. SafeAdd(oce, parameters, expr); .)
+ { "," Argument<out expr> (. SafeAdd(oce, parameters, expr); .) }
+ ]
+ ")" (. pexpr = oce; .)
+ [ CollectionOrObjectInitializer<out expr> (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) ]
+ | (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .)
+ CollectionOrObjectInitializer<out expr> (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .)
+ (. pexpr = oce; .)
+ )
+
+ /*--- array creation expression: */
+ | "["
+ (. ArrayCreateExpression ace = new ArrayCreateExpression(type);
+ /* we must not change RankSpecifier on the null type reference*/
+ if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); }
+ pexpr = ace;
+ int dims = 0; List<int> ranks = new List<int>();
+ .)
+ (
+ { "," (. dims += 1; .) }
+ "]" (. ranks.Add(dims); dims = 0; .)
+ { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) }
+ (. ace.CreateType.RankSpecifier = ranks.ToArray(); .)
+ CollectionInitializer<out expr> (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .)
+ | Expr<out expr> (. if (expr != null) parameters.Add(expr); .)
+ { "," (. dims += 1; .)
+ Expr<out expr> (. if (expr != null) parameters.Add(expr); .)
+ }
+ "]" (. ranks.Add(dims); ace.Arguments = parameters; dims = 0; .)
+ { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) }
+ (. ace.CreateType.RankSpecifier = ranks.ToArray(); .)
+ [ CollectionInitializer<out expr> (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) ]
+ )
+ )
+.
+
+/* Lambda expression with parameter list */
+LambdaExpression<out Expression outExpr>
+(.
+ LambdaExpression lambda = new LambdaExpression();
+ lambda.StartLocation = la.Location;
+ ParameterDeclarationExpression p;
+ outExpr = lambda;
+.)
+=
+ "("
+ [
+ LambdaExpressionParameter<out p> (. SafeAdd(lambda, lambda.Parameters, p); .)
+ { ","
+ LambdaExpressionParameter<out p> (. SafeAdd(lambda, lambda.Parameters, p); .)
+ }
+ ]
+ ")"
+ "=>"
+ LambdaExpressionBody<lambda>
+.
+
+ShortedLambdaExpression<IdentifierExpression ident, out Expression pexpr>
+(. LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; .)
+=
+ "=>"
+ /* not an IdentifierExpression, but a short lambda expression*/
+ (.
+ lambda.StartLocation = ident.StartLocation;
+ SafeAdd(lambda, lambda.Parameters, new ParameterDeclarationExpression(null, ident.Identifier));
+ lambda.Parameters[0].StartLocation = ident.StartLocation;
+ lambda.Parameters[0].EndLocation = ident.EndLocation;
+ .)
+ LambdaExpressionBody<lambda>
+.
+
+LambdaExpressionParameter<out ParameterDeclarationExpression p>
+(. Location start = la.Location; p = null;
+ TypeReference type;
+ ParameterModifiers mod = ParameterModifiers.In;
+.)
+=
+ ( IF (Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis)
+ Identifier
+ (. p = new ParameterDeclarationExpression(null, t.val);
+ p.StartLocation = start; p.EndLocation = t.EndLocation;
+ .)
+ | [ "ref" (. mod = ParameterModifiers.Ref; .)
+ | "out" (. mod = ParameterModifiers.Out; .)
+ ]
+ Type<out type>
+ Identifier
+ (. p = new ParameterDeclarationExpression(type, t.val, mod);
+ p.StartLocation = start; p.EndLocation = t.EndLocation;
+ .)
+ )
+.
+
+LambdaExpressionBody<LambdaExpression lambda>
+(. Expression expr; BlockStatement stmt; .)
+=
+ (
+ BlockInsideExpression<out stmt> (. lambda.StatementBody = stmt; .)
+ | Expr<out expr> (. lambda.ExpressionBody = expr; .)
+ )
+ (. lambda.EndLocation = t.EndLocation; .)
+ (. lambda.ExtendedEndLocation = la.Location; .)
+.
+
+AnonymousMethodExpr<out Expression outExpr>
+(.
+ AnonymousMethodExpression expr = new AnonymousMethodExpression();
+ expr.StartLocation = t.Location;
+ BlockStatement stmt;
+ List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
+ outExpr = expr;
+.)
+=
+ [
+ "("
+ [ FormalParameterList<p> (. expr.Parameters = p; .) ]
+ ")"
+ (. expr.HasParameterList = true; .)
+ ]
+ BlockInsideExpression<out stmt> (. expr.Body = stmt; .)
+ (. expr.EndLocation = t.Location; .)
+.
+
+BlockInsideExpression<out BlockStatement outStmt>
+(. Statement stmt = null; outStmt = null; .)
+=
+ /*--- ParseExpression doesn't set a compilation unit, */
+ /*--- so we can't use block then -> skip body of anonymous method */
+ (. if (compilationUnit != null) { .)
+ Block<out stmt> (. outStmt = (BlockStatement)stmt; .)
+ (. } else { .)
+ "{"
+ (. lexer.SkipCurrentBlock(0); .)
+ "}"
+ (. } .)
+.
+
+ConditionalOrExpr<ref Expression outExpr>
+(. Expression expr; .)
+=
+ ConditionalAndExpr<ref outExpr> { "||" UnaryExpr<out expr> ConditionalAndExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); .) }
+.
+
+ConditionalAndExpr<ref Expression outExpr>
+(. Expression expr; .)
+=
+ InclusiveOrExpr<ref outExpr> { "&&" UnaryExpr<out expr> InclusiveOrExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); .) }
+.
+
+InclusiveOrExpr<ref Expression outExpr>
+(. Expression expr; .)
+=
+ ExclusiveOrExpr<ref outExpr> { "|" UnaryExpr<out expr> ExclusiveOrExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); .) }
+.
+
+ExclusiveOrExpr<ref Expression outExpr>
+(. Expression expr; .)
+=
+ AndExpr<ref outExpr> { "^" UnaryExpr<out expr> AndExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); .) }
+.
+
+AndExpr<ref Expression outExpr>
+(. Expression expr; .)
+=
+ EqualityExpr<ref outExpr> { "&" UnaryExpr<out expr> EqualityExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); .) }
+.
+
+EqualityExpr<ref Expression outExpr>
+(.
+ Expression expr;
+ BinaryOperatorType op = BinaryOperatorType.None;
+.)
+=
+ RelationalExpr<ref outExpr>
+ {
+ (
+ "!=" (. op = BinaryOperatorType.InEquality; .)
+ | "==" (. op = BinaryOperatorType.Equality; .)
+ )
+ UnaryExpr<out expr> RelationalExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
+ }
+.
+
+RelationalExpr<ref Expression outExpr>
+(.
+ TypeReference type;
+ Expression expr;
+ BinaryOperatorType op = BinaryOperatorType.None;
+.)
+=
+ ShiftExpr<ref outExpr>
+ {
+ ( "<" (. op = BinaryOperatorType.LessThan; .)
+ | ">" (. op = BinaryOperatorType.GreaterThan; .)
+ | "<=" (. op = BinaryOperatorType.LessThanOrEqual; .)
+ | ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .)
+ )
+ UnaryExpr<out expr>
+ ShiftExpr<ref expr>
+ (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
+ |
+ ( "is"
+ TypeWithRestriction<out type, false, false>
+ [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind))
+ NullableQuestionMark<ref type> ]
+ (. outExpr = new TypeOfIsExpression(outExpr, type); .)
+ | "as"
+ TypeWithRestriction<out type, false, false>
+ [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind))
+ NullableQuestionMark<ref type> ]
+ (. outExpr = new CastExpression(type, outExpr, CastType.TryCast); .)
+ )
+ }
+.
+
+ShiftExpr<ref Expression outExpr>
+(.
+ Expression expr;
+ BinaryOperatorType op = BinaryOperatorType.None;
+.)
+=
+ AdditiveExpr<ref outExpr>
+ {
+ ( "<<" (. op = BinaryOperatorType.ShiftLeft; .)
+ | IF (IsShiftRight()) (
+ ">" ">" (. op = BinaryOperatorType.ShiftRight; .)
+ )
+ )
+ UnaryExpr<out expr> AdditiveExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
+ }
+.
+
+AdditiveExpr<ref Expression outExpr>
+(.
+ Expression expr;
+ BinaryOperatorType op = BinaryOperatorType.None;
+.)
+=
+ MultiplicativeExpr<ref outExpr>
+ {
+ (
+ "+" (. op = BinaryOperatorType.Add; .)
+ | "-" (. op = BinaryOperatorType.Subtract; .)
+ )
+ UnaryExpr<out expr> MultiplicativeExpr<ref expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
+ }
+.
+
+MultiplicativeExpr<ref Expression outExpr>
+(.
+ Expression expr;
+ BinaryOperatorType op = BinaryOperatorType.None;
+.)
+=
+ {
+ (
+ "*" (. op = BinaryOperatorType.Multiply; .)
+ | "/" (. op = BinaryOperatorType.Divide; .)
+ | "%" (. op = BinaryOperatorType.Modulus; .)
+ )
+ UnaryExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .)
+ }
+.
+
+/* .NET 2.0 rules */
+
+TypeName<out TypeReference typeRef, bool canBeUnbound>
+(. List<TypeReference> typeArguments = null;
+ string alias = null;
+ string qualident;
+ Location startLocation = la.Location;
+.)
+=
+ [ IF (IdentAndDoubleColon())
+ Identifier (. alias = t.val; .)
+ "::"
+ ]
+ Qualident<out qualident>
+ [TypeArgumentList<out typeArguments, canBeUnbound>]
+ (.
+ if (alias == null) {
+ typeRef = new TypeReference(qualident, typeArguments);
+ } else if (alias == "global") {
+ typeRef = new TypeReference(qualident, typeArguments);
+ typeRef.IsGlobal = true;
+ } else {
+ typeRef = new TypeReference(alias + "." + qualident, typeArguments);
+ }
+ .)
+ { IF (DotAndIdent())
+ "." (. typeArguments = null; .)
+ Qualident<out qualident>
+ [TypeArgumentList<out typeArguments, canBeUnbound>]
+ (. typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments); .)
+ }
+ (. typeRef.StartLocation = startLocation; .)
+.
+
+
+NullableQuestionMark<ref TypeReference typeRef>
+(. List<TypeReference> typeArguments = new List<TypeReference>(1); .)
+=
+ "?"
+ (.
+ if (typeRef != null) typeArguments.Add(typeRef);
+ typeRef = new TypeReference("System.Nullable", typeArguments) { IsKeyword = true };
+ .)
+.
+
+TypeArgumentList<out List<TypeReference> types, bool canBeUnbound>
+(.
+ types = new List<TypeReference>();
+ TypeReference type = null;
+.)
+=
+ "<"
+ ( IF (canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma))
+ (. types.Add(TypeReference.Null); .)
+ { "," (. types.Add(TypeReference.Null); .) }
+ | Type<out type> (. if (type != null) { types.Add(type); } .)
+ { "," Type<out type> (. if (type != null) { types.Add(type); } .) }
+ )
+ ">"
+.
+
+TypeParameterList<List<TemplateDefinition> templates>
+(.
+ AttributeSection section;
+ List<AttributeSection> attributes = new List<AttributeSection>();
+.)
+=
+ "<" { AttributeSection<out section> (. attributes.Add(section); .) }
+ Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)
+ { "," { AttributeSection<out section> (. attributes.Add(section); .) }
+ Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)}
+ ">"
+.
+
+TypeParameterConstraintsClause<List<TemplateDefinition> templates>
+(. string name = ""; TypeReference type; .)
+=
+ "where"
+ Identifier (. name = t.val; .)
+ ":"
+ TypeParameterConstraintsClauseBase<out type> (.
+ TemplateDefinition td = null;
+ foreach (TemplateDefinition d in templates) {
+ if (d.Name == name) {
+ td = d;
+ break;
+ }
+ }
+ if ( td != null && type != null) { td.Bases.Add(type); }
+ .)
+ { "," TypeParameterConstraintsClauseBase<out type> (.
+ td = null;
+ foreach (TemplateDefinition d in templates) {
+ if (d.Name == name) {
+ td = d;
+ break;
+ }
+ }
+ if ( td != null && type != null) { td.Bases.Add(type); }
+ .) }
+.
+
+TypeParameterConstraintsClauseBase<out TypeReference type>
+(. TypeReference t; type = null; .)
+=
+ "struct" (. type = TypeReference.StructConstraint; .)
+ | "class" (. type = TypeReference.ClassConstraint; .)
+ | "new" "(" ")" (. type = TypeReference.NewConstraint; .)
+ | Type<out t> (. type = t; .)
+.
+
+QueryExpression<out Expression outExpr>
+(. QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location;
+ QueryExpressionFromClause fromClause;
+.)
+=
+ QueryExpressionFromClause<out fromClause> (. q.FromClause = fromClause; .)
+ QueryExpressionBody<ref q>
+ (. q.EndLocation = t.EndLocation;
+ outExpr = q; /* set outExpr to q again if QueryExpressionBody changed it (can happen with 'into' clauses) */
+ .)
+.
+
+QueryExpressionFromClause<out QueryExpressionFromClause fc>
+(. fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location;
+.)
+=
+ "from"
+ QueryExpressionFromOrJoinClause<fc>
+ (. fc.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionJoinClause<out QueryExpressionJoinClause jc>
+(. jc = new QueryExpressionJoinClause(); jc.StartLocation = la.Location;
+ Expression expr;
+.)
+=
+ "join"
+ QueryExpressionFromOrJoinClause<jc>
+ "on"
+ Expr<out expr> (. jc.OnExpression = expr; .)
+ "equals"
+ Expr<out expr> (. jc.EqualsExpression = expr; .)
+ [ "into"
+ Identifier (. jc.IntoIdentifier = t.val; .)
+ ]
+ (. jc.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionFromOrJoinClause<QueryExpressionFromOrJoinClause fjc>
+(. TypeReference type; Expression expr; .)
+=
+ (. fjc.Type = null; .)
+ [ IF (IsLocalVarDecl()) Type<out type> (. fjc.Type = type; .) ]
+ Identifier (. fjc.Identifier = t.val; .)
+ "in"
+ Expr<out expr> (. fjc.InExpression = expr; .)
+.
+
+QueryExpressionBody<ref QueryExpression q>
+(. QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause;
+ QueryExpressionLetClause letClause; QueryExpressionJoinClause joinClause;
+ QueryExpressionOrderClause orderClause;
+ QueryExpressionSelectClause selectClause; QueryExpressionGroupClause groupClause;
+.)
+=
+ { ( QueryExpressionFromClause<out fromClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, fromClause); .)
+ | QueryExpressionWhereClause<out whereClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, whereClause); .)
+ | QueryExpressionLetClause<out letClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, letClause); .)
+ | QueryExpressionJoinClause<out joinClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, joinClause); .)
+ | QueryExpressionOrderByClause<out orderClause> (. SafeAdd<QueryExpressionClause>(q, q.MiddleClauses, orderClause); .)
+ ) }
+ ( QueryExpressionSelectClause<out selectClause> (. q.SelectOrGroupClause = selectClause; .)
+ | QueryExpressionGroupClause<out groupClause> (. q.SelectOrGroupClause = groupClause; .)
+ )
+ [ QueryExpressionIntoClause<ref q> ]
+.
+
+QueryExpressionWhereClause<out QueryExpressionWhereClause wc>
+(. Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location; .)
+=
+ "where"
+ Expr<out expr> (. wc.Condition = expr; .)
+ (. wc.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionLetClause<out QueryExpressionLetClause wc>
+(. Expression expr; wc = new QueryExpressionLetClause(); wc.StartLocation = la.Location; .)
+=
+ "let"
+ Identifier (. wc.Identifier = t.val; .)
+ "="
+ Expr<out expr> (. wc.Expression = expr; .)
+ (. wc.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionOrderByClause<out QueryExpressionOrderClause oc>
+(. QueryExpressionOrdering ordering; oc = new QueryExpressionOrderClause(); oc.StartLocation = la.Location; .)
+=
+ "orderby"
+ QueryExpressionOrdering<out ordering> (. SafeAdd(oc, oc.Orderings, ordering); .)
+ { ","
+ QueryExpressionOrdering<out ordering> (. SafeAdd(oc, oc.Orderings, ordering); .)
+ }
+ (. oc.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionOrdering<out QueryExpressionOrdering ordering>
+(. Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location; .)
+=
+ Expr<out expr> (. ordering.Criteria = expr; .)
+ [ "ascending" (. ordering.Direction = QueryExpressionOrderingDirection.Ascending; .)
+ | "descending" (. ordering.Direction = QueryExpressionOrderingDirection.Descending; .)
+ ]
+ (. ordering.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionSelectClause<out QueryExpressionSelectClause sc>
+(. Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location; .)
+=
+ "select"
+ Expr<out expr> (. sc.Projection = expr; .)
+ (. sc.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionGroupClause<out QueryExpressionGroupClause gc>
+(. Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; .)
+=
+ "group"
+ Expr<out expr> (. gc.Projection = expr; .)
+ "by"
+ Expr<out expr> (. gc.GroupBy = expr; .)
+ (. gc.EndLocation = t.EndLocation; .)
+.
+
+QueryExpressionIntoClause<ref QueryExpression q>
+(. QueryExpression firstQuery = q;
+ QueryExpression continuedQuery = new QueryExpression();
+ continuedQuery.StartLocation = q.StartLocation;
+ firstQuery.EndLocation = la.Location;
+ continuedQuery.FromClause = new QueryExpressionFromClause();
+ continuedQuery.FromClause.StartLocation = la.Location;
+ // nest firstQuery inside continuedQuery.
+ continuedQuery.FromClause.InExpression = firstQuery;
+ continuedQuery.IsQueryContinuation = true;
+ q = continuedQuery;
+.)
+=
+ "into"
+ Identifier (. continuedQuery.FromClause.Identifier = t.val; .)
+ (. continuedQuery.FromClause.EndLocation = t.EndLocation; .)
+ QueryExpressionBody<ref q>
+.
+
+/* allow usage of context sensitive keywords as identifiers */
+Identifier
+=
+/* when updating this list, ensure you also change KeywordList.IdentifierTokens*/
+ ident
+| "partial"
+| "where"
+| "get"
+| "set"
+| "add"
+| "remove"
+| "yield"
+| "select"
+| "group"
+| "by"
+| "into"
+| "from"
+| "ascending"
+| "descending"
+| "orderby"
+| "let"
+| "join"
+| "on"
+| "equals"
+.
+
+
+END CS.