module Text.Highlighting.Kate.Syntax.Ada ( highlight, parseExpression, syntaxName, syntaxExtensions ) where
import Text.Highlighting.Kate.Definitions
import Text.Highlighting.Kate.Common
import Text.ParserCombinators.Parsec
import Data.List (nub)
import qualified Data.Set as Set
import Data.Map (fromList)
import Data.Maybe (fromMaybe)
syntaxName :: String
syntaxName = "Ada"
syntaxExtensions :: String
syntaxExtensions = "*.adb;*.ads;*.ada;*.a"
highlight :: String -> Either String [SourceLine]
highlight input =
case runParser parseSource startingState "source" input of
Left err -> Left $ show err
Right result -> Right result
parseExpression :: GenParser Char SyntaxState LabeledSource
parseExpression = do
st <- getState
let oldLang = synStLanguage st
setState $ st { synStLanguage = "Ada" }
context <- currentContext <|> (pushContext "Default" >> 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 [("Ada",["Default"])], synStLanguage = "Ada", synStCurrentLine = "", synStCharsParsedInLine = 0, synStPrevChar = '\n', synStCaseSensitive = True, synStKeywordCaseSensitive = False, synStCaptures = []}
parseSourceLine = manyTill parseExpressionInternal pEndLine
pEndLine = do
newline <|> (eof >> return '\n')
context <- currentContext
case context of
"Default" -> return ()
"Region Marker" -> (popContext >> return ())
"String" -> (popContext >> return ())
"Comment" -> (popContext >> return ())
_ -> return ()
lineContents <- lookAhead wholeLine
updateState $ \st -> st { synStCurrentLine = lineContents, synStCharsParsedInLine = 0, synStPrevChar = '\n' }
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
let prevchar = if null txt then '\n' else last txt
updateState $ \st -> st { synStCharsParsedInLine = oldCharsParsed + length txt, synStPrevChar = prevchar }
return (nub [style, attr], txt)
styles = [("Normal Text","Normal"),("Keyword","Keyword"),("Pragmas","Keyword"),("Data Type","DataType"),("Decimal","DecVal"),("Base-N","BaseN"),("Float","Float"),("Char","Char"),("String","String"),("Comment","Comment"),("Symbol","Normal"),("Region Marker","RegionMarker")]
parseExpressionInternal = do
context <- currentContext
parseRules context <|> (pDefault >>= withAttribute (fromMaybe "" $ lookup context defaultAttributes))
list8340b1f88657b00e4f9cff5c1f0e66a040191992 = Set.fromList $ words $ "abort abs abstract accept access aliased all and array at begin body constant declare delay delta digits do else elsif end entry exception exit for function generic goto in interface is limited mod new not null of or others out overriding package pragma private procedure protected raise range rem record renames requeue return reverse separate subtype tagged task terminate then type until use when while with xor"
list3ba9ea9b9595ebdbc3905c71cdda6bf924d31dc9 = Set.fromList $ words $ "all_calls_remote assert assertion_policy asynchronous atomic atomic_components attach_handler controlled convention detect_blocking discard_names elaborate elaborate_all elaborate_body export import inline inspection_point interrupt_handler interrupt_priority linker_options list locking_policy no_return normalize_scalars optimize pack page partition_elaboration_policy preelaborable_initialization preelaborate priority priority_specific_dispatching profile pure queuing_policy relative_deadline remote_call_interface remote_types restrictions reviewable shared_passive storage_size suppress task_dispatching_policy unchecked_union unsuppress volatile volatile_components"
list105742b645b1ad2a1c82b2004c3b04fc83736368 = Set.fromList $ words $ "boolean char float integer long_float long_integer long_long_float long_long_integer short_float short_integer string wide_string wide_char wide_wide_char wide_wide_string"
defaultAttributes = [("Default","Normal Text"),("Region Marker","Region Marker"),("String","String"),("Comment","Comment")]
parseRules "Default" =
do (attr, result) <- (((pRegExpr (compileRegex "\\brecord\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bend\\s+record\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bcase\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bend\\s+case\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bif\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bend\\s+if\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bloop\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bend\\s+loop\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bselect\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bend\\s+select\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bbegin\\b") >>= withAttribute "Keyword"))
<|>
((pRegExpr (compileRegex "\\bend\\b") >>= withAttribute "Keyword"))
<|>
((pFirstNonSpace >> pString False "-- BEGIN" >>= withAttribute "Region Marker") >>~ pushContext "Region Marker")
<|>
((pFirstNonSpace >> pString False "-- END" >>= withAttribute "Region Marker") >>~ pushContext "Region Marker")
<|>
((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list8340b1f88657b00e4f9cff5c1f0e66a040191992 >>= withAttribute "Keyword"))
<|>
((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list3ba9ea9b9595ebdbc3905c71cdda6bf924d31dc9 >>= withAttribute "Pragmas"))
<|>
((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list105742b645b1ad2a1c82b2004c3b04fc83736368 >>= withAttribute "Data Type"))
<|>
((pFloat >>= withAttribute "Float"))
<|>
((pInt >>= withAttribute "Decimal"))
<|>
((pRegExpr (compileRegex "'.'") >>= withAttribute "Char"))
<|>
((pDetectChar False '"' >>= withAttribute "String") >>~ pushContext "String")
<|>
((pDetect2Chars False '-' '-' >>= withAttribute "Comment") >>~ pushContext "Comment")
<|>
((pAnyChar ":!%&()+,-/.*<=>|" >>= withAttribute "Symbol")))
return (attr, result)
parseRules "Region Marker" =
pzero
parseRules "String" =
do (attr, result) <- ((pDetectChar False '"' >>= withAttribute "String") >>~ (popContext >> return ()))
return (attr, result)
parseRules "Comment" =
pzero
parseRules x = fail $ "Unknown context" ++ x