The modified Shunting-Yard algorithm. The modifications allow function
application by juxtaposition (without any paren around the arguments)
and distfix operators. For a normal usage, it should be enough
to import only Text.Syntactical
, not directly this module.
- data Shunt a = S [SExpr a] [Tree a] [[SExpr a]] (Rule a)
- data Failure a
- = MissingBefore [[a]] a
- | MissingAfter [a] [a]
- | CantMix (Part a) (Part a)
- | MissingSubBetween a a
- | MissingSubBefore a
- | MissingSubAfter a
- | Ambiguity Ambiguity
- | Unexpected
- data Rule a
- initial :: [SExpr a] -> Shunt a
- isDone :: Shunt a -> Bool
- shunt :: Token a => Table a -> [SExpr a] -> Either (Failure a) (SExpr a)
- step :: Token a => Table a -> Shunt a -> Shunt a
- steps :: Token a => Table a -> [SExpr a] -> IO ()
- showFailure :: Token a => Failure a -> String
Documentation
The different failure cases the shunt
function can return.
The showFailure
function can be used to give them a textual
representation.
MissingBefore [[a]] a | missing parts before part |
MissingAfter [a] [a] | missing parts after parts |
CantMix (Part a) (Part a) | can't mix two operators |
MissingSubBetween a a | missing sub-expression between parts |
MissingSubBefore a | missing sub-expression before string |
MissingSubAfter a | missing sub-expression after string |
Ambiguity Ambiguity | a part is used ambiguously in multiple operators |
Unexpected | this is a bug if it happens |
shunt :: Token a => Table a -> [SExpr a] -> Either (Failure a) (SExpr a)Source
Parse a list of s-expressions according to an operator table.
Usually the s-expressions will be the result of applying Atom
to each token.