Debian Codegraph @

src/Yi/Lexer/common.hsinc

raw
1 -- -*- Haskell -*-
2
3 -- The include file for alex-generated syntax highlighters. Because alex
4 -- declares its own types, any wrapper must have the highlighter in scope...
5 -- so it must be included. Doubleplusyuck.
6
7 #define IBOX(n) (I# (n))
8
9 #define GEQ_(x, y) (GHC.Exts.tagToEnum# (x >=# y))
10 #define EQ_(x, y) (GHC.Exts.tagToEnum# (x ==# y))
11
12 -- | Scan one token. Return (maybe) a token and a new state.
13 alexScanToken :: (AlexState HlState, AlexInput) -> Maybe (Tok Token, (AlexState HlState, AlexInput))
14 alexScanToken (AlexState state lookedOfs pos, inp@(_prevCh,_bs,str)) =
15 let (scn,lookahead) = alexScanUser' state inp (stateToInit state)
16 lookedOfs' = max lookedOfs (posnOfs pos +~ Size lookahead) in
17 case scn of
18 AlexEOF -> Nothing
19 AlexError inp' -> Nothing
20 AlexSkip inp' len ->
21 let chunk = take (fromIntegral len) str
22 in alexScanToken (AlexState state lookedOfs' (moveStr pos chunk), inp')
23 AlexToken inp' len act ->
24 let (state', tokValue) = act chunk state
25 chunk = take (fromIntegral len) str
26 newPos = moveStr pos chunk
27 in Just (Tok tokValue (posnOfs newPos ~- posnOfs pos) pos, (AlexState state' lookedOfs' newPos, inp'))
28
29 alexScan' input (I# (sc))
30 = alexScanUser' undefined input (I# (sc))
31
32 alexScanUser' user input (I# (sc))
33 = case alex_scan_tkn' user input 0# input sc AlexNone of
34 (AlexNone, input', lookahead) ->
35 case alexGetByte input of
36 Nothing -> (AlexEOF, lookahead)
37 Just _ -> (AlexError input', lookahead)
38 (AlexLastSkip input'' len, _, lookahead) -> (AlexSkip input'' len, lookahead)
39 #if MIN_TOOL_VERSION_alex(3,2,0)
40 (AlexLastAcc k input'' len, _, lookahead) -> (AlexToken input'' len (alex_actions Data.Array.! k), lookahead)
41 #else
42 (AlexLastAcc k input'' len, _, lookahead) -> (AlexToken input'' len k, lookahead)
43 #endif
44
45
46 -- Same as alex_scan_tkn, but also return the length of lookahead.
47 alex_scan_tkn' user orig_input len input s last_acc =
48 input `seq` -- strict in the input
49 let new_acc = check_accs (alex_accept `quickIndex` IBOX(s)) in
50 new_acc `seq`
51 case alexGetByte input of
52 Nothing -> (new_acc, input, IBOX(len))
53 Just (c, new_input) ->
54 let base = alexIndexInt32OffAddr alex_base s
55 ord_c = case fromIntegral c of (I# x) -> x
56 offset = (base +# ord_c)
57 check = alexIndexInt16OffAddr alex_check offset
58
59 new_s = if GEQ_(offset, 0#) && EQ_(check, ord_c)
60 then alexIndexInt16OffAddr alex_table offset
61 else alexIndexInt16OffAddr alex_deflt s
62 new_len = if c < 0x80 || c >= 0xC0 then len +# 1# else len
63 in case new_s of
64 -1# -> (new_acc, input, IBOX(new_len))
65 -- on an error, we want to keep the input *before* the
66 -- character that failed, not after.
67 -- (but still, we looked after)
68 _ -> alex_scan_tkn' user orig_input new_len new_input new_s new_acc
69
70 where
71 check_accs (AlexAccNone) = last_acc
72 check_accs (AlexAcc a ) = AlexLastAcc a input IBOX(len)
73 check_accs (AlexAccSkip) = AlexLastSkip input IBOX(len)
74 #ifndef NO_ALEX_CONTEXTS
75 check_accs (AlexAccPred a predx rest)
76 | predx user orig_input IBOX(len) input
77 = AlexLastAcc a input IBOX(len)
78 | otherwise
79 = check_accs rest
80 check_accs (AlexAccSkipPred predx rest)
81 | predx user orig_input IBOX(len) input
82 = AlexLastSkip input IBOX(len)
83 | otherwise
84 = check_accs rest
85 #endif
86
87
88 c = actionConst
89 m = actionAndModify
90 ms = actionStringAndModify
91 cs = actionStringConst