summaryrefslogtreecommitdiff
path: root/grammar/src
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-06-02 15:01:12 +0800
committerJSDurand <mmemmew@gmail.com>2023-06-02 15:01:12 +0800
commita6e9f5172fa72094d5c7c2fadf29ffd8cc272687 (patch)
treeefc5326770af274960b26382dfbae2cc5bee96e5 /grammar/src
parent8486474f377faf2d800d79166a7abe6b975e3e50 (diff)
abnf: a skeleton for an ABNF parser
Diffstat (limited to 'grammar/src')
-rw-r--r--grammar/src/abnf.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/grammar/src/abnf.rs b/grammar/src/abnf.rs
new file mode 100644
index 0000000..00bc0b2
--- /dev/null
+++ b/grammar/src/abnf.rs
@@ -0,0 +1,37 @@
+//! This file implements the function to read a grammar from a string,
+//! in the [augmented Backus Naur
+//! form][https://en.wikipedia.org/wiki/Augmented_Backus–Naur_form].
+//! See [RFC5234][https://www.rfc-editor.org/rfc/rfc5234] for its
+//! specifications.
+//!
+//! In fact, the rules of ABNF are considered to be too strict. For
+//! example, only ASCII characters are allowed in the format, even
+//! within comments. I think any character should be allowed within
+//! comments, so the implementation here does that.
+
+use super::*;
+
+/// The type of errors encountered during parsing a grammar in the
+/// ABNF format. See the function [`abnf_to_grammar`] for the parsing
+/// function.
+#[derive(Debug, Clone, Copy)]
+pub enum Error {
+ /// Something invalid has occurred.
+ Invalid,
+}
+
+impl core::fmt::Display for Error {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ match self {
+ Error::Invalid => write!(f, "invalid"),
+ }
+ }
+}
+
+#[allow(unused)]
+/// This function converts a string to a grammar.
+pub fn abnf_to_grammar(str: impl AsRef<str>) -> Result<Grammar, Error> {
+ let str = str.as_ref();
+
+ todo!()
+}