Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LexBuffer<char>.LexemeSpan #172

Open
bent-rasmussen opened this issue Jul 15, 2023 · 0 comments
Open

LexBuffer<char>.LexemeSpan #172

bent-rasmussen opened this issue Jul 15, 2023 · 0 comments

Comments

@bent-rasmussen
Copy link

bent-rasmussen commented Jul 15, 2023

LexBuffer<'char> has this static method:

static member LexemeString(lexbuf: LexBuffer<char>) =
    System.String(lexbuf.Buffer, lexbuf.BufferScanStart, lexbuf.LexemeLength)

See https://github.com/fsprojects/FsLexYacc/blob/master/src/FsLexYacc.Runtime/Lexing.fs#L178C58-L178C58

We would like to try and get access to the buffer, without necessarily allocating a string, e.g.:

#if NETSTANDARD2_1
static member LexemeSpan(lexbuf: LexBuffer<char>) =
    new ReadOnlySpan<char>(lexbuf.Buffer, lexbuf.BufferScanStart, lexbuf.LexemeLength)
#endif

For example, we could use a StringPool to reuse prior allocations of equivalent strings:

let ident = StringPool.Shared.GetOrAdd(lexemeSpan)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant