@@ -121,6 +121,7 @@ namespace Internal.Utilities.Text.Lexing
121121 and set b = endPos <- b
122122
123123 member lexbuf.Lexeme = Array.sub buffer bufferScanStart lexemeLength
124+ member lexbuf.LexemeChar ( n ) = buffer.[ n+ bufferScanStart]
124125
125126 member lexbuf.BufferLocalStore = ( context :> IDictionary<_,_>)
126127 member lexbuf.LexemeLength with get() : int = lexemeLength and set v = lexemeLength <- v
@@ -130,8 +131,14 @@ namespace Internal.Utilities.Text.Lexing
130131 member lexbuf.BufferScanStart with get() : int = bufferScanStart and set v = bufferScanStart <- v
131132 member lexbuf.BufferAcceptAction with get() = bufferAcceptAction and set v = bufferAcceptAction <- v
132133 member lexbuf.RefillBuffer () = filler lexbuf
133- static member LexemeString ( lexbuf : LexBuffer < char >) =
134- new System.String( lexbuf.Buffer, lexbuf.BufferScanStart, lexbuf.LexemeLength)
134+
135+ static member LexemeString ( lexbuf : LexBuffer < LexBufferChar >) =
136+ #if FABLE_ COMPILER
137+ let chars = Array.init lexbuf.LexemeLength ( lexbuf.LexemeChar >> char)
138+ new System.String( chars)
139+ #else
140+ new System.String( lexbuf.Buffer, lexbuf.BufferScanStart, lexbuf.LexemeLength)
141+ #endif
135142
136143 member lexbuf.IsPastEndOfStream
137144 with get() = eof
@@ -169,18 +176,30 @@ namespace Internal.Utilities.Text.Lexing
169176 let buffer = Array.copy s
170177 LexBuffer< 'Char>. FromArrayNoCopy buffer
171178
172- // Important: This method takes ownership of the array
173- static member FromChars ( arr : char []) = LexBuffer.FromArrayNoCopy arr
179+ static member FromString ( s : string ) =
180+ #if FABLE_ COMPILER
181+ let arr = Array.init s.Length ( fun i -> uint16 s.[ i])
182+ LexBuffer.FromArrayNoCopy arr
183+ #else
184+ LexBuffer.FromArrayNoCopy ( s.ToCharArray())
185+ #endif
186+
187+ #if FABLE_ COMPILER
188+ and internal LexBufferChar = uint16
189+ #else
190+ and internal LexBufferChar = char
191+ #endif
192+
174193
175- module internal GenericImplFragments =
176- let startInterpret ( lexBuffer : LexBuffer < char >) =
194+ module GenericImplFragments =
195+ let startInterpret ( lexBuffer : LexBuffer < LexBufferChar >) =
177196 lexBuffer.BufferScanStart <- lexBuffer.BufferScanStart + lexBuffer.LexemeLength;
178197 lexBuffer.BufferMaxScanLength <- lexBuffer.BufferMaxScanLength - lexBuffer.LexemeLength;
179198 lexBuffer.BufferScanLength <- 0 ;
180199 lexBuffer.LexemeLength <- 0 ;
181200 lexBuffer.BufferAcceptAction <- - 1 ;
182201
183- let afterRefill ( trans : uint16 [][], sentinel , lexBuffer : LexBuffer < char >, scanUntilSentinel , endOfScan , state , eofPos ) =
202+ let afterRefill ( trans : uint16 [][], sentinel , lexBuffer : LexBuffer < LexBufferChar >, scanUntilSentinel , endOfScan , state , eofPos ) =
184203 // end of file occurs if we couldn't extend the buffer
185204 if lexBuffer.BufferScanLength = lexBuffer.BufferMaxScanLength then
186205 let snew = int trans.[ state].[ eofPos] // == EOF
@@ -194,9 +213,9 @@ namespace Internal.Utilities.Text.Lexing
194213 else
195214 scanUntilSentinel lexBuffer state
196215
197- let onAccept ( lexBuffer : LexBuffer < char >, a ) =
198- lexBuffer.LexemeLength <- lexBuffer.BufferScanLength;
199- lexBuffer.BufferAcceptAction <- a;
216+ let onAccept ( lexBuffer : LexBuffer < LexBufferChar >, a ) =
217+ lexBuffer.LexemeLength <- lexBuffer.BufferScanLength
218+ lexBuffer.BufferAcceptAction <- a
200219
201220 open GenericImplFragments
202221
@@ -223,15 +242,15 @@ namespace Internal.Utilities.Text.Lexing
223242 let baseForUnicodeCategories = numLowUnicodeChars+ numSpecificUnicodeChars* 2
224243 let unicodeCategory =
225244#if FX_ RESHAPED_ GLOBALIZATION
226- System.Globalization.CharUnicodeInfo.GetUnicodeCategory( inp)
245+ System.Globalization.CharUnicodeInfo.GetUnicodeCategory( char inp)
227246#else
228- System.Char.GetUnicodeCategory( inp)
247+ System.Char.GetUnicodeCategory( char inp)
229248#endif
230249 //System.Console.WriteLine("inp = {0}, unicodeCategory = {1}", [| box inp; box unicodeCategory |]);
231250 int trans.[ state].[ baseForUnicodeCategories + int32 unicodeCategory]
232251 else
233252 // This is the specific unicode character
234- let c = char ( int trans.[ state].[ baseForSpecificUnicodeChars+ i* 2 ])
253+ let c = trans.[ state].[ baseForSpecificUnicodeChars+ i* 2 ]
235254 //System.Console.WriteLine("c = {0}, inp = {1}, i = {2}", [| box c; box inp; box i |]);
236255 // OK, have we found the entry for a specific unicode character?
237256 if c = inp
@@ -254,7 +273,7 @@ namespace Internal.Utilities.Text.Lexing
254273 afterRefill ( trans, sentinel, lexBuffer, scanUntilSentinel, lexBuffer.EndOfScan, state, eofPos)
255274 else
256275 // read a character - end the scan if there are no further transitions
257- let inp = lexBuffer.Buffer.[ lexBuffer.BufferScanPos]
276+ let inp = uint16 lexBuffer.Buffer.[ lexBuffer.BufferScanPos]
258277
259278 // Find the new state
260279 let snew = lookupUnicodeCharacters state inp
@@ -272,7 +291,7 @@ namespace Internal.Utilities.Text.Lexing
272291 // 30 entries, one for each UnicodeCategory
273292 // 1 entry for EOF
274293
275- member tables.Interpret ( initialState , lexBuffer : LexBuffer < char >) =
294+ member tables.Interpret ( initialState , lexBuffer : LexBuffer < LexBufferChar >) =
276295 startInterpret( lexBuffer)
277296 scanUntilSentinel lexBuffer initialState
278297
0 commit comments