Browse Source

Implemented SD2-446: Support skipping method bodies in VB Lexer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1586 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
64971ec421
  1. 1
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs
  2. 2
      src/Libraries/NRefactory/Project/NRefactory.csproj
  3. 19
      src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs
  4. 2
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  5. 4
      src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs
  6. 21
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  7. 11
      src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs
  8. 10
      src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs
  9. 2
      src/Libraries/NRefactory/Project/Src/Parser/AbstractParser.cs
  10. 506
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
  11. 2591
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  12. 536
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  13. 40
      src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame
  14. 36
      src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame.new
  15. 40
      src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame.old
  16. 2424
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  17. 344
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  18. 269
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs
  19. 8
      src/Libraries/NRefactory/Test/Lexer/CSharp/CustomLexerTests.cs
  20. 16
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs

1
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs

@ -101,6 +101,7 @@ namespace VBNetBinding.Parser @@ -101,6 +101,7 @@ namespace VBNetBinding.Parser
ICompilationUnit Parse(ICSharpCode.NRefactory.Parser.IParser p, string fileName, IProjectContent projectContent)
{
p.Lexer.SpecialCommentTags = lexerTags;
p.ParseMethodBodies = false;
p.Parse();
NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(projectContent);

2
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -127,6 +127,8 @@ @@ -127,6 +127,8 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Src\Parser\Location.cs" />
<Compile Include="Src\Parser\CSharp\CSharpParser.cs" />
<Compile Include="Src\Parser\VBNet\VBNetParser.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Src\Lexer\CSharp\KeywordList.txt" />

19
src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs

@ -201,17 +201,6 @@ namespace ICSharpCode.NRefactory.Parser @@ -201,17 +201,6 @@ namespace ICSharpCode.NRefactory.Parser
protected abstract Token Next();
/// <summary>
/// Skips to the end of the current code block.
/// For this, the lexer must have read the next token AFTER the token opening the
/// block (so that Lexer.Token is the block-opening token, not Lexer.LookAhead).
/// After the call, Lexer.LookAhead will be the block-closing token.
/// </summary>
public virtual void SkipCurrentBlock()
{
throw new NotSupportedException();
}
protected bool IsIdentifierPart(int ch)
{
if (ch == 95) return true; // 95 = '_'
@ -293,5 +282,13 @@ namespace ICSharpCode.NRefactory.Parser @@ -293,5 +282,13 @@ namespace ICSharpCode.NRefactory.Parser
col += retStr.Length;
return retStr;
}
/// <summary>
/// Skips to the end of the current code block.
/// For this, the lexer must have read the next token AFTER the token opening the
/// block (so that Lexer.Token is the block-opening token, not Lexer.LookAhead).
/// After the call, Lexer.LookAhead will be the block-closing token.
/// </summary>
public abstract void SkipCurrentBlock(int targetToken);
}
}

2
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs

@ -800,7 +800,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -800,7 +800,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
/// block (so that Lexer.Token is the block-opening token, not Lexer.LookAhead).
/// After the call, Lexer.LookAhead will be the block-closing token.
/// </summary>
public override void SkipCurrentBlock()
public override void SkipCurrentBlock(int targetToken)
{
int braceCount = 0;
while (curToken != null) {

4
src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs

@ -76,12 +76,12 @@ namespace ICSharpCode.NRefactory.Parser @@ -76,12 +76,12 @@ namespace ICSharpCode.NRefactory.Parser
/// <returns>An <see cref="Token"/> object.</returns>
Token NextToken();
/// <summary>
/// <summary>
/// Skips to the end of the current code block.
/// For this, the lexer must have read the next token AFTER the token opening the
/// block (so that Lexer.Token is the block-opening token, not Lexer.LookAhead).
/// After the call, Lexer.LookAhead will be the block-closing token.
/// </summary>
void SkipCurrentBlock();
void SkipCurrentBlock(int targetToken);
}
}

