Geshi haskell

From CodersBase

Jump to: navigation, search

Here is the source code for haskell.php that does the highlighting, I wrote it in a couple hours and it is most likely buggy.

This is a short snippet to show it off a bit.

  1. module Main where
  2.  
  3. import Prelude
  4. import Control.Monad
  5.  
  6. main :: IO ()
  7. main = putStrLn "Hello, World!"
  8.  
  9. foo :: Bool
  10. foo = True -- or it False?
  11.  
  12. bar = product [1..]
  13.  
  14. {- baz is a tricky little function -}
  15. baz :: [a] -> [b]
  16. baz (x:xs) = [1,2]
  17.  
  18. quux = let x = 2
  19. y = 3
  20. in x + y
  21.  
  22. garbage :: IOException
  23. garbage = undefined


  1. <?php
  2. /*************************************************************************************
  3. * haskell.php
  4. * ----------
  5. * Author: Jason Dagit (dagit@codersbase.com) based on ocaml.php by Flaie (fireflaie@gmail.com)
  6. * Copyright: (c) 2005 Flaie, Nigel McNie (http://qbnz.com/highlighter)
  7. * Release Version: 1.0.7.7
  8. * CVS Revision Version: $Revision: 1.6 $
  9. * Date Started: 2005/08/27
  10. * Last Modified: $Date: 2006/02/25 00:46:33 $
  11. *
  12. * Haskell language file for GeSHi.
  13. *
  14. * CHANGES
  15. * -------
  16. * 2005/08/27 (1.0.0)
  17. * - First Release
  18. *
  19. * TODO (updated 2005/08/27)
  20. * -------------------------
  21. *
  22. *************************************************************************************
  23. *
  24. * This file is part of GeSHi.
  25. *
  26. * GeSHi is free software; you can redistribute it and/or modify
  27. * it under the terms of the GNU General Public License as published by
  28. * the Free Software Foundation; either version 2 of the License, or
  29. * (at your option) any later version.
  30. *
  31. * GeSHi is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. * GNU General Public License for more details.
  35. *
  36. * You should have received a copy of the GNU General Public License
  37. * along with GeSHi; if not, write to the Free Software
  38. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  39. *
  40. ************************************************************************************/
  41.  
  42. $language_data = array (
  43. 'LANG_NAME' => 'Haskell',
  44. 'COMMENT_SINGLE' => array( 1 => '--'),
  45. 'COMMENT_MULTI' => array('{-' => '-}'),
  46. 'CASE_KEYWORDS' => 0,
  47. 'QUOTEMARKS' => array('"'),
  48. 'ESCAPE_CHAR' => "\\",
  49. 'KEYWORDS' => array(
  50. /* main haskell keywords */
  51. 1 => array(
  52. 'as',
  53. 'case', 'of', 'class', 'data', 'default',
  54. 'deriving', 'do', 'forall', 'hiding', 'if', 'then',
  55. 'else', 'import', 'infix', 'infixl', 'infixr',
  56. 'instance', 'let', 'in', 'module', 'newtype',
  57. 'qualified', 'type', 'where'
  58. ),
  59. /* define names of main librarys, so we can link to it */
  60. 2 => array(
  61. 'Foreign', 'Numeric', 'Prelude'
  62. ),
  63. /* just link to Prelude functions, cause it's the default opened library when starting Haskell */
  64. 3 => array(
  65. 'not', 'otherwise', 'maybe',
  66. 'either', 'fst', 'snd', 'curry', 'uncurry',
  67. 'compare',
  68. 'max', 'min', 'succ', 'pred', 'toEnum', 'fromEnum',
  69. 'enumFrom', 'enumFromThen', 'enumFromTo',
  70. 'enumFromThenTo', 'minBound', 'maxBound',
  71. 'negate', 'abs', 'signum',
  72. 'fromInteger', 'toRational', 'quot', 'rem',
  73. 'div', 'mod', 'quotRem', 'divMod', 'toInteger',
  74. 'recip', 'fromRational', 'pi', 'exp',
  75. 'log', 'sqrt', 'logBase', 'sin', 'cos',
  76. 'tan', 'asin', 'acos', 'atan', 'sinh', 'cosh',
  77. 'tanh', 'asinh', 'acosh', 'atanh',
  78. 'properFraction', 'truncate', 'round', 'ceiling',
  79. 'floor', 'floatRadix', 'floatDigits', 'floatRange',
  80. 'decodeFloat', 'encodeFloat', 'exponent',
  81. 'significand', 'scaleFloat', 'isNaN', 'isInfinite',
  82. 'isDenomalized', 'isNegativeZero', 'isIEEE',
  83. 'atan2', 'subtract', 'even', 'odd', 'gcd',
  84. 'lcm', 'fromIntegral', 'realToFrac',
  85. 'return', 'fail', 'fmap',
  86. 'mapM', 'mapM_', 'sequence', 'sequence_',
  87. 'id', 'const','flip',
  88. 'until', 'asTypeOf', 'error', 'undefined',
  89. 'seq','map','filter', 'head',
  90. 'last', 'tail', 'init', 'null', 'length',
  91. 'reverse', 'foldl', 'foldl1', 'foldr',
  92. 'foldr1', 'and', 'or', 'any', 'all', 'sum',
  93. 'product', 'concat', 'concatMap', 'maximum',
  94. 'minimum', 'scanl', 'scanl1', 'scanr', 'scanr1',
  95. 'iterate', 'repeat', 'cycle', 'take', 'drop',
  96. 'splitAt', 'teakWhile', 'dropWhile', 'span',
  97. 'break', 'elem', 'notElem', 'lookup', 'zip',
  98. 'zip3', 'zipWith', 'zipWith3', 'unzip', 'unzip3',
  99. 'unzip', 'unzip3', 'lines', 'words', 'unlines',
  100. 'unwords', 'showPrec', 'show', 'showList',
  101. 'shows', 'showChar', 'showString', 'showParen',
  102. 'readsPrec', 'readList', 'reads', 'readParen',
  103. 'read', 'lex', 'putChar', 'putStr', 'putStrLn',
  104. 'print', 'getChar', 'getLine', 'getContents',
  105. 'interact', 'readFile', 'writeFile', 'appendFile',
  106. 'readIO', 'readLn', 'ioError', 'userError', 'catch'
  107. ),
  108. /* here Prelude Types */
  109. 4 => array (
  110. 'Bool', 'Maybe', 'Either', 'Ord', 'Ordering',
  111. 'Char', 'String', 'Eq', 'Enum', 'Bounded',
  112. 'Int', 'Integer', 'Float', 'Double', 'Rational',
  113. 'Num', 'Real', 'Integral', 'Fractional',
  114. 'Floating', 'RealFrac', 'RealFloat', 'Monad',
  115. 'Functor', 'Show', 'ShowS', 'Read', 'ReadS',
  116. 'IO'
  117. ),
  118. /* finally Prelude Exceptions */
  119. 5 => array (
  120. 'IOError', 'IOException'
  121. )
  122. ),
  123. /* highlighting symbols is really important in Haskell */
  124. 'SYMBOLS' => array(
  125. '|', '->', '<-', '@', '!', '::', '_', '~', '=',
  126. '&&', '||', '==', '/=', '<', '<=', '>',
  127. '>=','+', '-', '*','/', '**', '^', '^^',
  128. '>>=', '>>', '=<<', '$', '.', '$!',
  129. '++', '!!'
  130. ),
  131. 'CASE_SENSITIVE' => array(
  132. GESHI_COMMENTS => true,
  133. 1 => true,
  134. 2 => true, /* functions name are case seinsitive */
  135. 3 => true, /* types name too */
  136. 4 => true /* finally exceptions too */
  137. ),
  138. 'STYLES' => array(
  139. 'KEYWORDS' => array(
  140. 1 => 'color: #06c; font-weight: bold;', /* nice blue */
  141. 2 => 'color: #06c; font-weight: bold;', /* blue as well */
  142. 3 => 'font-weight: bold;', /* make the preduled functions bold */
  143. 4 => 'color: #cccc00; font-weight: bold;', /* give types a different bg */
  144. 5 => 'color: maroon;'
  145. ),
  146. 'COMMENTS' => array(
  147. 1 => 'color: #5d478b; font-style: italic;',
  148. 'MULTI' => 'color: #5d478b; font-style: italic;' /* light purpHle */
  149. ),
  150. 'ESCAPE_CHAR' => array(
  151. ),
  152. 'BRACKETS' => array(
  153. 0 => 'color: green;'
  154. ),
  155. 'STRINGS' => array(
  156. 0 => 'background-color: #3cb371;' /* nice green */
  157. ),
  158. 'NUMBERS' => array(
  159. 0 => 'color: red;' /* pink */
  160. ),
  161. 'METHODS' => array(
  162. 1 => 'color: #060;' /* dark green */
  163. ),
  164. 'REGEXPS' => array(
  165. ),
  166. 'SYMBOLS' => array(
  167. 0 => 'color: #66cc66; font-weight: bold;'
  168. ),
  169. 'SCRIPT' => array(
  170. )
  171. ),
  172. 'URLS' => array(
  173. /* some of keywords are Prelude functions */
  174. 1 => '',
  175. /* link to the wanted library */
  176. 2 => 'http://haskell.org/ghc/docs/latest/html/libraries/base/{FNAME}.html',
  177. /* link to Prelude functions */
  178. 3 => 'http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:{FNAME}',
  179. /* link to Prelude types */
  180. 4 => 'http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:{FNAME}',
  181. /* link to Prelude exceptions */
  182. 5 => 'http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:{FNAME}',
  183. ),
  184. 'OOLANG' => false,
  185. 'OBJECT_SPLITTERS' => array(
  186. ),
  187. 'REGEXPS' => array(
  188. ),
  189. 'STRICT_MODE_APPLIES' => GESHI_NEVER,
  190. 'SCRIPT_DELIMITERS' => array(
  191. ),
  192. 'HIGHLIGHT_STRICT_BLOCK' => array(
  193. )
  194. );
  195.  
  196. ?>
Personal tools