WIP: starting to fix this criminally inefficient parser for PDF's postfix-operator instructions
This commit is contained in:
parent
f9f799c59b
commit
bac08446dd
1 changed files with 13 additions and 1 deletions
|
@ -43,6 +43,7 @@ stateOperator Ri = (,) Ri <$> count 1 argument <* string "ri"
|
||||||
stateOperator I = (,) I <$> count 1 argument <* string "i"
|
stateOperator I = (,) I <$> count 1 argument <* string "i"
|
||||||
stateOperator Gs = (,) Gs <$> count 1 nameArg <* string "gs"
|
stateOperator Gs = (,) Gs <$> count 1 nameArg <* string "gs"
|
||||||
|
|
||||||
|
{-
|
||||||
textOperator :: MonadParser m => TextOperator -> m (Call TextOperator)
|
textOperator :: MonadParser m => TextOperator -> m (Call TextOperator)
|
||||||
textOperator Td = (,) Td <$> count 2 argument <* string "Td"
|
textOperator Td = (,) Td <$> count 2 argument <* string "Td"
|
||||||
textOperator TD = (,) TD <$> count 2 argument <* string "TD"
|
textOperator TD = (,) TD <$> count 2 argument <* string "TD"
|
||||||
|
@ -59,6 +60,17 @@ textOperator TL = (,) TL <$> count 1 argument <* string "TL"
|
||||||
textOperator Tf = (,) Tf <$> sequence [nameArg, argument] <* string "Tf"
|
textOperator Tf = (,) Tf <$> sequence [nameArg, argument] <* string "Tf"
|
||||||
textOperator Tr = (,) Tr <$> count 1 argument <* string "Tr"
|
textOperator Tr = (,) Tr <$> count 1 argument <* string "Tr"
|
||||||
textOperator Ts = (,) Ts <$> count 1 argument <* string "Ts"
|
textOperator Ts = (,) Ts <$> count 1 argument <* string "Ts"
|
||||||
|
-}
|
||||||
|
|
||||||
|
textOperator :: MonadParser m => TextOperator -> m TextOperator
|
||||||
|
textOperator textOp = string (show textOp) *> return textOp
|
||||||
|
|
||||||
|
textChunk :: MonadParser m => m (Either TextOperator Argument)
|
||||||
|
textChunk =
|
||||||
|
choice $ Left . textOperator <$> [minBound .. maxBound]
|
||||||
|
<|> choice $ Right <$> [stringArg, nameArg, arrayArg, argument]
|
||||||
|
|
||||||
|
aTextOperator :: MonadParser m => m (Call TextOperator)
|
||||||
|
|
||||||
a :: (Bounded o, Enum o, MonadParser m) => (o -> m (Call o)) -> m (Call o)
|
a :: (Bounded o, Enum o, MonadParser m) => (o -> m (Call o)) -> m (Call o)
|
||||||
a parserGenerator = choice $ parserGenerator <$> [minBound .. maxBound]
|
a parserGenerator = choice $ parserGenerator <$> [minBound .. maxBound]
|
||||||
|
@ -95,7 +107,7 @@ text :: ParserWithFont [ByteString]
|
||||||
text =
|
text =
|
||||||
string "BT" *> blank *> commands <* blank <* string "ET" <?> "Text operators"
|
string "BT" *> blank *> commands <* blank <* string "ET" <?> "Text operators"
|
||||||
where
|
where
|
||||||
commands = concat <$> (a textOperator >>= runOperator) `sepBy` blank
|
commands = concat <$> (aTextOperator >>= runOperator) `sepBy` blank
|
||||||
|
|
||||||
runOperator :: Call TextOperator -> ParserWithFont [ByteString]
|
runOperator :: Call TextOperator -> ParserWithFont [ByteString]
|
||||||
runOperator (Tf, [Typed (NameObject fontName), _]) =
|
runOperator (Tf, [Typed (NameObject fontName), _]) =
|
||||||
|
|
Loading…
Reference in a new issue