21
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
{
internal class Lexer : AbstractLexer
{
bool lineEnd = false;
bool lineEnd = true;
public Lexer(TextReader reader) : base(reader)
{
@ -61,7 +61,11 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -61,7 +61,11 @@ namespace ICSharpCode.NRefactory.Parser.VB
int x = Col - 1;
int y = Line;
if (HandleLineEnd(ch)) {
if (!lineEnd) {
if (lineEnd) {
// second line end before getting to a token
// -> here was a blank line
specialTracker.AddEndOfLine(new Location(x, y));
} else {
lineEnd = true;
return new Token(Tokens.EOL, x, y);
}
@ -707,5 +711,18 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -707,5 +711,18 @@ namespace ICSharpCode.NRefactory.Parser.VB
}
return null;
}
public override void SkipCurrentBlock(int targetToken)
{
int lastKind = -1;
int kind = base.lastToken.kind;
while (kind != Tokens.EOF &&
!(lastKind == Tokens.End && kind == targetToken))
{
lastKind = kind;
NextToken();
kind = lastToken.kind;
}
}
}
}

11
src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs

@ -152,6 +152,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -152,6 +152,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
/// <summary>
/// Prints a text that cannot be inserted before using WriteInPreviousLine
/// into the current line
/// </summary>
protected void PrintSpecialText(string specialText)
{
lineBeforeLastStart = text.Length;
text.Append(specialText);
lastLineStart = text.Length;
}
public void PrintTokenList(ArrayList tokenList)
{
foreach (int token in tokenList) {

10
src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs

@ -118,13 +118,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -118,13 +118,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
switch (comment.CommentType) {
case CommentType.Block:
// if (forceWriteInPreviousBlock) {
if (forceWriteInPreviousBlock) {
WriteInPreviousLine("/*" + comment.CommentText + "*/", forceWriteInPreviousBlock);
// } else {
// PrintText("/*");
// PrintText(comment.CommentText);
// PrintText("*/");
// }
} else {
PrintSpecialText("/*" + comment.CommentText + "*/");
}
break;
case CommentType.Documentation:
WriteLineInPreviousLine("///" + comment.CommentText, forceWriteInPreviousBlock);

2
src/Libraries/NRefactory/Project/Src/Parser/AbstractParser.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -19,7 +19,7 @@ namespace ICSharpCode.NRefactory.Parser
protected const string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
protected Errors errors;
protected ILexer lexer;
private ILexer lexer;
protected int errDist = minErrDist;

506
src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs

@ -0,0 +1,506 @@ @@ -0,0 +1,506 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 16.07.2006
* Time: 15:55
*/
using System;
using System.Text;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.Parser.CSharp
{
internal sealed partial class Parser : AbstractParser
{
Lexer lexer;
public Parser(ILexer lexer) : base(lexer)
{
this.lexer = (Lexer)lexer;
}
string assemblyName = null;
StringBuilder qualidentBuilder = new StringBuilder();
public string ContainingAssembly {
set {
assemblyName = value;
}
}
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) {
errors.Error(la.line, la.col, s);
}
errDist = 0;
}
public override Expression ParseExpression()
{
lexer.NextToken();
Expression expr;
Expr(out expr);
return expr;
}
// Begin ISTypeCast
bool IsTypeCast()
{
if (la.kind != Tokens.OpenParenthesis) {
return false;
}
if (IsSimpleTypeCast()) {
return true;
}
return GuessTypeCast();
}
// "(" ( typeKW [ "[" {","} "]" | "*" ] | void ( "[" {","} "]" | "*" ) ) ")"
// only for built-in types, all others use GuessTypeCast!
bool IsSimpleTypeCast ()
{
// assert: la.kind == _lpar
lexer.StartPeek();
Token pt = lexer.Peek();
if (!IsTypeKWForTypeCast(ref pt)) {
return false;
}
if (pt.kind == Tokens.Question)
pt = lexer.Peek();
return pt.kind == Tokens.CloseParenthesis;
}
/* !!! 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)
{
if (IsTypeKWForTypeCast(ref pt))
return true;
else
return IsTypeNameForTypeCast(ref pt);
}
// TypeName = ident [ "::" ident ] { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident } ["?"] PointerOrDims
/* !!! Proceeds from current peek position !!! */
bool IsTypeNameForTypeCast(ref Token pt)
{
// ident
if (pt.kind != Tokens.Identifier) {
return false;
}
pt = Peek();
// "::" ident
if (pt.kind == Tokens.DoubleColon) {
pt = Peek();
if (pt.kind != Tokens.Identifier) {
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) {
return IsPointerOrDims(ref pt);
}
return true;
}
// "(" TypeName ")" castFollower
bool GuessTypeCast ()
{
// assert: la.kind == _lpar
StartPeek();
Token pt = Peek();
if (!IsTypeNameForTypeCast(ref pt)) {
return false;
}
// ")"
if (pt.kind != Tokens.CloseParenthesis) {
return false;
}
// check successor
pt = Peek();
return Tokens.CastFollower[pt.kind] || (Tokens.TypeKW[pt.kind] && lexer.Peek().kind == Tokens.Dot);
}
// END IsTypeCast
/* 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 (pt.kind == Tokens.Identifier) {
qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val);
pt = Peek();
while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) {
pt = Peek();
if (pt.kind != Tokens.Identifier) {
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 la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Assign;
}
bool IsAssignment () { return IdentAndAsgn(); }
/* True, if ident is followed by ",", "=", or ";" */
bool IdentAndCommaOrAsgnOrSColon () {
int peek = Peek(1).kind;
return la.kind == Tokens.Identifier &&
(peek == Tokens.Comma || peek == Tokens.Assign || peek == Tokens.Semicolon);
}
bool IsVarDecl () { return IdentAndCommaOrAsgnOrSColon(); }
/* 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 && Peek(1).kind == Tokens.Identifier;
}
/* True, if ident is followed by ":" */
bool IdentAndColon () {
return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Colon;
}
bool IsLabel () { return IdentAndColon(); }
/* True, if ident is followed by "(" */
bool IdentAndLPar () {
return la.kind == Tokens.Identifier && 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 &&
pt.kind == Tokens.Identifier && pt.val == "assembly";
}
/* True, if "[" is followed by "," or "]" */
bool LBrackAndCommaOrRBrack () {
int peek = Peek(1).kind;
return la.kind == Tokens.OpenSquareBracket &&
(peek == Tokens.Comma || peek == Tokens.CloseSquareBracket);
}
bool IsDims () { return LBrackAndCommaOrRBrack(); }
/* 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) && pt.kind == Tokens.Identifier;
}
/* True if lookahead is type parameters (<...>) followed by the specified token */
bool IsGenericFollowedBy(int token)
{
Token t = la;
if (t.kind != Tokens.LessThan) return false;
StartPeek();
return SkipGeneric(ref t) && t.kind == token;
}
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 "where" */
bool IdentIsWhere () {
return la.kind == Tokens.Identifier && la.val == "where";
}
/* True, if lookahead ident is "get" */
bool IdentIsGet () {
return la.kind == Tokens.Identifier && la.val == "get";
}
/* True, if lookahead ident is "set" */
bool IdentIsSet () {
return la.kind == Tokens.Identifier && la.val == "set";
}
/* True, if lookahead ident is "add" */
bool IdentIsAdd () {
return la.kind == Tokens.Identifier && la.val == "add";
}
/* True, if lookahead ident is "remove" */
bool IdentIsRemove () {
return la.kind == Tokens.Identifier && la.val == "remove";
}
bool IsNotYieldStatement () {
return !IsYieldStatement();
}
/* True, if lookahead ident is "yield" and than follows a break or return */
bool IsYieldStatement () {
return la.kind == Tokens.Identifier && la.val == "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 ||
(cur == Tokens.Identifier &&
(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 IsTypeReferenceExpression(Expression expr)
{
if (expr is TypeReferenceExpression) return ((TypeReferenceExpression)expr).TypeReference.GenericTypes.Count == 0;
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
if (expr is TypeReferenceExpression) return true;
}
return expr is IdentifierExpression;
}
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
b.Append(fre.FieldName);
return result;
} else if (expr is IdentifierExpression) {
b.Append(((IdentifierExpression)expr).Identifier);
return true;
} else {
return false;
}
}
}
}

2591
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

536
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -9,488 +9,6 @@ using Types = ICSharpCode.NRefactory.Parser.AST.ClassType; @@ -9,488 +9,6 @@ using Types = ICSharpCode.NRefactory.Parser.AST.ClassType;
COMPILER CS /* AW 2002-12-30 renamed from CompilationUnit to CS */
/*----------------------------- token sets -------------------------------*/
string assemblyName = null;
StringBuilder qualidentBuilder = new StringBuilder();
public string ContainingAssembly {
set {
assemblyName = value;
}
}
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) {
errors.Error(la.line, la.col, s);
}
errDist = 0;
}
public override Expression ParseExpression()
{
lexer.NextToken();
Expression expr;
Expr(out expr);
return expr;
}
// Begin ISTypeCast
bool IsTypeCast()
{
if (la.kind != Tokens.OpenParenthesis) {
return false;
}
if (IsSimpleTypeCast()) {
return true;
}
return GuessTypeCast();
}
// "(" ( typeKW [ "[" {","} "]" | "*" ] | void ( "[" {","} "]" | "*" ) ) ")"
// only for built-in types, all others use GuessTypeCast!
bool IsSimpleTypeCast ()
{
// assert: la.kind == _lpar
lexer.StartPeek();
Token pt = lexer.Peek();
if (!IsTypeKWForTypeCast(ref pt)) {
return false;
}
if (pt.kind == Tokens.Question)
pt = lexer.Peek();
return pt.kind == Tokens.CloseParenthesis;
}
/* !!! 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)
{
if (IsTypeKWForTypeCast(ref pt))
return true;
else
return IsTypeNameForTypeCast(ref pt);
}
// TypeName = ident [ "::" ident ] { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident } ["?"] PointerOrDims
/* !!! Proceeds from current peek position !!! */
bool IsTypeNameForTypeCast(ref Token pt)
{
// ident
if (pt.kind != Tokens.Identifier) {
return false;
}
pt = Peek();
// "::" ident
if (pt.kind == Tokens.DoubleColon) {
pt = Peek();
if (pt.kind != Tokens.Identifier) {
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) {
return IsPointerOrDims(ref pt);
}
return true;
}
// "(" TypeName ")" castFollower
bool GuessTypeCast ()
{
// assert: la.kind == _lpar
StartPeek();
Token pt = Peek();
if (!IsTypeNameForTypeCast(ref pt)) {
return false;
}
// ")"
if (pt.kind != Tokens.CloseParenthesis) {
return false;
}
// check successor
pt = Peek();
return Tokens.CastFollower[pt.kind] || (Tokens.TypeKW[pt.kind] && lexer.Peek().kind == Tokens.Dot);
}
// END IsTypeCast
/* 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 (pt.kind == Tokens.Identifier) {
qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val);
pt = Peek();
while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) {
pt = Peek();
if (pt.kind != Tokens.Identifier) {
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 la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Assign;
}
bool IsAssignment () { return IdentAndAsgn(); }
/* True, if ident is followed by ",", "=", or ";" */
bool IdentAndCommaOrAsgnOrSColon () {
int peek = Peek(1).kind;
return la.kind == Tokens.Identifier &&
(peek == Tokens.Comma || peek == Tokens.Assign || peek == Tokens.Semicolon);
}
bool IsVarDecl () { return IdentAndCommaOrAsgnOrSColon(); }
/* 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 && Peek(1).kind == Tokens.Identifier;
}
/* True, if ident is followed by ":" */
bool IdentAndColon () {
return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Colon;
}
bool IsLabel () { return IdentAndColon(); }
/* True, if ident is followed by "(" */
bool IdentAndLPar () {
return la.kind == Tokens.Identifier && 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 &&
pt.kind == Tokens.Identifier && pt.val == "assembly";
}
/* True, if "[" is followed by "," or "]" */
bool LBrackAndCommaOrRBrack () {
int peek = Peek(1).kind;
return la.kind == Tokens.OpenSquareBracket &&
(peek == Tokens.Comma || peek == Tokens.CloseSquareBracket);
}
bool IsDims () { return LBrackAndCommaOrRBrack(); }
/* 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) && pt.kind == Tokens.Identifier;
}
/* True if lookahead is type parameters (<...>) followed by the specified token */
bool IsGenericFollowedBy(int token)
{
Token t = la;
if (t.kind != Tokens.LessThan) return false;
StartPeek();
return SkipGeneric(ref t) && t.kind == token;
}
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 "where" */
bool IdentIsWhere () {
return la.kind == Tokens.Identifier && la.val == "where";
}
/* True, if lookahead ident is "get" */
bool IdentIsGet () {
return la.kind == Tokens.Identifier && la.val == "get";
}
/* True, if lookahead ident is "set" */
bool IdentIsSet () {
return la.kind == Tokens.Identifier && la.val == "set";
}
/* True, if lookahead ident is "add" */
bool IdentIsAdd () {
return la.kind == Tokens.Identifier && la.val == "add";
}
/* True, if lookahead ident is "remove" */
bool IdentIsRemove () {
return la.kind == Tokens.Identifier && la.val == "remove";
}
bool IsNotYieldStatement () {
return !IsYieldStatement();
}
/* True, if lookahead ident is "yield" and than follows a break or return */
bool IsYieldStatement () {
return la.kind == Tokens.Identifier && la.val == "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 ||
(cur == Tokens.Identifier &&
(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 IsTypeReferenceExpression(Expression expr)
{
if (expr is TypeReferenceExpression) return ((TypeReferenceExpression)expr).TypeReference.GenericTypes.Count == 0;
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
if (expr is TypeReferenceExpression) return true;
}
return expr is IdentifierExpression;
}
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
b.Append(fre.FieldName);
return result;
} else if (expr is IdentifierExpression) {
b.Append(((IdentifierExpression)expr).Identifier);
return true;
} else {
return false;
}
}
/*------------------------------------------------------------------------*
*----- LEXER TOKEN LIST ------------------------------------------------*
@ -652,7 +170,7 @@ UsingDirective @@ -652,7 +170,7 @@ UsingDirective
string qualident = null; TypeReference aliasedType = null;
.)
=
"using" (. Point startPos = t.Location; .)
"using" (. Location startPos = t.Location; .)
Qualident<out qualident>
[ "=" NonArrayType<out aliasedType> ]
";" (.
@ -672,7 +190,7 @@ UsingDirective @@ -672,7 +190,7 @@ UsingDirective
GlobalAttributeSection
=
"[" (. Point startPos = t.Location; .) ident
"[" (. Location startPos = t.Location; .) ident
(. if (t.val != "assembly") Error("global attribute target specifier (\"assembly\") expected");
string attributeTarget = t.val;
List<ASTAttribute> attributes = new List<ASTAttribute>();
@ -747,7 +265,7 @@ AttributeSection<out AttributeSection section> @@ -747,7 +265,7 @@ AttributeSection<out AttributeSection section>
.)
=
"[" (. Point startPos = t.Location; .) /*--- attribute target specifier: */
"[" (. Location startPos = t.Location; .) /*--- attribute target specifier: */
[ IF (IsLocalAttrTarget())
( "event" (. attributeTarget = "event";.)
| "return" (. attributeTarget = "return";.)
@ -778,7 +296,7 @@ NamespaceMemberDecl @@ -778,7 +296,7 @@ NamespaceMemberDecl
string qualident;
.)
= /*--- namespace declaration: */
"namespace" (. Point startPos = t.Location; .)
"namespace" (. Location startPos = t.Location; .)
Qualident<out qualident> (. INode node = new NamespaceDeclaration(qualident);
node.StartLocation = startPos;
compilationUnit.AddChild(node);
@ -1189,7 +707,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1189,7 +707,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
.)
=
/*--- constant declaration: */ (. m.Check(Modifier.Constants); .)
"const" (.Point startPos = t.Location; .)
"const" (.Location startPos = t.Location; .)
Type<out type> ident (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifier.Const);
fd.StartLocation = m.GetDeclarationLocation(startPos);
VariableDeclaration f = new VariableDeclaration(t.val);
@ -1205,7 +723,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1205,7 +723,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
| /*--- void method (procedure) declaration: */
IF (NotVoidPointer()) (. m.Check(Modifier.PropertysEventsMethods); .)
"void" (. Point startPos = t.Location; .)
"void" (. Location startPos = t.Location; .)
( IF (IsExplicitInterfaceImplementation())
TypeName<out explicitInterface, false>
(.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
@ -1268,7 +786,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1268,7 +786,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
| /*--- constructor or static contructor declaration: */
IF (IdentAndLPar()) (. m.Check(Modifier.Constructors | Modifier.StaticConstructors); .)
ident (. string name = t.val; Point startPos = t.Location; .) "(" [ (. m.Check(Modifier.Constructors); .)
ident (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifier.Constructors); .)
FormalParameterList<p>
]
")" (.ConstructorInitializer init = null; .)
@ -1286,12 +804,12 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1286,12 +804,12 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
| /*--- conversion operator declaration: */ (. m.Check(Modifier.Operators);
if (m.isNone) Error("at least one modifier must be set");
bool isImplicit = true;
Point startPos = Point.Empty;
Location startPos = Location.Empty;
.)
( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) )
"operator" Type<out type> (. TypeReference operatorType = type; .)
"(" Type<out type> ident (. string varName = t.val; .) ")"
(. Point endPos = t.Location; .)
(. Location endPos = t.Location; .)
( Block<out stmt> | ";" (. stmt = null; .) )
(.
@ -1313,7 +831,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1313,7 +831,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
| /*--- inner type declaration: */
TypeDecl<m, attributes>
| Type<out type> (. Point startPos = t.Location; .)
| Type<out type> (. Location startPos = t.Location; .)
(
/*--- operator declaration: */ (. OverloadableOperatorType op;
m.Check(Modifier.Operators);
@ -1329,7 +847,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1329,7 +847,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
}
.)*/
)
(. Point endPos = t.Location; .)
(. Location endPos = t.Location; .)
")" ( Block<out stmt> | ";" )
(.
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
@ -1359,7 +877,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1359,7 +877,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
/*--- unqualified indexer declaration (without interface name): */
| (. m.Check(Modifier.Indexers); .)
"this" "[" FormalParameterList<p> "]" (. Point endLocation = t.EndLocation; .) "{" (.
"this" "[" FormalParameterList<p> "]" (. Location endLocation = t.EndLocation; .) "{" (.
IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
indexer.StartLocation = startPos;
indexer.EndLocation = endLocation;
@ -1381,7 +899,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1381,7 +899,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
} .)
| ident (. qualident = t.val; .)
)
(. Point qualIdentEndLocation = t.EndLocation; .)
(. Location qualIdentEndLocation = t.EndLocation; .)
(
/*--- "not void" method (function) declaration: */
@ -1434,7 +952,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1434,7 +952,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
"{" (. Point bodyStart = t.Location; .)
"{" (. Location bodyStart = t.Location; .)
AccessorDecls<out getRegion, out setRegion>
"}" (. indexer.BodyStart = bodyStart;
indexer.BodyEnd = t.EndLocation;
@ -1450,7 +968,7 @@ ClassMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1450,7 +968,7 @@ ClassMemberDecl<Modifiers m, List<AttributeSection> attributes>
(. Statement stmt = null; .)
=
StructMemberDecl<m, attributes>
| /*--- destructor declaration: */ (. m.Check(Modifier.Destructors); Point startPos = t.Location; .)
| /*--- destructor declaration: */ (. m.Check(Modifier.Destructors); Location startPos = t.Location; .)
"~" ident (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes);
d.Modifier = m.Modifier;
d.StartLocation = m.GetDeclarationLocation(startPos);
@ -1472,7 +990,7 @@ InterfaceMemberDecl @@ -1472,7 +990,7 @@ InterfaceMemberDecl
string name;
PropertyGetRegion getBlock;
PropertySetRegion setBlock;
Point startLocation = new Point(-1, -1);
Location startLocation = new Location(-1, -1);
List<TemplateDefinition> templates = new List<TemplateDefinition>();
.)
=
@ -1494,7 +1012,7 @@ InterfaceMemberDecl @@ -1494,7 +1012,7 @@ InterfaceMemberDecl
| (
Type<out type> (. if (startLocation.X == -1) startLocation = t.Location; .)
(
ident (. name = t.val; Point qualIdentEndLocation = t.EndLocation; .)
ident (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .)
(
/*--- interface "not void" method (function) declaration: */
/* .NET 2.0 */
@ -1510,11 +1028,11 @@ InterfaceMemberDecl @@ -1510,11 +1028,11 @@ InterfaceMemberDecl
.)
/*--- interface property declaration: */
| (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); .)
"{" (. Point 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; .)
"{" (. 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> "]" (.Point bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); .)
"{" (. Point 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;.)
| "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.X == -1) startLocation = t.Location; .) Type<out type> ident (. EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes, null);
@ -1582,7 +1100,7 @@ GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attribute @@ -1582,7 +1100,7 @@ GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attribute
=
ident /* "get" is not a keyword! */
(. if (t.val != "get") Error("get expected"); .)
(. Point startLocation = t.Location; .)
(. Location startLocation = t.Location; .)
( Block<out stmt> | ";" )
(. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
(. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .)
@ -1593,7 +1111,7 @@ SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attribute @@ -1593,7 +1111,7 @@ SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attribute
=
ident /* "set" is not a keyword! */
(. if (t.val != "set") Error("set expected"); .)
(. Point startLocation = t.Location; .)
(. Location startLocation = t.Location; .)
( Block<out stmt> | ";" )
(. setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); .)
(. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .)
@ -1630,7 +1148,7 @@ InterfaceAccessors<out PropertyGetRegion getBlock, out PropertySetRegion setBloc @@ -1630,7 +1148,7 @@ InterfaceAccessors<out PropertyGetRegion getBlock, out PropertySetRegion setBloc
.)
=
{ AttributeSection<out section> (. attributes.Add(section); .) }
(. Point startLocation = la.Location; .)
(. Location startLocation = la.Location; .)
(
IF (IdentIsGet()) ident (. getBlock = new PropertyGetRegion(null, attributes); .)
| IF (IdentIsSet()) ident (. setBlock = new PropertySetRegion(null, attributes); .)
@ -1669,7 +1187,7 @@ Block<out Statement stmt> /* not BlockStatement because of EmbeddedStatement */ @@ -1669,7 +1187,7 @@ Block<out Statement stmt> /* not BlockStatement because of EmbeddedStatement */
"{" (. BlockStatement blockStmt = new BlockStatement();
blockStmt.StartLocation = t.EndLocation;
compilationUnit.BlockStart(blockStmt);
if (!parseMethodContents) lexer.SkipCurrentBlock();
if (!parseMethodContents) lexer.SkipCurrentBlock(0);
.)
{ Statement }
"}" (.
@ -1828,7 +1346,7 @@ Statement @@ -1828,7 +1346,7 @@ Statement
TypeReference type;
Expression expr;
Statement stmt = null;
Point startPos = la.Location;
Location startPos = la.Location;
.)
=
(
@ -1900,7 +1418,7 @@ EmbeddedStatement<out Statement statement> @@ -1900,7 +1418,7 @@ EmbeddedStatement<out Statement statement>
[ Expr<out expr> ] ";"
[ ForIterator<out iterator> ] ")"
EmbeddedStatement<out embeddedStatement> (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .)
| "foreach" "(" Type<out type> ident (. string varName = t.val; Point start = t.Location;.)
| "foreach" "(" Type<out type> ident (. string varName = t.val; Location start = t.Location;.)
"in" Expr<out expr> ")"
EmbeddedStatement<out embeddedStatement> (. statement = new ForeachStatement(type, varName , expr, embeddedStatement);
statement.EndLocation = t.EndLocation;
@ -2281,7 +1799,7 @@ AnonymousMethodExpr<out Expression outExpr> @@ -2281,7 +1799,7 @@ AnonymousMethodExpr<out Expression outExpr>
Block<out stmt> (. expr.Body = (BlockStatement)stmt; .)
(. } else { .)
"{"
(. lexer.SkipCurrentBlock(); .)
(. lexer.SkipCurrentBlock(0); .)
"}"
(. } .)
(. expr.EndLocation = t.Location; .)

40
src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame

@ -8,7 +8,7 @@ using System.Reflection; @@ -8,7 +8,7 @@ using System.Reflection;
-->tokens
internal class Parser : AbstractParser
partial class Parser : AbstractParser
{
-->constants
const bool T = true;
@ -21,48 +21,12 @@ internal class Parser : AbstractParser @@ -21,48 +21,12 @@ internal class Parser : AbstractParser
*/
-->productions
public Parser(ILexer lexer) : base(lexer)
{
}
public override void Parse()
{
-->parseRoot
}
protected void ExpectWeak(int n, int follow)
{
if (lexer.LookAhead.kind == n) {
lexer.NextToken();
} else {
SynErr(n);
while (!StartOf(follow)) {
lexer.NextToken();
}
}
}
protected bool WeakSeparator(int n, int syFol, int repFol)
{
bool[] s = new bool[maxT + 1];
if (lexer.LookAhead.kind == n) {
lexer.NextToken();
return true;
} else if (StartOf(repFol)) {
return false;
} else {
for (int i = 0; i <= maxT; i++) {
s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
}
SynErr(n);
while (!s[lexer.LookAhead.kind]) {
lexer.NextToken();
}
return StartOf(syFol);
}
}
protected override void SynErr(int line, int col, int errorNumber)
{
errors.count++;
@ -74,7 +38,7 @@ internal class Parser : AbstractParser @@ -74,7 +38,7 @@ internal class Parser : AbstractParser
errors.Error(line, col, s);
}
protected bool StartOf(int s)
private bool StartOf(int s)
{
return set[s, lexer.LookAhead.kind];
}

36
src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame.new

@ -30,41 +30,7 @@ internal class Parser : AbstractParser @@ -30,41 +30,7 @@ internal class Parser : AbstractParser
-->parseRoot
}
protected void ExpectWeak(int n, int follow)
{
if (lexer.LookAhead.kind == n) {
lexer.NextToken();
} else {
SynErr(n);
while (!StartOf(follow)) {
lexer.NextToken();
}
}
}
protected bool WeakSeparator(int n, int syFol, int repFol)
{
bool[] s = new bool[maxT + 1];
if (lexer.LookAhead.kind == n) {
lexer.NextToken();
return true;
} else if (StartOf(repFol)) {
return false;
} else {
for (int i = 0; i <= maxT; i++) {
s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
}
SynErr(n);
while (!s[lexer.LookAhead.kind]) {
lexer.NextToken();
}
return StartOf(syFol);
}
}
protected bool StartOf(int s)
private bool StartOf(int s)
{
return set[s, lexer.LookAhead.kind];
}

40
src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame.old

@ -8,7 +8,7 @@ using System.Reflection; @@ -8,7 +8,7 @@ using System.Reflection;
-->tokens
internal class Parser : AbstractParser
partial class Parser : AbstractParser
{
-->constants
const bool T = true;
@ -21,48 +21,12 @@ internal class Parser : AbstractParser @@ -21,48 +21,12 @@ internal class Parser : AbstractParser
*/
-->productions
public Parser(ILexer lexer) : base(lexer)
{
}
public override void Parse()
{
-->parseRoot
}
protected void ExpectWeak(int n, int follow)
{
if (lexer.LookAhead.kind == n) {
lexer.NextToken();
} else {
SynErr(n);
while (!StartOf(follow)) {
lexer.NextToken();
}
}
}
protected bool WeakSeparator(int n, int syFol, int repFol)
{
bool[] s = new bool[maxT + 1];
if (lexer.LookAhead.kind == n) {
lexer.NextToken();
return true;
} else if (StartOf(repFol)) {
return false;
} else {
for (int i = 0; i <= maxT; i++) {
s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
}
SynErr(n);
while (!s[lexer.LookAhead.kind]) {
lexer.NextToken();
}
return StartOf(syFol);
}
}
protected override void SynErr(int line, int col, int errorNumber)
{
errors.count++;
@ -74,7 +38,7 @@ internal class Parser : AbstractParser @@ -74,7 +38,7 @@ internal class Parser : AbstractParser
errors.Error(line, col, s);
}
protected bool StartOf(int s)
private bool StartOf(int s)
{
return set[s, lexer.LookAhead.kind];
}

2424
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

344
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -8,252 +8,6 @@ using ASTAttribute = ICSharpCode.NRefactory.Parser.AST.Attribute; @@ -8,252 +8,6 @@ using ASTAttribute = ICSharpCode.NRefactory.Parser.AST.Attribute;
COMPILER VBNET
private Stack withStatements;
private StringBuilder qualidentBuilder = new StringBuilder();
Token t
{
[System.Diagnostics.DebuggerStepThrough]
get {
return lexer.Token;
}
}
Token la
{
[System.Diagnostics.DebuggerStepThrough]
get {
return lexer.LookAhead;
}
}
/* Return the n-th token after the current lookahead token */
void StartPeek()
{
lexer.StartPeek();
}
Token Peek()
{
return lexer.Peek();
}
Token Peek (int n)
{
lexer.StartPeek();
Token x = la;
while (n > 0) {
x = lexer.Peek();
n--;
}
return x;
}
public void Error(string s)
{
if (errDist >= minErrDist) {
errors.Error(la.line, la.col, s);
}
errDist = 0;
}
public override Expression ParseExpression()
{
lexer.NextToken();
Expression expr;
Expr(out expr);
return expr;
}
bool LeaveBlock()
{
int peek = Peek(1).kind;
return Tokens.BlockSucc[la.kind] && (la.kind != Tokens.End || peek == Tokens.EOL || peek == Tokens.Colon);
}
/* True, if "." is followed by an ident */
bool DotAndIdentOrKw () {
int peek = Peek(1).kind;
return la.kind == Tokens.Dot && (peek == Tokens.Identifier || peek >= Tokens.AddHandler);
}
bool IsEndStmtAhead()
{
int peek = Peek(1).kind;
return la.kind == Tokens.End && (peek == Tokens.EOL || peek == Tokens.Colon);
}
bool IsNotClosingParenthesis() {
return la.kind != Tokens.CloseParenthesis;
}
/*
True, if ident is followed by "="
*/
bool IdentAndAsgn () {
if(la.kind == Tokens.Identifier) {
if(Peek(1).kind == Tokens.Assign) return true;
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
}
return false;
}
/*
True, if ident is followed by "=" or by ":" and "="
*/
bool IsNamedAssign() {
// if(Peek(1).kind == Tokens.Assign) return true; // removed: not in the lang spec
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
return false;
}
bool IsObjectCreation() {
return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
}
/*
True, if "<" is followed by the ident "assembly" or "module"
*/
bool IsGlobalAttrTarget () {
Token pt = Peek(1);
return la.kind == Tokens.LessThan && ( string.Equals(pt.val, "assembly", StringComparison.InvariantCultureIgnoreCase) || string.Equals(pt.val, "module", StringComparison.InvariantCultureIgnoreCase));
}
/*
True if the next token is a "(" and is followed by "," or ")"
*/
bool IsDims()
{
int peek = Peek(1).kind;
return la.kind == Tokens.OpenParenthesis
&& (peek == Tokens.Comma || peek == Tokens.CloseParenthesis);
}
bool IsSize()
{
return la.kind == Tokens.OpenParenthesis;
}
/*
True, if the comma is not a trailing one,
like the last one in: a, b, c,
*/
bool NotFinalComma() {
int peek = Peek(1).kind;
return la.kind == Tokens.Comma &&
peek != Tokens.CloseCurlyBrace;
}
/*
True, if the next token is "Else" and this one
if followed by "If"
*/
bool IsElseIf()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Else && peek == Tokens.If;
}
/*
True if the next token is goto and this one is
followed by minus ("-") (this is allowd in in
error clauses)
*/
bool IsNegativeLabelName()
{
int peek = Peek(1).kind;
return la.kind == Tokens.GoTo && peek == Tokens.Minus;
}
/*
True if the next statement is a "Resume next" statement
*/
bool IsResumeNext()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Resume && peek == Tokens.Next;
}
/*
True, if ident/literal integer is followed by ":"
*/
bool IsLabel()
{
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
&& Peek(1).kind == Tokens.Colon;
}
bool IsNotStatementSeparator()
{
return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL;
}
bool IsAssignment ()
{
return IdentAndAsgn();
}
bool IsMustOverride(Modifiers m)
{
return m.Contains(Modifier.Abstract);
}
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
b.Append(fre.FieldName);
return result;
} else if (expr is IdentifierExpression) {
b.Append(((IdentifierExpression)expr).Identifier);
return true;
} else {
return false;
}
}
/*
True, if lookahead is a local attribute target specifier,
i.e. one of "event", "return", "field", "method",
"module", "param", "property", or "type"
*/
bool IsLocalAttrTarget() {
// TODO
return false;
}
/* START AUTOGENERATED TOKENS SECTION */
TOKENS
/* ----- terminal classes ----- */
@ -475,7 +229,6 @@ VBNET @@ -475,7 +229,6 @@ VBNET
(.
lexer.NextToken(); // get the first token
compilationUnit = new CompilationUnit();
withStatements = new Stack();
.) =
{ EOL }
{ OptionStmt }
@ -486,7 +239,7 @@ VBNET @@ -486,7 +239,7 @@ VBNET
.
OptionStmt (. INode node = null; bool val = true; .) =
"Option" (. Point startPos = t.Location; .)
"Option" (. Location startPos = t.Location; .)
(
"Explicit" [ OptionValue<ref val> ]
(. node = new OptionDeclaration(OptionType.Explicit, val); .)
@ -527,7 +280,7 @@ ImportsStmt @@ -527,7 +280,7 @@ ImportsStmt
.) =
"Imports"
(.
Point startPos = t.Location;
Location startPos = t.Location;
Using u;
.)
ImportClause<out u> (. if (u != null) { usings.Add(u); } .)
@ -572,7 +325,7 @@ NamespaceMemberDecl @@ -572,7 +325,7 @@ NamespaceMemberDecl
.) =
"Namespace"
(.
Point startPos = t.Location;
Location startPos = t.Location;
.)
Qualident<out qualident>
(.
@ -959,7 +712,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -959,7 +712,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
| /* 9.2.1 */
"Sub"
(.
Point startPos = t.Location;
Location startPos = t.Location;
.)
(
(.
@ -981,7 +734,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -981,7 +734,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
HandlesClause<out handlesClause>
)
]
(. Point endLocation = t.EndLocation; .)
(. Location endLocation = t.EndLocation; .)
EOL
(
/* abstract methods without a body */
@ -1010,22 +763,38 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1010,22 +763,38 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.InterfaceImplementations = implementsClause;
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
.)
Block<out stmt>
(.
compilationUnit.BlockEnd();
methodDeclaration.Body = (BlockStatement)stmt;
(. if (parseMethodContents) { .)
Block<out stmt>
"End" "Sub"
(. } else {
// don't parse method body
lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement();
if (t.kind != Tokens.Sub) throw new ApplicationException("Failed to skip sub");
}
.)
"End" "Sub" (. methodDeclaration.Body.EndLocation = t.EndLocation; .) EOL
(. methodDeclaration.Body = (BlockStatement)stmt; .)
(. methodDeclaration.Body.EndLocation = t.EndLocation; .) EOL
)
/* 9.3 */
| "New" [ "(" [ FormalParameterList<p> ] ")" ]
(. m.Check(Modifier.Constructors); .)
(. Point constructorEndLocation = t.EndLocation; .)
(. Location constructorEndLocation = t.EndLocation; .)
EOL
Block<out stmt>
"End" "Sub" (. Point endLocation = t.EndLocation; .) EOL
(. if (parseMethodContents) { .)
Block<out stmt>
"End" "Sub"
(. } else {
// don't parse method body
lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement();
if (t.kind != Tokens.Sub) throw new ApplicationException("Failed to skip sub");
}
.)
(. Location endLocation = t.EndLocation; .) EOL
(.
ConstructorDeclaration cd = new ConstructorDeclaration("New", m.Modifier, p, attributes);
cd.StartLocation = m.GetDeclarationLocation(startPos);
@ -1041,7 +810,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1041,7 +810,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
(.
m.Check(Modifier.VBMethods);
string name = String.Empty;
Point startPos = t.Location;
Location startPos = t.Location;
MethodDeclaration methodDeclaration;List<string> handlesClause = null;
List<InterfaceImplementation> implementsClause = null;
AttributeSection returnTypeAttributeSection = null;
@ -1095,15 +864,16 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1095,15 +864,16 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
}
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
.)
Block<out stmt>
(.
compilationUnit.BlockEnd();
methodDeclaration.Body = (BlockStatement)stmt;
.)
"End" "Function"
(.
if (parseMethodContents) { .)
Block<out stmt>
"End" "Function"
(. } else {
// don't parse method body
lexer.SkipCurrentBlock(Tokens.Function); stmt = new BlockStatement();
if (t.kind != Tokens.Function) throw new ApplicationException("Failed to skip function");
}
methodDeclaration.Body = (BlockStatement)stmt;
methodDeclaration.Body.StartLocation = methodDeclaration.EndLocation;
methodDeclaration.Body.EndLocation = t.EndLocation;
.)
@ -1114,7 +884,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1114,7 +884,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
"Declare"
(.
m.Check(Modifier.VBExternalMethods);
Point startPos = t.Location;
Location startPos = t.Location;
CharsetModifier charsetModifer = CharsetModifier.None;
string library = String.Empty;
string alias = null;
@ -1154,7 +924,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1154,7 +924,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
"Event"
(.
m.Check(Modifier.VBEvents);
Point startPos = t.Location;
Location startPos = t.Location;
EventDeclaration eventDeclaration;
string name = String.Empty;
List<InterfaceImplementation> implementsClause = null;
@ -1174,7 +944,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1174,7 +944,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
.)
EOL
| /* 9.6 */
(. Point startPos = t.Location; .)
(. Location startPos = t.Location; .)
(.
m.Check(Modifier.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
@ -1212,7 +982,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1212,7 +982,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
"Property"
(.
m.Check(Modifier.VBProperties);
Point startPos = t.Location;
Location startPos = t.Location;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier (. string propertyName = t.val; .)
@ -1260,7 +1030,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1260,7 +1030,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
.)
)
|
"Custom" (. Point startPos = t.Location; .) "Event"
"Custom" (. Location startPos = t.Location; .) "Event"
(.
m.Check(Modifier.VBCustomEvents);
EventAddRemoveRegion eventAccessorDeclaration;
@ -1321,7 +1091,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1321,7 +1091,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
"Operator"
(.
m.Check(Modifier.VBOperators);
Point startPos = t.Location;
Location startPos = t.Location;
TypeReference returnType = NullTypeReference.Instance;
TypeReference operandType = NullTypeReference.Instance;
string operandName;
@ -1342,7 +1112,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1342,7 +1112,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParamModifier.In)); .)
}
")"
(. Point endPos = t.EndLocation; .)
(. Location endPos = t.EndLocation; .)
[ "As" { AttributeSection<out section> (. returnTypeAttributes.Add(section); .) } TypeName<out returnType> (. endPos = t.EndLocation; .) EOL ]
Block<out stmt> "End" "Operator" EOL
(.
@ -1487,7 +1257,7 @@ AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock> @@ -1487,7 +1257,7 @@ AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
GetAccessorDecl<out PropertyGetRegion getBlock, List<AttributeSection> attributes>
(. Statement stmt = null; .) =
"Get"
(. Point startLocation = t.Location; .)
(. Location startLocation = t.Location; .)
EOL
Block<out stmt>
(. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
@ -1502,7 +1272,7 @@ SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attribute @@ -1502,7 +1272,7 @@ SetAccessorDecl<out PropertySetRegion setBlock, List<AttributeSection> attribute
Statement stmt = null; List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
.) =
"Set"
(. Point startLocation = t.Location; .)
(. Location startLocation = t.Location; .)
[ "(" [ FormalParameterList<p> ] ")" ]
EOL
Block<out stmt>
@ -1820,7 +1590,7 @@ InvocationExpression<ref Expression pexpr> @@ -1820,7 +1590,7 @@ InvocationExpression<ref Expression pexpr>
List<Expression> parameters = null;
TypeReference type; .)
=
"(" (. Point start = t.Location; .)
"(" (. Location start = t.Location; .)
( "Of"
TypeName<out type> (. if (type != null) typeParameters.Add(type); .)
{
@ -2185,7 +1955,7 @@ TypeArgumentList<List<TypeReference> typeArguments> @@ -2185,7 +1955,7 @@ TypeArgumentList<List<TypeReference> typeArguments>
.
GlobalAttributeSection =
(. Point startPos = t.Location; .)
(. Location startPos = t.Location; .)
"<" ("Assembly" | "Module")
(. string attributeTarget = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
List<ASTAttribute> attributes = new List<ASTAttribute>();
@ -2260,7 +2030,7 @@ AttributeSection<out AttributeSection section> @@ -2260,7 +2030,7 @@ AttributeSection<out AttributeSection section>
ASTAttribute attribute;
.) =
"<" (. Point startPos = t.Location; .)
"<" (. Location startPos = t.Location; .)
[ IF (IsLocalAttrTarget())
( "Event" (. attributeTarget = "event";.)
| "Return" (. attributeTarget = "return";.)
@ -2366,7 +2136,7 @@ Block<out Statement stmt> @@ -2366,7 +2136,7 @@ Block<out Statement stmt>
Statement
(.
Statement stmt = null;
Point startPos = la.Location;
Location startPos = la.Location;
string label = String.Empty;
.) =
@ -2507,7 +2277,7 @@ EmbeddedStatement<out Statement statement> @@ -2507,7 +2277,7 @@ EmbeddedStatement<out Statement statement>
Expression group = null;
TypeReference typeReference;
string typeName;
Point startLocation = t.Location;
Location startLocation = t.Location;
.)
(
/* 10.9.3 */
@ -2846,17 +2616,15 @@ WithStatement<out Statement withStatement> @@ -2846,17 +2616,15 @@ WithStatement<out Statement withStatement>
Statement blockStmt = null;
Expression expr = null;
.) =
"With" (. Point start = t.Location; .)
"With" (. Location start = t.Location; .)
Expr<out expr> EndOfStmt
(.
withStatement = new WithStatement(expr);
withStatement.StartLocation = start;
withStatements.Push(withStatement);
.)
Block<out blockStmt>
(.
((WithStatement)withStatement).Body = (BlockStatement)blockStmt;
withStatements.Pop();
.)
"End" "With"
(. withStatement.EndLocation = t.Location; .)

269
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

@ -0,0 +1,269 @@ @@ -0,0 +1,269 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 16.07.2006
* Time: 15:55
*/
using System;
using System.Text;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.Parser.VB
{
internal sealed partial class Parser : AbstractParser
{
Lexer lexer;
public Parser(ILexer lexer) : base(lexer)
{
this.lexer = (Lexer)lexer;
}
private StringBuilder qualidentBuilder = new StringBuilder();
Token t
{
[System.Diagnostics.DebuggerStepThrough]
get {
return lexer.Token;
}
}
Token la
{
[System.Diagnostics.DebuggerStepThrough]
get {
return lexer.LookAhead;
}
}
/* Return the n-th token after the current lookahead token */
void StartPeek()
{
lexer.StartPeek();
}
Token Peek()
{
return lexer.Peek();
}
Token Peek (int n)
{
lexer.StartPeek();
Token x = la;
while (n > 0) {
x = lexer.Peek();
n--;
}
return x;
}
public void Error(string s)
{
if (errDist >= minErrDist) {
errors.Error(la.line, la.col, s);
}
errDist = 0;
}
public override Expression ParseExpression()
{
lexer.NextToken();
Expression expr;
Expr(out expr);
return expr;
}
bool LeaveBlock()
{
int peek = Peek(1).kind;
return Tokens.BlockSucc[la.kind] && (la.kind != Tokens.End || peek == Tokens.EOL || peek == Tokens.Colon);
}
/* True, if "." is followed by an ident */
bool DotAndIdentOrKw () {
int peek = Peek(1).kind;
return la.kind == Tokens.Dot && (peek == Tokens.Identifier || peek >= Tokens.AddHandler);
}
bool IsEndStmtAhead()
{
int peek = Peek(1).kind;
return la.kind == Tokens.End && (peek == Tokens.EOL || peek == Tokens.Colon);
}
bool IsNotClosingParenthesis() {
return la.kind != Tokens.CloseParenthesis;
}
/*
True, if ident is followed by "="
*/
bool IdentAndAsgn () {
if(la.kind == Tokens.Identifier) {
if(Peek(1).kind == Tokens.Assign) return true;
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
}
return false;
}
/*
True, if ident is followed by "=" or by ":" and "="
*/
bool IsNamedAssign() {
// if(Peek(1).kind == Tokens.Assign) return true; // removed: not in the lang spec
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
return false;
}
bool IsObjectCreation() {
return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
}
/*
True, if "<" is followed by the ident "assembly" or "module"
*/
bool IsGlobalAttrTarget () {
Token pt = Peek(1);
return la.kind == Tokens.LessThan && ( string.Equals(pt.val, "assembly", StringComparison.InvariantCultureIgnoreCase) || string.Equals(pt.val, "module", StringComparison.InvariantCultureIgnoreCase));
}
/*
True if the next token is a "(" and is followed by "," or ")"
*/
bool IsDims()
{
int peek = Peek(1).kind;
return la.kind == Tokens.OpenParenthesis
&& (peek == Tokens.Comma || peek == Tokens.CloseParenthesis);
}
bool IsSize()
{
return la.kind == Tokens.OpenParenthesis;
}
/*
True, if the comma is not a trailing one,
like the last one in: a, b, c,
*/
bool NotFinalComma() {
int peek = Peek(1).kind;
return la.kind == Tokens.Comma &&
peek != Tokens.CloseCurlyBrace;
}
/*
True, if the next token is "Else" and this one
if followed by "If"
*/
bool IsElseIf()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Else && peek == Tokens.If;
}
/*
True if the next token is goto and this one is
followed by minus ("-") (this is allowd in in
error clauses)
*/
bool IsNegativeLabelName()
{
int peek = Peek(1).kind;
return la.kind == Tokens.GoTo && peek == Tokens.Minus;
}
/*
True if the next statement is a "Resume next" statement
*/
bool IsResumeNext()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Resume && peek == Tokens.Next;
}
/*
True, if ident/literal integer is followed by ":"
*/
bool IsLabel()
{
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
&& Peek(1).kind == Tokens.Colon;
}
bool IsNotStatementSeparator()
{
return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL;
}
bool IsAssignment ()
{
return IdentAndAsgn();
}
bool IsMustOverride(Modifiers m)
{
return m.Contains(Modifier.Abstract);
}
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
b.Append(fre.FieldName);
return result;
} else if (expr is IdentifierExpression) {
b.Append(((IdentifierExpression)expr).Identifier);
return true;
} else {
return false;
}
}
/*
True, if lookahead is a local attribute target specifier,
i.e. one of "event", "return", "field", "method",
"module", "param", "property", or "type"
*/
bool IsLocalAttrTarget() {
// TODO
return false;
}
}
}

8
src/Libraries/NRefactory/Test/Lexer/CSharp/CustomLexerTests.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
ILexer lexer = GenerateLexer(new StringReader("{}+"));
Assert.AreEqual(Tokens.OpenCurlyBrace, lexer.NextToken().kind);
lexer.NextToken();
lexer.SkipCurrentBlock();
lexer.SkipCurrentBlock(Tokens.CloseCurlyBrace);
Assert.AreEqual(Tokens.CloseCurlyBrace, lexer.LookAhead.kind);
Assert.AreEqual(Tokens.Plus, lexer.NextToken().kind);
Assert.AreEqual(Tokens.EOF, lexer.NextToken().kind);
@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
ILexer lexer = GenerateLexer(new StringReader("{ TestMethod('}'); /* }}} */ while(1) {break;} }+"));
Assert.AreEqual(Tokens.OpenCurlyBrace, lexer.NextToken().kind);
lexer.NextToken();
lexer.SkipCurrentBlock();
lexer.SkipCurrentBlock(Tokens.CloseCurlyBrace);
Assert.AreEqual(Tokens.CloseCurlyBrace, lexer.LookAhead.kind);
Assert.AreEqual(Tokens.Plus, lexer.NextToken().kind);
Assert.AreEqual(Tokens.EOF, lexer.NextToken().kind);
@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
lexer.Peek();
lexer.Peek();
lexer.Peek();
lexer.SkipCurrentBlock();
lexer.SkipCurrentBlock(Tokens.CloseCurlyBrace);
Assert.AreEqual(Tokens.CloseCurlyBrace, lexer.LookAhead.kind);
Assert.AreEqual(Tokens.Plus, lexer.NextToken().kind);
Assert.AreEqual(Tokens.EOF, lexer.NextToken().kind);
@ -92,7 +92,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -92,7 +92,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
lexer.Peek();
lexer.Peek();
lexer.Peek();
lexer.SkipCurrentBlock();
lexer.SkipCurrentBlock(Tokens.CloseCurlyBrace);
Assert.AreEqual(Tokens.CloseCurlyBrace, lexer.LookAhead.kind);
Assert.AreEqual(Tokens.Plus, lexer.NextToken().kind);
Assert.AreEqual(Tokens.EOF, lexer.NextToken().kind);

16
src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs

@ -162,5 +162,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -162,5 +162,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
End Function
End Class");
}
[Test]
public void BlankLinesVB()
{
TestProgramVB("Imports System\n" +
"\n" +
"Imports System.IO");
TestProgramVB("Imports System\n" +
"\n" +
"\n" +
"Imports System.IO");
TestProgramVB("\n" +
"' Some comment\n" +
"\n" +
"Imports System.IO");
}
}
}

Loading…
Cancel
Save