Skip to content

Simplify Syntax

Choose a tag to compare

@jsim2010 jsim2010 released this 23 Jan 20:13

This release brings fairly major changes to the rec syntax. The overarching goal of these changes was to make rec simpler in 3 ways:

  1. Composing a rec generally requires less characters.
  2. Reading a rec is easier.
  3. The code implementing rec is simpler due to removing some structures and utilizing some internal macros to reduce code repetition in the library.

Breaking changes:

  • Atom has been removed. Now rec includes the Element trait which serves a similar function of converting multiple types into Recs with the exception that Rec also implements Element. Also Pattern methods define and load now take an Element.
  • Rec no longer has a rpt method and the Quantifier trait and ConstantQuantifiers VAR, SOME and OPT have been removed. Instead, quantifiers are generated directly from functions.
    • var(Element), some(Element) and opt(Element) replace the ConstantQuantifiers while exact(reps, Element), min(min_reps, Element) and btwn(min_reps, max_reps, Element) replace the value Quantifiers.
    • all functions except exact provide a lazy version by prepending lazy_ to the function name. Ex: lazy_var(Element).
  • Rec no longer has a name method. Instead, capture groups are generated using a tkn! macro (tkn is an abbreviation of token). The syntax is: tkn!(Element => name), which defines Element as a capture group with the given name. Ex: tkn!(some(ChCls::Digit) => "number").
  • ChCls variants None and WhSpc have been renamed to Not and Whitespace respectively.

New features:

  • ChCls includes a new variant Sign which matches either a + or a -.