on master help sign in
extend and fix parser library documentation
06af0c1martinbaker
docs/parserLibrary/lexer.rst+25−19
@@ -10,13 +10,16 @@ module:
10
10
11 lex : TokenMap a -> String -> (List (TokenData a), (Int, Int, String))
11 lex : TokenMap a -> String -> (List (TokenData a), (Int, Int, String))
12
12
13+.. list-table::
14+
13−This function takes a String and returns a list of tokens. With the tokens we
15+ * - This function takes a String and returns a list of tokens. With the
14−have indexes back to the original string which can be used in error messages:
16+ tokens we have indexes back to the original string which can be used
17+ in error messages:
15
18
16−.. image:: ../image/tokenise.png
19+ - .. image:: ../image/tokenise.png
17− :width: 330px
20+ :width: 330px
18− :height: 73px
21+ :height: 73px
19− :alt: diagram illustrating these stages of lexer
22+ :alt: diagram illustrating these stages of lexer
20
23
21TokenMap
24TokenMap
22--------
25--------
@@ -34,21 +37,24 @@ this information:
34 (Lexer, String -> tokenType)
37 (Lexer, String -> tokenType)
35
38
36So for each Lexer in the list, if a substring in the input matches, run
39So for each Lexer in the list, if a substring in the input matches, run
37−the associated function to produce a token of type `tokenType`
40+the associated function to produce a token of type ``tokenType``
38
41
39−from Text.Lexer.Core:
42+.. list-table::
40
43
41−.. code-block:: idris
44+ * - from Text.Lexer.Core
45+ : https://github.com/idris-lang/Idris-dev/blob/master/libs/contrib/Text/Lexer/Core.idr
42
46
43− TokenMap : (tokenType : Type) -> Type
47+ - .. code-block:: idris
44− TokenMap tokenType = List (Lexer, String -> tokenType)
45
48
46−We can create a tokenMap by using a function like this:
49+ TokenMap : (tokenType : Type) -> Type
50+ TokenMap tokenType = List (Lexer, String -> tokenType)
47
51
52+ * - We can create a tokenMap by using a function like this:
53+
48−.. code-block:: idris
54+ - .. code-block:: idris
49
55
50− myTokenMap : TokenMap Token
56+ myTokenMap : TokenMap Token
51− myTokenMap = [(is 'a',CharLit)]
57+ myTokenMap = [(is 'a',CharLit)]
52
58
53Once we have a TokenMap we can use it to lex many strings.
59Once we have a TokenMap we can use it to lex many strings.
54
60
@@ -74,7 +80,7 @@ combined, for example,
74
80
75.. list-table::
81.. list-table::
76
82
77− * - <+> means sequence two recognisers. If either consumes a character,
83+ * - ``<+>`` means sequence two recognisers. If either consumes a character,
78 the sequence is guaranteed to consume a character.
84 the sequence is guaranteed to consume a character.
79
85
80 - .. code-block:: idris
86 - .. code-block:: idris
@@ -83,7 +89,7 @@ combined, for example,
83 SeqEat (Pred (\ARG => intToBool (prim__eqChar ARG 'a')))
89 SeqEat (Pred (\ARG => intToBool (prim__eqChar ARG 'a')))
84 (Delay (is 'b')) : Recognise True
90 (Delay (is 'b')) : Recognise True
85
91
86− * - <|> means if both consume, the combination is guaranteed
92+ * - ``<|>`` means if both consume, the combination is guaranteed
87 to consumer a character:
93 to consumer a character:
88
94
89 - .. code-block:: idris
95 - .. code-block:: idris
@@ -161,7 +167,7 @@ able to parse simple arithmetic expressions, like this:
161so we need:
167so we need:
162
168
163- Numbers (for now integer literals are good enough).
169- Numbers (for now integer literals are good enough).
164−- Some operators (for now '+', '-' and '*' will do.
170+- Some operators (for now ``+``, ``-`` and ``*`` will do.
165- Opening and closing Parentheses.
171- Opening and closing Parentheses.
166
172
167We can define these, as tokens, like this:
173We can define these, as tokens, like this:
@@ -178,7 +184,7 @@ We can define these, as tokens, like this:
178 | EndInput
184 | EndInput
179
185
180It may help with debugging and to implement error messages to
186It may help with debugging and to implement error messages to
181−implement 'show' for these tokens:
187+implement ``show`` for these tokens:
182
188
183.. code-block:: idris
189.. code-block:: idris
184
190