|
|
|
@ -23,7 +23,6 @@
@@ -23,7 +23,6 @@
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using ICSharpCode.NRefactory.Editor; |
|
|
|
|
using System.Text; |
|
|
|
@ -39,15 +38,28 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -39,15 +38,28 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
readonly CSharpFormattingOptions options; |
|
|
|
|
readonly TextEditorOptions textEditorOptions; |
|
|
|
|
readonly StringBuilder wordBuf = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
readonly StringBuilder currentIndent = new StringBuilder(); |
|
|
|
|
Indent thisLineindent; |
|
|
|
|
Indent indent; |
|
|
|
|
Indent indentDelta; |
|
|
|
|
|
|
|
|
|
public IList<string> ConditionalSymbols { |
|
|
|
|
get; |
|
|
|
|
set; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public TextLocation Location { |
|
|
|
|
get { |
|
|
|
|
return new TextLocation(line, col); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int Offset { |
|
|
|
|
get { |
|
|
|
|
return offset; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string ThisLineIndent { |
|
|
|
|
get { |
|
|
|
|
return thisLineindent.IndentString; |
|
|
|
@ -56,7 +68,13 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -56,7 +68,13 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
|
|
|
|
|
public string NewLineIndent { |
|
|
|
|
get { |
|
|
|
|
return indent.IndentString; |
|
|
|
|
return indent.IndentString + indentDelta.IndentString; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool NeedsReindent { |
|
|
|
|
get { |
|
|
|
|
return ThisLineIndent != currentIndent.ToString(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,21 +84,23 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -66,21 +84,23 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
this.options = formattingOptions; |
|
|
|
|
this.textEditorOptions = textEditorOptions; |
|
|
|
|
this.indent = new Indent(textEditorOptions); |
|
|
|
|
this.indentDelta = new Indent(textEditorOptions); |
|
|
|
|
this.thisLineindent = new Indent(textEditorOptions); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CSharpIndentEngine (CSharpIndentEngine prototype) |
|
|
|
|
CSharpIndentEngine(CSharpIndentEngine prototype) |
|
|
|
|
{ |
|
|
|
|
this.document = prototype.document; |
|
|
|
|
this.options = prototype.options; |
|
|
|
|
this.textEditorOptions = prototype.textEditorOptions; |
|
|
|
|
this.indent = prototype.indent.Clone(); |
|
|
|
|
this.indentDelta = prototype.indentDelta.Clone(); |
|
|
|
|
this.thisLineindent = prototype.thisLineindent.Clone(); |
|
|
|
|
this.offset = prototype.offset; |
|
|
|
|
this.inside = prototype.inside; |
|
|
|
|
this.IsLineStart = prototype.IsLineStart; |
|
|
|
|
this.pc = prototype.pc; |
|
|
|
|
this.parenStack = new Stack<TextLocation>(prototype.parenStack.Reverse ()); |
|
|
|
|
this.parenStack = new Stack<TextLocation>(prototype.parenStack.Reverse()); |
|
|
|
|
this.currentBody = prototype.currentBody; |
|
|
|
|
this.nextBody = prototype.nextBody; |
|
|
|
|
this.addContinuation = prototype.addContinuation; |
|
|
|
@ -89,7 +109,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -89,7 +109,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
this.popNextParenBlock = prototype.popNextParenBlock; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public CSharpIndentEngine Clone () |
|
|
|
|
public CSharpIndentEngine Clone() |
|
|
|
|
{ |
|
|
|
|
return new CSharpIndentEngine(this); |
|
|
|
|
} |
|
|
|
@ -98,17 +118,15 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -98,17 +118,15 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
Inside inside = Inside.Empty; |
|
|
|
|
bool IsLineStart = true; |
|
|
|
|
char pc; |
|
|
|
|
Stack<TextLocation> parenStack = new Stack<TextLocation> (); |
|
|
|
|
Stack<TextLocation> parenStack = new Stack<TextLocation>(); |
|
|
|
|
Body currentBody; |
|
|
|
|
Body nextBody; |
|
|
|
|
bool addContinuation; |
|
|
|
|
int line, col; |
|
|
|
|
bool popNextParenBlock; |
|
|
|
|
|
|
|
|
|
bool readPreprocessorExpression; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Reset() |
|
|
|
|
public void Reset() |
|
|
|
|
{ |
|
|
|
|
offset = 0; |
|
|
|
|
thisLineindent.Reset(); |
|
|
|
@ -123,7 +141,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -123,7 +141,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
line = col = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void UpdateToOffset (int toOffset) |
|
|
|
|
public void UpdateToOffset(int toOffset) |
|
|
|
|
{ |
|
|
|
|
if (toOffset < offset) |
|
|
|
|
Reset(); |
|
|
|
@ -131,29 +149,59 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -131,29 +149,59 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
Push(document.GetCharAt(i)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool IsInStringOrChar { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag(Inside.StringOrChar); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsInStringOrChar { |
|
|
|
|
public bool IsInComment { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag (Inside.StringOrChar); |
|
|
|
|
return inside.HasFlag(Inside.Comment); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsInComment { |
|
|
|
|
public bool IsInPreProcessorComment { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag (Inside.Comment); |
|
|
|
|
return inside.HasFlag(Inside.PreProcessorComment); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsInPreProcessorComment { |
|
|
|
|
public bool IsInPreProcessorDirective { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag (Inside.PreProcessorComment); |
|
|
|
|
return inside.HasFlag(Inside.PreProcessor); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsInVerbatimString { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag(Inside.VerbatimString); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool IsInsideDocLineComment { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag(Inside.DocComment); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool IsInsideMultiLineComment { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag(Inside.MultiLineComment); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool IsInsideStringLiteral { |
|
|
|
|
get { |
|
|
|
|
return inside.HasFlag(Inside.StringLiteral); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Flags] |
|
|
|
|
public enum Inside { |
|
|
|
|
public enum Inside |
|
|
|
|
{ |
|
|
|
|
Empty = 0, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreProcessor = (1 << 0), |
|
|
|
|
PreProcessorComment = (1 << 12), |
|
|
|
|
|
|
|
|
@ -161,153 +209,153 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -161,153 +209,153 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
LineComment = (1 << 2), |
|
|
|
|
DocComment = (1 << 11), |
|
|
|
|
Comment = (MultiLineComment | LineComment | DocComment), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VerbatimString = (1 << 3), |
|
|
|
|
StringLiteral = (1 << 4), |
|
|
|
|
CharLiteral = (1 << 5), |
|
|
|
|
String = (VerbatimString | StringLiteral), |
|
|
|
|
StringOrChar = (String | CharLiteral), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Attribute = (1 << 6), |
|
|
|
|
ParenList = (1 << 7), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FoldedStatement = (1 << 8), |
|
|
|
|
Block = (1 << 9), |
|
|
|
|
Case = (1 << 10), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FoldedOrBlock = (FoldedStatement | Block), |
|
|
|
|
FoldedBlockOrCase = (FoldedStatement | Block | Case) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Pre processor evaluation (from cs-tokenizer.cs)
|
|
|
|
|
static bool is_identifier_start_character (int c) |
|
|
|
|
#region Pre processor evaluation (from cs-tokenizer.cs)
|
|
|
|
|
static bool is_identifier_start_character(int c) |
|
|
|
|
{ |
|
|
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter ((char)c); |
|
|
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter((char)c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool is_identifier_part_character (char c) |
|
|
|
|
static bool is_identifier_part_character(char c) |
|
|
|
|
{ |
|
|
|
|
if (c >= 'a' && c <= 'z') |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (c >= 'A' && c <= 'Z') |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (c == '_' || (c >= '0' && c <= '9')) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (c < 0x80) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
return Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation; |
|
|
|
|
|
|
|
|
|
return Char.IsLetter(c) || Char.GetUnicodeCategory(c) == UnicodeCategory.ConnectorPunctuation; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool eval_val (string s) |
|
|
|
|
bool eval_val(string s) |
|
|
|
|
{ |
|
|
|
|
if (s == "true") |
|
|
|
|
return true; |
|
|
|
|
if (s == "false") |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
return ConditionalSymbols != null && ConditionalSymbols.Contains (s); |
|
|
|
|
|
|
|
|
|
return ConditionalSymbols != null && ConditionalSymbols.Contains(s); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool pp_primary (ref string s) |
|
|
|
|
|
|
|
|
|
bool pp_primary(ref string s) |
|
|
|
|
{ |
|
|
|
|
s = s.Trim (); |
|
|
|
|
s = s.Trim(); |
|
|
|
|
int len = s.Length; |
|
|
|
|
|
|
|
|
|
if (len > 0){ |
|
|
|
|
|
|
|
|
|
if (len > 0) { |
|
|
|
|
char c = s [0]; |
|
|
|
|
|
|
|
|
|
if (c == '('){ |
|
|
|
|
s = s.Substring (1); |
|
|
|
|
bool val = pp_expr (ref s, false); |
|
|
|
|
if (s.Length > 0 && s [0] == ')'){ |
|
|
|
|
s = s.Substring (1); |
|
|
|
|
|
|
|
|
|
if (c == '(') { |
|
|
|
|
s = s.Substring(1); |
|
|
|
|
bool val = pp_expr(ref s, false); |
|
|
|
|
if (s.Length > 0 && s [0] == ')') { |
|
|
|
|
s = s.Substring(1); |
|
|
|
|
return val; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (is_identifier_start_character (c)){ |
|
|
|
|
|
|
|
|
|
if (is_identifier_start_character(c)) { |
|
|
|
|
int j = 1; |
|
|
|
|
|
|
|
|
|
while (j < len){ |
|
|
|
|
|
|
|
|
|
while (j < len) { |
|
|
|
|
c = s [j]; |
|
|
|
|
|
|
|
|
|
if (is_identifier_part_character (c)){ |
|
|
|
|
|
|
|
|
|
if (is_identifier_part_character(c)) { |
|
|
|
|
j++; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
bool v = eval_val (s.Substring (0, j)); |
|
|
|
|
s = s.Substring (j); |
|
|
|
|
bool v = eval_val(s.Substring(0, j)); |
|
|
|
|
s = s.Substring(j); |
|
|
|
|
return v; |
|
|
|
|
} |
|
|
|
|
bool vv = eval_val (s); |
|
|
|
|
bool vv = eval_val(s); |
|
|
|
|
s = ""; |
|
|
|
|
return vv; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool pp_unary (ref string s) |
|
|
|
|
|
|
|
|
|
bool pp_unary(ref string s) |
|
|
|
|
{ |
|
|
|
|
s = s.Trim (); |
|
|
|
|
s = s.Trim(); |
|
|
|
|
int len = s.Length; |
|
|
|
|
|
|
|
|
|
if (len > 0){ |
|
|
|
|
if (s [0] == '!'){ |
|
|
|
|
if (len > 1 && s [1] == '='){ |
|
|
|
|
|
|
|
|
|
if (len > 0) { |
|
|
|
|
if (s [0] == '!') { |
|
|
|
|
if (len > 1 && s [1] == '=') { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
s = s.Substring (1); |
|
|
|
|
return ! pp_primary (ref s); |
|
|
|
|
s = s.Substring(1); |
|
|
|
|
return ! pp_primary(ref s); |
|
|
|
|
} else |
|
|
|
|
return pp_primary (ref s); |
|
|
|
|
return pp_primary(ref s); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool pp_eq (ref string s) |
|
|
|
|
|
|
|
|
|
bool pp_eq(ref string s) |
|
|
|
|
{ |
|
|
|
|
bool va = pp_unary (ref s); |
|
|
|
|
|
|
|
|
|
s = s.Trim (); |
|
|
|
|
bool va = pp_unary(ref s); |
|
|
|
|
|
|
|
|
|
s = s.Trim(); |
|
|
|
|
int len = s.Length; |
|
|
|
|
if (len > 0){ |
|
|
|
|
if (s [0] == '='){ |
|
|
|
|
if (len > 2 && s [1] == '='){ |
|
|
|
|
s = s.Substring (2); |
|
|
|
|
return va == pp_unary (ref s); |
|
|
|
|
if (len > 0) { |
|
|
|
|
if (s [0] == '=') { |
|
|
|
|
if (len > 2 && s [1] == '=') { |
|
|
|
|
s = s.Substring(2); |
|
|
|
|
return va == pp_unary(ref s); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} else if (s [0] == '!' && len > 1 && s [1] == '='){ |
|
|
|
|
s = s.Substring (2); |
|
|
|
|
|
|
|
|
|
return va != pp_unary (ref s); |
|
|
|
|
|
|
|
|
|
} else if (s [0] == '!' && len > 1 && s [1] == '=') { |
|
|
|
|
s = s.Substring(2); |
|
|
|
|
|
|
|
|
|
return va != pp_unary(ref s); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return va; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool pp_and (ref string s) |
|
|
|
|
|
|
|
|
|
bool pp_and(ref string s) |
|
|
|
|
{ |
|
|
|
|
bool va = pp_eq (ref s); |
|
|
|
|
|
|
|
|
|
s = s.Trim (); |
|
|
|
|
bool va = pp_eq(ref s); |
|
|
|
|
|
|
|
|
|
s = s.Trim(); |
|
|
|
|
int len = s.Length; |
|
|
|
|
if (len > 0){ |
|
|
|
|
if (s [0] == '&'){ |
|
|
|
|
if (len > 2 && s [1] == '&'){ |
|
|
|
|
s = s.Substring (2); |
|
|
|
|
return (va & pp_and (ref s)); |
|
|
|
|
if (len > 0) { |
|
|
|
|
if (s [0] == '&') { |
|
|
|
|
if (len > 2 && s [1] == '&') { |
|
|
|
|
s = s.Substring(2); |
|
|
|
|
return (va & pp_and(ref s)); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -315,22 +363,22 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -315,22 +363,22 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
} |
|
|
|
|
return va; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Evaluates an expression for `#if' or `#elif'
|
|
|
|
|
//
|
|
|
|
|
bool pp_expr (ref string s, bool isTerm) |
|
|
|
|
bool pp_expr(ref string s, bool isTerm) |
|
|
|
|
{ |
|
|
|
|
bool va = pp_and (ref s); |
|
|
|
|
s = s.Trim (); |
|
|
|
|
bool va = pp_and(ref s); |
|
|
|
|
s = s.Trim(); |
|
|
|
|
int len = s.Length; |
|
|
|
|
if (len > 0){ |
|
|
|
|
if (len > 0) { |
|
|
|
|
char c = s [0]; |
|
|
|
|
|
|
|
|
|
if (c == '|'){ |
|
|
|
|
if (len > 2 && s [1] == '|'){ |
|
|
|
|
s = s.Substring (2); |
|
|
|
|
return va | pp_expr (ref s, isTerm); |
|
|
|
|
|
|
|
|
|
if (c == '|') { |
|
|
|
|
if (len > 2 && s [1] == '|') { |
|
|
|
|
s = s.Substring(2); |
|
|
|
|
return va | pp_expr(ref s, isTerm); |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
@ -340,29 +388,30 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -340,29 +388,30 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return va; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool eval (string s) |
|
|
|
|
|
|
|
|
|
bool eval(string s) |
|
|
|
|
{ |
|
|
|
|
bool v = pp_expr (ref s, true); |
|
|
|
|
s = s.Trim (); |
|
|
|
|
if (s.Length != 0){ |
|
|
|
|
bool v = pp_expr(ref s, true); |
|
|
|
|
s = s.Trim(); |
|
|
|
|
if (s.Length != 0) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return v; |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
void Push(char ch) |
|
|
|
|
|
|
|
|
|
public void Push(char ch) |
|
|
|
|
{ |
|
|
|
|
if (readPreprocessorExpression) { |
|
|
|
|
wordBuf.Append(ch); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (inside.HasFlag (Inside.VerbatimString) && pc == '"' && ch != '"') { |
|
|
|
|
inside &= ~Inside.String; |
|
|
|
|
if (inside.HasFlag(Inside.VerbatimString) && pc == '"' && ch != '"') { |
|
|
|
|
inside &= ~Inside.StringLiteral; |
|
|
|
|
} |
|
|
|
|
switch (ch) { |
|
|
|
|
case '#': |
|
|
|
@ -373,7 +422,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -373,7 +422,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
if (IsInStringOrChar || IsInPreProcessorComment) |
|
|
|
|
break; |
|
|
|
|
if (pc == '/') { |
|
|
|
|
if (inside.HasFlag (Inside.Comment)) { |
|
|
|
|
if (inside.HasFlag(Inside.Comment)) { |
|
|
|
|
inside |= Inside.DocComment; |
|
|
|
|
} else { |
|
|
|
|
inside |= Inside.Comment; |
|
|
|
@ -386,29 +435,39 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -386,29 +435,39 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
if (pc == '/') |
|
|
|
|
inside |= Inside.MultiLineComment; |
|
|
|
|
break; |
|
|
|
|
case ' ': |
|
|
|
|
currentIndent.Append(' '); |
|
|
|
|
break; |
|
|
|
|
case '\t': |
|
|
|
|
var nextTabStop = (col - 1 + textEditorOptions.IndentSize) / textEditorOptions.IndentSize; |
|
|
|
|
col = 1 + nextTabStop * textEditorOptions.IndentSize; |
|
|
|
|
currentIndent.Append('\t'); |
|
|
|
|
offset++; |
|
|
|
|
return; |
|
|
|
|
case '\r': |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (readPreprocessorExpression) { |
|
|
|
|
if (!eval (wordBuf.ToString ())) |
|
|
|
|
if (!eval(wordBuf.ToString())) |
|
|
|
|
inside |= Inside.PreProcessorComment; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inside &= ~(Inside.Comment | Inside.String | Inside.CharLiteral | Inside.PreProcessor); |
|
|
|
|
CheckKeyword(wordBuf.ToString()); |
|
|
|
|
wordBuf.Length = 0; |
|
|
|
|
indent.Push(indentDelta); |
|
|
|
|
indentDelta = new Indent(textEditorOptions); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (addContinuation) { |
|
|
|
|
indent.Push (IndentType.Continuation); |
|
|
|
|
indent.Push(IndentType.Continuation); |
|
|
|
|
} |
|
|
|
|
thisLineindent = indent.Clone (); |
|
|
|
|
thisLineindent = indent.Clone(); |
|
|
|
|
addContinuation = false; |
|
|
|
|
IsLineStart = true; |
|
|
|
|
readPreprocessorExpression = false; |
|
|
|
|
col = 1; |
|
|
|
|
line++; |
|
|
|
|
currentIndent.Length = 0; |
|
|
|
|
break; |
|
|
|
|
case '\n': |
|
|
|
|
if (pc == '\r') |
|
|
|
@ -417,16 +476,16 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -417,16 +476,16 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
case '"': |
|
|
|
|
if (IsInComment || IsInPreProcessorComment) |
|
|
|
|
break; |
|
|
|
|
if (inside.HasFlag (Inside.String)) { |
|
|
|
|
if (inside.HasFlag(Inside.StringLiteral)) { |
|
|
|
|
if (pc != '\\') |
|
|
|
|
inside &= ~Inside.String; |
|
|
|
|
inside &= ~Inside.StringLiteral; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (pc =='@') { |
|
|
|
|
if (pc == '@') { |
|
|
|
|
inside |= Inside.VerbatimString; |
|
|
|
|
} else { |
|
|
|
|
inside |= Inside.String; |
|
|
|
|
inside |= Inside.StringLiteral; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case '<': |
|
|
|
@ -434,27 +493,29 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -434,27 +493,29 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
case '(': |
|
|
|
|
if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) |
|
|
|
|
break; |
|
|
|
|
parenStack.Push (new TextLocation (line, col)); |
|
|
|
|
parenStack.Push(new TextLocation(line, col)); |
|
|
|
|
popNextParenBlock = true; |
|
|
|
|
indent.Push (IndentType.Block); |
|
|
|
|
indent.Push(IndentType.Block); |
|
|
|
|
break; |
|
|
|
|
case '>': |
|
|
|
|
case ']': |
|
|
|
|
case ')': |
|
|
|
|
if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) |
|
|
|
|
break; |
|
|
|
|
if (popNextParenBlock) |
|
|
|
|
parenStack.Pop (); |
|
|
|
|
indent.Pop (); |
|
|
|
|
if (popNextParenBlock && parenStack.Count > 0) |
|
|
|
|
parenStack.Pop(); |
|
|
|
|
if (indent.Count > 0) |
|
|
|
|
indent.Pop(); |
|
|
|
|
indent.ExtraSpaces = 0; |
|
|
|
|
break; |
|
|
|
|
case ',': |
|
|
|
|
if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) |
|
|
|
|
break; |
|
|
|
|
if (parenStack.Count > 0 && parenStack.Peek ().Line == line) { |
|
|
|
|
indent.Pop (); |
|
|
|
|
if (parenStack.Count > 0 && parenStack.Peek().Line == line) { |
|
|
|
|
if (indent.Count > 0) |
|
|
|
|
indent.Pop(); |
|
|
|
|
popNextParenBlock = false; |
|
|
|
|
indent.ExtraSpaces = parenStack.Peek ().Column - 1 - thisLineindent.CurIndent; |
|
|
|
|
indent.ExtraSpaces = parenStack.Peek().Column - 1 - thisLineindent.CurIndent; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case '{': |
|
|
|
@ -464,14 +525,21 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -464,14 +525,21 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
if (indent.Count > 0 && indent.Peek() == IndentType.Continuation) |
|
|
|
|
indent.Pop(); |
|
|
|
|
addContinuation = false; |
|
|
|
|
AddIndentation (currentBody); |
|
|
|
|
AddIndentation(currentBody); |
|
|
|
|
break; |
|
|
|
|
case '}': |
|
|
|
|
if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) |
|
|
|
|
break; |
|
|
|
|
indent.Pop (); |
|
|
|
|
if (indent.Count > 0 && indent.Peek() == IndentType.Continuation) |
|
|
|
|
indent.Pop(); |
|
|
|
|
if (indentDelta.CurIndent > 0) { |
|
|
|
|
indentDelta.Pop(); |
|
|
|
|
if (indentDelta.Count > 0 && indentDelta.Peek() == IndentType.Continuation) |
|
|
|
|
indentDelta.Pop(); |
|
|
|
|
} else { |
|
|
|
|
if (thisLineindent.Count > 0) |
|
|
|
|
thisLineindent.Pop(); |
|
|
|
|
if (indent.Count > 0) |
|
|
|
|
indent.Pop(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case ';': |
|
|
|
|
if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) |
|
|
|
@ -480,9 +548,9 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -480,9 +548,9 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
indent.Pop(); |
|
|
|
|
break; |
|
|
|
|
case '\'': |
|
|
|
|
if (IsInComment || inside.HasFlag (Inside.String) || IsInPreProcessorComment) |
|
|
|
|
if (IsInComment || inside.HasFlag(Inside.StringLiteral) || IsInPreProcessorComment) |
|
|
|
|
break; |
|
|
|
|
if (inside.HasFlag (Inside.CharLiteral)) { |
|
|
|
|
if (inside.HasFlag(Inside.CharLiteral)) { |
|
|
|
|
if (pc != '\\') |
|
|
|
|
inside &= ~Inside.CharLiteral; |
|
|
|
|
} else { |
|
|
|
@ -495,12 +563,12 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -495,12 +563,12 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
if ((wordBuf.Length == 0 ? char.IsLetter(ch) : char.IsLetterOrDigit(ch)) || ch == '_') { |
|
|
|
|
wordBuf.Append(ch); |
|
|
|
|
} else { |
|
|
|
|
if (inside.HasFlag (Inside.PreProcessor)) { |
|
|
|
|
if (wordBuf.ToString () == "endif") { |
|
|
|
|
if (inside.HasFlag(Inside.PreProcessor)) { |
|
|
|
|
if (wordBuf.ToString() == "endif") { |
|
|
|
|
inside &= ~Inside.PreProcessorComment; |
|
|
|
|
} else if (wordBuf.ToString () == "if") { |
|
|
|
|
} else if (wordBuf.ToString() == "if") { |
|
|
|
|
readPreprocessorExpression = true; |
|
|
|
|
} else if (wordBuf.ToString () == "elif") { |
|
|
|
|
} else if (wordBuf.ToString() == "elif") { |
|
|
|
|
inside &= ~Inside.PreProcessorComment; |
|
|
|
|
readPreprocessorExpression = true; |
|
|
|
|
} |
|
|
|
@ -511,13 +579,14 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -511,13 +579,14 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (addContinuation) { |
|
|
|
|
indent.Push (IndentType.Continuation); |
|
|
|
|
indent.Push(IndentType.Continuation); |
|
|
|
|
addContinuation = false; |
|
|
|
|
} |
|
|
|
|
IsLineStart &= ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'; |
|
|
|
|
pc = ch; |
|
|
|
|
if (ch != '\n' && ch != '\r') |
|
|
|
|
col++; |
|
|
|
|
offset++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddIndentation(BraceStyle braceStyle) |
|
|
|
@ -529,11 +598,11 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -529,11 +598,11 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
case BraceStyle.NextLine: |
|
|
|
|
case BraceStyle.NextLineShifted: |
|
|
|
|
case BraceStyle.BannerStyle: |
|
|
|
|
indent.Push (IndentType.Block); |
|
|
|
|
indentDelta.Push(IndentType.Block); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case BraceStyle.NextLineShifted2: |
|
|
|
|
indent.Push (IndentType.DoubleBlock); |
|
|
|
|
indentDelta.Push(IndentType.DoubleBlock); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -542,26 +611,26 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -542,26 +611,26 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
{ |
|
|
|
|
switch (body) { |
|
|
|
|
case Body.None: |
|
|
|
|
indent.Push (IndentType.Block); |
|
|
|
|
indentDelta.Push(IndentType.Block); |
|
|
|
|
break; |
|
|
|
|
case Body.Namespace: |
|
|
|
|
AddIndentation (options.NamespaceBraceStyle); |
|
|
|
|
AddIndentation(options.NamespaceBraceStyle); |
|
|
|
|
break; |
|
|
|
|
case Body.Class: |
|
|
|
|
AddIndentation (options.ClassBraceStyle); |
|
|
|
|
AddIndentation(options.ClassBraceStyle); |
|
|
|
|
break; |
|
|
|
|
case Body.Struct: |
|
|
|
|
AddIndentation (options.StructBraceStyle); |
|
|
|
|
AddIndentation(options.StructBraceStyle); |
|
|
|
|
break; |
|
|
|
|
case Body.Interface: |
|
|
|
|
AddIndentation (options.InterfaceBraceStyle); |
|
|
|
|
AddIndentation(options.InterfaceBraceStyle); |
|
|
|
|
break; |
|
|
|
|
case Body.Enum: |
|
|
|
|
AddIndentation (options.EnumBraceStyle); |
|
|
|
|
AddIndentation(options.EnumBraceStyle); |
|
|
|
|
break; |
|
|
|
|
case Body.Switch: |
|
|
|
|
if (options.IndentSwitchBody) |
|
|
|
|
indent.Push (IndentType.Empty); |
|
|
|
|
indentDelta.Push(IndentType.Empty); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw new ArgumentOutOfRangeException(); |
|
|
|
@ -572,11 +641,14 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -572,11 +641,14 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
{ |
|
|
|
|
None, |
|
|
|
|
Namespace, |
|
|
|
|
Class, Struct, Interface, Enum, |
|
|
|
|
Class, |
|
|
|
|
Struct, |
|
|
|
|
Interface, |
|
|
|
|
Enum, |
|
|
|
|
Switch |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CheckKeyword (string keyword) |
|
|
|
|
void CheckKeyword(string keyword) |
|
|
|
|
{ |
|
|
|
|
switch (currentBody) { |
|
|
|
|
case Body.None: |
|
|
|
|