Offset 1, 11 lines modified | Offset 1, 11 lines modified |
1 | <html><head><meta·http-equiv="Content-Type"·content="text/html;·charset=ISO-8859-1"><title>5.3. Wrappers</title><link·rel="stylesheet"·type="text/css"·href="fptools.css"><meta·name="generator"·content="DocBook·XSL·Stylesheets·V1.76.1"><link·rel="home"·href="index.html"·title="Alex·User·Guide"><link·rel="up"·href="api.html"·title="Chapter 5. The·Interface·to·an·Alex-generated·lexer"><link·rel="prev"·href="basic-api.html"·title="5.2. Basic·interface"><link·rel="next"·href="invoking.html"·title="Chapter 6. Invoking·Alex"></head><body·bgcolor="white"·text="black"·link="#0000FF"·vlink="#840084"·alink="#0000FF"><div·class="navheader"><table·width="100%"·summary="Navigation·header"><tr><th·colspan="3"·align="center">5.3. Wrappers</th></tr><tr><td·width="20%"·align="left"><a·accesskey="p"·href="basic-api.html">Prev</a> </td><th·width="60%"·align="center">Chapter 5. The·Interface·to·an·Alex-generated·lexer</th><td·width="20%"·align="right"> <a·accesskey="n"·href="invoking.html">Next</a></td></tr></table><hr></div><div·✂ | 1 | <html><head><meta·http-equiv="Content-Type"·content="text/html;·charset=ISO-8859-1"><title>5.3. Wrappers</title><link·rel="stylesheet"·type="text/css"·href="fptools.css"><meta·name="generator"·content="DocBook·XSL·Stylesheets·V1.76.1"><link·rel="home"·href="index.html"·title="Alex·User·Guide"><link·rel="up"·href="api.html"·title="Chapter 5. The·Interface·to·an·Alex-generated·lexer"><link·rel="prev"·href="basic-api.html"·title="5.2. Basic·interface"><link·rel="next"·href="invoking.html"·title="Chapter 6. Invoking·Alex"></head><body·bgcolor="white"·text="black"·link="#0000FF"·vlink="#840084"·alink="#0000FF"><div·class="navheader"><table·width="100%"·summary="Navigation·header"><tr><th·colspan="3"·align="center">5.3. Wrappers</th></tr><tr><td·width="20%"·align="left"><a·accesskey="p"·href="basic-api.html">Prev</a> </td><th·width="60%"·align="center">Chapter 5. The·Interface·to·an·Alex-generated·lexer</th><td·width="20%"·align="right"> <a·accesskey="n"·href="invoking.html">Next</a></td></tr></table><hr></div><div·✂ |
2 | ······declaration·in·your·file:</p><pre·class="programlisting">%wrapper·"<em·class="replaceable"><code>name</code></em>"</pre><p>where·<em·class="replaceable"><code>name</code></em>·is·the·name·of·the | 2 | ······declaration·in·your·file:</p><pre·class="programlisting">%wrapper·"<em·class="replaceable"><code>name</code></em>"</pre><p>where·<em·class="replaceable"><code>name</code></em>·is·the·name·of·the |
3 | ······wrapper,·eg.·<code·class="literal">basic</code>.··The·following·sections | 3 | ······wrapper,·eg.·<code·class="literal">basic</code>.··The·following·sections |
4 | ······describe·each·of·the·wrappers·that·come·with·Alex.</p><div·class="section"·title='5.3.1. The·"basic"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63428152"></a>5.3.1. The·"basic"·wrapper</h3></div></div></div><p>The·basic·wrapper·is·a·good·way·to·obtain·a·function·of | 4 | ······describe·each·of·the·wrappers·that·come·with·Alex.</p><div·class="section"·title='5.3.1. The·"basic"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63395384"></a>5.3.1. The·"basic"·wrapper</h3></div></div></div><p>The·basic·wrapper·is·a·good·way·to·obtain·a·function·of |
5 | » type·<code·class="literal">String·->·[token]</code>·from·a·lexer | 5 | » type·<code·class="literal">String·->·[token]</code>·from·a·lexer |
6 | » specification,·with·little·fuss.</p><p>It·provides·definitions·for | 6 | » specification,·with·little·fuss.</p><p>It·provides·definitions·for |
7 | ········<code·class="literal">AlexInput</code>,·<code·class="literal">alexGetByte</code> | 7 | ········<code·class="literal">AlexInput</code>,·<code·class="literal">alexGetByte</code> |
8 | » and·<code·class="literal">alexInputPrevChar</code>·that·are·suitable·for | 8 | » and·<code·class="literal">alexInputPrevChar</code>·that·are·suitable·for |
9 | » lexing·a·<code·class="literal">String</code>·input.··It·also·provides·a | 9 | » lexing·a·<code·class="literal">String</code>·input.··It·also·provides·a |
10 | » function·<code·class="literal">alexScanTokens</code>·which·takes·a | 10 | » function·<code·class="literal">alexScanTokens</code>·which·takes·a |
11 | » <code·class="literal">String</code>·input·and·returns·a·list·of·the | 11 | » <code·class="literal">String</code>·input·and·returns·a·list·of·the |
Offset 35, 15 lines modified | Offset 35, 15 lines modified |
35 | ················AlexSkip··inp'·len·····->·go·inp' | 35 | ················AlexSkip··inp'·len·····->·go·inp' |
36 | ················AlexToken·inp'·len·act·->·act·(take·len·str)·:·go·inp' | 36 | ················AlexToken·inp'·len·act·->·act·(take·len·str)·:·go·inp' |
37 | </pre><p>The·type·signature·for·<code·class="literal">alexScanTokens</code> | 37 | </pre><p>The·type·signature·for·<code·class="literal">alexScanTokens</code> |
38 | ········is·commented·out,·because·the·<code·class="literal">token</code>·type·is | 38 | ········is·commented·out,·because·the·<code·class="literal">token</code>·type·is |
39 | ········unknown.··All·of·the·actions·in·your·lexical·specification | 39 | ········unknown.··All·of·the·actions·in·your·lexical·specification |
40 | ········should·have·type:</p><pre·class="programlisting">{·...·}·::·String·->·token</pre><p>for·some·type·<code·class="literal">token</code>.</p><p>For·an·example·of·the·use·of·the·basic·wrapper,·see·the | 40 | ········should·have·type:</p><pre·class="programlisting">{·...·}·::·String·->·token</pre><p>for·some·type·<code·class="literal">token</code>.</p><p>For·an·example·of·the·use·of·the·basic·wrapper,·see·the |
41 | ········file·<code·class="literal">examples/Tokens.x</code>·in·the·Alex | 41 | ········file·<code·class="literal">examples/Tokens.x</code>·in·the·Alex |
42 | » distribution.</p></div><div·class="section"·title='5.3.2. The·"posn"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63438776"></a>5.3.2. The·"posn"·wrapper</h3></div></div></div><p>The·posn·wrapper·provides·slightly·more·functionality | 42 | » distribution.</p></div><div·class="section"·title='5.3.2. The·"posn"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63406008"></a>5.3.2. The·"posn"·wrapper</h3></div></div></div><p>The·posn·wrapper·provides·slightly·more·functionality |
43 | » than·the·basic·wrapper:·it·keeps·track·of·line·and·column | 43 | » than·the·basic·wrapper:·it·keeps·track·of·line·and·column |
44 | » numbers·of·tokens·in·the·input·text.</p><p>The·posn·wrapper·provides·the·following,·in·addition·to | 44 | » numbers·of·tokens·in·the·input·text.</p><p>The·posn·wrapper·provides·the·following,·in·addition·to |
45 | » the·straightforward·definitions·of | 45 | » the·straightforward·definitions·of |
46 | » <code·class="literal">alexGetByte</code>·and | 46 | » <code·class="literal">alexGetByte</code>·and |
47 | » <code·class="literal">alexInputPrevChar</code>:</p><pre·class="programlisting"> | 47 | » <code·class="literal">alexInputPrevChar</code>:</p><pre·class="programlisting"> |
48 | data·AlexPosn·=·AlexPn·!Int··--·absolute·character·offset | 48 | data·AlexPosn·=·AlexPn·!Int··--·absolute·character·offset |
49 | ·······················!Int··--·line·number | 49 | ·······················!Int··--·line·number |
Offset 61, 15 lines modified | Offset 61, 15 lines modified |
61 | ················AlexEOF·->·[] | 61 | ················AlexEOF·->·[] |
62 | ················AlexError·((AlexPn·_·line·column),_,_,_)·->·error·$·"lexical·error·at·"·++·(show·line)·++·"·line,·"·++·(show·column)·++·"·column" | 62 | ················AlexError·((AlexPn·_·line·column),_,_,_)·->·error·$·"lexical·error·at·"·++·(show·line)·++·"·line,·"·++·(show·column)·++·"·column" |
63 | ················AlexSkip··inp'·len·····->·go·inp' | 63 | ················AlexSkip··inp'·len·····->·go·inp' |
64 | ················AlexToken·inp'·len·act·->·act·pos·(take·len·str)·:·go·inp' | 64 | ················AlexToken·inp'·len·act·->·act·pos·(take·len·str)·:·go·inp' |
65 | </pre><p>The·types·of·the·token·actions·should·be:</p><pre·class="programlisting">{·...·}·::·AlexPosn·->·String·->·token</pre><p>For·an·example·using·the·<code·class="literal">posn</code> | 65 | </pre><p>The·types·of·the·token·actions·should·be:</p><pre·class="programlisting">{·...·}·::·AlexPosn·->·String·->·token</pre><p>For·an·example·using·the·<code·class="literal">posn</code> |
66 | » wrapper,·see·the·file | 66 | » wrapper,·see·the·file |
67 | » <code·class="literal">examples/Tokens_posn.x</code>·in·the·Alex | 67 | » <code·class="literal">examples/Tokens_posn.x</code>·in·the·Alex |
68 | » distribution.</p></div><div·class="section"·title='5.3.3. The·"monad"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63444152"></a>5.3.3. The·"monad"·wrapper</h3></div></div></div><p>The·<code·class="literal">monad</code>·wrapper·is·the·most | 68 | » distribution.</p></div><div·class="section"·title='5.3.3. The·"monad"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63411384"></a>5.3.3. The·"monad"·wrapper</h3></div></div></div><p>The·<code·class="literal">monad</code>·wrapper·is·the·most |
69 | » flexible·of·the·wrappers·provided·with·Alex.··It·includes·a | 69 | » flexible·of·the·wrappers·provided·with·Alex.··It·includes·a |
70 | » state·monad·which·keeps·track·of·the·current·input·and·text | 70 | » state·monad·which·keeps·track·of·the·current·input·and·text |
71 | » position,·and·the·startcode.··It·is·intended·to·be·a·template | 71 | » position,·and·the·startcode.··It·is·intended·to·be·a·template |
72 | » for·building·your·own·monads·-·feel·free·to·copy·the·code·and | 72 | » for·building·your·own·monads·-·feel·free·to·copy·the·code·and |
73 | » modify·it·to·build·a·monad·with·the·facilities·you | 73 | » modify·it·to·build·a·monad·with·the·facilities·you |
74 | » need.</p><pre·class="programlisting">data·AlexState·=·AlexState·{ | 74 | » need.</p><pre·class="programlisting">data·AlexState·=·AlexState·{ |
75 | ········alex_pos·::·!AlexPosn,··--·position·at·current·input·location | 75 | ········alex_pos·::·!AlexPosn,··--·position·at·current·input·location |
Offset 101, 15 lines modified | Offset 101, 15 lines modified |
101 | --·andBegin·::·AlexAction·result·->·Int·->·AlexAction·result | 101 | --·andBegin·::·AlexAction·result·->·Int·->·AlexAction·result |
102 | (act·`andBegin`·code)·input·len·=·do·alexSetStartCode·code;·act·input·len | 102 | (act·`andBegin`·code)·input·len·=·do·alexSetStartCode·code;·act·input·len |
| |
103 | --·begin·::·Int·->·AlexAction·result | 103 | --·begin·::·Int·->·AlexAction·result |
104 | begin·code·=·skip·`andBegin`·code | 104 | begin·code·=·skip·`andBegin`·code |
| |
105 | --·token·::·(String·->·Int·->·token)·->·AlexAction·token | 105 | --·token·::·(String·->·Int·->·token)·->·AlexAction·token |
106 | token·t·input·len·=·return·(t·input·len)</pre></div><div·class="section"·title='5.3.4. The·"monadUserState"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63451960"></a>5.3.4. The·"monadUserState"·wrapper</h3></div></div></div><p>The·<code·class="literal">monadUserState</code>·wrapper·is·built· | 106 | token·t·input·len·=·return·(t·input·len)</pre></div><div·class="section"·title='5.3.4. The·"monadUserState"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63423288"></a>5.3.4. The·"monadUserState"·wrapper</h3></div></div></div><p>The·<code·class="literal">monadUserState</code>·wrapper·is·built· |
107 | ····upon·the·<code·class="literal">monad</code>·wrapper.·It·includes·a·reference | 107 | ····upon·the·<code·class="literal">monad</code>·wrapper.·It·includes·a·reference |
108 | ····to·a·type·which·must·be·defined·in·the·user's·program,· | 108 | ····to·a·type·which·must·be·defined·in·the·user's·program,· |
109 | ····<code·class="literal">AlexUserState</code>,·and·a·call·to·an·initialization | 109 | ····<code·class="literal">AlexUserState</code>,·and·a·call·to·an·initialization |
110 | ····function·which·must·also·be·defined·in·the·user's·program, | 110 | ····function·which·must·also·be·defined·in·the·user's·program, |
111 | ····<code·class="literal">alexInitUserState</code>.·It·gives·great·flexibility | 111 | ····<code·class="literal">alexInitUserState</code>.·It·gives·great·flexibility |
112 | ····because·it·is·now·possible·to·add·any·needed·information·and·carry | 112 | ····because·it·is·now·possible·to·add·any·needed·information·and·carry |
113 | ····it·during·the·whole·lexing·phase.</p><p>The·generated·code·is·the·same·as·in·the·<code·class="literal">monad</code>· | 113 | ····it·during·the·whole·lexing·phase.</p><p>The·generated·code·is·the·same·as·in·the·<code·class="literal">monad</code>· |
Offset 162, 28 lines modified | Offset 162, 28 lines modified |
162 | getLexerStringValue·=·do·ust·<-·alexGetUserState;·return·(lexerStringValue·ust) | 162 | getLexerStringValue·=·do·ust·<-·alexGetUserState;·return·(lexerStringValue·ust) |
| |
163 | setLexerStringValue·::·String·->·Alex·() | 163 | setLexerStringValue·::·String·->·Alex·() |
164 | setLexerStringValue·ss·=·do·ust·<-·alexGetUserState;·alexSetUserState·ust{lexerStringValue=ss} | 164 | setLexerStringValue·ss·=·do·ust·<-·alexGetUserState;·alexSetUserState·ust{lexerStringValue=ss} |
| |
165 | addCharToLexerStringValue·::·Char·->·Alex·() | 165 | addCharToLexerStringValue·::·Char·->·Alex·() |
166 | addCharToLexerStringValue·c·=·do·ust·<-·alexGetUserState;·alexSetUserState·ust{lexerStringValue=c:(lexerStringValue·ust)} | 166 | addCharToLexerStringValue·c·=·do·ust·<-·alexGetUserState;·alexSetUserState·ust{lexerStringValue=c:(lexerStringValue·ust)} |
167 | </pre></div><div·class="section"·title='5.3.5. The·"gscan"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63461688"></a>5.3.5. The·"gscan"·wrapper</h3></div></div></div><p>The·<code·class="literal">gscan</code>·wrapper·is·provided·mainly | 167 | </pre></div><div·class="section"·title='5.3.5. The·"gscan"·wrapper'><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63433016"></a>5.3.5. The·"gscan"·wrapper</h3></div></div></div><p>The·<code·class="literal">gscan</code>·wrapper·is·provided·mainly |
168 | » for·historical·reasons:·it·exposes·an·interface·which·is·very | 168 | » for·historical·reasons:·it·exposes·an·interface·which·is·very |
169 | » similar·to·that·provided·by·Alex·version·1.x.··The·interface | 169 | » similar·to·that·provided·by·Alex·version·1.x.··The·interface |
170 | » is·intended·to·be·very·general,·allowing·actions·to·modify·the | 170 | » is·intended·to·be·very·general,·allowing·actions·to·modify·the |
171 | » startcode,·and·pass·around·an·arbitrary·state·value.</p><pre·class="programlisting">alexGScan·::·StopAction·state·result·->·state·->·String·->·result | 171 | » startcode,·and·pass·around·an·arbitrary·state·value.</p><pre·class="programlisting">alexGScan·::·StopAction·state·result·->·state·->·String·->·result |
| |
172 | type·StopAction·state·result· | 172 | type·StopAction·state·result· |
173 | ·········=·AlexPosn·->·Char·->·String·->·(Int,state)·->·result</pre><p>The·token·actions·should·all·have·this·type:</p><pre·class="programlisting">{·...·}······::·AlexPosn················--·token·position | 173 | ·········=·AlexPosn·->·Char·->·String·->·(Int,state)·->·result</pre><p>The·token·actions·should·all·have·this·type:</p><pre·class="programlisting">{·...·}······::·AlexPosn················--·token·position |
174 | ·············->·Char····················--·previous·character | 174 | ·············->·Char····················--·previous·character |
175 | ·············->·String··················--·input·string·at·token | 175 | ·············->·String··················--·input·string·at·token |
176 | ·············->·Int·····················--·length·of·token | 176 | ·············->·Int·····················--·length·of·token |
177 | ·············->·((Int,state)·->·result)·--·continuation | 177 | ·············->·((Int,state)·->·result)·--·continuation |
178 | ·············->·(Int,state)·············--·current·(startcode,state) | 178 | ·············->·(Int,state)·············--·current·(startcode,state) |
179 | ·············->·result</pre></div><div·class="section"·title="5.3.6. The·bytestring·wrappers"><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63464760"></a>5.3.6. The·bytestring·wrappers</h3></div></div></div><p>The·<code·class="literal">basic-bytestring</code>, | 179 | ·············->·result</pre></div><div·class="section"·title="5.3.6. The·bytestring·wrappers"><div·class="titlepage"><div><div><h3·class="title"><a·name="idp63440184"></a>5.3.6. The·bytestring·wrappers</h3></div></div></div><p>The·<code·class="literal">basic-bytestring</code>, |
180 | » <code·class="literal">posn-bytestring</code>·and | 180 | » <code·class="literal">posn-bytestring</code>·and |
181 | » <code·class="literal">monad-bytestring</code>·wrappers·are·variations·on·the | 181 | » <code·class="literal">monad-bytestring</code>·wrappers·are·variations·on·the |
182 | » <code·class="literal">basic</code>,·<code·class="literal">posn</code>·and | 182 | » <code·class="literal">basic</code>,·<code·class="literal">posn</code>·and |
183 | » <code·class="literal">monad</code>·wrappers·that·use·lazy | 183 | » <code·class="literal">monad</code>·wrappers·that·use·lazy |
184 | » <code·class="literal">ByteString</code>s·as·the·input·and·token·types·instead·of | 184 | » <code·class="literal">ByteString</code>s·as·the·input·and·token·types·instead·of |
185 | » an·ordinary·<code·class="literal">String</code>.</p><p>The·point·of·using·these·wrappers·is·that | 185 | » an·ordinary·<code·class="literal">String</code>.</p><p>The·point·of·using·these·wrappers·is·that |
186 | » <code·class="literal">ByteString</code>s·provide·a·more·memory·efficient | 186 | » <code·class="literal">ByteString</code>s·provide·a·more·memory·efficient |
Offset 203, 40 lines modified | Offset 203, 40 lines modified |
203 | » convert·to·a·strict·<code·class="literal">ByteString</code>·or·perhaps·something | 203 | » convert·to·a·strict·<code·class="literal">ByteString</code>·or·perhaps·something |
204 | » more·compact·still.·Note·also·that·by·default·tokens·share·space·with | 204 | » more·compact·still.·Note·also·that·by·default·tokens·share·space·with |
205 | » the·input·<code·class="literal">ByteString</code>·which·has·the·advantage·that·it | 205 | » the·input·<code·class="literal">ByteString</code>·which·has·the·advantage·that·it |
206 | » does·not·need·to·make·a·copy·but·it·also·prevents·the·input·from·being | 206 | » does·not·need·to·make·a·copy·but·it·also·prevents·the·input·from·being |
207 | » garbage·collected.·It·may·make·sense·in·some·applications·to·use | 207 | » garbage·collected.·It·may·make·sense·in·some·applications·to·use |
208 | » <code·class="literal">ByteString</code>'s·<code·class="literal">copy</code>·function·to | 208 | » <code·class="literal">ByteString</code>'s·<code·class="literal">copy</code>·function·to |
209 | » unshare·tokens·that·will·be·kept·for·a·long·time,·to·allow·the·original | 209 | » unshare·tokens·that·will·be·kept·for·a·long·time,·to·allow·the·original |
210 | » input·to·be·collected.</p><div·class="section"·title='5.3.6.1. The·"basic-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63478456"></a>5.3.6.1. The·"basic-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">basic-bytestring</code>·wrapper·is·the·same·as | 210 | » input·to·be·collected.</p><div·class="section"·title='5.3.6.1. The·"basic-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63453880"></a>5.3.6.1. The·"basic-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">basic-bytestring</code>·wrapper·is·the·same·as |
211 | » the·<code·class="literal">basic</code>·wrapper·but·with·lazy | 211 | » the·<code·class="literal">basic</code>·wrapper·but·with·lazy |
212 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> | 212 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> |
213 | import·qualified·Data.ByteString.Lazy·as·ByteString | 213 | import·qualified·Data.ByteString.Lazy·as·ByteString |
| |
214 | type·AlexInput·=·(Char,·······--·previous·char | 214 | type·AlexInput·=·(Char,·······--·previous·char |
215 | ··················ByteString.ByteString)·--·current·input·string | 215 | ··················ByteString.ByteString)·--·current·input·string |
| |
216 | alexGetByte·::·AlexInput·->·Maybe·(Char,AlexInput) | 216 | alexGetByte·::·AlexInput·->·Maybe·(Char,AlexInput) |
| |
217 | alexInputPrevChar·::·AlexInput·->·Char | 217 | alexInputPrevChar·::·AlexInput·->·Char |
| |
218 | --·alexScanTokens·::·String·->·[token] | 218 | --·alexScanTokens·::·String·->·[token] |
219 | </pre><p>All·of·the·actions·in·your·lexical·specification | 219 | </pre><p>All·of·the·actions·in·your·lexical·specification |
220 | ········should·have·type:</p><pre·class="programlisting">{·...·}·::·ByteString.ByteString·->·token</pre><p>for·some·type·<code·class="literal">token</code>.</p></div><div·class="section"·title='5.3.6.2. The·"posn-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63500344"></a>5.3.6.2. The·"posn-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">posn-bytestring</code>·wrapper·is·the·same·as | 220 | ········should·have·type:</p><pre·class="programlisting">{·...·}·::·ByteString.ByteString·->·token</pre><p>for·some·type·<code·class="literal">token</code>.</p></div><div·class="section"·title='5.3.6.2. The·"posn-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63504440"></a>5.3.6.2. The·"posn-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">posn-bytestring</code>·wrapper·is·the·same·as |
221 | » the·<code·class="literal">posn</code>·wrapper·but·with·lazy | 221 | » the·<code·class="literal">posn</code>·wrapper·but·with·lazy |
222 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> | 222 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> |
223 | import·qualified·Data.ByteString.Lazy·as·ByteString | 223 | import·qualified·Data.ByteString.Lazy·as·ByteString |
| |
224 | type·AlexInput·=·(AlexPosn,···--·current·position, | 224 | type·AlexInput·=·(AlexPosn,···--·current·position, |
225 | ··················Char,·······--·previous·char | 225 | ··················Char,·······--·previous·char |
226 | ··················ByteString.ByteString)·--·current·input·string | 226 | ··················ByteString.ByteString)·--·current·input·string |
| |
227 | --·alexScanTokens·::·ByteString.ByteString·->·[token] | 227 | --·alexScanTokens·::·ByteString.ByteString·->·[token] |
228 | </pre><p>All·of·the·actions·in·your·lexical·specification | 228 | </pre><p>All·of·the·actions·in·your·lexical·specification |
229 | ········should·have·type:</p><pre·class="programlisting">{·...·}·::·AlexPosn·->·ByteString.ByteString·->·token</pre><p>for·some·type·<code·class="literal">token</code>.</p></div><div·class="section"·title='5.3.6.3. The·"monad-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63505848"></a>5.3.6.3. The·"monad-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">monad-bytestring</code>·wrapper·is·the·same·as | 229 | ········should·have·type:</p><pre·class="programlisting">{·...·}·::·AlexPosn·->·ByteString.ByteString·->·token</pre><p>for·some·type·<code·class="literal">token</code>.</p></div><div·class="section"·title='5.3.6.3. The·"monad-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63514040"></a>5.3.6.3. The·"monad-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">monad-bytestring</code>·wrapper·is·the·same·as |
230 | » the·<code·class="literal">monad</code>·wrapper·but·with·lazy | 230 | » the·<code·class="literal">monad</code>·wrapper·but·with·lazy |
231 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> | 231 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> |
232 | import·qualified·Data.ByteString.Lazy·as·ByteString | 232 | import·qualified·Data.ByteString.Lazy·as·ByteString |
| |
233 | data·AlexState·=·AlexState·{ | 233 | data·AlexState·=·AlexState·{ |
234 | ········alex_pos·::·!AlexPosn,··--·position·at·current·input·location | 234 | ········alex_pos·::·!AlexPosn,··--·position·at·current·input·location |
235 | ········alex_inp·::·ByteString.ByteString,·--·the·current·input | 235 | ········alex_inp·::·ByteString.ByteString,·--·the·current·input |
Offset 249, 15 lines modified | Offset 249, 15 lines modified |
| |
249 | runAlex··········::·ByteString.ByteString·->·Alex·a·->·Either·String·a | 249 | runAlex··········::·ByteString.ByteString·->·Alex·a·->·Either·String·a |
| |
250 | --·token·::·(ByteString.ByteString·->·Int·->·token)·->·AlexAction·token | 250 | --·token·::·(ByteString.ByteString·->·Int·->·token)·->·AlexAction·token |
251 | </pre><p>All·of·the·actions·in·your·lexical·specification | 251 | </pre><p>All·of·the·actions·in·your·lexical·specification |
252 | ········have·the·same·type·as·in·the·<code·class="literal">monad</code>·wrapper.·It·is | 252 | ········have·the·same·type·as·in·the·<code·class="literal">monad</code>·wrapper.·It·is |
253 | » only·the·types·of·the·function·to·run·the·monad·and·the·type·of·the | 253 | » only·the·types·of·the·function·to·run·the·monad·and·the·type·of·the |
254 | » <code·class="literal">token</code>·function·that·change.</p></div><div·class="section"·title='5.3.6.4. The·"monadUserState-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63515064"></a>5.3.6.4. The·"monadUserState-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">monadUserState-bytestring</code>·wrapper·is·the·same·as | 254 | » <code·class="literal">token</code>·function·that·change.</p></div><div·class="section"·title='5.3.6.4. The·"monadUserState-bytestring"·wrapper'><div·class="titlepage"><div><div><h4·class="title"><a·name="idp63519160"></a>5.3.6.4. The·"monadUserState-bytestring"·wrapper</h4></div></div></div><p>The·<code·class="literal">monadUserState-bytestring</code>·wrapper·is·the·same·as |
255 | » the·<code·class="literal">monadUserState</code>·wrapper·but·with·lazy | 255 | » the·<code·class="literal">monadUserState</code>·wrapper·but·with·lazy |
256 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> | 256 | » <code·class="literal">ByteString</code>·instead·of·<code·class="literal">String</code>:</p><pre·class="programlisting"> |
257 | import·qualified·Data.ByteString.Lazy·as·ByteString | 257 | import·qualified·Data.ByteString.Lazy·as·ByteString |
| |
258 | ata·AlexState·=·AlexState·{ | 258 | ata·AlexState·=·AlexState·{ |
259 | ········alex_pos·::·!AlexPosn,··--·position·at·current·input·location | 259 | ········alex_pos·::·!AlexPosn,··--·position·at·current·input·location |
260 | ········alex_inp·::·ByteString.ByteString,·--·the·current·input | 260 | ········alex_inp·::·ByteString.ByteString,·--·the·current·input |