Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add lexer for compile results

  • Loading branch information...
commit 4127b8c65616de022156329632d8ae79e71ab06f 1 parent f5e956a
jeanphilippe.bernardy@gmail.com authored
Showing with 52 additions and 0 deletions.
  1. +39 −0 Yi/Lexer/Compilation.x
  2. +11 −0 Yi/Modes.hs
  3. +2 −0  yi.cabal
View
39 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"
+}
View
11 Yi/Modes.hs
@@ -7,6 +7,7 @@ import qualified Yi.Lexer.Latex as Latex
import qualified Yi.Lexer.Srmc as Srmc
import qualified Yi.Lexer.Cabal as Cabal
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.Alex as Alex
import Yi.Lexer.Alex (Tok(..), Posn(..))
@@ -21,6 +22,7 @@ import Yi.Mode.Haskell
import Yi.Buffer.HighLevel (fillParagraph)
fundamental, defaultFundamentalMode :: Mode syntax
+compilationMode :: Mode (LinearResult (Tok Compilation.Token))
latexMode, cppMode, literateHaskellMode, cabalMode, srmcMode, ocamlMode :: Mode (LinearResult Stroke)
fundamental = emptyMode
@@ -48,6 +50,15 @@ cppMode = fundamental
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
{
modeHL = ExtHL $ mkHighlighter' LiterateHaskell.initState LiterateHaskell.alexScanToken id
View
2  yi.cabal
@@ -127,6 +127,7 @@ library
other-modules:
Paths_yi,
Yi.Lexer.Alex
+ Yi.Lexer.Compilation
Yi.Lexer.Cplusplus
Yi.Lexer.Haskell
Yi.Lexer.LiterateHaskell
@@ -261,6 +262,7 @@ executable yi
Yi.GHC
Yi.Lexer.Alex
+ Yi.Lexer.Compilation
Yi.Lexer.Cplusplus
Yi.Lexer.Haskell
Yi.Lexer.LiterateHaskell
Please sign in to comment.
Something went wrong with that request. Please try again.