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()
|
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
|
public class Lexer
|
||||||
{
|
{
|
||||||
|
private bool SaveComments { get; }
|
||||||
private readonly string _text;
|
private readonly string _text;
|
||||||
private readonly Diagnostics _diagnostics;
|
private readonly Diagnostics _diagnostics;
|
||||||
private int _position;
|
private int _position;
|
||||||
|
|
||||||
private Lexer(string text, Diagnostics diagnostics)
|
private Lexer(string text, Diagnostics diagnostics, bool saveComments)
|
||||||
{
|
{
|
||||||
|
SaveComments = saveComments;
|
||||||
_text = text;
|
_text = text;
|
||||||
_diagnostics = diagnostics;
|
_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();
|
return lexer.Lex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ namespace Upsilon.Parser
|
||||||
switch (next.Kind)
|
switch (next.Kind)
|
||||||
{
|
{
|
||||||
case SyntaxKind.Comment:
|
case SyntaxKind.Comment:
|
||||||
|
if (SaveComments)
|
||||||
_activeComments.Add(next.Value.ToString());
|
_activeComments.Add(next.Value.ToString());
|
||||||
continue;
|
continue;
|
||||||
case SyntaxKind.FunctionKeyword:
|
case SyntaxKind.FunctionKeyword:
|
||||||
|
@ -202,17 +205,21 @@ namespace Upsilon.Parser
|
||||||
{
|
{
|
||||||
_position++;
|
_position++;
|
||||||
var start = _position;
|
var start = _position;
|
||||||
var stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = null;
|
||||||
|
if (SaveComments)
|
||||||
|
{
|
||||||
|
stringBuilder = new StringBuilder();
|
||||||
if (Current != ' ')
|
if (Current != ' ')
|
||||||
stringBuilder.Append(Current);
|
stringBuilder.Append(Current);
|
||||||
|
}
|
||||||
while (Next != '\n' && Next != '\0')
|
while (Next != '\n' && Next != '\0')
|
||||||
{
|
{
|
||||||
stringBuilder.Append(Next);
|
stringBuilder?.Append(Next);
|
||||||
_position++;
|
_position++;
|
||||||
}
|
}
|
||||||
var str = stringBuilder.ToString();
|
var str = stringBuilder?.ToString();
|
||||||
_position++;
|
_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;
|
_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();
|
return (BlockStatementSyntax) new Parser(tokens, diagnostics).ParseScriptSyntax();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,13 @@ namespace Upsilon.Parser
|
||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SyntaxToken(SyntaxKind kind, int position, int length, object value)
|
||||||
|
{
|
||||||
|
Kind = kind;
|
||||||
|
Span = new TextSpan(position, length);
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
public override SyntaxKind Kind { get; }
|
public override SyntaxKind Kind { get; }
|
||||||
public object Value { get; }
|
public object Value { get; }
|
||||||
public string[] CommentData { get; set; }
|
public string[] CommentData { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue