Changeset 30714 in project


Ignore:
Timestamp:
04/16/14 00:16:14 (7 years ago)
Author:
Moritz Heidkamp
Message:

comparse: Document end-of-input, maybe, zero-or-more, and one-or-more

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/comparse

    r30713 r30714  
    9999touching the remainder is needed quite frequently, Comparse provides
    100100the {{result}} parser combinator which does just that. Using it we can
    101 write {{double-item}} more conveniently like this:
     101write {{double-item}} like this:
    102102
    103103
     
    131131<procedure>(result value)</procedure>
    132132
    133 Returns a parser which always succeeds, leaves the input untouched and
    134 returns {{value}}.
     133Returns a parser which always succeeds, returning {{value}} as the
     134parse result and the untouched input as the remainder.
    135135
    136136
     
    143143
    144144A parser which consumes and returns the first item of {{input}},
    145 i.e. it returns that item and the tail of {{input}}. Fails if
    146 {{input}} is empty.
     145i.e. it returns that item as the parse result and the tail of
     146{{input}} as the remainder. Fails if {{input}} is empty.
     147
     148
     149<procedure>(end-of-input input)</procedure>
     150
     151A parser which returns {{#t}} as the parse result and the untouched
     152{{input}} as the remainder if {{input}} is empty.
    147153
    148154
     
    244250of the preceding parser, respectively, and returns the result of
    245251{{content}} with the remainder of {{close}}.
     252
     253
     254<procedure>(maybe parser)</procedure>
     255
     256Returns a parser which applies {{parser}} to the input and returns its
     257result and remainder if it succeeds. Otherwise it returns {{#f}} as
     258the parse result and the untouched input as the remainder.
     259
     260
     261<procedure>(zero-or-more parser)</procedure>
     262
     263Returns a parser which applies {{parser}} to its input. If that fails,
     264it returns {{()}} as the parse result and the untouched input as the
     265remainder. Otherwise it applies {{parser}} again to the remainder of
     266the previous application and so forth, collecting all parse result in
     267a list. That list is then returned as the parse result and the
     268remainder of the last successful application of {{parser}} as the
     269remainder.
     270
     271
     272<procedure>(one-or-more parser)</procedure>
     273
     274Returns a parser which applies {{parser}} to its input. If that fails,
     275it also fails. Otherwise it applies {{parser}} again to the remainder
     276of the previous application and so forth, collecting all parse result
     277in a list. That list is then returned as the parse result and the
     278remainder of the last successful application of {{parser}} as the
     279remainder.
    246280
    247281
Note: See TracChangeset for help on using the changeset viewer.