This repository has been archived by the owner on Jul 31, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jgm@berkeley.edu
committed
Jun 23, 2009
1 parent
b5bf95c
commit 287bc55
Showing
4 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{- This module was generated from data in the Kate syntax highlighting file relaxngcompact.xml, version 0.1, | ||
by Rintze Zelle -} | ||
|
||
module Text.Highlighting.Kate.Syntax.Relaxngcompact ( highlight, parseExpression, syntaxName, syntaxExtensions ) where | ||
import Text.Highlighting.Kate.Definitions | ||
import Text.Highlighting.Kate.Common | ||
import Text.ParserCombinators.Parsec | ||
import Data.List (nub) | ||
import Data.Map (fromList) | ||
import Data.Maybe (fromMaybe) | ||
|
||
-- | Full name of language. | ||
syntaxName :: String | ||
syntaxName = "RelaxNG-Compact" | ||
|
||
-- | Filename extensions for this language. | ||
syntaxExtensions :: String | ||
syntaxExtensions = "*.rnc" | ||
|
||
-- | Highlight source code using this syntax definition. | ||
highlight :: String -> Either String [SourceLine] | ||
highlight input = | ||
case runParser parseSource startingState "source" input of | ||
Left err -> Left $ show err | ||
Right result -> Right result | ||
|
||
-- | Parse an expression using appropriate local context. | ||
parseExpression :: GenParser Char SyntaxState LabeledSource | ||
parseExpression = do | ||
st <- getState | ||
let oldLang = synStLanguage st | ||
setState $ st { synStLanguage = "RelaxNG-Compact" } | ||
context <- currentContext <|> (pushContext "Normal Text" >> currentContext) | ||
result <- parseRules context | ||
updateState $ \st -> st { synStLanguage = oldLang } | ||
return result | ||
|
||
parseSource = do | ||
lineContents <- lookAhead wholeLine | ||
updateState $ \st -> st { synStCurrentLine = lineContents } | ||
result <- manyTill parseSourceLine eof | ||
return $ map normalizeHighlighting result | ||
|
||
startingState = SyntaxState {synStContexts = fromList [("RelaxNG-Compact",["Normal Text"])], synStLanguage = "RelaxNG-Compact", synStCurrentLine = "", synStCharsParsedInLine = 0, synStCaseSensitive = True, synStKeywordCaseSensitive = True, synStCaptures = []} | ||
|
||
parseSourceLine = manyTill parseExpressionInternal pEndLine | ||
|
||
pEndLine = do | ||
newline <|> (eof >> return '\n') | ||
context <- currentContext | ||
case context of | ||
"Normal Text" -> return () | ||
"Comments" -> (popContext >> return ()) | ||
"string" -> return () | ||
_ -> return () | ||
lineContents <- lookAhead wholeLine | ||
updateState $ \st -> st { synStCurrentLine = lineContents, synStCharsParsedInLine = 0 } | ||
|
||
withAttribute attr txt = do | ||
if null txt | ||
then fail "Parser matched no text" | ||
else return () | ||
let style = fromMaybe "" $ lookup attr styles | ||
st <- getState | ||
let oldCharsParsed = synStCharsParsedInLine st | ||
updateState $ \st -> st { synStCharsParsedInLine = oldCharsParsed + length txt } | ||
return (nub [style, attr], txt) | ||
|
||
styles = [("Normal Text","Normal"),("Comments","Comment"),("String","String"),("Keyword","Keyword")] | ||
|
||
parseExpressionInternal = do | ||
context <- currentContext | ||
parseRules context <|> (pDefault >>= withAttribute (fromMaybe "" $ lookup context defaultAttributes)) | ||
|
||
defaultAttributes = [("Normal Text","Normal Text"),("Comments","Comments"),("string","String")] | ||
|
||
parseRules "Normal Text" = | ||
do (attr, result) <- (((pFirstNonSpace >> pDetect2Chars False '#' '#' >>= withAttribute "Comments") >>~ pushContext "Comments") | ||
<|> | ||
((pKeyword " \n\t.():!+,<=>%&*/;?[]^{|}~\\" ["attribute","div","element","empty","external","grammar","include","inherit","list","mixed","notAllowed","parent","start","string","text","token"] >>= withAttribute "Keyword")) | ||
<|> | ||
((pDetectChar False '"' >>= withAttribute "String") >>~ pushContext "string")) | ||
return (attr, result) | ||
|
||
parseRules "Comments" = | ||
pzero | ||
|
||
parseRules "string" = | ||
do (attr, result) <- ((pDetectChar False '"' >>= withAttribute "String") >>~ (popContext >> return ())) | ||
return (attr, result) | ||
|
||
parseRules x = fail $ "Unknown context" ++ x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE language SYSTEM "language.dtd"> | ||
<language name="RelaxNG-Compact" version="0.1" kateversion="2.4" section="Markup" extensions="*.rnc" casesensitive="1" author="Rintze Zelle" license="LGPL"> | ||
<highlighting> | ||
<list name="RNC keywords"> | ||
<item> attribute </item> | ||
<item> div </item> | ||
<item> element </item> | ||
<item> empty </item> | ||
<item> external </item> | ||
<item> grammar </item> | ||
<item> include </item> | ||
<item> inherit </item> | ||
<item> list </item> | ||
<item> mixed </item> | ||
<item> notAllowed </item> | ||
<item> parent </item> | ||
<item> start </item> | ||
<item> string </item> | ||
<item> text </item> | ||
<item> token </item> | ||
</list> | ||
<contexts> | ||
<context attribute="Normal Text" lineEndContext="#stay" name="Normal Text" > | ||
<Detect2Chars attribute="Comments" char="#" char1="#" firstNonSpace="true" context="Comments"/> | ||
<keyword attribute="Keyword" context="#stay" String="RNC keywords" /> | ||
<DetectChar attribute="String" context="string" char=""" /> | ||
</context> | ||
<context attribute="Comments" lineEndContext="#pop" name="Comments" > | ||
</context> | ||
<context attribute="String" lineEndContext="#stay" name="string" > | ||
<DetectChar attribute="String" context="#pop" char=""" /> | ||
</context> | ||
</contexts> | ||
<itemDatas> | ||
<itemData name="Normal Text" defStyleNum="dsNormal" /> | ||
<itemData name="Comments" defStyleNum="dsComment" /> | ||
<itemData name="String" defStyleNum="dsString" /> | ||
<itemData name="Keyword" defStyleNum="dsKeyword" /> | ||
</itemDatas> | ||
</highlighting> | ||
<general> | ||
<keywords weakDeliminator="-"/> | ||
</general> | ||
</language> |