Browse Source

fix Cannot load designer when using 'select case' - http://community.sharpdevelop.net/forums/p/15838/41446.aspx#41446

4.2
Siegfried Pammer 13 years ago
parent
commit
e9bfd6145f
  1. 15
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg
  2. 4
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.cs
  3. 2
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  4. 3215
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs
  5. 1
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/PushParser.frame
  6. 14
      src/Libraries/NRefactory/Test/Parser/Statements/SwitchStatementTests.cs

15
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg

@ -1137,10 +1137,19 @@ MultilineIfRemainder = @@ -1137,10 +1137,19 @@ MultilineIfRemainder =
SelectStatement =
"Select" [ "Case" ] Expression StatementTerminator
{
"Case" (
// HACK: '<' is recognized as XML literal, if occurring at the start of an expression
// in the CaseClause however it can only be a less-than-sign and vbc does not allow XML literals.
// we use a simple xmlAllowed flag:
// the flag is only set to false immetiately before the expression is parsed and set to true once '<'
// is recognized as less-than-sign to allow normal behavior of the lexer in later expressions.
"Case" (. xmlAllowed = false; .) (
"Else" |
( [ "Is" ] ComparisonOperator SimpleExpressionWithSuffix | Expression )
{ "," ( [ "Is" ] ComparisonOperator SimpleExpressionWithSuffix | Expression ) }
( (. xmlAllowed = true; .) [ "Is" ] ComparisonOperator SimpleExpressionWithSuffix
| (. xmlAllowed = true; .) Expression )
{ "," (. xmlAllowed = false; .)
( (. xmlAllowed = true; .) [ "Is" ] ComparisonOperator SimpleExpressionWithSuffix
| (. xmlAllowed = true; .) Expression )
}
)
StatementTerminatorAndBlock
}

4
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.cs

@ -121,6 +121,10 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -121,6 +121,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
set { readXmlIdentifier = value; }
}
public bool XmlAllowed {
get { return xmlAllowed; }
}
public bool NextTokenIsStartOfImportsOrAccessExpression {
get { return nextTokenIsStartOfImportsOrAccessExpression; }
}

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

@ -317,7 +317,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -317,7 +317,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
return new Token(Tokens.XmlEndInlineVB, new Location(x, y), new Location(Col, Line));
}
#endregion
if (ch == '<' && (ef.NextTokenIsPotentialStartOfExpression || ef.NextTokenIsStartOfImportsOrAccessExpression)) {
if (ch == '<' && ef.XmlAllowed && (ef.NextTokenIsPotentialStartOfExpression || ef.NextTokenIsStartOfImportsOrAccessExpression)) {
xmlModeStack.Push(new XmlModeInfo(ef.NextTokenIsStartOfImportsOrAccessExpression));
XmlModeInfo info = xmlModeStack.Peek();
int x = Col - 1;

3215
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

1
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/PushParser.frame

@ -37,6 +37,7 @@ partial class ExpressionFinder { @@ -37,6 +37,7 @@ partial class ExpressionFinder {
bool wasQualifierTokenAtStart = false;
bool nextTokenIsPotentialStartOfExpression = false;
bool readXmlIdentifier = false;
bool xmlAllowed = true;
bool identifierExpected = false;
bool nextTokenIsStartOfImportsOrAccessExpression = false;
bool isMissingModifier = false;

14
src/Libraries/NRefactory/Test/Parser/Statements/SwitchStatementTests.cs

@ -39,6 +39,20 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -39,6 +39,20 @@ namespace ICSharpCode.NRefactory.Tests.Ast
SwitchSection sec = switchStmt.SwitchSections[0];
Assert.AreEqual(0, sec.SwitchLabels.Count);
}
[Test]
public void SpecialCaseStatement()
{
SwitchStatement stmt = ParseUtilVBNet.ParseStatement<SwitchStatement>("Select Case a\nCase < 50\nCase > 20, < 10\nEnd Select");
Assert.AreEqual("a", ((IdentifierExpression)stmt.SwitchExpression).Identifier);
}
[Test]
public void SpecialCaseStatement2()
{
SwitchStatement stmt = ParseUtilVBNet.ParseStatement<SwitchStatement>("Select Case a\nCase < 50\nEnd Select");
Assert.AreEqual("a", ((IdentifierExpression)stmt.SwitchExpression).Identifier);
}
#endregion
}
}

Loading…
Cancel
Save