mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-23 09:52:55 -06:00
Limit GSL/JSGF/SRGS ABNF grammar line width to 80.
This commit is contained in:
@@ -34,8 +34,12 @@ import Data.Char (toUpper,toLower)
|
|||||||
import Data.List (partition)
|
import Data.List (partition)
|
||||||
import Text.PrettyPrint.HughesPJ
|
import Text.PrettyPrint.HughesPJ
|
||||||
|
|
||||||
|
width :: Int
|
||||||
|
width = 80
|
||||||
|
|
||||||
gslPrinter :: Options -> StateGrammar -> String
|
gslPrinter :: Options -> StateGrammar -> String
|
||||||
gslPrinter opts s = show $ prGSL $ makeSimpleSRG opts s
|
gslPrinter opts s = renderStyle st $ prGSL $ makeSimpleSRG opts s
|
||||||
|
where st = style { lineLength = width }
|
||||||
|
|
||||||
prGSL :: SRG -> Doc
|
prGSL :: SRG -> Doc
|
||||||
prGSL (SRG{grammarName=name,startCat=start,origStartCat=origStart,rules=rs})
|
prGSL (SRG{grammarName=name,startCat=start,origStartCat=origStart,rules=rs})
|
||||||
|
|||||||
@@ -38,11 +38,14 @@ import Data.Maybe
|
|||||||
import Text.PrettyPrint.HughesPJ
|
import Text.PrettyPrint.HughesPJ
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
|
||||||
|
width :: Int
|
||||||
|
width = 80
|
||||||
|
|
||||||
jsgfPrinter :: Maybe SISRFormat
|
jsgfPrinter :: Maybe SISRFormat
|
||||||
-> Options
|
-> Options
|
||||||
-> StateGrammar -> String
|
-> StateGrammar -> String
|
||||||
jsgfPrinter sisr opts s = show $ prJSGF sisr $ makeSimpleSRG opts s
|
jsgfPrinter sisr opts s = renderStyle st $ prJSGF sisr $ makeSimpleSRG opts s
|
||||||
|
where st = style { lineLength = width }
|
||||||
|
|
||||||
prJSGF :: Maybe SISRFormat -> SRG -> Doc
|
prJSGF :: Maybe SISRFormat -> SRG -> Doc
|
||||||
prJSGF sisr srg@(SRG{grammarName=name,grammarLanguage=ml,
|
prJSGF sisr srg@(SRG{grammarName=name,grammarLanguage=ml,
|
||||||
|
|||||||
@@ -39,15 +39,19 @@ import Data.Maybe
|
|||||||
import Text.PrettyPrint.HughesPJ
|
import Text.PrettyPrint.HughesPJ
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
|
||||||
|
width :: Int
|
||||||
|
width = 80
|
||||||
|
|
||||||
srgsAbnfPrinter :: Maybe SISRFormat
|
srgsAbnfPrinter :: Maybe SISRFormat
|
||||||
-> Bool -- ^ Include probabilities
|
-> Bool -- ^ Include probabilities
|
||||||
-> Options
|
-> Options
|
||||||
-> StateGrammar -> String
|
-> StateGrammar -> String
|
||||||
srgsAbnfPrinter sisr probs opts s = show $ prABNF sisr probs $ makeSimpleSRG opts s
|
srgsAbnfPrinter sisr probs opts s = showDoc $ prABNF sisr probs $ makeSimpleSRG opts s
|
||||||
|
|
||||||
srgsAbnfNonRecursivePrinter :: Options -> StateGrammar -> String
|
srgsAbnfNonRecursivePrinter :: Options -> StateGrammar -> String
|
||||||
srgsAbnfNonRecursivePrinter opts s = show $ prABNF Nothing False $ makeNonRecursiveSRG opts s
|
srgsAbnfNonRecursivePrinter opts s = showDoc $ prABNF Nothing False $ makeNonRecursiveSRG opts s
|
||||||
|
|
||||||
|
showDoc = renderStyle (style { lineLength = width })
|
||||||
|
|
||||||
prABNF :: Maybe SISRFormat -> Bool -> SRG -> Doc
|
prABNF :: Maybe SISRFormat -> Bool -> SRG -> Doc
|
||||||
prABNF sisr probs srg@(SRG{grammarName=name,grammarLanguage=ml,
|
prABNF sisr probs srg@(SRG{grammarName=name,grammarLanguage=ml,
|
||||||
|
|||||||
Reference in New Issue
Block a user