Skip to content

Commit

Permalink
Add lexer for compile results
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanphilippe.bernardy@gmail.com committed Jul 23, 2008
1 parent f5e956a commit 4127b8c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Yi/Lexer/Compilation.x
@@ -0,0 +1,39 @@
-- -*- haskell -*-
--
-- Lexical syntax for illiterate Haskell 98.
--
-- (c) Simon Marlow 2003, with the caveat that much of this is
-- translated directly from the syntax in the Haskell 98 report.
--

{
module Yi.Lexer.Compilation (initState, alexScanToken, Token(..)) where
import Yi.Lexer.Alex
import Yi.Regex
}

$digit = 0-9
$any = [.\n]
@number = $digit+

tokens :-
^.+":" @number ":" @number ":" .*$ { \str st -> let Just (_before, arr, _after) = matchOnceText re $ map snd str
in (st, Report (fst $ arr!1) (read $ fst $ arr!2) (read $ fst $ arr!3) (fst $ arr!4)) }
^[.]+$ ; -- text
\n ; -- just ignore newlines.

{
re :: Regex
re = makeRegex "^(.+):([0-9]+):([0-9]+):(.*)$"

type HlState = ()
data Token
= Report String Int Int String
| Text String
deriving Show

stateToInit () = 0
initState = ()

#include "alex.hsinc"
}
11 changes: 11 additions & 0 deletions Yi/Modes.hs
Expand Up @@ -7,6 +7,7 @@ import qualified Yi.Lexer.Latex as Latex
import qualified Yi.Lexer.Srmc as Srmc import qualified Yi.Lexer.Srmc as Srmc
import qualified Yi.Lexer.Cabal as Cabal import qualified Yi.Lexer.Cabal as Cabal
import qualified Yi.Lexer.Cplusplus as Cplusplus import qualified Yi.Lexer.Cplusplus as Cplusplus
import qualified Yi.Lexer.Compilation as Compilation
import qualified Yi.Lexer.OCaml as OCaml import qualified Yi.Lexer.OCaml as OCaml
import qualified Yi.Lexer.Alex as Alex import qualified Yi.Lexer.Alex as Alex
import Yi.Lexer.Alex (Tok(..), Posn(..)) import Yi.Lexer.Alex (Tok(..), Posn(..))
Expand All @@ -21,6 +22,7 @@ import Yi.Mode.Haskell
import Yi.Buffer.HighLevel (fillParagraph) import Yi.Buffer.HighLevel (fillParagraph)


fundamental, defaultFundamentalMode :: Mode syntax fundamental, defaultFundamentalMode :: Mode syntax
compilationMode :: Mode (LinearResult (Tok Compilation.Token))
latexMode, cppMode, literateHaskellMode, cabalMode, srmcMode, ocamlMode :: Mode (LinearResult Stroke) latexMode, cppMode, literateHaskellMode, cabalMode, srmcMode, ocamlMode :: Mode (LinearResult Stroke)


fundamental = emptyMode fundamental = emptyMode
Expand Down Expand Up @@ -48,6 +50,15 @@ cppMode = fundamental
modeHL = ExtHL $ mkHighlighter' Cplusplus.initState Cplusplus.alexScanToken id modeHL = ExtHL $ mkHighlighter' Cplusplus.initState Cplusplus.alexScanToken id
} }


compilationMode = emptyMode
{
modeHL = ExtHL $ mkHighlighter (linearIncrScanner . Alex.lexScanner Compilation.alexScanToken Compilation.initState)
(\begin end pos -> linearGetStrokes begin end pos . fmap tokenToStroke)
}
where tokenToStroke (Tok t len posn) = (posnOfs posn, tokenToStyle t, posnOfs posn +~ len)
tokenToStyle _ = commentStyle


literateHaskellMode = fundamental literateHaskellMode = fundamental
{ {
modeHL = ExtHL $ mkHighlighter' LiterateHaskell.initState LiterateHaskell.alexScanToken id modeHL = ExtHL $ mkHighlighter' LiterateHaskell.initState LiterateHaskell.alexScanToken id
Expand Down
2 changes: 2 additions & 0 deletions yi.cabal
Expand Up @@ -127,6 +127,7 @@ library
other-modules: other-modules:
Paths_yi, Paths_yi,
Yi.Lexer.Alex Yi.Lexer.Alex
Yi.Lexer.Compilation
Yi.Lexer.Cplusplus Yi.Lexer.Cplusplus
Yi.Lexer.Haskell Yi.Lexer.Haskell
Yi.Lexer.LiterateHaskell Yi.Lexer.LiterateHaskell
Expand Down Expand Up @@ -261,6 +262,7 @@ executable yi
Yi.GHC Yi.GHC


Yi.Lexer.Alex Yi.Lexer.Alex
Yi.Lexer.Compilation
Yi.Lexer.Cplusplus Yi.Lexer.Cplusplus
Yi.Lexer.Haskell Yi.Lexer.Haskell
Yi.Lexer.LiterateHaskell Yi.Lexer.LiterateHaskell
Expand Down

0 comments on commit 4127b8c

Please sign in to comment.