Dont save data comments if disabled through options
This commit is contained in:
parent
b7d01b02f1
commit
8b08aea404
|
@ -56,7 +56,7 @@ namespace Upsilon.Evaluator
|
|||
|
||||
internal void Parse()
|
||||
{
|
||||
_parsed = Parser.Parser.Parse(_scriptString, Diagnostics);
|
||||
_parsed = Parser.Parser.Parse(_scriptString, Diagnostics, Options.SaveDataComments);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,19 +7,21 @@ namespace Upsilon.Parser
|
|||
{
|
||||
public class Lexer
|
||||
{
|
||||
private bool SaveComments { get; }
|
||||
private readonly string _text;
|
||||
private readonly Diagnostics _diagnostics;
|
||||
private int _position;
|
||||
|
||||
private Lexer(string text, Diagnostics diagnostics)
|
||||
private Lexer(string text, Diagnostics diagnostics, bool saveComments)
|
||||
{
|
||||
SaveComments = saveComments;
|
||||
_text = text;
|
||||
_diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
public static ImmutableArray<SyntaxToken> Lex(string text, Diagnostics diagnostics)
|
||||
public static ImmutableArray<SyntaxToken> Lex(string text, Diagnostics diagnostics, bool saveComments)
|
||||
{
|
||||
var lexer = new Lexer(text, diagnostics);
|
||||
var lexer = new Lexer(text, diagnostics, saveComments);
|
||||
return lexer.Lex();
|
||||
}
|
||||
|
||||
|
@ -38,7 +40,8 @@ namespace Upsilon.Parser
|
|||
switch (next.Kind)
|
||||
{
|
||||
case SyntaxKind.Comment:
|
||||
_activeComments.Add(next.Value.ToString());
|
||||
if (SaveComments)
|
||||
_activeComments.Add(next.Value.ToString());
|
||||
continue;
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
case SyntaxKind.LocalKeyword:
|
||||
|
@ -202,17 +205,21 @@ namespace Upsilon.Parser
|
|||
{
|
||||
_position++;
|
||||
var start = _position;
|
||||
var stringBuilder = new StringBuilder();
|
||||
if (Current != ' ')
|
||||
stringBuilder.Append(Current);
|
||||
StringBuilder stringBuilder = null;
|
||||
if (SaveComments)
|
||||
{
|
||||
stringBuilder = new StringBuilder();
|
||||
if (Current != ' ')
|
||||
stringBuilder.Append(Current);
|
||||
}
|
||||
while (Next != '\n' && Next != '\0')
|
||||
{
|
||||
stringBuilder.Append(Next);
|
||||
stringBuilder?.Append(Next);
|
||||
_position++;
|
||||
}
|
||||
var str = stringBuilder.ToString();
|
||||
var str = stringBuilder?.ToString();
|
||||
_position++;
|
||||
return new SyntaxToken(SyntaxKind.Comment, start, str, str);
|
||||
return new SyntaxToken(SyntaxKind.Comment, start, _position - start, str);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,9 +18,9 @@ namespace Upsilon.Parser
|
|||
_diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
public static BlockStatementSyntax Parse(string text, Diagnostics diagnostics)
|
||||
public static BlockStatementSyntax Parse(string text, Diagnostics diagnostics, bool saveComments)
|
||||
{
|
||||
var tokens = Lexer.Lex(text, diagnostics);
|
||||
var tokens = Lexer.Lex(text, diagnostics, saveComments);
|
||||
return (BlockStatementSyntax) new Parser(tokens, diagnostics).ParseScriptSyntax();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,15 @@ namespace Upsilon.Parser
|
|||
{
|
||||
public SyntaxToken(SyntaxKind kind, int position, string text, object value)
|
||||
{
|
||||
Kind = kind;
|
||||
Span = new TextSpan(position, text.Length);
|
||||
Kind = kind;
|
||||
Span = new TextSpan(position, text.Length);
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public SyntaxToken(SyntaxKind kind, int position, int length, object value)
|
||||
{
|
||||
Kind = kind;
|
||||
Span = new TextSpan(position, length);
|
||||
Value = value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue