Better comments

This commit is contained in:
2018-11-26 13:59:57 +01:00
parent e02eb39753
commit a66b1abbf5
3 changed files with 35 additions and 8 deletions

View File

@@ -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);
}
}

View File

@@ -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];
}
}