UnityExplorer/src/CSConsole/Lexers/CommentLexer.cs

52 lines
1.4 KiB
C#
Raw Normal View History

using UnityEngine;
2021-05-10 15:58:49 +10:00
namespace UnityExplorer.CSConsole.Lexers
2021-05-10 15:58:49 +10:00
{
public class CommentLexer : Lexer
{
private enum CommentType
{
Line,
Block
}
// forest green
protected override Color HighlightColor => new(0.34f, 0.65f, 0.29f, 1.0f);
2021-05-10 15:58:49 +10:00
public override bool TryMatchCurrent(LexerBuilder lexer)
{
if (lexer.Current == '/')
{
lexer.PeekNext();
if (lexer.Current == '/')
{
// line comment. read to end of line or file.
do
{
lexer.Commit();
lexer.PeekNext();
}
while (!lexer.EndOrNewLine);
return true;
}
else if (lexer.Current == '*')
{
// block comment, read until end of file or closing '*/'
lexer.PeekNext();
do
{
lexer.PeekNext();
lexer.Commit();
}
while (!lexer.EndOfInput && !(lexer.Current == '/' && lexer.Previous == '*'));
return true;
2021-06-05 19:36:09 +10:00
}
2021-05-10 15:58:49 +10:00
}
return false;
}
}
}