Last active
March 1, 2024 12:10
-
-
Save inariksit/d142c322919103aa7a0f53daefe4a6ba to your computer and use it in GitHub Desktop.
To handle metavariables in GF, don't use `fg` and `gf`
This file contains 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
import PGF | |
import Debug.Trace (trace) | |
import Data.Foldable (asum) | |
import Test | |
getMeta :: Expr -> Int | |
getMeta expr = case go expr of | |
Just i -> trace (unwords ["expression", showExpr [] expr, "contains the metavariable", show i, ", returning it"]) i | |
Nothing -> trace (unwords ["expression", showExpr [] expr, "doesn't contain a metavariable, defaulting to 42"]) 42 | |
where | |
go e = | |
case unMeta e of | |
Just i -> Just i | |
Nothing -> | |
case unApp e of | |
Just (f,args) -> asum $ fmap go args | |
Nothing -> Nothing | |
main :: IO () | |
main = do | |
test <- readPGF "Test.pgf" | |
let testLan = head $ languages test | |
let testCat = fromJust $ readType "foo" | |
let s = "foo" | |
let tree = head $ parse test testLan testCat s | |
putStrLn ("parsing done of " ++ linearize test testLan tree) | |
let changedTree = changeMetaVar tree | |
putStrLn ("tree changed to " ++ linearize test testLan changedTree) | |
changeMetaVar :: Expr -> Expr | |
changeMetaVar foo = mkApp (mkCId "mkBar") [mkInt $ getMeta foo] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment