Better comments
This commit is contained in:
parent
e02eb39753
commit
a66b1abbf5
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<long>();
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal(100, result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue