1
0
forked from GitHub/gf-core

Support dynamic param values

This commit is contained in:
John J. Camilleri
2021-02-03 13:16:10 +01:00
parent 132f693713
commit 42b9e7036e
7 changed files with 110 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
abstract Scratch = {
abstract Params = {
cat S ; F ;
fun
FtoS : F -> S ;

View File

@@ -0,0 +1,5 @@
Params: FtoS f1
ParamsCnc: PR R1 Q2
Params: FtoS f2
ParamsCnc: PR R2 _

View File

@@ -0,0 +1,20 @@
concrete ParamsCnc of Params = {
param
R = R1 | R2 ;
P = PR R Q | PP ;
Q = Q1 | Q2 ;
lincat
S = Str ;
F = { r : R } ;
lin
f1 = { r = R1 } ;
f2 = { r = R2 } ;
FtoS f = tbl ! PR f.r Q2 ;
oper
tbl = table {
PR R1 Q1 => "PR R1 Q1" ;
PR R1 Q2 => "PR R1 Q2" ;
PR R2 _ => "PR R2 _" ;
PP => "PP"
} ;
}

View File

@@ -1,2 +0,0 @@
Scratch: FtoS f1
ScratchCnc: R1 Q2

View File

@@ -1,18 +0,0 @@
concrete ScratchCnc of Scratch = {
param
R = R1 | R2 ;
P = PR R Q | PP ;
Q = Q1 | Q2 ;
lincat
S = Str ;
F = { p : P => Str } ;
lin
f1 = f2 ;
f2 = { p = table {
PR R1 Q1 => "R1 Q1" ;
PR R1 Q2 => "R1 Q2" ;
PR R2 _ => "R2 _" ;
PP => "PP"
} } ;
FtoS f = f.p ! PR R1 Q2 ;
}

View File

@@ -15,9 +15,9 @@ dir = "testsuite" </> "lpgf"
main :: IO ()
main = do
doGrammar "Scratch"
doGrammar "Params"
doGrammar "Walking"
doGrammar "Foods"
-- doGrammar "Foods"
doGrammar :: String -> IO ()
doGrammar gname = do
@@ -55,6 +55,7 @@ doGrammar gname = do
putStrLn ""
error "Test failed"
-- | Group list of lines by blank lines
groups :: [String] -> [[String]]
groups [] = []
groups ss = let (a,b) = break (=="") ss in a : groups (drop 1 b)