Better comments
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user