diff --git a/Upsilon/Parser/Lexer.cs b/Upsilon/Parser/Lexer.cs index 6d4f2ce..85c9fe0 100644 --- a/Upsilon/Parser/Lexer.cs +++ b/Upsilon/Parser/Lexer.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Immutable; using System.Text; using Upsilon.Text; @@ -34,6 +35,8 @@ namespace Upsilon.Parser var next = LexNext(); if (next.Kind != SyntaxKind.WhiteSpace) { + if (next.Kind == SyntaxKind.Comment) + continue; array.Add(next); if (next.Kind == SyntaxKind.EndOfFile) break; @@ -186,6 +189,7 @@ namespace Upsilon.Parser private SyntaxToken LexComments() { + _position++; var start = _position; var stringBuilder = new StringBuilder(); if (Current != ' ') @@ -195,8 +199,8 @@ namespace Upsilon.Parser stringBuilder.Append(Next); _position++; } - var str = stringBuilder.ToString(); + _position++; return new SyntaxToken(SyntaxKind.Comment, start, str, str); } } diff --git a/Upsilon/Parser/Parser.cs b/Upsilon/Parser/Parser.cs index c5a3627..278de3a 100644 --- a/Upsilon/Parser/Parser.cs +++ b/Upsilon/Parser/Parser.cs @@ -27,18 +27,13 @@ namespace Upsilon.Parser private SyntaxToken Current => Get(0); private SyntaxToken Next => Get(1); - private SyntaxToken Get(int offset, bool allowComment = false) + private SyntaxToken Get(int offset) { if (_position + offset >= _tokens.Length) return new SyntaxToken(SyntaxKind.EndOfFile, _position + offset, "\0", null); else { - var token = _tokens[_position + offset]; - if (token.Kind == SyntaxKind.Comment && !allowComment) - { - return Get(offset + 1); - } - return token; + return _tokens[_position + offset]; } } diff --git a/UpsilonTests/GeneralTests/CommentTests.cs b/UpsilonTests/GeneralTests/CommentTests.cs new file mode 100644 index 0000000..1889304 --- /dev/null +++ b/UpsilonTests/GeneralTests/CommentTests.cs @@ -0,0 +1,28 @@ +using Upsilon.Evaluator; +using Xunit; + +namespace UpsilonTests.GeneralTests +{ + public class CommentTests : TestClass + { + public CommentTests(StaticScriptFixture fix) : base(fix) + { + } + + [Fact] + public void BasicComment() + { + const string input = @" +-- test comment +return 100 +"; + var script = new Script(input, BoundScope, StaticScope); + Assert.Empty(script.Diagnostics.Messages); + var result = script.Evaluate(); + Assert.Empty(script.Diagnostics.Messages); + Assert.Equal(100, result); + + } + + } +} \ No newline at end of file