mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-24 01:12:41 +08:00
33 lines
814 B
C#
33 lines
814 B
C#
using UnityEngine;
|
|
|
|
namespace UnityExplorer.CSConsole.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;
|
|
}
|
|
}
|
|
|
|
}
|