|
|
|
@ -387,12 +387,12 @@ namespace VBNetBinding.FormattingStrategy
@@ -387,12 +387,12 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
Token currentToken = null; |
|
|
|
|
Token prevToken = null; |
|
|
|
|
|
|
|
|
|
while ((currentToken = lexer.NextToken()).kind != Tokens.EOF) { |
|
|
|
|
while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) { |
|
|
|
|
if (prevToken == null) |
|
|
|
|
prevToken = currentToken; |
|
|
|
|
|
|
|
|
|
if (IsBlockStart(lexer, currentToken, prevToken)) { |
|
|
|
|
if ((tokens.Count > 0 && tokens.Peek().kind != Tokens.Interface) || IsDeclaration(currentToken.kind)) |
|
|
|
|
if ((tokens.Count > 0 && tokens.Peek().Kind != Tokens.Interface) || IsDeclaration(currentToken.Kind)) |
|
|
|
|
tokens.Push(currentToken); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -422,12 +422,12 @@ namespace VBNetBinding.FormattingStrategy
@@ -422,12 +422,12 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
int diff = 0; |
|
|
|
|
|
|
|
|
|
foreach (Token t in missingEnds) { |
|
|
|
|
if (!IsSingleLine(t.line, textArea)) { |
|
|
|
|
if (IsMatchingStatement(t, statement) && ((diff = lineNr - t.line + 1) > -1)) { |
|
|
|
|
if (!IsSingleLine(t.Location.Line, textArea)) { |
|
|
|
|
if (IsMatchingStatement(t, statement) && ((diff = lineNr - t.Location.Line + 1) > -1)) { |
|
|
|
|
if (closest == null) { |
|
|
|
|
closest = t; |
|
|
|
|
} else { |
|
|
|
|
if (diff < lineNr - closest.line + 1) |
|
|
|
|
if (diff < lineNr - closest.Location.Line + 1) |
|
|
|
|
closest = t; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -457,13 +457,13 @@ namespace VBNetBinding.FormattingStrategy
@@ -457,13 +457,13 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
|
|
|
|
|
bool IsMatchingEnd(Token begin, Token end) |
|
|
|
|
{ |
|
|
|
|
if (begin.kind == end.kind) |
|
|
|
|
if (begin.Kind == end.Kind) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
if (begin.kind == Tokens.For && end.kind == Tokens.Next) |
|
|
|
|
if (begin.Kind == Tokens.For && end.Kind == Tokens.Next) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
if (begin.kind == Tokens.Do && end.kind == Tokens.Loop) |
|
|
|
|
if (begin.Kind == Tokens.Do && end.Kind == Tokens.Loop) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
@ -473,14 +473,14 @@ namespace VBNetBinding.FormattingStrategy
@@ -473,14 +473,14 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
{ |
|
|
|
|
// funktioniert noch nicht!
|
|
|
|
|
|
|
|
|
|
if (token.val == "For" && statement.EndStatement == "Next") |
|
|
|
|
if (token.Kind == Tokens.For && statement.EndStatement == "Next") |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
if (token.val == "Do" && statement.EndStatement.StartsWith("Loop")) |
|
|
|
|
if (token.Kind == Tokens.Do && statement.EndStatement.StartsWith("Loop")) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
bool empty = !string.IsNullOrEmpty(token.val); |
|
|
|
|
bool match = statement.EndStatement.IndexOf(token.val, StringComparison.InvariantCultureIgnoreCase) != -1; |
|
|
|
|
bool empty = !string.IsNullOrEmpty(token.Value); |
|
|
|
|
bool match = statement.EndStatement.IndexOf(token.Value, StringComparison.InvariantCultureIgnoreCase) != -1; |
|
|
|
|
|
|
|
|
|
return empty && match; |
|
|
|
|
} |
|
|
|
@ -531,86 +531,86 @@ namespace VBNetBinding.FormattingStrategy
@@ -531,86 +531,86 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
Token currentToken = null; |
|
|
|
|
Token prevToken = null; |
|
|
|
|
|
|
|
|
|
while ((currentToken = lexer.NextToken()).kind != Tokens.EOF) { |
|
|
|
|
while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) { |
|
|
|
|
if (prevToken == null) |
|
|
|
|
prevToken = currentToken; |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.MustOverride) |
|
|
|
|
if (currentToken.Kind == Tokens.MustOverride) |
|
|
|
|
isMustOverride = true; |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.Delegate) |
|
|
|
|
if (currentToken.Kind == Tokens.Delegate) |
|
|
|
|
isDelegate = true; |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.Declare) |
|
|
|
|
if (currentToken.Kind == Tokens.Declare) |
|
|
|
|
isDeclare = true; |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.EOL) |
|
|
|
|
if (currentToken.Kind == Tokens.EOL) |
|
|
|
|
isDelegate = isDeclare = isMustOverride = false; |
|
|
|
|
|
|
|
|
|
if (IsSpecialCase(currentToken, prevToken)) { |
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, currentToken.line - 1, begin, end); |
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, currentToken.Location.Line - 1, begin, end); |
|
|
|
|
indentation--; |
|
|
|
|
ApplyToRange(textArea, ref indentation, currentToken.line - 1, currentToken.line, begin, end); |
|
|
|
|
ApplyToRange(textArea, ref indentation, currentToken.Location.Line - 1, currentToken.Location.Line, begin, end); |
|
|
|
|
indentation++; |
|
|
|
|
|
|
|
|
|
oldLine = currentToken.line; |
|
|
|
|
oldLine = currentToken.Location.Line; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (IsBlockEnd(currentToken, prevToken)) { |
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, currentToken.line - 1, begin, end); |
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, currentToken.Location.Line - 1, begin, end); |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.Interface) |
|
|
|
|
if (currentToken.Kind == Tokens.Interface) |
|
|
|
|
inInterface = false; |
|
|
|
|
|
|
|
|
|
if (!inInterface && !isMustOverride && !isDeclare && !isDelegate) { |
|
|
|
|
indentation--; |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.Select) |
|
|
|
|
if (currentToken.Kind == Tokens.Select) |
|
|
|
|
indentation--; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
oldLine = currentToken.line - 1; |
|
|
|
|
oldLine = currentToken.Location.Line - 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (IsBlockStart(lexer, currentToken, prevToken)) { |
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, currentToken.line, begin, end); |
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, currentToken.Location.Line, begin, end); |
|
|
|
|
|
|
|
|
|
if (!inInterface && !isMustOverride && !isDeclare && !isDelegate) { |
|
|
|
|
indentation++; |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.Select) |
|
|
|
|
if (currentToken.Kind == Tokens.Select) |
|
|
|
|
indentation++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (currentToken.kind == Tokens.Interface) |
|
|
|
|
if (currentToken.Kind == Tokens.Interface) |
|
|
|
|
inInterface = true; |
|
|
|
|
|
|
|
|
|
oldLine = currentToken.line; |
|
|
|
|
oldLine = currentToken.Location.Line; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
prevToken = currentToken; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// do last indent step
|
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, prevToken.line, begin, end); |
|
|
|
|
ApplyToRange(textArea, ref indentation, oldLine, prevToken.Location.Line, begin, end); |
|
|
|
|
|
|
|
|
|
return indentation; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsBlockStart(ILexer lexer, Token current, Token prev) |
|
|
|
|
{ |
|
|
|
|
if (blockTokens.Contains(current.kind)) { |
|
|
|
|
if (current.kind == Tokens.If) { |
|
|
|
|
if (prev.kind != Tokens.EOL) |
|
|
|
|
if (blockTokens.Contains(current.Kind)) { |
|
|
|
|
if (current.Kind == Tokens.If) { |
|
|
|
|
if (prev.Kind != Tokens.EOL) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
lexer.StartPeek(); |
|
|
|
|
|
|
|
|
|
Token currentToken = null; |
|
|
|
|
|
|
|
|
|
while ((currentToken = lexer.Peek()).kind != Tokens.EOL) { |
|
|
|
|
if (currentToken.kind == Tokens.Then) { |
|
|
|
|
if (lexer.Peek().kind == Tokens.EOL) |
|
|
|
|
while ((currentToken = lexer.Peek()).Kind != Tokens.EOL) { |
|
|
|
|
if (currentToken.Kind == Tokens.Then) { |
|
|
|
|
if (lexer.Peek().Kind == Tokens.EOL) |
|
|
|
|
return true; |
|
|
|
|
else |
|
|
|
|
return false; |
|
|
|
@ -618,47 +618,47 @@ namespace VBNetBinding.FormattingStrategy
@@ -618,47 +618,47 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (current.kind == Tokens.Function) { |
|
|
|
|
if (current.Kind == Tokens.Function) { |
|
|
|
|
lexer.StartPeek(); |
|
|
|
|
|
|
|
|
|
if (lexer.Peek().kind == Tokens.OpenParenthesis) |
|
|
|
|
if (lexer.Peek().Kind == Tokens.OpenParenthesis) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (current.kind == Tokens.With && prev.kind != Tokens.EOL) |
|
|
|
|
if (current.Kind == Tokens.With && prev.Kind != Tokens.EOL) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
if (current.kind == Tokens.While && (prev.kind == Tokens.Skip || prev.kind == Tokens.Take)) |
|
|
|
|
if (current.Kind == Tokens.While && (prev.Kind == Tokens.Skip || prev.Kind == Tokens.Take)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
if (current.kind == Tokens.Select && prev.kind != Tokens.EOL) |
|
|
|
|
if (current.Kind == Tokens.Select && prev.Kind != Tokens.EOL) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
if (current.kind == Tokens.Class || current.kind == Tokens.Structure) { |
|
|
|
|
if (current.Kind == Tokens.Class || current.Kind == Tokens.Structure) { |
|
|
|
|
lexer.StartPeek(); |
|
|
|
|
|
|
|
|
|
Token t = lexer.Peek(); |
|
|
|
|
|
|
|
|
|
if (t.kind == Tokens.CloseParenthesis || t.kind == Tokens.CloseCurlyBrace || t.kind == Tokens.Comma) |
|
|
|
|
if (t.Kind == Tokens.CloseParenthesis || t.Kind == Tokens.CloseCurlyBrace || t.Kind == Tokens.Comma) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (current.kind == Tokens.Module) { |
|
|
|
|
if (current.Kind == Tokens.Module) { |
|
|
|
|
lexer.StartPeek(); |
|
|
|
|
|
|
|
|
|
Token t = lexer.Peek(); |
|
|
|
|
|
|
|
|
|
if (t.kind == Tokens.Colon) |
|
|
|
|
if (t.Kind == Tokens.Colon) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (prev.kind == Tokens.End || |
|
|
|
|
prev.kind == Tokens.Loop || |
|
|
|
|
prev.kind == Tokens.Exit || |
|
|
|
|
prev.kind == Tokens.Continue || |
|
|
|
|
prev.kind == Tokens.Resume || |
|
|
|
|
prev.kind == Tokens.GoTo || |
|
|
|
|
prev.kind == Tokens.Do) |
|
|
|
|
if (prev.Kind == Tokens.End || |
|
|
|
|
prev.Kind == Tokens.Loop || |
|
|
|
|
prev.Kind == Tokens.Exit || |
|
|
|
|
prev.Kind == Tokens.Continue || |
|
|
|
|
prev.Kind == Tokens.Resume || |
|
|
|
|
prev.Kind == Tokens.GoTo || |
|
|
|
|
prev.Kind == Tokens.Do) |
|
|
|
|
return false; |
|
|
|
|
else |
|
|
|
|
return true; |
|
|
|
@ -669,18 +669,18 @@ namespace VBNetBinding.FormattingStrategy
@@ -669,18 +669,18 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
|
|
|
|
|
bool IsBlockEnd(Token current, Token prev) |
|
|
|
|
{ |
|
|
|
|
if (current.kind == Tokens.Next) { |
|
|
|
|
if (prev.kind == Tokens.Resume) |
|
|
|
|
if (current.Kind == Tokens.Next) { |
|
|
|
|
if (prev.Kind == Tokens.Resume) |
|
|
|
|
return false; |
|
|
|
|
else |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (current.kind == Tokens.Loop) |
|
|
|
|
if (current.Kind == Tokens.Loop) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
if (blockTokens.Contains(current.kind)) { |
|
|
|
|
if (prev.kind == Tokens.End) |
|
|
|
|
if (blockTokens.Contains(current.Kind)) { |
|
|
|
|
if (prev.Kind == Tokens.End) |
|
|
|
|
return true; |
|
|
|
|
else |
|
|
|
|
return false; |
|
|
|
@ -691,11 +691,11 @@ namespace VBNetBinding.FormattingStrategy
@@ -691,11 +691,11 @@ namespace VBNetBinding.FormattingStrategy
|
|
|
|
|
|
|
|
|
|
bool IsSpecialCase(Token current, Token prev) |
|
|
|
|
{ |
|
|
|
|
switch (current.kind) { |
|
|
|
|
switch (current.Kind) { |
|
|
|
|
case Tokens.Else: |
|
|
|
|
return true; |
|
|
|
|
case Tokens.Case: |
|
|
|
|
if (prev.kind == Tokens.Select) |
|
|
|
|
if (prev.Kind == Tokens.Select) |
|
|
|
|
return false; |
|
|
|
|
else |
|
|
|
|
return true; |
|
|
|
|