Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/utils/prim-lexing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ namespace Internal.Utilities.Text.Lexing
buffer <- repl


// A full type signature is required on this method because it is used at more specific types within its own scope
static member FromFunction (f : 'Char[] * int * int -> int) : LexBuffer<'Char> =
let extension= Array.zeroCreate 4096
let filler (lexBuffer: LexBuffer<'Char>) =
Expand All @@ -155,15 +154,20 @@ namespace Internal.Utilities.Text.Lexing
lexBuffer.BufferMaxScanLength <- lexBuffer.BufferScanLength + n
new LexBuffer<'Char>(filler)

// A full type signature is required on this method because it is used at more specific types within its own scope
static member FromArray (s: 'Char[]) : LexBuffer<'Char> =
// Important: This method takes ownership of the array
static member FromArrayNoCopy (buffer: 'Char[]) : LexBuffer<'Char> =
let lexBuffer = new LexBuffer<'Char>(fun _ -> ())
let buffer = Array.copy s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the ; while you are touching this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, were left due to oversight.

lexBuffer.Buffer <- buffer;
lexBuffer.BufferMaxScanLength <- buffer.Length;
lexBuffer.Buffer <- buffer
lexBuffer.BufferMaxScanLength <- buffer.Length
lexBuffer

static member FromChars (arr:char[]) = LexBuffer.FromArray arr
// Important: this method does copy the array
static member FromArray (s: 'Char[]) : LexBuffer<'Char> =
let buffer = Array.copy s
LexBuffer<'Char>.FromArrayNoCopy buffer

// Important: This method takes ownership of the array
static member FromChars (arr:char[]) = LexBuffer.FromArrayNoCopy arr

module GenericImplFragments =
let startInterpret(lexBuffer:LexBuffer<char>)=
Expand Down
1 change: 1 addition & 0 deletions src/utils/prim-lexing.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type internal LexBuffer<'Char> =
member IsPastEndOfStream: bool with get,set

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FromArryNoCopy should go here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that FromArray isn't exposed in this file, this is why I haven't added the extra method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks

/// Create a lex buffer suitable for Unicode lexing that reads characters from the given array.
/// Important: does take ownership of the array.
static member FromChars: char[] -> LexBuffer<char>
/// Create a lex buffer that reads character or byte inputs by using the given function.
static member FromFunction: ('Char[] * int * int -> int) -> LexBuffer<'Char>
Expand Down