Last active
March 12, 2019 15:31
-
-
Save gabriel-fallen/0b7863d9499775609771319e7267fd48 to your computer and use it in GitHub Desktop.
Trying to build an aliasing CFPQ.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Tests | |
open System.Diagnostics | |
open NUnit.Framework | |
open AbstractAnalysis.Common | |
open Yard.Generators.Common.DataStructures | |
open Yard.Generators.GLL.AbstractParser | |
open Yard.Generators.GLL.ParserCommon | |
open GrammarCombinator.Combinators | |
open AI.Taint.Engine.Utils | |
module private Utils = | |
let buildTestGraph triples (ps: ParserSourceGLL) = | |
let allVs = triples |> Array.collect (fun (f,t,l) -> [|f * 1<positionInInput>; t * 1<positionInInput>|]) |> Set.ofArray |> Array.ofSeq | |
let g = new SimpleInputGraph<string>(allVs, ps.StringToToken) | |
[| for (f, t, l) in triples -> new ParserEdge<_>(f, t, l) |] | |
|> g.AddVerticesAndEdgeRange | |
|> ignore | |
g | |
let expractPath ps graph nonTermName maxLength = | |
let gss, sppf, _ = parse ps graph true | |
let nt = sppf.GetNonTermByName nonTermName ps | |
let pathset = sppf.Iterate nt ps maxLength | |
pathset | |
[<TestClass>] | |
type TestClass () = | |
[<Test>] | |
member this.Test1 () = | |
let triples = [| | |
(0, 1, "foo"); | |
(1, 0, "foo_rev"); | |
(2, 1, "foo"); | |
(1, 2, "foo_rev") | |
|] | |
let testAliased = | |
<@ | |
let rec aliasedTo () = tok "foo_rev" + aliasedTo () + tok "foo" + aliasedTo () <|> Eps | |
in aliasedTo () | |
@> | |
let ps = testAliased |> GrammarCombinator.GrammarGenerator.generate "aliasedTo" |> psgll | |
let g = Utils.buildTestGraph triples ps | |
let path = Utils.expractPath ps g "aliasedTo$0" 10 | |
for (x, first, last) in path do | |
Debug.WriteLine("{0}: {1} -> {2}", x, first, last) | |
Assert.Pass() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment