1 Commits

Author SHA1 Message Date
Patrick Stevens
50b4dc89fc Downgrade FSharp.Core (#22) 2024-06-23 12:22:37 +01:00
4 changed files with 28 additions and 18 deletions

9
PrattParser/Map.fs Normal file
View File

@@ -0,0 +1,9 @@
namespace WoofWare.PrattParser
[<RequireQualifiedAccess>]
module internal Map =
// For compat reasons, we target a very low FSharp.Core.
let change k f m =
match f (Map.tryFind k m) with
| None -> Map.remove k m
| Some v -> Map.add k v m

View File

@@ -252,8 +252,8 @@ module Parser =
| Some token -> token, rest
| None ->
match parser.BracketLike.TryGetValue (parser.GetTag firstToken) with
| true, parse ->
match Map.tryFind (parser.GetTag firstToken) parser.BracketLike with
| Some parse ->
// This is an ambiguous parse if multiple parsers genuinely matched.
// (We already filter to the longest possible matching parser.)
match parseBracketLike parser inputString parse [] rest with
@@ -263,13 +263,13 @@ module Parser =
failwithf
"Ambiguous parse for bracket-like construct. You should restrict the grammar. %+A"
firstToken
| false, _ ->
| None ->
match parser.UnaryPrefix.TryGetValue (parser.GetTag firstToken) with
| true, (((), precedence), assemble) ->
match Map.tryFind (parser.GetTag firstToken) parser.UnaryPrefix with
| Some (((), precedence), assemble) ->
let rhs, rest = parseInner parser inputString rest precedence
assemble rhs, rest
| false, _ -> failwithf "didn't get an atom or prefix, got: %+A" firstToken
| None -> failwithf "didn't get an atom or prefix, got: %+A" firstToken
let rec go (lhs : 'expr) (tokens : 'token list) : 'expr * 'token list =
match tokens with
@@ -277,30 +277,30 @@ module Parser =
| op :: rest ->
let fromBracketed =
match parser.BracketLike.TryGetValue (parser.GetTag op) with
| true, parse ->
match Map.tryFind (parser.GetTag op) parser.BracketLike with
| Some parse ->
let parse = parse |> List.filter _.ConsumeBeforeInitialToken
match parseBracketLike parser inputString parse [ lhs ] rest with
| [ result ] -> Some result
| _ :: _ -> failwithf "Ambiguous parse (multiple matches) at token %+A" op
| [] -> None
| false, _ -> None
| None -> None
match fromBracketed with
| Some (lhs, rest) -> go lhs rest
| None ->
match parser.UnaryPostfix.TryGetValue (parser.GetTag op) with
| true, ((precedence, ()), construct) ->
match Map.tryFind (parser.GetTag op) parser.UnaryPostfix with
| Some ((precedence, ()), construct) ->
if precedence < minBinding then
lhs, rest
else
go (construct lhs) rest
| false, _ ->
| None ->
match parser.Infix.TryGetValue (parser.GetTag op) with
| true, ((leftBinding, rightBinding), construct) ->
match Map.tryFind (parser.GetTag op) parser.Infix with
| Some ((leftBinding, rightBinding), construct) ->
if leftBinding < minBinding then
lhs, op :: rest
else
@@ -308,7 +308,7 @@ module Parser =
let rhs, remainingTokens = parseInner parser inputString rest rightBinding
go (construct lhs rhs) remainingTokens
| false, _ ->
| None ->
// TODO: This could be function application!
lhs, op :: rest

View File

@@ -18,6 +18,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Map.fs" />
<Compile Include="Parser.fs"/>
<EmbeddedResource Include="version.json" />
<EmbeddedResource Include="SurfaceBaseline.txt"/>
@@ -32,7 +33,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.0" />
<PackageReference Update="FSharp.Core" Version="4.3.4" />
</ItemGroup>
</Project>

View File

@@ -18,8 +18,8 @@
})
(fetchNuGet {
pname = "FSharp.Core";
version = "6.0.0";
sha256 = "1hjhvr39c1vpgrdmf8xln5q86424fqkvy9nirkr29vl2461d2039";
version = "4.3.4";
sha256 = "1sg6i4q5nwyzh769g76f6c16876nvdpn83adqjr2y9x6xsiv5p5j";
})
(fetchNuGet {
pname = "FSharp.Core";