Skip to content

Commit

Permalink
Parser: handle context shift to external context...
Browse files Browse the repository at this point in the history
e.g., `BashOneLine##Bash`.  Closes #139.
  • Loading branch information
jgm committed Jan 19, 2022
1 parent 782054d commit b08632e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions skylighting-core/src/Skylighting/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,17 @@ getList el = do
"item" -> return $ Item $ T.strip $ getTextContent el'
"include" -> do
let (syntaxname, listname) =
case T.breakOn "##"
(T.strip (getTextContent el')) of
(x ,y) | T.null y -> ("", x)
| otherwise -> (T.drop 2 y, x)
splitContext (getTextContent el')
return $ IncludeList (syntaxname, listname)
x -> throwError $ "Unknown element " ++ show x ++
" in list"

splitContext :: Text -> (Text, Text)
splitContext t =
case T.breakOn "##" (T.strip t) of
(x, y) | T.null y -> ("", x)
| otherwise -> (T.drop 2 y, x)

getParser :: Monad m
=> Bool -> Text -> ItemData -> M.Map Text [ListItem] -> KeywordAttr
-> Text -> Element -> ExceptT String m Rule
Expand Down Expand Up @@ -344,7 +347,13 @@ parseContextSwitch syntaxname t =
else
case T.stripPrefix "#pop" t of
Just rest -> Pop : parseContextSwitch syntaxname rest
Nothing -> [Push (syntaxname, T.dropWhile (=='!') t)]
Nothing ->
let (othersyntax, contextname) =
splitContext (T.dropWhile (=='!') t)
syntaxname' = if T.null othersyntax
then syntaxname
else othersyntax
in [Push (syntaxname', contextname)]

type ItemData = M.Map Text TokenType

Expand Down

0 comments on commit b08632e

Please sign in to comment.