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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! Shared traits for the options API.

#[cfg(feature = "write")]
use crate::constants::FormattedSize;

// TRAITS
// ------

/// Shared trait for all writer options.
#[cfg(feature = "write")]
pub trait WriteOptions: Default {
    /// Determine if the options are valid.
    fn is_valid(&self) -> bool;

    /// Get an upper bound on the buffer size.
    fn buffer_size<T: FormattedSize, const FORMAT: u128>(&self) -> usize;
}

/// Shared trait for all parser options.
#[cfg(feature = "parse")]
pub trait ParseOptions: Default {
    /// Determine if the options are valid.
    fn is_valid(&self) -> bool;
}

// PRE-DEFINED CONSTANTS
// ---------------------

// The following constants have the following signifiers:
//  ${X}_LITERAL - Applies to all literal values for that language.
//  ${X}_STRING - Applies to all string values for that language.
//  ${X} - Applies to all values for that language.
//  ${X}_(NAN|INF|INFINITY) - Applies to only a single special value.
//  IF it's not defined, all values are the default.

macro_rules! literal {
    ($name:ident, $value:ident) => {
        pub const $name: Option<&[u8]> = $value;
    };
    ($name:ident, $value:literal) => {
        pub const $name: Option<&[u8]> = Some($value);
    };
}

literal!(RUST_LITERAL, None);
// RUST_STRING
literal!(PYTHON_LITERAL, None);
// PYTHON_STRING
literal!(CXX_LITERAL_NAN, b"NAN");
literal!(CXX_LITERAL_INF, b"INFINITY");
literal!(CXX_LITERAL_INFINITY, b"INFINITY");
// CXX_STRING
literal!(C_LITERAL_NAN, b"NAN");
literal!(C_LITERAL_INF, b"INFINITY");
literal!(C_LITERAL_INFINITY, b"INFINITY");
// C_STRING
literal!(RUBY, None);
literal!(SWIFT_LITERAL, None);
// SWIFT_STRING
literal!(GO_LITERAL, None);
// GO_STRING
literal!(HASKELL_LITERAL, None);
literal!(HASKELL_STRING_INF, b"Infinity");
literal!(HASKELL_STRING_INFINITY, b"Infinity");
literal!(JAVASCRIPT_INF, b"Infinity");
literal!(JAVASCRIPT_INFINITY, b"Infinity");
literal!(PERL_LITERAL, None);
// PERL_STRING
literal!(PHP_LITERAL_NAN, b"NAN");
literal!(PHP_LITERAL_INF, b"INF");
literal!(PHP_LITERAL_INFINITY, b"INF");
// PHP_STRING
literal!(JAVA_LITERAL, None);
literal!(JAVA_STRING_INF, b"Infinity");
literal!(JAVA_STRING_INFINITY, b"Infinity");
literal!(R_LITERAL_INF, b"Inf");
literal!(R_LITERAL_INFINITY, b"Inf");
// R_STRING
literal!(KOTLIN_LITERAL, None);
literal!(KOTLIN_STRING_INF, b"Infinity");
literal!(KOTLIN_STRING_INFINITY, b"Infinity");
literal!(JULIA_LITERAL_INF, b"Inf");
literal!(JULIA_LITERAL_INFINITY, b"Inf");
// JULIA_STRING
literal!(CSHARP_LITERAL, None);
literal!(CSHARP_STRING_INF, b"Infinity");
literal!(CSHARP_STRING_INFINITY, b"Infinity");
literal!(KAWA, None);
literal!(GAMBITC, None);
literal!(GUILE, None);
literal!(CLOJURE_LITERAL, None);
literal!(CLOJURE_STRING_INF, b"Infinity");
literal!(CLOJURE_STRING_INFINITY, b"Infinity");
literal!(ERLANG_LITERAL_NAN, b"nan");
literal!(ERLANG_STRING, None);
literal!(ELM_LITERAL, None);
literal!(ELM_STRING_NAN, None);
literal!(ELM_STRING_INF, b"Infinity");
literal!(ELM_STRING_INFINITY, b"Infinity");
literal!(SCALA_LITERAL, None);
literal!(SCALA_STRING_INF, b"Infinity");
literal!(SCALA_STRING_INFINITY, b"Infinity");
literal!(ELIXIR, None);
literal!(FORTRAN_LITERAL, None);
// FORTRAN_STRING
literal!(D_LITERAL, None);
// D_STRING
literal!(COFFEESCRIPT_INF, b"Infinity");
literal!(COFFEESCRIPT_INFINITY, b"Infinity");
literal!(COBOL, None);
literal!(FSHARP_LITERAL_NAN, b"nan");
literal!(FSHARP_LITERAL_INF, b"infinity");
literal!(FSHARP_LITERAL_INFINITY, b"infinity");
// FSHARP_STRING
literal!(VB_LITERAL, None);
literal!(VB_STRING_INF, None);
literal!(VB_STRING_INFINITY, None);
literal!(OCAML_LITERAL_NAN, b"nan");
literal!(OCAML_LITERAL_INF, b"infinity");
literal!(OCAML_LITERAL_INFINITY, b"infinity");
// OCAML_STRING
literal!(OBJECTIVEC, None);
literal!(REASONML_LITERAL_NAN, b"nan");
literal!(REASONML_LITERAL_INF, b"infinity");
literal!(REASONML_LITERAL_INFINITY, b"infinity");
// REASONML_STRING
literal!(MATLAB_LITERAL_INF, b"inf");
literal!(MATLAB_LITERAL_INFINITY, b"Inf");
// MATLAB_STRING
literal!(ZIG_LITERAL, None);
// ZIG_STRING
literal!(SAGE_LITERAL_INF, b"infinity");
literal!(SAGE_LITERAL_INFINITY, b"Infinity");
// SAGE_STRING
literal!(JSON, None);
literal!(TOML, None);
literal!(YAML, None);
literal!(XML_INF, None);
literal!(XML_INFINITY, None);
literal!(SQLITE, None);
literal!(POSTGRESQL, None);
literal!(MYSQL, None);
literal!(MONGODB_INF, b"Infinity");
literal!(MONGODB_INFINITY, b"Infinity");