diff --git a/src/sly/lexer/LexerPosition.cs b/src/sly/lexer/LexerPosition.cs index ee04922f..db610723 100644 --- a/src/sly/lexer/LexerPosition.cs +++ b/src/sly/lexer/LexerPosition.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; namespace sly.lexer @@ -18,33 +19,19 @@ public LexerPosition(int index, int line, int column, string mode = ModeAttribut Index = index; Line = line; Column = column; - Indentations = ImmutableStack.Empty; - Indentations2 = new List(); Mode = mode; } - public LexerPosition(int index, int line, int column, ImmutableStack indentations, IList indentations2, string mode = ModeAttribute.DefaultLexerMode) : this(index, line, column, mode) - { - Indentations = indentations; - Indentations2 = indentations2; - } - - public LexerPosition(int index, int line, int column, ImmutableStack indentations, IList indentations2, int currentIndentation, string mode = ModeAttribute.DefaultLexerMode) : this(index, line, column, indentations, indentations2, mode) + public LexerPosition(int index, int line, int column, int currentIndentation, string mode = ModeAttribute.DefaultLexerMode) : this(index, line, column, mode) { CurrentIndentation = currentIndentation; - Indentations2 = indentations2; } public bool IsStartOfLine => Column == 0; - - public ImmutableStack Indentations { get; set; } - - public IList Indentations2 { get; set; } - - public string PreviousIndentation { get; set; } = ""; public int CurrentIndentation { get; set; } + [JsonIgnore] public LexerIndentation Indentation { get; set; } = new LexerIndentation(); public int Column { get; set; } @@ -81,7 +68,7 @@ public int CompareTo(object obj) public LexerPosition Clone() { - return new LexerPosition(Index, Line, Column, Indentations, Indentations2, CurrentIndentation) + return new LexerPosition(Index, Line, Column, CurrentIndentation) { Indentation = this.Indentation.Clone(), Mode = Mode diff --git a/src/sly/lexer/Token.cs b/src/sly/lexer/Token.cs index f897c3aa..8f3025f5 100644 --- a/src/sly/lexer/Token.cs +++ b/src/sly/lexer/Token.cs @@ -188,6 +188,7 @@ public Token Previous(int channelId) public bool IsUnIndent { get; set; } = false; + [JsonIgnore] public bool IsNoIndent { get; set; } = false; public bool IsIndentation => IsIndent || IsUnIndent || IsNoIndent; diff --git a/src/sly/lexer/fsm/FSMLexer.cs b/src/sly/lexer/fsm/FSMLexer.cs index 5a4da5e0..aef21580 100644 --- a/src/sly/lexer/fsm/FSMLexer.cs +++ b/src/sly/lexer/fsm/FSMLexer.cs @@ -317,7 +317,7 @@ private FSMMatch ConsumeIndents3(ReadOnlyMemory source, LexerPosition l { case LexerIndentationType.Indent: { - var indent = FSMMatch.Indent(lexerPosition.Indentations.Count() + 1); + var indent = FSMMatch.Indent(lexerPosition.Indentation.CurrentLevel); indent.Result = new Token { IsIndent = true, @@ -331,14 +331,11 @@ private FSMMatch ConsumeIndents3(ReadOnlyMemory source, LexerPosition l indent.NewPosition = lexerPosition.Clone(); indent.NewPosition.Index += currentShift.Length; indent.NewPosition.Column += currentShift.Length; - indent.NewPosition.Indentations = indent.NewPosition.Indentations.Push(currentShift); - indent.NewPosition.Indentations2.Add(currentShift); - indent.NewPosition.PreviousIndentation = currentShift; return indent; } case LexerIndentationType.UIndent: { - var uIndent = FSMMatch.UIndent(lexerPosition.Indentations.Count() + 1); + var uIndent = FSMMatch.UIndent(lexerPosition.Indentation.CurrentLevel); uIndent.Result = new Token { IsIndent = false, @@ -352,22 +349,17 @@ private FSMMatch ConsumeIndents3(ReadOnlyMemory source, LexerPosition l uIndent.NewPosition = lexerPosition.Clone(); uIndent.NewPosition.Index += currentShift.Length; uIndent.NewPosition.Column += currentShift.Length; - uIndent.NewPosition.Indentations = uIndent.NewPosition.Indentations.Push(currentShift); - uIndent.NewPosition.Indentations2.Add(currentShift); - uIndent.NewPosition.PreviousIndentation = currentShift; return uIndent; } case LexerIndentationType.None: { - var noIndent = FSMMatch.Indent(lexerPosition.Indentations.Count()); + var noIndent = FSMMatch.Indent(lexerPosition.Indentation.CurrentLevel); noIndent.IsNoIndent = true; noIndent.IsIndent = false; noIndent.IsUnIndent = false; noIndent.NewPosition = lexerPosition.Clone(); noIndent.NewPosition.Index += currentShift.Length; noIndent.NewPosition.Column += currentShift.Length; - noIndent.NewPosition.PreviousIndentation = currentShift; - return noIndent; } case LexerIndentationType.Error: diff --git a/src/sly/sly.csproj b/src/sly/sly.csproj index 2f3a8ce6..f00abb0f 100644 --- a/src/sly/sly.csproj +++ b/src/sly/sly.csproj @@ -6,10 +6,10 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb #LY is a parser generator halfway between parser combinators and parser generator like ANTLR b3b00 - 3.2.2 + 3.2.3 https://github.com/b3b00/sly https://github.com/b3b00/sly - 3.2.2 + 3.2.3 Library