1
0
forked from GitHub/gf-core

-printer=regexp handles precedence

This commit is contained in:
bringert
2007-06-28 01:25:36 +00:00
parent f2710ba80d
commit 448e1db488
2 changed files with 10 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ import GF.Compile.ShellState (StateGrammar)
regexpPrinter :: Options -> StateGrammar -> String
regexpPrinter opts s = prRE $ dfa2re $ cfgToFA opts s
regexpPrinter opts s = (++"\n") $ prRE $ dfa2re $ cfgToFA opts s
multiRegexpPrinter :: Options -> StateGrammar -> String
multiRegexpPrinter opts s = prREs $ mfa2res $ cfgToMFA opts s

View File

@@ -131,9 +131,13 @@ symbolsRE (RESymbol x) = [x]
-- Debugging
prRE :: RE String -> String
prRE (REUnion []) = "<NULL>"
prRE (REUnion xs) = "(" ++ concat (intersperse " | " (map prRE xs)) ++ ")"
prRE (REConcat xs) = "(" ++ unwords (map prRE xs) ++ ")"
prRE (RERepeat x) = "(" ++ prRE x ++ ")*"
prRE (RESymbol s) = s
prRE = prRE' 0
prRE' _ (REUnion []) = "<NULL>"
prRE' n (REUnion xs) = p n 1 (concat (intersperse " | " (map (prRE' 1) xs)))
prRE' n (REConcat xs) = p n 2 (unwords (map (prRE' 2) xs))
prRE' n (RERepeat x) = p n 3 (prRE' 3 x) ++ "*"
prRE' _ (RESymbol s) = s
p n m s | n >= m = "(" ++ s ++ ")"
| True = s