Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Parsers are actually type abbreviations for functions from streams to replies:</p> <pre><code>Parser&lt;_,_&gt; is just CharStream&lt;_&gt; -&gt; Reply&lt;_&gt; </code></pre> <p>Keeping that in mind, you can easily write a custom parser for positions:</p> <pre><code>let position : CharStream&lt;_&gt; -&gt; Reply&lt;Position&gt; = fun stream -&gt; Reply(stream.Position) (* OR *) let position : Parser&lt;_,_&gt; = fun stream -&gt; Reply stream.Position </code></pre> <p>and atttach position information to every bit you parse using</p> <pre><code>position .&gt;&gt;. yourParser (*or tuple2 position yourParser*) </code></pre> <p>position parser does not consume any input and thus it is safe to combine in that way.</p> <p>You <em>can</em> keep the code change required restricted to a single line and avoid uncontrollable code spread:</p> <pre><code>type AST = Slash of int64 | Hash of int64 let slash : Parser&lt;AST,_&gt; = char '/' &gt;&gt;. pint64 |&gt;&gt; Slash let hash : Parser&lt;AST,_&gt; = char '#' &gt;&gt;. pint64 |&gt;&gt; Hash let ast : Parser&lt;AST,_&gt; = slash &lt;|&gt; hash (*if this is the final parser used for parsing lists of your ASTs*) let manyAst : Parser&lt; AST list,_&gt; = many (ast .&gt;&gt; spaces) let manyAstP : Parser&lt;(Position * AST) list,_&gt; = many ((position .&gt;&gt;. ast) .&gt;&gt; spaces) (*you can opt in to parse position information for every bit you parse just by modifiying only the combined parser *) </code></pre> <p><strong>Update</strong>: FParsec has a predefined parser for positions: <a href="http://www.quanttec.com/fparsec/reference/charparsers.html#members.getPosition" rel="nofollow">http://www.quanttec.com/fparsec/reference/charparsers.html#members.getPosition</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload