Skip to content

Commit 07c732f

Browse files
committed
RST docs: label code blocks by language
- `haskell` - `none` for large `alex` code snippets that fail to parse as `haskell` - `sh` for command invokations Unlabeled code blocks are short `alex` snippets mostly showing grammar definitions. These are to be highlighted by the default language picked for this documentation.
1 parent 789d546 commit 07c732f

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

doc/api.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ you get access to the lowest-level API to the lexer. You must provide
6363
definitions for the following, either in the same module or imported
6464
from another module:
6565

66-
::
66+
.. code-block:: haskell
6767
6868
type AlexInput
6969
alexGetByte :: AlexInput -> Maybe (Word8,AlexInput)
@@ -80,7 +80,7 @@ safely forget about the previous character in the input stream, and have
8080

8181
Alex will provide the following function:
8282

83-
::
83+
.. code-block:: haskell
8484
8585
alexScan :: AlexInput -- The current input
8686
-> Int -- The "start code"
@@ -137,7 +137,7 @@ scheme. Wrappers are described in the next section.
137137
There is another entry point, which is useful if your grammar contains
138138
any predicates (see :ref:`Contexts <contexts>`):
139139

140-
::
140+
.. code-block:: haskell
141141
142142
alexScanUser
143143
:: user -- predicate state
@@ -179,7 +179,7 @@ initial startcode is always set to zero.
179179
Here is the actual code included in the lexer when the basic wrapper is
180180
selected:
181181

182-
::
182+
.. code-block:: haskell
183183
184184
type AlexInput = (Char, -- previous char
185185
[Byte], -- rest of the bytes for the current char
@@ -207,7 +207,7 @@ The type signature for ``alexScanTokens`` is commented out, because the
207207
``token`` type is unknown. All of the actions in your lexical
208208
specification should have type:
209209

210-
::
210+
.. code-block:: haskell
211211
212212
{ ... } :: String -> token
213213
@@ -227,7 +227,7 @@ The posn wrapper provides the following, in addition to the
227227
straightforward definitions of ``alexGetByte`` and
228228
``alexInputPrevChar``:
229229

230-
::
230+
.. code-block:: haskell
231231
232232
data AlexPosn = AlexPn !Int -- absolute character offset
233233
!Int -- line number
@@ -249,7 +249,7 @@ straightforward definitions of ``alexGetByte`` and
249249
250250
The types of the token actions should be:
251251

252-
::
252+
.. code-block:: haskell
253253
254254
{ ... } :: AlexPosn -> String -> token
255255
@@ -265,7 +265,7 @@ and text position, and the startcode. It is intended to be a template
265265
for building your own monads - feel free to copy the code and modify it
266266
to build a monad with the facilities you need.
267267

268-
::
268+
.. code-block:: haskell
269269
270270
data AlexState = AlexState {
271271
alex_pos :: !AlexPosn, -- position at current input location
@@ -300,34 +300,34 @@ to build a monad with the facilities you need.
300300
The ``monad`` wrapper expects that you define a variable ``alexEOF``
301301
with the following signature:
302302

303-
::
303+
.. code-block:: haskell
304304
305305
alexEOF :: Alex result
306306
307307
To invoke a scanner under the ``monad`` wrapper, use ``alexMonadScan``:
308308

309-
::
309+
.. code-block:: haskell
310310
311311
alexMonadScan :: Alex result
312312
313313
The token actions should have the following type:
314314

315-
::
315+
.. code-block:: haskell
316316
317317
type AlexAction result = AlexInput -> Int -> Alex result
318318
{ ... } :: AlexAction result
319319
320320
The Alex file must also define a function ``alexEOF``, which will be
321321
executed on when the end-of-file is scanned:
322322

323-
::
323+
.. code-block:: haskell
324324
325325
alexEOF :: Alex result
326326
327327
The ``monad`` wrapper also provides some useful combinators for
328328
constructing token actions:
329329

330-
::
330+
.. code-block:: haskell
331331
332332
-- skip :: AlexAction result
333333
skip input len = alexMonadScan
@@ -357,7 +357,7 @@ places:
357357
1) The definition of the general state, which now refers to a type
358358
``AlexUserState`` that must be defined in the Alex file.
359359

360-
::
360+
.. code-block:: haskell
361361
362362
data AlexState = AlexState {
363363
alex_pos :: !AlexPosn, -- position at current input location
@@ -371,7 +371,7 @@ places:
371371
2) The initialization code, where a user-specified routine
372372
(``alexInitUserState``) will be called.
373373

374-
::
374+
.. code-block:: haskell
375375
376376
runAlex :: String -> Alex a -> Either String a
377377
runAlex input (Alex f)
@@ -386,15 +386,15 @@ places:
386386
3) Two helper functions (``alexGetUserState`` and ``alexSetUserState``)
387387
are defined.
388388

389-
::
389+
.. code-block:: haskell
390390
391391
alexGetUserState :: Alex AlexUserState
392392
alexSetUserState :: AlexUserState -> Alex ()
393393
394394
Here is an example of code in the user's Alex file defining the type and
395395
function:
396396

