Accessing Input Elements#

When dealing with complex input formats, attaching constraints can be complex, as elements can occur multiple times in a generated input. Fandango offers a few mechanisms to disambiguate these, and to specify specific contexts in which to search for elements.

Derivation Trees#

So far, we have always assumed that Fandango generates strings from the grammar. Behind the scenes, though, Fandango creates a far richer data structure - a so-called derivation tree that maintains the structure of the string and allows accessing individual elements. Every time Fandango sees a grammar rule

<symbol> ::= ...

it generates a derivation tree whose root is <symbol> and whose children are the elements of the right-hand side of the rule.

Let’s have a look at our persons.fan spec:

<start> ::= <person_name> "," <age>
<person_name> ::= <first_name> " " <last_name>
<first_name> ::= <name>
<last_name> ::= <name>
<name> ::= <ascii_uppercase_letter><ascii_lowercase_letter>+
<age> ::= <digit>+

The <start> rule says

<start> ::= <person_name> "," <age>

Then, a resulting derivation tree for <start> looks like this:

_images/ce67d5b85467add2e5b5e73ee365d938cd469e7a75e638dd6fa08b9547ae2769.png

As Fandango expands more and more symbols, it expands the derivation tree accordingly. Since the grammar definition for <person_name> says

<person_name> ::= <first_name> " " <last_name>

the above derivation tree would be extended to

_images/4fa4968f75dd5a18575ee1c39c54f82eb03018bb238f5949af7dad5babf22b94.png

And if we next extend <age> and then <digit> based on their definitions

<age> ::= <digit>+

our tree gets to look like this:

_images/b1b0b00242a346fd4a244929b1376d5a28a8bf90ee454fb065ab79e380f39720.png

Repeating the process, it thus obtains a tree like this:

_images/3e0b8dbf999a2cf38f640b33de35c945c5f3f5fbe6201f798a4d304564937296.png

Note how the tree records the entire history of how it was created - how it was derived, actually.

To obtain a string from the tree, we traverse its children left-to-right, ignoring all nonterminal symbols (in <...>) and considering only the terminal symbols (in quotes). This is what we get for the above tree:

Ex Pltz,18

And this is the string Fandango produces. However, viewing the Fandango results as derivation trees allows us to access elements of the Fandango-produced strings and to express constraints on them.

Diagnosing Derivation Trees#

To examine the derivation trees that Fandango produces, use the --format=grammar output format. This produces the output in a grammar-like format, where children are indented under their respective parents. As an example, here is how to print a derivation tree from persons.fan:

