@@ -63,7 +63,7 @@ you get access to the lowest-level API to the lexer. You must provide
63
63
definitions for the following, either in the same module or imported
64
64
from another module:
65
65
66
- ::
66
+ .. code-block :: haskell
67
67
68
68
type AlexInput
69
69
alexGetByte :: AlexInput -> Maybe (Word8,AlexInput)
@@ -80,7 +80,7 @@ safely forget about the previous character in the input stream, and have
80
80
81
81
Alex will provide the following function:
82
82
83
- ::
83
+ .. code-block :: haskell
84
84
85
85
alexScan :: AlexInput -- The current input
86
86
-> Int -- The "start code"
@@ -137,7 +137,7 @@ scheme. Wrappers are described in the next section.
137
137
There is another entry point, which is useful if your grammar contains
138
138
any predicates (see :ref: `Contexts <contexts >`):
139
139
140
- ::
140
+ .. code-block :: haskell
141
141
142
142
alexScanUser
143
143
:: user -- predicate state
@@ -179,7 +179,7 @@ initial startcode is always set to zero.
179
179
Here is the actual code included in the lexer when the basic wrapper is
180
180
selected:
181
181
182
- ::
182
+ .. code-block :: haskell
183
183
184
184
type AlexInput = (Char, -- previous char
185
185
[Byte], -- rest of the bytes for the current char
@@ -207,7 +207,7 @@ The type signature for ``alexScanTokens`` is commented out, because the
207
207
``token `` type is unknown. All of the actions in your lexical
208
208
specification should have type:
209
209
210
- ::
210
+ .. code-block :: haskell
211
211
212
212
{ ... } :: String -> token
213
213
@@ -227,7 +227,7 @@ The posn wrapper provides the following, in addition to the
227
227
straightforward definitions of ``alexGetByte `` and
228
228
``alexInputPrevChar ``:
229
229
230
- ::
230
+ .. code-block :: haskell
231
231
232
232
data AlexPosn = AlexPn !Int -- absolute character offset
233
233
!Int -- line number
@@ -249,7 +249,7 @@ straightforward definitions of ``alexGetByte`` and
249
249
250
250
The types of the token actions should be:
251
251
252
- ::
252
+ .. code-block :: haskell
253
253
254
254
{ ... } :: AlexPosn -> String -> token
255
255
@@ -265,7 +265,7 @@ and text position, and the startcode. It is intended to be a template
265
265
for building your own monads - feel free to copy the code and modify it
266
266
to build a monad with the facilities you need.
267
267
268
- ::
268
+ .. code-block :: haskell
269
269
270
270
data AlexState = AlexState {
271
271
alex_pos :: !AlexPosn, -- position at current input location
@@ -300,34 +300,34 @@ to build a monad with the facilities you need.
300
300
The ``monad `` wrapper expects that you define a variable ``alexEOF ``
301
301
with the following signature:
302
302
303
- ::
303
+ .. code-block :: haskell
304
304
305
305
alexEOF :: Alex result
306
306
307
307
To invoke a scanner under the ``monad `` wrapper, use ``alexMonadScan ``:
308
308
309
- ::
309
+ .. code-block :: haskell
310
310
311
311
alexMonadScan :: Alex result
312
312
313
313
The token actions should have the following type:
314
314
315
- ::
315
+ .. code-block :: haskell
316
316
317
317
type AlexAction result = AlexInput -> Int -> Alex result
318
318
{ ... } :: AlexAction result
319
319
320
320
The Alex file must also define a function ``alexEOF ``, which will be
321
321
executed on when the end-of-file is scanned:
322
322
323
- ::
323
+ .. code-block :: haskell
324
324
325
325
alexEOF :: Alex result
326
326
327
327
The ``monad `` wrapper also provides some useful combinators for
328
328
constructing token actions:
329
329
330
- ::
330
+ .. code-block :: haskell
331
331
332
332
-- skip :: AlexAction result
333
333
skip input len = alexMonadScan
@@ -357,7 +357,7 @@ places:
357
357
1) The definition of the general state, which now refers to a type
358
358
``AlexUserState `` that must be defined in the Alex file.
359
359
360
- ::
360
+ .. code-block :: haskell
361
361
362
362
data AlexState = AlexState {
363
363
alex_pos :: !AlexPosn, -- position at current input location
@@ -371,7 +371,7 @@ places:
371
371
2) The initialization code, where a user-specified routine
372
372
(``alexInitUserState ``) will be called.
373
373
374
- ::
374
+ .. code-block :: haskell
375
375
376
376
runAlex :: String -> Alex a -> Either String a
377
377
runAlex input (Alex f)
@@ -386,15 +386,15 @@ places:
386
386
3) Two helper functions (``alexGetUserState `` and ``alexSetUserState ``)
387
387
are defined.
388
388
389
- ::
389
+ .. code-block :: haskell
390
390
391
391
alexGetUserState :: Alex AlexUserState
392
392
alexSetUserState :: AlexUserState -> Alex ()
393
393
394
394
Here is an example of code in the user's Alex file defining the type and
395
395
function:
396
396
397
- ::
397
+ .. code-block :: haskell
398
398
399
399
data AlexUserState = AlexUserState
400
400
{
@@ -433,7 +433,7 @@ version 1.x. The interface is intended to be very general, allowing
433
433
actions to modify the startcode, and pass around an arbitrary state
434
434
value.
435
435
436
- ::
436
+ .. code-block :: haskell
437
437
438
438
alexGScan :: StopAction state result -> state -> String -> result
439
439
@@ -442,7 +442,7 @@ value.
442
442
443
443
The token actions should all have this type:
444
444
445
- ::
445
+ .. code-block :: haskell
446
446
447
447
{ ... } :: AlexPosn -- token position
448
448
-> Char -- previous character
@@ -488,7 +488,7 @@ The "basic-bytestring" wrapper
488
488
The ``basic-bytestring `` wrapper is the same as the ``basic `` wrapper
489
489
but with lazy ``ByteString `` instead of ``String ``:
490
490
491
- ::
491
+ .. code-block :: haskell
492
492
493
493
import qualified Data.ByteString.Lazy as ByteString
494
494
@@ -504,7 +504,7 @@ but with lazy ``ByteString`` instead of ``String``:
504
504
505
505
All of the actions in your lexical specification should have type:
506
506
507
- ::
507
+ .. code-block :: haskell
508
508
509
509
{ ... } :: ByteString.ByteString -> token
510
510
@@ -516,7 +516,7 @@ The "posn-bytestring" wrapper
516
516
The ``posn-bytestring `` wrapper is the same as the ``posn `` wrapper but
517
517
with lazy ``ByteString `` instead of ``String ``:
518
518
519
- ::
519
+ .. code-block :: haskell
520
520
521
521
import qualified Data.ByteString.Lazy as ByteString
522
522
@@ -529,7 +529,7 @@ with lazy ``ByteString`` instead of ``String``:
529
529
530
530
All of the actions in your lexical specification should have type:
531
531
532
- ::
532
+ .. code-block :: haskell
533
533
534
534
{ ... } :: AlexPosn -> ByteString.ByteString -> token
535
535
@@ -541,7 +541,7 @@ The "monad-bytestring" wrapper
541
541
The ``monad-bytestring `` wrapper is the same as the ``monad `` wrapper
542
542
but with lazy ``ByteString `` instead of ``String ``:
543
543
544
- ::
544
+ .. code-block :: haskell
545
545
546
546
import qualified Data.ByteString.Lazy as ByteString
547
547
@@ -576,7 +576,7 @@ The ``monadUserState-bytestring`` wrapper is the same as the
576
576
``monadUserState `` wrapper but with lazy ``ByteString `` instead of
577
577
``String ``:
578
578
579
- ::
579
+ .. code-block :: haskell
580
580
581
581
import qualified Data.ByteString.Lazy as ByteString
582
582
@@ -619,7 +619,7 @@ more typeclass constraints. The following shows a simple lexer that
619
619
makes use of this to interpret the meaning of tokens using the ``Read ``
620
620
typeclass:
621
621
622
- ::
622
+ .. code-block :: none
623
623
624
624
%wrapper "basic"
625
625
%token "Token s"
@@ -659,7 +659,7 @@ directive can be used to specify the typeclass in the same way as with a
659
659
wrapper. The following example shows the use of typeclasses with a
660
660
"homegrown" monadic lexer:
661
661
662
- ::
662
+ .. code-block :: none
663
663
664
664
{
665
665
{-# LANGUAGE FlexibleContexts #-}
0 commit comments