Skip to content

LexBuffer<char>.LexemeSpan #172

@bent-rasmussen

Description

@bent-rasmussen

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions