rename Lexer folder to match namespace, some cleanups and color adjustments

This commit is contained in:
Sinai
2021-05-11 01:43:08 +10:00
parent 2efce9eb0e
commit 617d68f7e9
11 changed files with 166 additions and 131 deletions

View File

@ -0,0 +1,32 @@
using UnityEngine;
namespace UnityExplorer.UI.CSharpConsole.Lexers
{
public class NumberLexer : Lexer
{
// Maroon
protected override Color HighlightColor => new Color(0.58f, 0.33f, 0.33f, 1.0f);
private bool IsNumeric(char c) => char.IsNumber(c) || c == '.';
public override bool TryMatchCurrent(LexerBuilder lexer)
{
// previous character must be whitespace or delimiter
if (!lexer.IsDelimiter(lexer.Previous, true))
return false;
if (!IsNumeric(lexer.Current))
return false;
while (!lexer.EndOfInput)
{
lexer.Commit();
if (!IsNumeric(lexer.PeekNext()))
break;
}
return true;
}
}
}