Skip to content

Commit

Permalink
Merge pull request #465 from b3b00/bugfix/issue464
Browse files Browse the repository at this point in the history
Bugfix/issue464
  • Loading branch information
b3b00 authored Jul 16, 2024
2 parents 3d6d488 + 3e16650 commit b9923c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/sly/lexer/EOLType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public enum EolType
Mac,
Environment,

Eof,

No
}
}
6 changes: 5 additions & 1 deletion src/sly/lexer/fsm/EOLManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static ReadOnlyMemory<char> GetToEndOfLine(this ReadOnlyMemory<char> valu
end = IsEndOfLine(value, CurrentPosition);
}

return value.Slice(position, CurrentPosition - position + (end == EolType.Windows ? 2 : 1));
return value.Slice(position, CurrentPosition - position + (end == EolType.Eof ? 0 : end == EolType.Windows ? 2 : 1));
}

public static ReadOnlyMemory<char> RemoveEndOfLineChars(this ReadOnlyMemory<char> value)
Expand All @@ -38,6 +38,10 @@ public static ReadOnlyMemory<char> RemoveEndOfLineChars(this ReadOnlyMemory<char
public static EolType IsEndOfLine(ReadOnlyMemory<char> value, int position)
{
var end = EolType.No;
if (position >= value.Length)
{
return EolType.Eof;
}
var n = value.At<char>(position);
switch (n)
{
Expand Down
21 changes: 21 additions & 0 deletions tests/ParserTests/comments/SingleLineCommentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ public void TestGenericMultiLineCommentWithSingleLineComment()
var tokens = r.Tokens;
Check.That(r.Error.UnexpectedChar).IsEqualTo('*');
}

[Fact]
public void TestCommentOnLastLine()
{
var lexerRes = LexerBuilder.BuildLexer(new BuildResult<ILexer<SingleLineCommentsToken>>());
Check.That(lexerRes).IsOk();

var lexer = lexerRes.Result as GenericLexer<SingleLineCommentsToken>;

var dump = lexer.ToString();

var r =lexer?.Tokenize(@"
1.0
// this is the final comment");
Check.That(r).IsOkLexing();
var comment = r.Tokens[1];
Check.That(comment).IsNotNull();
Check.That(comment.TokenID).IsEqualTo(SingleLineCommentsToken.COMMENT);
Check.That(comment.Value).Contains("this is the final comment");

}

[Fact]
public void TestGenericSingleLineComment()
Expand Down

0 comments on commit b9923c1

Please sign in to comment.