nelly
A grammar-based generator.
Matthew Shaw <mshaw.cx@gmail.com>
<%pre
import sys
%>
::NT(start)
: 'A' # comment
| 'B' <% print($$) %>
;
<%post
print($$)
%>
Constants
Constants in productions can consist of double-quoted strings, single-quoted strings, decimal, hexadecimal.
A: "A" | 'A' | \d65 | \x41;
Concatenation
Productions are concatenated when they are seperated by white-space.
CONCAT: "CONC" \x41 "TEN" \d65 "TION";
Selection
When multiple productions are present one is chosen at random.
NUMBER: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
Grouping
GRP: ('A'|'B') ('C'|'D');
Possible values are ‘AC’, ‘AD’, ‘BC’, or ‘BD’.
Ranges
NUM1: ('0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'){3};
NUM2: ('0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'){1,5};
NUM1 will generate a 3-digit number while NUM2 will generate a number of random length between 1 and 5 digits.
Slicing
A sub-string of a production can be referenced using indices.
SLICE1: "0123456789" [:]; // 0123456789
SLICE2: "0123456789" [4]; // 4
SLICE3: "0123456789" [:4]; // 0123
SLICE4: "0123456789" [4:]; // 456789
SLICE5: "0123456789" [2:8]; // 234567
SLICE6: "0123456789" [-4]; // 6
SLICE7: "0123456789" [-4:]; // 6789
SLICE8: "0123456789" [:-4]; // 012345
SLICE9: "0123456789" [2:-2]; // 234567
The output of each production is documented in the comment proceeding it.
Inline Python
<%pre
import base64
%>
NT: %base64.b64encode('string');
Non-Terminals
NT1: "The value of NT2 is " NT2;
NT2: "substitution";
Semantic Actions
$$
PSA1: PSA2 <% var = $$ %>;
PSA2: "one" | "two";
In this example the Python variable var will contain either ‘one’ or ‘two’ for future use.
Variable Non-Terminals
$*
NT1: $NT2;
$NT2:
"I WILL BE SUBSTITUTED INTO NT1 IN LOWERCASE"
<%
$* = $$.lower()
%>
;
Back Reference
BR: "A" | "B";
NT: BR \BR;
$BR: ("a"|"b") <% $* = $$.upper() %>;
NT: $BR \$BR;
In both cases NT will generate the string ‘AA’ or ‘BB’ but not ‘AB’ or ‘BA’.
Metadata
Release files for nelly 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nelly-0.7.2.tar.gz | 22.7 kB | Without provenance | Details for nelly-0.7.2.tar.gz |
Release files / nelly-0.7.2.tar.gz
| Download URL | nelly-0.7.2.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c300a639a2ed35b3ada35226f75437b426302378aff29a99f86b899529497ac1
|
|
BLAKE2b-256 checksum How to use checksums |
bcc4c484a246c4c15be0220680286291a5fa99a34a16f340a91e5f0278f84749
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
|
Security for nelly 0.7.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.