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
John MacFarlane
committed
Feb 14, 2010
0 parents
commit 937deda
Showing
17 changed files
with
1,588 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright (c) 2010 John MacFarlane | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Isaac Jones nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,13 @@ | ||
import Distribution.Simple | ||
import Distribution.Simple.Program | ||
import Distribution.Simple.LocalBuildInfo | ||
|
||
main :: IO () | ||
main = do | ||
defaultMainWithHooks $ simpleUserHooks { | ||
confHook = myConfHook } | ||
|
||
myConfHook info flags = do | ||
local <- (confHook simpleUserHooks) info flags | ||
return $ local{ withPrograms = userSpecifyArgs "alex" ["-t","alex","--ghc"] $ withPrograms local } | ||
|
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,47 @@ | ||
add other languages | ||
x haskell | ||
x css | ||
x c | ||
x cpp | ||
x csharp | ||
x cabal | ||
x lhs | ||
x java | ||
|
||
_ alex | ||
_ GNU Make | ||
|
||
_ latex | ||
_ xml | ||
_ html | ||
_ javascript | ||
_ sql | ||
|
||
_ ruby | ||
_ erb | ||
_ perl | ||
_ python | ||
_ lua | ||
_ php | ||
_ assembly | ||
_ clojure | ||
_ commonlisp | ||
_ d | ||
_ erlang | ||
_ fortran | ||
_ llvm | ||
_ objectivec | ||
_ ocaml | ||
_ smalltalk | ||
_ prolog | ||
_ scala | ||
_ tcl | ||
_ vb | ||
_ bash | ||
_ awk | ||
_ diff | ||
_ yaml | ||
_ xlst | ||
_ scheme | ||
_ figure out way to reuse code sections? | ||
|
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,38 @@ | ||
module Text.Highlighting.Illuminate ( tokenize, languages, asANSI, asHtmlCSS, defaultCSS ) where | ||
import Data.Char (toLower) | ||
import Text.Highlighting.Illuminate.Token | ||
import qualified Text.Highlighting.Illuminate.C as C | ||
import qualified Text.Highlighting.Illuminate.Cabal as Cabal | ||
import qualified Text.Highlighting.Illuminate.CPlusPlus as CPlusPlus | ||
import qualified Text.Highlighting.Illuminate.CSharp as CSharp | ||
import qualified Text.Highlighting.Illuminate.CSS as CSS | ||
import qualified Text.Highlighting.Illuminate.Haskell as Haskell | ||
import qualified Text.Highlighting.Illuminate.Java as Java | ||
import qualified Text.Highlighting.Illuminate.LiterateHaskell as LiterateHaskell | ||
|
||
tokenize :: String -> String -> Either String [Token] | ||
tokenize lang source = | ||
case scannerFor (map toLower lang) of | ||
Just scan -> scan source | ||
Nothing -> Left $ "Unknown language `" ++ lang ++ "'" | ||
|
||
scannerFor :: String -> Maybe (String -> Either String [Token]) | ||
scannerFor lang = | ||
let table = concatMap (\(ls,_,sc) -> map (\x -> (x,sc)) ls) langTable | ||
in lookup (map toLower lang) table | ||
|
||
languages :: [String] | ||
languages = map (\(_,s,_) -> s) langTable | ||
|
||
langTable :: [([String], String, (String -> Either String [Token]))] | ||
langTable = | ||
[ (["haskell","hs"], "Haskell", Haskell.scanner) | ||
, (["literatehaskell", "lhs"], "Literate Haskell", LiterateHaskell.scanner) | ||
, (["c"], "C", C.scanner) | ||
, (["java"], "Java", Java.scanner) | ||
, (["cpp","cplusplus","c++"], "C++", CPlusPlus.scanner) | ||
, (["csharp","c#","cs"], "C#", CSharp.scanner) | ||
, (["css"], "CSS", CSS.scanner) | ||
, (["cabal"], "Cabal", Cabal.scanner) | ||
] | ||
|
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,81 @@ | ||
{ | ||
{-# OPTIONS -w #-} -- Suppress warnings from alex-generated code | ||
module Text.Highlighting.Illuminate.C (scanner) where | ||
} | ||
|
||
%wrapper "illuminate" | ||
|
||
$alpha = [A-Za-z] | ||
$digit = [0-9] | ||
$alphanum = [$alpha $digit] | ||
$wordchar = [$alphanum \_] | ||
$symbol = [\~ \! \% \^ \* \( \) \- \+ \= \[ \] \" \: \; \, \. \/ \? \& \< \> \|] | ||
$hexdigit = [$digit A-F a-f] | ||
@hexnumber = "0x" $hexdigit+ | ||
@number = [\+ \-]? (@hexnumber | | ||
(($digit* \.)? $digit+ ([eE] [\+\-]? $digit+)?) | ||
) u? (("int" ("8"|"16"|"32"|"64")) | L)? | ||
@keyword = ("__asm"|"__cdecl"|"__declspec"|"__export"|"__far16"| | ||
"__fastcall"|"__fortran"|"__import"| | ||
"__pascal"|"__rtti"|"__stdcall"|"_asm"|"_cdecl"| | ||
"__except"|"_export"|"_far16"|"_fastcall"| | ||
"__finally"|"_fortran"|"_import"|"_pascal"|"_stdcall"| | ||
"__thread"|"__try"|"asm"|"auto"| | ||
"break"|"case"|"catch"|"cdecl"|"const"|"continue"|"default"| | ||
"do"|"else"|"enum"|"extern"|"for"|"goto"| | ||
"if"|"pascal"| | ||
"register"|"return"|"sizeof"|"static"| | ||
"struct"|"switch"| | ||
"typedef"|"union"| | ||
"volatile"|"while") | ||
@alert = (TODO|FIXME|BUG)[\:]? | ||
@type = ("bool|char|double|float|int|long"|"short|signed|unsigned|void|wchar_t") | ||
@string = \" ([^ \" \\] | \\ .)* \" | ||
@char = \' ([^ \' \\] | \\ .)* \' | ||
tokens :- | ||
<comment> { | ||
"*/" { popContext ==> tok Comment } | ||
@alert { tok Alert } | ||
} | ||
|
||
<linecomment> { | ||
@alert { tok Alert } | ||
\n { popContext ==> tok Whitespace } | ||
} | ||
|
||
<struct> { | ||
$white+ { tok Whitespace } | ||
$wordchar+ { popContext ==> tok Type } | ||
} | ||
|
||
<include> { | ||
$white+ { tok Whitespace } | ||
\< [^ \>]* \> { popContext ==> tok String } | ||
\" @string \" { popContext ==> tok String } | ||
} | ||
<0> { | ||
"/*" { pushContext (comment, Comment) ==> tok Comment } | ||
"//" { pushContext (linecomment, Comment) ==> tok Comment } | ||
^ $white* $wordchar+ \: { tok Label } | ||
"struct" / $white { pushContext (struct, Plain) ==> tok Keyword } | ||
^ $white* \# $white* "include" { pushContext (include, Plain) ==> tok Preproc } | ||
^ $white* \# $white* $wordchar* { tok Preproc } | ||
@keyword / ~$wordchar { tok Keyword } | ||
@type / ~$wordchar { tok Type } | ||
@number { tok Number } | ||
@string { tok String } | ||
@char { tok Char } | ||
$symbol { tok Symbol } | ||
[\{ \}] { tok CBracket } | ||
[$alpha \_] $wordchar* $white* / \( { tok Function } | ||
[$alpha \_]$wordchar* { tok VarId } | ||
} | ||
. { plain } | ||
\n { tok Whitespace } | ||
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,89 @@ | ||
{ | ||
{-# OPTIONS -w #-} -- Suppress warnings from alex-generated code | ||
module Text.Highlighting.Illuminate.CPlusPlus (scanner) where | ||
} | ||
|
||
%wrapper "illuminate" | ||
|
||
$alpha = [A-Za-z] | ||
$digit = [0-9] | ||
$alphanum = [$alpha $digit] | ||
$wordchar = [$alphanum \_] | ||
$symbol = [\~ \! \% \^ \* \( \) \- \+ \= \[ \] \" \: \; \, \. \/ \? \& \< \> \|] | ||
$hexdigit = [$digit A-F a-f] | ||
@hexnumber = "0x" $hexdigit+ | ||
@number = [\+ \-]? (@hexnumber | | ||
(($digit* \.)? $digit+ ([eE] [\+\-]? $digit+)?) | ||
) u? (("int" ("8"|"16"|"32"|"64")) | L)? | ||
@ckeyword = ("__asm"|"__cdecl"|"__declspec"|"__export"|"__far16"| | ||
"__fastcall"|"__fortran"|"__import"| | ||
"__pascal"|"__rtti"|"__stdcall"|"_asm"|"_cdecl"| | ||
"__except"|"_export"|"_far16"|"_fastcall"| | ||
"__finally"|"_fortran"|"_import"|"_pascal"|"_stdcall"| | ||
"__thread"|"__try"|"asm"|"auto"| | ||
"break"|"case"|"catch"|"cdecl"|"const"|"continue"|"default"| | ||
"do"|"else"|"enum"|"extern"|"for"|"goto"| | ||
"if"|"pascal"| | ||
"register"|"return"|"sizeof"|"static"| | ||
"struct"|"switch"| | ||
"typedef"|"union"| | ||
"volatile"|"while") | ||
@cppkeyword = ("class"|"const_cast"|"delete"| | ||
"dynamic_cast"|"explicit"|"false"|"friend"| | ||
"inline"|"mutable"|"namespace"|"new"|"operator"|"private"| | ||
"protected"|"public"|"reinterpret_cast"|"static_cast"| | ||
"template"|"this"|"throw"|"true"| | ||
"try"|"typeid"|"typename"|"using"|"virtual") | ||
@keyword = @ckeyword | @cppkeyword | ||
@alert = (TODO|FIXME|BUG)[\:]? | ||
@type = ("bool|char|double|float|int|long"|"short|signed|unsigned|void|wchar_t") | ||
@string = \" ([^ \" \\] | \\ .)* \" | ||
@char = \' ([^ \' \\] | \\ .)* \' | ||
tokens :- | ||
<comment> { | ||
"*/" { popContext ==> tok Comment } | ||
@alert { tok Alert } | ||
} | ||
|
||
<linecomment> { | ||
@alert { tok Alert } | ||
\n { popContext ==> tok Whitespace } | ||
} | ||
|
||
<struct> { | ||
$white+ { tok Whitespace } | ||
$wordchar+ { popContext ==> tok Type } | ||
} | ||
|
||
<include> { | ||
$white+ { tok Whitespace } | ||
\< [^ \>]* \> { popContext ==> tok String } | ||
\" @string \" { popContext ==> tok String } | ||
} | ||
<0> { | ||
"/*" { pushContext (comment, Comment) ==> tok Comment } | ||
"//" { pushContext (linecomment, Comment) ==> tok Comment } | ||
^ $white* $wordchar+ \: { tok Label } | ||
("struct"|"class"|"typename") / $white { pushContext (struct, Plain) ==> tok Keyword } | ||
^ $white* \# $white* "include" { pushContext (include, Plain) ==> tok Preproc } | ||
^ $white* \# $white* $wordchar* { tok Preproc } | ||
@keyword / ~$wordchar { tok Keyword } | ||
@type / ~$wordchar { tok Type } | ||
@number { tok Number } | ||
@string { tok String } | ||
@char { tok Char } | ||
$symbol { tok Symbol } | ||
[\{ \}] { tok CBracket } | ||
[$alpha \_] $wordchar* $white* / \( { tok Function } | ||
[$alpha \_]$wordchar* { tok VarId } | ||
} | ||
. { plain } | ||
\n { tok Whitespace } | ||
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,74 @@ | ||
{ | ||
{-# OPTIONS -w #-} -- Suppress warnings from alex-generated code | ||
module Text.Highlighting.Illuminate.CSS (scanner) where | ||
} | ||
|
||
%wrapper "illuminate" | ||
|
||
$wordchar = [0-9a-zA-Z\_] | ||
$symbol = [\~ \! \% \^ \* \( \) \- \+ \= \[ \] \" \: \; \, \. \/ \? \& \< \> \|] | ||
$digit = [0-9] | ||
$hexdigit = [0-9a-fA-F] | ||
@selector = [\. \#] $wordchar+ | ||
@alert = (TODO|FIXME|BUG)[\:]? | ||
@property = ("azimuth" | "background" | "background-attachment" | | ||
"background-color" | "background-image" | "background-position" | | ||
"background-repeat" | "border" | "border-collapse" | "border-color" | | ||
"border-spacing" | "border-style" | "border-top" | "border-right" | | ||
"border-bottom" | "border-left" | "border-top-color" | | ||
"border-right-color" | "border-bottom-color" | "border-left-color" | | ||
"border-top-style" | "border-right-style" | "border-bottom-style" | | ||
"border-left-style" | "border-top-width" | "border-right-width" | | ||
"border-bottom-width" | "border-left-width" | "border-width" | | ||
"bottom" | "caption-side" | "clear" | "clip" | "color" | "content" | | ||
"counter-increment" | "counter-reset" | "cue" | "cue-after" | | ||
"cue-before" | "cursor" | "direction" | "display" | "elevation" | | ||
"empty-cells" | "float" | "font-family" | "font-size" | | ||
"font-size-adjust" | "font-stretch" | "font-style" | "font-variant" | | ||
"font-weight" | "font" | "height" | "left" | "letter-spacing" | | ||
"line-height" | "list-style" | "list-style-image" | "list-style-position" | | ||
"list-style-type" | "margin" | "margin-top" | "margin-right" | | ||
"margin-bottom" | "margin-left" | "marker-offset" | "marks" | "max-height" | | ||
"max-width" | "min-height" | "min-width" | "orphans" | "outline" | | ||
"outline-color" | "outline-style" | "outline-width" | "overflow" | | ||
"padding" | "padding-top" | "padding-right" | "padding-bottom" | | ||
"padding-left" | "page" | "page-break-after" | "page-break-before" | | ||
"page-break-inside" | "pause" | "pause-after" | "pause-before" | | ||
"pitch" | "pitch-range" | "play-during" | "position" | "quotes" | | ||
"richness" | "right" | "size" | "speak" | "speak-header" | "speak-numeral" | | ||
"speak-punctuation" | "speech-rate" | "stress" | "table-layout" | "text-align" | | ||
"text-decoration" | "text-indent" | "text-shadow" | "text-transform" | "top" | | ||
"unicode-bidi" | "vertical-align" | "visibility" | "voice-family" | "volume" | | ||
"white-space" | "widows" | "width" | "word-spacing" | "z-index") | ||
tokens :- | ||
<comment> { | ||
"*/" { popContext ==> tok Comment } | ||
@alert { tok Alert } | ||
} | ||
|
||
<linecomment> { | ||
@alert { tok Alert } | ||
\n { popContext ==> tok Whitespace } | ||
} | ||
|
||
<cbracket> { | ||
\# $hexdigit+ { tok Number } | ||
$digit+ { tok Number } | ||
@property / $white* \: { tok Property } | ||
$symbol { tok Symbol } | ||
\} { popContext ==> tok CBracket } | ||
} | ||
|
||
<0,cbracket> "/*" { pushContext (comment, Comment) ==> tok Comment } | ||
<0,cbracket> "//" .* { pushContext (linecomment, Comment) ==> tok Comment } | ||
<0> @selector { tok Selector } | ||
<0> $wordchar+ / ~$wordchar { tok String } | ||
<0> \{ { pushContext (cbracket, Plain) ==> tok CBracket } | ||
<0> $symbol { tok Symbol } | ||
|
||
. { plain } | ||
\n { tok Whitespace } | ||
|
Oops, something went wrong.