$ fandango fuzz -f persons.fan -n 1 --format=grammar
<start> ::= <person_name> ',' <age>  # Position 0x0000 (0); Aqwlsxsvunuqlykmguykt Yxvrkmdcyviqthymndxy,6053337261160
  <person_name> ::= <first_name> ' ' <last_name>  # Position 0x0001 (1); Aqwlsxsvunuqlykmguykt Yxvrkmdcyviqthymndxy
    <first_name> ::= <name>
      <name> ::= <ascii_uppercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter>  # Aqwlsxsvunuqlykmguykt
        <ascii_uppercase_letter> ::= <_ascii_uppercase_letter>
          <_ascii_uppercase_letter> ::= 'A'  # Position 0x0002 (2)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'q'  # Position 0x0003 (3)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'w'  # Position 0x0004 (4)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'l'  # Position 0x0005 (5)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 's'  # Position 0x0006 (6)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'x'  # Position 0x0007 (7)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 's'  # Position 0x0008 (8)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'v'  # Position 0x0009 (9)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'u'  # Position 0x000a (10)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'n'  # Position 0x000b (11)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'u'  # Position 0x000c (12)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'q'  # Position 0x000d (13)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'l'  # Position 0x000e (14)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'y'  # Position 0x000f (15)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'k'  # Position 0x0010 (16)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'm'  # Position 0x0011 (17)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'g'  # Position 0x0012 (18)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'u'  # Position 0x0013 (19)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'y'  # Position 0x0014 (20)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'k'  # Position 0x0015 (21)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 't'  # Position 0x0016 (22)
    <last_name> ::= <name>
      <name> ::= <ascii_uppercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter> <ascii_lowercase_letter>  # Yxvrkmdcyviqthymndxy
        <ascii_uppercase_letter> ::= <_ascii_uppercase_letter>
          <_ascii_uppercase_letter> ::= 'Y'  # Position 0x0017 (23)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'x'  # Position 0x0018 (24)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'v'  # Position 0x0019 (25)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'r'  # Position 0x001a (26)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'k'  # Position 0x001b (27)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'm'  # Position 0x001c (28)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'd'  # Position 0x001d (29)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'c'  # Position 0x001e (30)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'y'  # Position 0x001f (31)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'v'  # Position 0x0020 (32)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'i'  # Position 0x0021 (33)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'q'  # Position 0x0022 (34)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 't'  # Position 0x0023 (35)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'h'  # Position 0x0024 (36)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'y'  # Position 0x0025 (37)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'm'  # Position 0x0026 (38)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'n'  # Position 0x0027 (39)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'd'  # Position 0x0028 (40)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'x'  # Position 0x0029 (41)
        <ascii_lowercase_letter> ::= <_ascii_lowercase_letter>
          <_ascii_lowercase_letter> ::= 'y'  # Position 0x002a (42)
  <age> ::= <digit> <digit> <digit> <digit> <digit> <digit> <digit> <digit> <digit> <digit> <digit> <digit> <digit>  # 6053337261160
    <digit> ::= <_digit>
      <_digit> ::= '6'  # Position 0x002b (43)
    <digit> ::= <_digit>
      <_digit> ::= '0'  # Position 0x002c (44)
    <digit> ::= <_digit>
      <_digit> ::= '5'  # Position 0x002d (45)
    <digit> ::= <_digit>
      <_digit> ::= '3'  # Position 0x002e (46)
    <digit> ::= <_digit>
      <_digit> ::= '3'  # Position 0x002f (47)
    <digit> ::= <_digit>
      <_digit> ::= '3'  # Position 0x0030 (48)
    <digit> ::= <_digit>
      <_digit> ::= '7'  # Position 0x0031 (49)
    <digit> ::= <_digit>
      <_digit> ::= '2'  # Position 0x0032 (50)
    <digit> ::= <_digit>
      <_digit> ::= '6'  # Position 0x0033 (51)
    <digit> ::= <_digit>
      <_digit> ::= '1'  # Position 0x0034 (52)
    <digit> ::= <_digit>
      <_digit> ::= '1'  # Position 0x0035 (53)
    <digit> ::= <_digit>
      <_digit> ::= '6'  # Position 0x0036 (54)
    <digit> ::= <_digit>
      <_digit> ::= '0'  # Position 0x0037 (55)

We see how the produced derivation tree consists of a <start> symbol, whose <first_name> and <last_name> children expand into <name> and letters; the <age> symbol expands into <digit> symbols.

