-
Can you please help defining a Hex Literal using the Generic Lexer. Example [a-fA-F0-9]+ thanks |
Beta Was this translation helpful? Give feedback.
Answered by
b3b00
Jun 30, 2024
Replies: 2 comments 3 replies
-
Hello, I will look at it tomorrow. In the meantime you can look at lexer extension that is the way to do it |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here is a quick answer. using sly.lexer;
using sly.lexer.fsm;
using sly.i18n;
namespace hexa
{
public enum hexalexer
{
[Extension]
HEX,
}
public class Extendedhexalexer
{
public static void Extendhexalexer(hexalexer token, LexemeAttribute lexem, GenericLexer<hexalexer> lexer)
{
if (token == hexalexer.HEX)
{
NodeCallback<GenericToken> callbackHEX = (FSMMatch<GenericToken> match) =>
{
// this store the token id the the FSMMatch object to be later returned by GenericLexer.Tokenize
match.Properties[GenericLexer<hexalexer>.DerivedToken] = hexalexer.HEX;
return match;
};
var builder = lexer.FSMBuilder;
builder.GoTo("start").Transition('0')
.Transition('x')
.MultiRangeTransition(('0', '9'), ('a', 'f'), ('A', 'F'))
.Mark("mark#1")
.MultiRangeTransitionTo("mark#1", ('0', '9'), ('a', 'f'), ('A', 'F'))
.End(GenericToken.Extension)
.CallBack(callbackHEX);
}
}
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
utech626
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a quick answer.