2020-10-28 06:39:26 +11:00
|
|
|
|
using System.Collections.Generic;
|
2020-10-26 01:07:59 +11:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-11-13 23:50:24 +11:00
|
|
|
|
namespace UnityExplorer.CSConsole.Lexer
|
2020-10-26 01:07:59 +11:00
|
|
|
|
{
|
2020-11-11 00:16:01 +11:00
|
|
|
|
public class CommentMatch : Matcher
|
2020-10-26 01:07:59 +11:00
|
|
|
|
{
|
|
|
|
|
public string lineCommentStart = @"//";
|
|
|
|
|
public string blockCommentStart = @"/*";
|
|
|
|
|
public string blockCommentEnd = @"*/";
|
|
|
|
|
|
|
|
|
|
public override Color HighlightColor => new Color(0.34f, 0.65f, 0.29f, 1.0f);
|
|
|
|
|
public override IEnumerable<char> StartChars => new char[] { lineCommentStart[0], blockCommentStart[0] };
|
|
|
|
|
public override IEnumerable<char> EndChars => new char[] { blockCommentEnd[0] };
|
2020-11-11 00:16:01 +11:00
|
|
|
|
public override bool IsImplicitMatch(CSharpLexer lexer) => IsMatch(lexer, lineCommentStart) || IsMatch(lexer, blockCommentStart);
|
2020-10-26 01:07:59 +11:00
|
|
|
|
|
2020-11-11 00:16:01 +11:00
|
|
|
|
private bool IsMatch(CSharpLexer lexer, string commentType)
|
2020-10-26 01:07:59 +11:00
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(commentType))
|
|
|
|
|
{
|
|
|
|
|
lexer.Rollback();
|
|
|
|
|
|
|
|
|
|
bool match = true;
|
|
|
|
|
for (int i = 0; i < commentType.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (commentType[i] != lexer.ReadNext())
|
|
|
|
|
{
|
|
|
|
|
match = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (match)
|
|
|
|
|
{
|
2020-11-11 00:16:01 +11:00
|
|
|
|
// Read until end of line or file
|
|
|
|
|
while (!IsEndLineOrEndFile(lexer, lexer.ReadNext())) { }
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 00:16:01 +11:00
|
|
|
|
private bool IsEndLineOrEndFile(CSharpLexer lexer, char character) => lexer.EndOfStream || character == '\n' || character == '\r';
|
2020-10-26 01:07:59 +11:00
|
|
|
|
}
|
|
|
|
|
}
|