397-
::
397+
.. code-block:: haskell
398398
399399
data AlexUserState = AlexUserState
400400
{
@@ -433,7 +433,7 @@ version 1.x. The interface is intended to be very general, allowing
433433
actions to modify the startcode, and pass around an arbitrary state
434434
value.
435435

436-
::
436+
.. code-block:: haskell
437437
438438
alexGScan :: StopAction state result -> state -> String -> result
439439
@@ -442,7 +442,7 @@ value.
442442
443443
The token actions should all have this type:
444444

445-
::
445+
.. code-block:: haskell
446446
447447
{ ... } :: AlexPosn -- token position
448448
-> Char -- previous character
@@ -488,7 +488,7 @@ The "basic-bytestring" wrapper
488488
The ``basic-bytestring`` wrapper is the same as the ``basic`` wrapper
489489
but with lazy ``ByteString`` instead of ``String``:
490490

491-
::
491+
.. code-block:: haskell
492492
493493
import qualified Data.ByteString.Lazy as ByteString
494494
@@ -504,7 +504,7 @@ but with lazy ``ByteString`` instead of ``String``:
504504
505505
All of the actions in your lexical specification should have type:
506506

507-
::
507+
.. code-block:: haskell
508508
509509
{ ... } :: ByteString.ByteString -> token
510510
@@ -516,7 +516,7 @@ The "posn-bytestring" wrapper
516516
The ``posn-bytestring`` wrapper is the same as the ``posn`` wrapper but
517517
with lazy ``ByteString`` instead of ``String``:
518518

519-
::
519+
.. code-block:: haskell
520520
521521
import qualified Data.ByteString.Lazy as ByteString
522522
@@ -529,7 +529,7 @@ with lazy ``ByteString`` instead of ``String``:
529529
530530
All of the actions in your lexical specification should have type:
531531

532-
::
532+
.. code-block:: haskell
533533
534534
{ ... } :: AlexPosn -> ByteString.ByteString -> token
535535
@@ -541,7 +541,7 @@ The "monad-bytestring" wrapper
541541
The ``monad-bytestring`` wrapper is the same as the ``monad`` wrapper
542542
but with lazy ``ByteString`` instead of ``String``:
543543

544-
::
544+
.. code-block:: haskell
545545
546546
import qualified Data.ByteString.Lazy as ByteString
547547
@@ -576,7 +576,7 @@ The ``monadUserState-bytestring`` wrapper is the same as the
576576
``monadUserState`` wrapper but with lazy ``ByteString`` instead of
577577
``String``:
578578

579-
::
579+
.. code-block:: haskell
580580
581581
import qualified Data.ByteString.Lazy as ByteString
582582
@@ -619,7 +619,7 @@ more typeclass constraints. The following shows a simple lexer that
619619
makes use of this to interpret the meaning of tokens using the ``Read``
620620
typeclass:
621621

622-
::
622+
.. code-block:: none
623623
624624
%wrapper "basic"
625625
%token "Token s"
@@ -659,7 +659,7 @@ directive can be used to specify the typeclass in the same way as with a
659659
wrapper. The following example shows the use of typeclasses with a
660660
"homegrown" monadic lexer:
661661

662-
::
662+
.. code-block:: none
663663
664664
{
665665
{-# LANGUAGE FlexibleContexts #-}

doc/introduction.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ generates a Haskell module containing code for scanning text
1111
efficiently. Alex is designed to be familiar to existing lex users,
1212
although it does depart from lex in a number of ways.
1313

14-
A sample specification would be the following::
14+
A sample specification would be the following:
15+
16+
.. code-block:: none
1517
1618
{
1719
module Main (main) where
@@ -93,7 +95,7 @@ standard output.
9395
Alex has kindly provided the following function which we can use to
9496
invoke the scanner:
9597

96-
..code-block:: haskell
98+
.. code-block:: haskell
9799
98100
alexScanTokens :: String -> [Token]
99101
@@ -110,15 +112,15 @@ no requirement for the scanner to return a list of tokens.
110112
With this specification in the file ``Tokens.x``, Alex can be used to
111113
generate ``Tokens.hs``:
112114

113-
::
115+
.. code-block:: sh
114116
115117
$ alex Tokens.x
116118
117119
If the module needed to be placed in a different file, ``Main.hs`` for
118120
example, then the output filename can be specified using the ``-o``
119121
option:
120122

121-
::
123+
.. code-block:: sh
122124
123125
$ alex Tokens.x -o Main.hs
124126

doc/invoking.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Invoking Alex
66

77
The command line syntax for Alex is entirely standard:
88

9-
::
9+
.. code-block:: sh
1010
1111
$ alex { option } file.x { option }
1212

doc/syntax.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Right context is rather more general. There are three forms:
210210
This form is called a *predicate* on the rule. The Haskell expression
211211
inside the curly braces should have type:
212212

213-
::
213+
.. code-block:: haskell
214214
215215
{ ... } :: user -- predicate state
216216
-> AlexInput -- input stream before the token
@@ -256,7 +256,7 @@ whose value is of type ``Int``. For example, if we mentioned startcodes
256256
``foo`` and ``bar`` in the lexical spec, then Alex will create
257257
definitions such as:
258258

259-
::
259+
.. code-block:: haskell
260260
261261
foo = 1
262262
bar = 2

0 commit comments

Comments
 (0)