Skip to content

Commit

Permalink
v 3.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Jul 11, 2024
1 parent f82d13e commit 3dbfc3e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
21 changes: 4 additions & 17 deletions src/sly/lexer/LexerPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

namespace sly.lexer

Expand All @@ -18,33 +19,19 @@ public LexerPosition(int index, int line, int column, string mode = ModeAttribut
Index = index;
Line = line;
Column = column;
Indentations = ImmutableStack<string>.Empty;
Indentations2 = new List<string>();
Mode = mode;
}

public LexerPosition(int index, int line, int column, ImmutableStack<string> indentations, IList<string> indentations2, string mode = ModeAttribute.DefaultLexerMode) : this(index, line, column, mode)
{
Indentations = indentations;
Indentations2 = indentations2;
}

public LexerPosition(int index, int line, int column, ImmutableStack<string> indentations, IList<string> 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<string> Indentations { get; set; }

public IList<string> 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; }
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/sly/lexer/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public Token<T> Previous(int channelId)

public bool IsUnIndent { get; set; } = false;

[JsonIgnore]
public bool IsNoIndent { get; set; } = false;

public bool IsIndentation => IsIndent || IsUnIndent || IsNoIndent;
Expand Down
14 changes: 3 additions & 11 deletions src/sly/lexer/fsm/FSMLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private FSMMatch<N> ConsumeIndents3(ReadOnlyMemory<char> source, LexerPosition l
{
case LexerIndentationType.Indent:
{
var indent = FSMMatch<N>.Indent(lexerPosition.Indentations.Count<string>() + 1);
var indent = FSMMatch<N>.Indent(lexerPosition.Indentation.CurrentLevel);
indent.Result = new Token<N>
{
IsIndent = true,
Expand All @@ -331,14 +331,11 @@ private FSMMatch<N> ConsumeIndents3(ReadOnlyMemory<char> 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<N>.UIndent(lexerPosition.Indentations.Count<string>() + 1);
var uIndent = FSMMatch<N>.UIndent(lexerPosition.Indentation.CurrentLevel);
uIndent.Result = new Token<N>
{
IsIndent = false,
Expand All @@ -352,22 +349,17 @@ private FSMMatch<N> ConsumeIndents3(ReadOnlyMemory<char> 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<N>.Indent(lexerPosition.Indentations.Count<string>());
var noIndent = FSMMatch<N>.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:
Expand Down
4 changes: 2 additions & 2 deletions src/sly/sly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<Description>#LY is a parser generator halfway between parser combinators and parser generator like ANTLR</Description>
<Authors>b3b00</Authors>
<version>3.2.2</version>
<version>3.2.3</version>
<PackageProjectUrl>https://github.com/b3b00/sly</PackageProjectUrl>
<RepositoryUrl>https://github.com/b3b00/sly</RepositoryUrl>
<PackageVersion>3.2.2</PackageVersion>
<PackageVersion>3.2.3</PackageVersion>
<ApplicationIcon/>
<OutputType>Library</OutputType>
<StartupObject/>
Expand Down

0 comments on commit 3dbfc3e

Please sign in to comment.