@@ -119,6 +119,7 @@ namespace Internal.Utilities.Text.Lexing
119119 and set b = endPos <- b
120120
121121 member lexbuf.Lexeme = Array.sub buffer bufferScanStart lexemeLength
122+ member lexbuf.LexemeChar ( n ) = buffer.[ n+ bufferScanStart]
122123
123124 member lexbuf.BufferLocalStore = ( context :> IDictionary<_,_>)
124125 member lexbuf.LexemeLength with get() : int = lexemeLength and set v = lexemeLength <- v
@@ -128,8 +129,14 @@ namespace Internal.Utilities.Text.Lexing
128129 member lexbuf.BufferScanStart with get() : int = bufferScanStart and set v = bufferScanStart <- v
129130 member lexbuf.BufferAcceptAction with get() = bufferAcceptAction and set v = bufferAcceptAction <- v
130131 member lexbuf.RefillBuffer () = filler lexbuf
131- static member LexemeString ( lexbuf : LexBuffer < char >) =
132- new System.String( lexbuf.Buffer, lexbuf.BufferScanStart, lexbuf.LexemeLength)
132+
133+ static member LexemeString ( lexbuf : LexBuffer < LexBufferChar >) =
134+ #if FABLE_ COMPILER
135+ let chars = Array.init lexbuf.LexemeLength ( lexbuf.LexemeChar >> char)
136+ new System.String( chars)
137+ #else
138+ new System.String( lexbuf.Buffer, lexbuf.BufferScanStart, lexbuf.LexemeLength)
139+ #endif
133140
134141 member lexbuf.IsPastEndOfStream
135142 with get() = eof
@@ -167,18 +174,30 @@ namespace Internal.Utilities.Text.Lexing
167174 let buffer = Array.copy s
168175 LexBuffer< 'Char>. FromArrayNoCopy buffer
169176
170- // Important: This method takes ownership of the array
171- static member FromChars ( arr : char []) = LexBuffer.FromArrayNoCopy arr
177+ static member FromString ( s : string ) =
178+ #if FABLE_ COMPILER
179+ let arr = Array.init s.Length ( fun i -> uint16 s.[ i])
180+ LexBuffer.FromArrayNoCopy arr
181+ #else
182+ LexBuffer.FromArrayNoCopy ( s.ToCharArray())
183+ #endif
184+
185+ #if FABLE_ COMPILER
186+ and internal LexBufferChar = uint16
187+ #else
188+ and internal LexBufferChar = char
189+ #endif
190+
172191
173192 module GenericImplFragments =
174- let startInterpret ( lexBuffer : LexBuffer < char >)=
193+ let startInterpret ( lexBuffer : LexBuffer < LexBufferChar >)=
175194 lexBuffer.BufferScanStart <- lexBuffer.BufferScanStart + lexBuffer.LexemeLength;
176195 lexBuffer.BufferMaxScanLength <- lexBuffer.BufferMaxScanLength - lexBuffer.LexemeLength;
177196 lexBuffer.BufferScanLength <- 0 ;
178197 lexBuffer.LexemeLength <- 0 ;
179198 lexBuffer.BufferAcceptAction <- - 1 ;
180199
181- let afterRefill ( trans : uint16 [][], sentinel , lexBuffer : LexBuffer < char >, scanUntilSentinel , endOfScan , state , eofPos ) =
200+ let afterRefill ( trans : uint16 [][], sentinel , lexBuffer : LexBuffer < LexBufferChar >, scanUntilSentinel , endOfScan , state , eofPos ) =
182201 // end of file occurs if we couldn't extend the buffer
183202 if lexBuffer.BufferScanLength = lexBuffer.BufferMaxScanLength then
184203 let snew = int trans.[ state].[ eofPos] // == EOF
@@ -192,9 +211,9 @@ namespace Internal.Utilities.Text.Lexing
192211 else
193212 scanUntilSentinel lexBuffer state
194213
195- let onAccept ( lexBuffer : LexBuffer < char >, a ) =
196- lexBuffer.LexemeLength <- lexBuffer.BufferScanLength;
197- lexBuffer.BufferAcceptAction <- a;
214+ let onAccept ( lexBuffer : LexBuffer < LexBufferChar >, a ) =
215+ lexBuffer.LexemeLength <- lexBuffer.BufferScanLength
216+ lexBuffer.BufferAcceptAction <- a
198217
199218 open GenericImplFragments
200219
@@ -221,15 +240,15 @@ namespace Internal.Utilities.Text.Lexing
221240 let baseForUnicodeCategories = numLowUnicodeChars+ numSpecificUnicodeChars* 2
222241 let unicodeCategory =
223242#if FX_ RESHAPED_ GLOBALIZATION
224- System.Globalization.CharUnicodeInfo.GetUnicodeCategory( inp)
243+ System.Globalization.CharUnicodeInfo.GetUnicodeCategory( char inp)
225244#else
226- System.Char.GetUnicodeCategory( inp)
245+ System.Char.GetUnicodeCategory( char inp)
227246#endif
228247 //System.Console.WriteLine("inp = {0}, unicodeCategory = {1}", [| box inp; box unicodeCategory |]);
229248 int trans.[ state].[ baseForUnicodeCategories + int32 unicodeCategory]
230249 else
231250 // This is the specific unicode character
232- let c = char ( int trans.[ state].[ baseForSpecificUnicodeChars+ i* 2 ])
251+ let c = trans.[ state].[ baseForSpecificUnicodeChars+ i* 2 ]
233252 //System.Console.WriteLine("c = {0}, inp = {1}, i = {2}", [| box c; box inp; box i |]);
234253 // OK, have we found the entry for a specific unicode character?
235254 if c = inp
@@ -252,7 +271,7 @@ namespace Internal.Utilities.Text.Lexing
252271 afterRefill ( trans, sentinel, lexBuffer, scanUntilSentinel, lexBuffer.EndOfScan, state, eofPos)
253272 else
254273 // read a character - end the scan if there are no further transitions
255- let inp = lexBuffer.Buffer.[ lexBuffer.BufferScanPos]
274+ let inp = uint16 lexBuffer.Buffer.[ lexBuffer.BufferScanPos]
256275
257276 // Find the new state
258277 let snew = lookupUnicodeCharacters state inp
@@ -270,7 +289,7 @@ namespace Internal.Utilities.Text.Lexing
270289 // 30 entries, one for each UnicodeCategory
271290 // 1 entry for EOF
272291
273- member tables.Interpret ( initialState , lexBuffer : LexBuffer < char >) =
292+ member tables.Interpret ( initialState , lexBuffer : LexBuffer < LexBufferChar >) =
274293 startInterpret( lexBuffer)
275294 scanUntilSentinel lexBuffer initialState
276295
0 commit comments