Skip to content

Commit

Permalink
Merge pull request #203 from dawedawe/add_fable_support
Browse files Browse the repository at this point in the history
add Fable support to FsLexYacc.Runtime
  • Loading branch information
nojaf authored Apr 8, 2024
2 parents 444b890 + 86d76e1 commit 3e31ff5
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 22 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 11.3.0 - Unreleased
* Add Fable support to FsLexYacc.Runtime.

#### 11.2.0 - 12 May, 2023
* Add `--open` option for fslex.
* Generate signature files for transformed files in fslex.
Expand Down
8 changes: 4 additions & 4 deletions src/FsLex.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("FsLex.Core")>]
[<assembly: AssemblyProductAttribute("FsLexYacc")>]
[<assembly: AssemblyDescriptionAttribute("FsLex/FsYacc lexer/parser generation tools")>]
[<assembly: AssemblyVersionAttribute("11.2.0")>]
[<assembly: AssemblyFileVersionAttribute("11.2.0")>]
[<assembly: AssemblyVersionAttribute("11.3.0")>]
[<assembly: AssemblyFileVersionAttribute("11.3.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsLex.Core"
let [<Literal>] AssemblyProduct = "FsLexYacc"
let [<Literal>] AssemblyDescription = "FsLex/FsYacc lexer/parser generation tools"
let [<Literal>] AssemblyVersion = "11.2.0"
let [<Literal>] AssemblyFileVersion = "11.2.0"
let [<Literal>] AssemblyVersion = "11.3.0"
let [<Literal>] AssemblyFileVersion = "11.3.0"
8 changes: 4 additions & 4 deletions src/FsLex/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("FsLex")>]
[<assembly: AssemblyProductAttribute("FsLexYacc")>]
[<assembly: AssemblyDescriptionAttribute("FsLex/FsYacc lexer/parser generation tools")>]
[<assembly: AssemblyVersionAttribute("11.2.0")>]
[<assembly: AssemblyFileVersionAttribute("11.2.0")>]
[<assembly: AssemblyVersionAttribute("11.3.0")>]
[<assembly: AssemblyFileVersionAttribute("11.3.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsLex"
let [<Literal>] AssemblyProduct = "FsLexYacc"
let [<Literal>] AssemblyDescription = "FsLex/FsYacc lexer/parser generation tools"
let [<Literal>] AssemblyVersion = "11.2.0"
let [<Literal>] AssemblyFileVersion = "11.2.0"
let [<Literal>] AssemblyVersion = "11.3.0"
let [<Literal>] AssemblyFileVersion = "11.3.0"
8 changes: 4 additions & 4 deletions src/FsLexYacc.Runtime/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("FsLexYacc.Runtime")>]
[<assembly: AssemblyProductAttribute("FsLexYacc.Runtime")>]
[<assembly: AssemblyDescriptionAttribute("FsLex/FsYacc lexer/parser generation tools")>]
[<assembly: AssemblyVersionAttribute("11.2.0")>]
[<assembly: AssemblyFileVersionAttribute("11.2.0")>]
[<assembly: AssemblyVersionAttribute("11.3.0")>]
[<assembly: AssemblyFileVersionAttribute("11.3.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsLexYacc.Runtime"
let [<Literal>] AssemblyProduct = "FsLexYacc.Runtime"
let [<Literal>] AssemblyDescription = "FsLex/FsYacc lexer/parser generation tools"
let [<Literal>] AssemblyVersion = "11.2.0"
let [<Literal>] AssemblyFileVersion = "11.2.0"
let [<Literal>] AssemblyVersion = "11.3.0"
let [<Literal>] AssemblyFileVersion = "11.3.0"
4 changes: 4 additions & 0 deletions src/FsLexYacc.Runtime/FsLexYacc.Runtime.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
<Compile Include="Parsing.fs" />
<Content Include="../../docs/img/logo.png" PackagePath="logo.png" />
</ItemGroup>
<ItemGroup>
<Content Include="@(Compile)" Pack="true" PackagePath="fable/%(RelativeDir)%(Filename)%(Extension)" />
<Content Include="$(MSBuildThisFileFullPath)" Pack="true" PackagePath="fable/" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
13 changes: 11 additions & 2 deletions src/FsLexYacc.Runtime/Lexing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ and [<Sealed>] LexBuffer<'char>(filler: LexBufferFiller<'char>) as this =
static member FromString(s: string) =
LexBuffer<char>.FromArray(s.ToCharArray())

#if !FABLE_COMPILER
static member FromTextReader(tr: System.IO.TextReader) : LexBuffer<char> =
LexBuffer<char>
.FromReadFunctions(Some tr.Read, Some(tr.ReadAsync >> Async.AwaitTask))
Expand All @@ -275,6 +276,7 @@ and [<Sealed>] LexBuffer<'char>(filler: LexBufferFiller<'char>) as this =
static member FromStream(stream: System.IO.Stream) : LexBuffer<byte> =
LexBuffer<byte>
.FromReadFunctions(Some(stream.Read), Some(fun (buf, offset, len) -> stream.AsyncRead(buf, offset = offset, count = len)))
#endif

module GenericImplFragments =
let startInterpret (lexBuffer: LexBuffer<_>) =
Expand Down Expand Up @@ -400,7 +402,13 @@ type UnicodeTables(trans: uint16[] array, accept: uint16[]) =
// which covers all Unicode characters not covered in other
// ways
let baseForUnicodeCategories = numLowUnicodeChars + numSpecificUnicodeChars * 2
let unicodeCategory = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(inp)

let unicodeCategory =
#if FABLE_COMPILER
System.Char.GetUnicodeCategory(inp)
#else
System.Globalization.CharUnicodeInfo.GetUnicodeCategory(inp)
#endif
//System.Console.WriteLine("inp = {0}, unicodeCategory = {1}", [| box inp; box unicodeCategory |])
int trans.[state].[baseForUnicodeCategories + int32 unicodeCategory]
else
Expand Down Expand Up @@ -489,7 +497,7 @@ type UnicodeTables(trans: uint16[] array, accept: uint16[]) =
static member Create(trans, accept) = UnicodeTables(trans, accept)

open System.IO

#if !FABLE_COMPILER
let UnicodeFileAsLexbuf (filename, codePage: int option) : FileStream * StreamReader * LexBuffer<char> =
// Use the .NET functionality to auto-detect the unicode encoding
// It also presents the bytes read to the lexer in UTF8 decoded form
Expand All @@ -504,3 +512,4 @@ let UnicodeFileAsLexbuf (filename, codePage: int option) : FileStream * StreamRe
let lexbuf = LexBuffer.FromFunction(reader.Read)
lexbuf.EndPos <- Position.FirstLine(filename)
stream, reader, lexbuf
#endif
8 changes: 8 additions & 0 deletions src/FsLexYacc.Runtime/Lexing.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ type LexBuffer<'char> =
[<System.Obsolete("Use LexBuffer<byte>.FromFunction instead")>]
static member FromByteFunction: (byte[] -> int -> int) -> LexBuffer<byte>

#if !FABLE_COMPILER

/// Create a lex buffer suitable for use with a Unicode lexer that reads character inputs from the given text reader
static member FromTextReader: System.IO.TextReader -> LexBuffer<char>

/// Create a lex buffer suitable for use with ASCII byte lexing that reads byte inputs from the given binary reader
static member FromBinaryReader: System.IO.BinaryReader -> LexBuffer<byte>

#endif

/// The type of tables for an ascii lexer generated by fslex.
[<Sealed>]
type AsciiTables =
Expand All @@ -152,10 +156,14 @@ type UnicodeTables =
[<System.Obsolete("Async interretation of lexer tables is now obsolete and will be removed. Please use a background thread if you want async lexing")>]
member AsyncInterpret: initialState: int * LexBuffer<char> -> Async<int>

#if !FABLE_COMPILER

/// Standard utility to create a Unicode LexBuffer
///
/// One small annoyance is that LexBuffers are not IDisposable. This means
/// we can't just return the LexBuffer object, since the file it wraps wouldn't
/// get closed when we're finished with the LexBuffer. Hence we return the stream,
/// the reader and the LexBuffer. The caller should dispose the first two when done.
val UnicodeFileAsLexbuf: string * int option -> System.IO.FileStream * System.IO.StreamReader * LexBuffer<char>

#endif
8 changes: 4 additions & 4 deletions src/FsYacc.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("FsYacc.Core")>]
[<assembly: AssemblyProductAttribute("FsLexYacc")>]
[<assembly: AssemblyDescriptionAttribute("FsLex/FsYacc lexer/parser generation tools")>]
[<assembly: AssemblyVersionAttribute("11.2.0")>]
[<assembly: AssemblyFileVersionAttribute("11.2.0")>]
[<assembly: AssemblyVersionAttribute("11.3.0")>]
[<assembly: AssemblyFileVersionAttribute("11.3.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsYacc.Core"
let [<Literal>] AssemblyProduct = "FsLexYacc"
let [<Literal>] AssemblyDescription = "FsLex/FsYacc lexer/parser generation tools"
let [<Literal>] AssemblyVersion = "11.2.0"
let [<Literal>] AssemblyFileVersion = "11.2.0"
let [<Literal>] AssemblyVersion = "11.3.0"
let [<Literal>] AssemblyFileVersion = "11.3.0"
8 changes: 4 additions & 4 deletions src/FsYacc/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("FsYacc")>]
[<assembly: AssemblyProductAttribute("FsLexYacc")>]
[<assembly: AssemblyDescriptionAttribute("FsLex/FsYacc lexer/parser generation tools")>]
[<assembly: AssemblyVersionAttribute("11.2.0")>]
[<assembly: AssemblyFileVersionAttribute("11.2.0")>]
[<assembly: AssemblyVersionAttribute("11.3.0")>]
[<assembly: AssemblyFileVersionAttribute("11.3.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsYacc"
let [<Literal>] AssemblyProduct = "FsLexYacc"
let [<Literal>] AssemblyDescription = "FsLex/FsYacc lexer/parser generation tools"
let [<Literal>] AssemblyVersion = "11.2.0"
let [<Literal>] AssemblyFileVersion = "11.2.0"
let [<Literal>] AssemblyVersion = "11.3.0"
let [<Literal>] AssemblyFileVersion = "11.3.0"

0 comments on commit 3e31ff5

Please sign in to comment.