The comments (after #) show the individual positions into the input, as well as the values of compound symbols.

What is the full string represented by the above derivation tree?

Tip

The --format=grammar option is great for debugging, especially binary formats.

Specifying Paths#

One effect of Fandango producing derivation trees rather than “just” strings is that we can define special operators that allow us to access subtrees (or sub-elements) of the produced strings - and express constraints on them. This is especially useful if we want constraints to apply only in specific contexts - say, as part of some element <a>, but not as part of an element <b>.

Accessing Children#

The expression <foo>[N] accesses the N-th child of <foo>, starting with zero.

If <foo> is defined in the grammar as

<foo> ::= <bar> ":" <baz>

then <foo>[0] returns the <bar> element, <foo>[1] returns ":", and <foo>[2] returns the <baz> element.

In our persons.fan derivation tree for Ex Pltz, for instance, <start>[0] would return the <person_name> element ("Ex Pltz"), and <start>[2] would return the <age> element (18).

We can use this to access elements in specific contexts. For instance, if we want to refer to a <name> element, but only if it is the child of a <first_name> element, we can refer to it as <first_name>[0] - the first child of a <first_name> element:

<first_name> ::= <name>

Here is a constraint that makes Fandango produce first names that end with x:

$ fandango fuzz -f persons.fan -n 10 -c '<first_name>[0].endswith("x")'
Ydhjix Pdmzrjjwsdfhqxovtwgym,33599
Kypqx Ooofqvlizlyfwlr,18686300697
Ydhjix Dfscetdt,99820691502780
Kypqx Amtmcumqmuxlgblshxqqz,89024317068834
Ydhjix Pdmzrjjwsdfhqxovtwgym,61457575010938926
Kypqx Ooofqvlizlyfwlr,18686300696
Ydhjix Pdmzrjjwsdfhqxovtwgym,62208233
Ydhjix Pdmzrjjwsdfhqxovtwgym,93599
Kypqx Ooofqvlizlyfwlr,19686300697
Ydhjix Mdmzrjjwsdfhqxovtwgym,33599

Tip

As in Python, you can use negative indexes to refer to the last elements. <age>[-1], for instance, gives you the last child of an <age> subtree.

Important

While symbols act as strings in many contexts, this is where they differ. To access the first character of a symbol <foo>, you need to explicitly convert it to a string first, as in str(<foo>)[0].

Slices#

Fandango also allows you to use Python slice syntax to access multiple children at once. <name>[n:m] returns a new (unnamed) root which has <name>[n], <name>[n + 1], …, <name>[m - 1] as children. This is useful, for instance, if you want to compare several children against a string:

$ fandango fuzz -f persons-faker.fan -n 10 -c '<name>[0:2] == "Ch"'
Cheyenne Christensen,034852942210723
Cheyenne Christensen,41481094449504763
Cheyenne Christensen,034882942210723
Christine Christensen,034852942210723
Cheyenne Christensen,724234347378
Cheyenne Christensen,0706980306050882
Christine Christensen,034852942210623
Cheyenne Christensen,0706980307050882
Cheryl Christensen,41481094449504763
Cheyenne Chang,3986535426190957905

Would one also be able to use <start>[0:2] == "Ch" to obtain inputs that all start with "Ch"?

Indeed, to have the string start with "Ch", you (again) need to convert <start> into a string first, and then access its individual characters:

$ fandango fuzz -f persons-faker.fan -n 10 -c 'str(<start>)[0:2] == "Ch"'
Chad Stuart,65152456365764418917
Chad Harris,958159100
Christopher Burton,469594376893
Christopher Jones,502179
Christopher Hall,205
Chad Austin,6141
Christopher Jones,205
Christopher Hall,502179
Chad Stuart,65152456365764468917
Christopher Murray,0016424826

Fandango supports the full Python slice semantics:

  • An omitted first index defaults to zero, so <foo>[:2] returns the first two children.

  • An omitted second index defaults to the size of the string being sliced, so <foo>[2:] returns all children starting with <foo>[2].

  • Both the first and the second index can be negative again.

Selecting Children#

Referring to children by number, as in <foo>[0], can be a bit cumbersome. This is why in Fandango, you can also refer to elements by name.

The expression <foo>.<bar> allows accessing elements <bar> when they are a direct child of a symbol <foo>. This requires that <bar> occurs in the grammar rule defining <foo>:

<foo> ::= ...some expansion that has <bar>...

To refer to the <name> element as a direct child of a <first_name> element, you thus write <first_name>.<name>. This allows you to express the earlier constraint in a possibly more readable form:

$ fandango fuzz -f persons.fan -n 10 -c '<first_name>.<name>.endswith("x")'
Wtbrucirpxwbx Fuggibevilwsppdp,6663532
Ezxxtbcsamvcbucbucjx Aljcjdjdavgmfxculpfb,437125
Mriucyxazhrx Cbiypyubaqklwmfxjl,42377985
Avztubuveeympiusjx Lwcyzwbtvkyzouaz,62307444298712535
Avztubuveeympiusjx Lwcyzwbtvkyzouaz,62397444298712535
Griucyxazhrx Cbiypyubaqklwmfxjl,42377985
Ezxxtbcsamvcbucbucjx Aljcjdjdavgmfrculpfb,437125
Ezxxtbcsamvcbucbbcjx Aljcjdjdavgmfxculpfb,437125
Wtbrucirpxwbx Fuggiuevilwsppdp,6663532
Ezxxtbcsamvcbucbucjx Aljcjdjdavgmfxculbfb,437125

Note

You can only access nonterminal children this way; <person_name>." " (the space in the <person_name>) gives an error.

Selecting Descendants#

Often, you want to refer to elements in a particular context set by the enclosing element. This is why in Fandango, you can also refer to descendants.

The expression <foo>..<bar> allows accessing elements <bar> when they are a descendant of a symbol <foo>. <bar> is a descendant of <foo> if

  • <bar> is a child of <foo>; or

  • one of <foo>’s children has <bar> as a descendant.

If that sounds like a recursive definition, that is because it is. A simpler way to think about <foo>..<bar> may be “All <bar>s that occur within <foo>”.

Let us take a look at some rules in our persons.fan example:

<first_name> ::= <name>
<last_name> ::= <name>
<name> ::= <ascii_uppercase_letter><ascii_lowercase_letter>+
<ascii_uppercase_letter> ::= "A" | "B" | "C" | ... | "Z"

To refer to all <ascii_uppercase_letter> element as descendant of a <first_name> element, you thus write <first_name>..<ascii_uppercase_letter>.

Hence, to make all uppercase letters X, but only as part of a first name, you may write

$ fandango fuzz -f persons.fan -n 10 -c '<first_name>..<ascii_uppercase_letter> == "X"'
Xipfjtflknbeqezjohx Fhljmfkmdwe,074183648469504999
Xtc Blcyehrvndsztqnby,84020459
Xlgda Dggoxojsyy,8
Xaieccxqucvmtbahjcdb Jbz,1213754764280
Xkuxdnymnhe Sicehqqwua,071553260601
Xojmxbkfvvyyqadd Zxnkwycadplssljzwt,520134120266013
Xmcvyv Kjhgkuifqorhp,0374794240677
Xv En,2
Xxxepqtojtqjfvnozt Kklqcndyfeggwqfey,28041777752276
Xmootabocqkcbpclafh Qiycgtqgsmd,34958763732478587291

Chains#

You can freely combine [], ., and .. into chains that select subtrees. What would the expression <start>[0].<last_name>..<ascii_lowercase_letter> refer to, for instance?

Let’s use this in a constraint:

$ fandango fuzz -f persons.fan -n 10 -c '<start>[0].<last_name>..<ascii_lowercase_letter> == "x"'
Pvxyqfk Hxxxxxxxxxxxxxxxxx,4932539358670644028
Wshocokzrhgyqtnqk Axxxxxxxx,90494
Lbrnxpnqxacjxrcmz Dxxxxxxxxxxxxxxxx,3086676524
Wtqj Fx,24
Uazlrazhdjyfbqewdvk Axxxxxxx,3650287157957747908
Dfhkboold Zxxxxxxxxxxxxxxxxxxxx,593
Czz Lxx,406816061063516694
Likwe Txxxxxxxxxxx,6002168095571456692
Qlhpplpjnu Xxxxxxx,2309058181132319903
Uydstyldmxefh Uxxxxxxx,0096038648780226

Quantifiers#

By default, whenever you use a symbol <foo> in a constraint, this constraint applies to all occurrences of <foo> in the produced output string. For your purposes, though, one such instance already may suffice. This is why Fandango allows expressing quantification in constraints.

Star Expressions#

In Fandango, you can prefix an element with * to obtain a collection of all these elements within an individual string. Hence, *<name> is a collection of all <name> elements within the generated string. This syntax can be used in a variety of ways. For instance, we can have a constraint check whether a particular element is in the collection:

"Pablo" in *<name>

This constraint evaluates to True if any of the values in *<name> (= one of the two <name> elements) is equal to "Pablo". *-expressions are mostly useful in quantifiers, which we discuss below.

Existential Quantification#

To express that within a particular scope, at least one instance of a symbol must satisfy a constraint, use a *-expression in combination with any():

any(CONSTRAINT for ELEM in *SCOPE)

where

  • SCOPE is a nonterminal (e.g. <age>);

  • ELEM is a Python variable; and

  • CONSTRAINT is a constraint over ELEM

Hence, the expression

any(n.startswith("A") for n in *<name>)

ensures there is at least one element <name> that starts with an “A”:

Let us decompose this expression for a moment:

  • The expression for n in *<name> lets Python iterate over *<name> (all <name> objects within a person)…

  • … and evaluate n.startswith("A") for each of them, resulting in a collection of Boolean values.

  • The Python function any(list) returns True if at least one element in list is True.

So, what we get is existential quantification:

$ fandango fuzz -f persons.fan -n 10 -c 'any(n.startswith("A") for n in *<name>)'
Sstobsv Aqajthcxhvrbditxcy,6390533
Vmqgel Astrsi,528343565
Hhjlkqngxhlccclyb Ahejqt,203
Anxydlad Pxdemstcaczldzevudkxk,6140
Anhbwjgr Ifgb,4190183
Hhjlkqngxhlccclyb Ahejqt,103
Anxydlad Pxdemstcaczldzevudkxk,6240
Anhbwjgr Aqajthcxhvrbditxcy,4190183
Hhjlkqngxhlccclyb Ahecqt,203
Anxydlad Tfw,6140

Universal Quantification#

Where there are existential quantifiers, there also are universal quantifiers. Here we use the Python all() function; all(list) evaluates to True only if all elements in list are True.

We use a *-expression in combination with all():

all(CONSTRAINT for ELEM in *SCOPE)

Hence, the expression

all(c == "a" for c in *<first_name>..<ascii_lowercase_letter>)

ensures that all sub-elements <ascii_lowercase_letter> in <first_name> have the value “a”.

Again, let us decompose this expression:

  • The expression for c in *<first_name>..<ascii_lowercase_letter> lets Python iterate over all <ascii_lowercase_letter> objects within <first_name>

  • … and evaluate c == "a" for each of them, resulting in a collection of Boolean values.

  • The Python function all(list) returns True if all elements in list are True.

So, what we get is universal quantification:

$ fandango fuzz -f persons.fan -n 10 -c 'all(c == "a" for c in *<first_name>..<ascii_lowercase_letter>)'
Kaaaaaaaaaaaaaaaaaaa Ouwmledcinw,6785261646712488141
Maaa Embb,3730867120967095
Gaaaaaaaaaaa Rgmkhwebmpswxztxws,102
Kaaaaaaaaaaaaa Nzmbjnvktfxvfdrcq,06255
Laaaaaaaaaaaaa Adhiaexmk,8132009229917412174
Gaaaaaaaaaaaaaaa Awpibjlpnnuhnisiotb,798015025757963
Qaaaaaaaaaaaaaaaaa Jijfvxmfhxolueln,47449018962294
Baaaaaaaaaaaaaaaaaaa Nqiqyrck,8732461407342
Saaaaaaaaaaaaaaaaaaaa Gkuvdvbmnm,204880817022314
Yaaaaaaaaaaaaaaaa Tvifryzenpdkopaqrf,2157077198141747

By default, all symbols are universally quantified within <start>, so a dedicated universal quantifier is only needed if you want to limit the scope to some sub-element. This is what we do here with <first_name>..<ascii_lowercase_letter>, limiting the scope to <first_name>.

Given the default universal quantification, you can actually achieve the same effect as above without all() and without a *. How?

Old-Style Quantifiers#

Prior to version 1.0, Fandango supported another style of quantifiers:

  • The expression forall SYMBOL in EXPRESSION: CONSTRAINT is equivalent to all(CONSTRAINT for ELEM in *EXPRESSION: )

  • The expression exists SYMBOL in EXPRESSION: CONSTRAINT is equivalent to any(CONSTRAINT for ELEM in *EXPRESSION: )

with SYMBOL being a symbol (in <...>, so not a Python object) which can be referred to in CONSTRAINT.

To express that at least one letter in <first_name> should be 'a', write

exists <c> in <first_name>: str(<c>) == 'a'
$ fandango fuzz -f persons.fan -n 5 -c 'exists <c> in <ascii_lowercase_letter>: str(<c>) == "a"'
Chmntzvmqapsbzyevm Iq,31928909451
Caaaaaamaaaaazaavm Iq,31928909451
Xaaaaagaaaazaaaaaja Va,6407500096
Ftxfejtp Gvfjnlzizahgwta,1687260714998923
Faaaaata Gafjaaaazaaaata,1687260714998923
$ fandango fuzz -f persons.fan -n 5 -c 'forall <c> in <ascii_lowercase_letter>: str(<c>) == "a"'
Oa Daaaa,9497
Xaaa Ba,04852871011903
Iaaaaaaa Oaa,6820329548598106627
Caaaa Ea,17
Oa Eaaaa,9497

Deprecated since version 1.0: Old-style quantifiers will be deprecated in a future Fandango version. Use all() and any() instead.