Paste number 53252: seq implementation

Paste number 53252: seq implementation
Pasted by: |Agent
6 months, 3 weeks ago
#dylan | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
define method seq (#rest sub-rules :: <function>) => (rule :: <function>)
   method (stream) => (success, tokens)
      let pos = stream.stream-position;
      let product = make(<stretchy-sequence>);
      let failed = #f;
      for (rule in sub-rules, until: failed)
         let (success, tokens) = rule(stream);
         if (success)
            product := product.add!(tokens)
         else
            failed := rule
         end if
      end for;
      if (failed)
         stream.stream-position := pos;
         product := make(<parser-error>,
               format-string: "Expected %s", format-args: $rule-names[rule])
      end if;
      values(~failed, product)
   end method
end method;

This paste has no annotations.

Colorize as:
Show Line Numbers

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.