1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! # Parser
//!
//! Herein is the parser for the `xDy` language. [`Parser::parse`] is the main
//! entry point, which discards leading whitespace before parsing a
//! [function](Function). The recognized grammar is as follows, in Extended
//! Backus-Naur Form (EBNF), where non-terminals are in lowercase and terminals
//! are in uppercase:
//!
//! ```text
//! function ::= parameters? expression
//! parameters ::= parameter (',' parameter)* ':'
//! parameter ::= IDENTIFIER
//! expression ::= add_sub
//! add_sub ::= mul_div_mod (('+' | '-') mul_div_mod)*
//! mul_div_mod ::= unary (('*' | '/' | '%') unary)*
//! unary ::= '-' unary | exponent
//! exponent ::= primary ('^' unary)?
//! primary ::= range | dice | group | variable | binding | CONSTANT
//! group ::= '(' expression ')'
//! variable ::= '{' IDENTIFIER '}'
//! binding ::= IDENTIFIER '@' '(' expression ')'
//! range ::= '[' expression ':' expression ']'
//! dice ::= base_dice drop_clause*
//! base_dice ::= dice_count D_OPERATOR (standard_faces | custom_faces)
//! dice_count ::= CONSTANT | variable | binding | group
//! standard_faces ::= CONSTANT | variable | binding | group
//! custom_faces ::= '[' CONSTANT (',' CONSTANT)* ']'
//! drop_clause ::= 'drop' ('lowest' | 'highest') drop_expression?
//! drop_expression::= CONSTANT | variable | binding | group
//! CONSTANT ::= '-'? DIGIT+
//! D_OPERATOR ::= 'd' | 'D'
//! IDENTIFIER ::= (ALPHA | '_') (ALPHANUMERIC | '_' | '-')*
//! ```
//!
//! The following railroad diagram is generated from the EBNF grammar above:
//! Parsing is based on the [`nom`] library, which provides a combinator-based
//! approach to parsing.
pub use *;
pub use *;
use ;
use crateFunction;
////////////////////////////////////////////////////////////////////////////////
// Parser. //
////////////////////////////////////////////////////////////////////////////////
/// The `xDy` parser. Use [`Parser::parse`] as the high-level entry point; the
/// individual parser combinators exposed by this module are available for
/// low-level uses but are not recommended for most clients.
;