|
|
|
|
|
|
Synopsis |
|
|
|
|
Main Monads |
|
data St |
The state used in the computation of the fixed point. | Constructors | St | | gr :: !Grammar | The current term grammar. | renamer :: !Renamer | The Renamer. | lastLabel :: !Label | The last generated label. | labelCount :: !Int | Index for the next label to be generated. | userLabs :: !Int | Number of user specified labels in the .rules file. | newLabels :: !Int | Number of generated labels, minus the number of joined labels. | maxLabels :: !Int | Bound on newLabels. Constant set by user. | joinCount :: !Int | Number of joined labels. | maxJoin :: !Int | Bound on joinCount. Constant set by user. | stage :: !Int | Current stage in the computation of the fixed point. | failure :: !Bool | Whether the analysis failed. | batchOpt :: !Bool | Tells whether we must avoid interacting with the user.
Set by the user. | quietOpt :: !Bool | Verbosity option set by user. | inputFile :: !(Maybe String) | The name of the .rules file. | outputFile :: !(Maybe String) | The name of the output file, if any. | anonymousOpt :: !Bool | Whether the output file should record the name of the input file
inside. Set by the user. | outputRulesOpt :: !Bool | Whether to put the rewriting rules into the output file, in spite of
the output grammar begin closed under such rules. | emptyMattersOpt :: !Bool | Whether to allow for rewriting ground terms which can not be
expanded into a pure term, but denote "empty" term sets. | useHintsOpt :: !Bool | When rewriting T for @l:T, whether to prefer to use @l
in the rewritten T, if possible. Used by addPlainTermSomewhere. | preferUserLabelsOpt :: !Bool | Whether to prefer user @labels rather than $labels.
Used by addPlainTermSomewhere. | joinUserLabelsOpt :: !Bool | | rules :: ![Rule] | The normalized rules we are closing under. | rawRules :: ![Rule] | The (not yet normalized) rules from the input file.
We store them here to eventually copy them into the output file. | intersections :: ![Intersection] | The intersection rules. |
|
|
|
|
type NonDetReader = ReaderT St [] |
Read-only (w.r.t. St) non-deterministic computation. |
|
type IOState = StateT St IO |
Read-write (w.r.t. St) deterministic IO-enabled computation. |
|
Merging Grammar Monads into Ours |
|
doGr :: GrState a -> IOState a |
Perform a read-write actions on the Grammar. |
|
readGr :: GrReader a -> IOState a |
Perform a deterministic Grammar read. |
|
pickFromGr :: GrReader [a] -> NonDetReader a |
Perform a non-deterministic Grammar read. |
|
Pattern Matching |
|
matchTermWithGroundTerm :: Term -> Term -> NonDetReader Subst |
Match a Term pattern with a ground Term, non-deterministically
returning the unifying Substs. |
|
matchSomewhere_c :: Variable -> Term -> NonDetReader Subst |
Match a plain Term pattern somewhere in the grammar. |
|
matchSomewhere_hv :: Variable -> Head -> Variable -> NonDetReader Subst |
Match a Term pattern of the form h(X) somewhere in the grammar. |
|
matchSomewhere_hvv :: Variable -> Head -> Variable -> Variable -> NonDetReader Subst |
Match a Term pattern of the form h(X,Y) somewhere in the grammar. |
|
matchSomewhere_hlv :: Variable -> Head -> Term -> Variable -> NonDetReader Subst |
Match a Term pattern of the form h(@lab,Y) somewhere in the grammar. |
|
matchSomewhere_hvl :: Variable -> Head -> Variable -> Term -> NonDetReader Subst |
Match a Term pattern of the form h(X,@lab) somewhere in the grammar. |
|
matchClause :: Clause -> NonDetReader Subst |
Generic pattern matching for a Clause. Yields all matching
substitutions, non-deterministically. |
|
matchRule :: Rule -> NonDetReader (Label, Term) |
|
matchRules :: [Rule] -> NonDetReader (Label, Term) |
Apply all Rules and return (non-deterministically) all the ground
Terms that would need to be added to Labels. |
|
Stage Driver |
|
mayCreateLabels :: IOState Bool |
Check whether we can add a fresh Label to gr. |
|
mayJoinLabels :: IOState Bool |
Check whether the join bound has been reached. |
|
mayPromptUser :: IOState Bool |
Check whether we can ask the user at this stage. |
|
triedEverything :: IOState Bool |
Check whether we already tried all the strategies, including user
interaction. In this case, we need to reuse a Label, hoping not to
lose too much precision in the approximation. |
|
alreadyFailed :: IOState Bool |
Check whether the analisys has failed. |
|
handleMatch :: Int -> (Label, Term) -> IOState Int |
Insert a new Term into the Grammar, incrementing the Int if not
possible now. |
|
closeUnderRules :: IOState () |
Main driver for all stages. Loops until the state reaches a fixed point. |
|
Grammar Changes |
|
newLabel :: IOState Label |
Return a fresh Label. |
|
addPlainTermToSet :: Label -> Term -> IOState () |
Add a plain Term to the set of Label in the gr.
Also, print a dot for every added Term. |
|
addGroundTermToSet :: Label -> Term -> IOState (Maybe ()) |
Try to add a ground Term to the set of Label in the gr.
If necessary, the production is changed into Chomsky Normal Form. |
|
addGroundTermSomewhere |
:: Maybe Label | Hint: try this first. | -> Term | | -> IOState (Maybe Label) | | Try to find a place for a plain Term anywhere in the gr,
choosing the 'best' Label. If possible, do not change gr. |
|
|
addPlainTermSomewhere |
:: Maybe Label | Hint: try this first. | -> Term | | -> IOState (Maybe Label) | | Try to find a place for a plain Term anywhere in the gr,
choosing the 'best' Label. If possible, do not change gr.
On failure (e.g., early stage, so we want to try the alternatives first),
return Nothing; otherwise return Just Label. |
|
|
tryToJoinLabels :: IOState () |
Try to reclain some Label slots by joining two Labels if they have
similar sets.
- NOTE
- In general, joining labels might lead to a non terminating
algorithm, since joining makes the grammar size to decrease. Currently,
we enforce termination by not allowing more than maxJoin joins.
|
|
User Interaction |
|
displayGrammar :: IOState () |
Print the gr to the user. |
|
displayUsedLabels :: IOState () |
Print information about available Label slots to the user. |
|
displayStatistics :: IOState () |
|
promptUser :: Term -> IOState (Maybe Label) |
Ask the user what to do, i.e. ask for a Label whose set is where to
place the Term.
If Term is MinTerm, do not ask anything, but let the user explore the
state. |
|
pureExamples :: [Label] -> Term -> NonDetReader Term |
Instantiate a ground Term into a pure Term in all the possible
ways, in a non-deterministic fashion. Avoid infinite loops on the grammar
reachability graph. |
|
parseFile :: IOState Bool |
Parse and type check a .rules file. If succeeds, returns the rules
in Chomsky Normal Form, and stores the original ones in the St state. |
|
saveFixedPoint :: IOState () |
Save the grammar in a file, if it was requested. |
|
parseOptions :: [String] -> IOState () |
Parse command line options and update St accordingly. |
|
usageError :: IOState () |
Display usage. |
|
initialState :: St |
|
main :: IO () |
|
Produced by Haddock version 0.6 |