0 | module Text.ILex.Lexer
 1 |
 2 | import public Text.ILex.DFA
 3 | import public Data.Enum
 4 | import Data.ByteString
 5 | import Data.Linear.Token
 6 |
 7 | %default total
 8 |
 9 | public export
10 | record Env (q : Type) (s : Type -> Type) where
11 |   constructor E
12 |   state   : s q
13 |   1 token : T1 q
14 |
15 | public export
16 | 0 Step1 : (q : Type) -> (r : Bits32) -> (s : Type -> Type) -> Type
17 | Step1 q r s = s q -> F1 q (Index r)
18 |
19 | public export
20 | 0 Fun1 : (q : Type) -> (s : Type -> Type) -> Type -> Type
21 | Fun1 q s a = (1 sk : Env q s) -> R1 q a
22 |
23 | public export
24 | 0 Run1 : (q : Type) -> (r : Bits32) -> (s : Type -> Type) -> Type
25 | Run1 q r s = Fun1 q s (Index r)
26 |
27 | public export
28 | 0 Step : (q : Type) -> (r : Bits32) -> (s : Type -> Type) -> Type
29 | Step q r s = Trans (Run1 q r s)
30 |
31 | export %inline
32 | toState : Index r -> Step q r s
33 | toState v = Run $ \(E _ t) => v # t
34 |
35 | ||| An array of arrays describing a lexer's state machine.
36 | public export
37 | 0 ByteStep : Nat -> (q : Type) -> (r : Bits32) -> (s : Type -> Type) -> Type
38 | ByteStep n q r s = IArray 256 (Transition n $ Run1 q r s)
39 |
40 | ||| An array of arrays describing a lexer's state machine.
41 | public export
42 | 0 Stepper : Nat -> (q : Type) -> (r : Bits32) -> (s : Type -> Type) -> Type
43 | Stepper n q r s = IArray (S n) (ByteStep n q r s)
44 |
45 | ||| A discrete finite automaton (DFA) encoded as
46 | ||| an array of state transitions plus an array
47 | ||| describing the terminal token states.
48 | public export
49 | 0 DFA1 : (q : Type) -> (r : Bits32) -> (s : Type -> Type) -> Type
50 | DFA1 q r s = DFA (Run1 q r s)
51 |
52 | public export
53 | 0 Steps : (q : Type) -> (r : Bits32) -> (s : Type -> Type) -> Type
54 | Steps q r s = TokenMap (Step q r s)
55 |