Skip to content

How to track position? #19

Answered by teo-tsirpanis
fponticelli asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, thanks for the question and thanks for using Farkle! I am glad to see such appreciation for it.

That's a good question. Farkle actually has the ability to allow user code to track the position of tokens. Let's take a look at an example from the quick start guide:

let numberStringRegex =
    Regex.regexString @"\d+(\.\d+)?(e[+-]?\d+)?"
    |> terminal "Number" (T(fun _ x -> float (x.ToString())))

See the first ignored parameter in the last line's lambda? It holds an object of type ITransformerContext, which has properties that expose the token's starting and ending position. You can write with that something like the following:

let numberStringRegex =
    Regex.regexString @"\d+(\.\…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@teo-tsirpanis
Comment options

@fponticelli
Comment options

@teo-tsirpanis
Comment options

@fponticelli
Comment options

Answer selected by teo-tsirpanis
Comment options

You must be logged in to vote
1 reply
@teo-tsirpanis
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants