From 99608dcda88de52d049bbd07d2df05ca6ed5e5f4 Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj <38898766+apskhem@users.noreply.github.com> Date: Wed, 10 Jan 2024 21:14:30 +0700 Subject: [PATCH] feat: CDDL module structure (#55) * feat: module extension * refactor: compact return type * chore: fmtfix * fix: lint * fix: function docs comment * feat: add placeholders * refactor: compact error mapping * fix: remove cddl test error type * fix: postlude test * fix: move postlude content inside test * docs: CDDLErrorType * docs: fix typo * fix: test print * feat: placeholder files * refactor: remove direct type * chore: fix linting * fix: return unit instead * fix: input as &mut String * chore: fmtfix --- .../cddl-parser/src/grammar/cddl_modules.pest | 1 + .../src/grammar/{cddl.pest => rfc_8610.pest} | 0 .../cddl-parser/src/grammar/rfc_9615.pest | 1 + hermes/crates/cbork/cddl-parser/src/lib.rs | 130 ++++++++++++++---- .../cbork/cddl-parser/tests/byte_sequences.rs | 17 ++- .../cbork/cddl-parser/tests/character_sets.rs | 49 +++---- .../cbork/cddl-parser/tests/comments.rs | 17 ++- .../cbork/cddl-parser/tests/identifiers.rs | 13 +- .../cbork/cddl-parser/tests/literal_values.rs | 29 ++-- .../cbork/cddl-parser/tests/text_sequences.rs | 13 +- 10 files changed, 185 insertions(+), 85 deletions(-) create mode 100644 hermes/crates/cbork/cddl-parser/src/grammar/cddl_modules.pest rename hermes/crates/cbork/cddl-parser/src/grammar/{cddl.pest => rfc_8610.pest} (100%) create mode 100644 hermes/crates/cbork/cddl-parser/src/grammar/rfc_9615.pest diff --git a/hermes/crates/cbork/cddl-parser/src/grammar/cddl_modules.pest b/hermes/crates/cbork/cddl-parser/src/grammar/cddl_modules.pest new file mode 100644 index 000000000..908bc39a6 --- /dev/null +++ b/hermes/crates/cbork/cddl-parser/src/grammar/cddl_modules.pest @@ -0,0 +1 @@ +// working in progress \ No newline at end of file diff --git a/hermes/crates/cbork/cddl-parser/src/grammar/cddl.pest b/hermes/crates/cbork/cddl-parser/src/grammar/rfc_8610.pest similarity index 100% rename from hermes/crates/cbork/cddl-parser/src/grammar/cddl.pest rename to hermes/crates/cbork/cddl-parser/src/grammar/rfc_8610.pest diff --git a/hermes/crates/cbork/cddl-parser/src/grammar/rfc_9615.pest b/hermes/crates/cbork/cddl-parser/src/grammar/rfc_9615.pest new file mode 100644 index 000000000..c9aaec9b2 --- /dev/null +++ b/hermes/crates/cbork/cddl-parser/src/grammar/rfc_9615.pest @@ -0,0 +1 @@ +// working in progress diff --git a/hermes/crates/cbork/cddl-parser/src/lib.rs b/hermes/crates/cbork/cddl-parser/src/lib.rs index cd0c81608..241283f85 100644 --- a/hermes/crates/cbork/cddl-parser/src/lib.rs +++ b/hermes/crates/cbork/cddl-parser/src/lib.rs @@ -7,24 +7,86 @@ use std::fmt::Debug; pub use pest::Parser; -use pest_derive::Parser; extern crate derive_more; use derive_more::{Display, From}; +use pest::{error::Error, iterators::Pairs}; -// Parser with DEBUG rules. These rules are only used in tests. -#[derive(Parser)] -#[grammar = "grammar/cddl.pest"] -#[grammar = "grammar/cddl_test.pest"] // Ideally this would only be used in tests. -pub struct CDDLParser; +pub mod rfc_8610 { + pub use pest::Parser; -/// Represents an error that may occur during CDDL parsing. -#[derive(Display, Debug, From)] -pub struct CDDLError(pest::error::Error); + #[derive(pest_derive::Parser)] + #[grammar = "grammar/rfc_8610.pest"] + pub struct RFC8610Parser; +} + +pub mod rfc_9615 { + pub use pest::Parser; + + #[derive(pest_derive::Parser)] + #[grammar = "grammar/rfc_8610.pest"] + #[grammar = "grammar/rfc_9615.pest"] + pub struct RFC8610Parser; +} + +pub mod cddl { + pub use pest::Parser; + + #[derive(pest_derive::Parser)] + #[grammar = "grammar/rfc_8610.pest"] + #[grammar = "grammar/rfc_9615.pest"] + #[grammar = "grammar/cddl_modules.pest"] + pub struct RFC8610Parser; +} + +pub mod cddl_test { + pub use pest::Parser; + + // Parser with DEBUG rules. These rules are only used in tests. + #[derive(pest_derive::Parser)] + #[grammar = "grammar/rfc_8610.pest"] + #[grammar = "grammar/rfc_9615.pest"] + #[grammar = "grammar/cddl_modules.pest"] + #[grammar = "grammar/cddl_test.pest"] // Ideally this would only be used in tests. + pub struct CDDLTestParser; +} + +/// Represents different parser extensions for handling CDDL specifications. +pub enum Extension { + /// RFC8610 ONLY limited parser. + RFC8610Parser, + /// RFC8610 and RFC9615 limited parser. + RFC9615Parser, + /// RFC8610, RFC9615, and CDDL modules. + CDDLParser, +} // CDDL Standard Postlude - read from an external file pub const POSTLUDE: &str = include_str!("grammar/postlude.cddl"); +// TODO: this is temporary. need to add more pragmatic nodes +#[derive(Debug)] +pub enum AST<'a> { + RFC8610(Pairs<'a, rfc_8610::Rule>), + RFC9615(Pairs<'a, rfc_9615::Rule>), + CDDL(Pairs<'a, cddl::Rule>), +} + +/// Represents different types of errors related to different types of extension. +#[derive(Display, Debug)] +pub enum CDDLErrorType { + /// An error related to RFC 8610 extension. + RFC8610(Error), + /// An error related to RFC 9615 extension. + RFC9615(Error), + /// An error related to CDDL modules extension. + CDDL(Error), +} + +/// Represents an error that may occur during CDDL parsing. +#[derive(Display, Debug, From)] +pub struct CDDLError(CDDLErrorType); + /// Parses and checks semantically a CDDL input string. /// /// # Arguments @@ -45,35 +107,53 @@ pub const POSTLUDE: &str = include_str!("grammar/postlude.cddl"); /// # Examples /// /// ```rs -/// use cddl_parser::parse_cddl; +/// use cddl_parser::{parse_cddl, Extension}; /// use std:fs; /// -/// let input = fs::read_to_string("path/to/your/file.cddl").unwrap(); -/// let result = parse_cddl(&input); +/// let mut input = fs::read_to_string("path/to/your/file.cddl").unwrap(); +/// let result = parse_cddl(&mut input, &Extension::CDDLParser); /// assert!(result.is_ok()); /// ``` -pub fn parse_cddl(input: &str) -> Result<(), Box> { - let result = CDDLParser::parse(Rule::cddl, input); - - match result { - Ok(c) => println!("{c:?}"), - Err(e) => { - println!("{e:?}"); - println!("{e}"); - return Err(Box::new(CDDLError::from(e))); +pub fn parse_cddl<'a>( + input: &'a mut String, extension: &Extension, +) -> Result>, Box> { + input.push_str("\n\n"); + input.push_str(POSTLUDE); + + let result = match extension { + Extension::RFC8610Parser => { + rfc_8610::RFC8610Parser::parse(rfc_8610::Rule::cddl, input) + .map(AST::RFC8610) + .map_err(CDDLErrorType::RFC8610) }, - } + Extension::RFC9615Parser => { + rfc_9615::RFC8610Parser::parse(rfc_9615::Rule::cddl, input) + .map(AST::RFC9615) + .map_err(CDDLErrorType::RFC9615) + }, + Extension::CDDLParser => { + cddl::RFC8610Parser::parse(cddl::Rule::cddl, input) + .map(AST::CDDL) + .map_err(CDDLErrorType::CDDL) + }, + }; + + result.map(Box::new).map_err(|e| { + println!("{e:?}"); + println!("{e}"); - Ok(()) + Box::new(CDDLError::from(e)) + }) } #[cfg(test)] mod tests { - use crate::{parse_cddl, POSTLUDE}; + use crate::*; #[test] fn it_works() { - let result = parse_cddl(POSTLUDE); + let mut input = String::new(); + let result = parse_cddl(&mut input, &Extension::CDDLParser); match result { Ok(c) => println!("{c:?}"), diff --git a/hermes/crates/cbork/cddl-parser/tests/byte_sequences.rs b/hermes/crates/cbork/cddl-parser/tests/byte_sequences.rs index b8f70d917..d17203754 100644 --- a/hermes/crates/cbork/cddl-parser/tests/byte_sequences.rs +++ b/hermes/crates/cbork/cddl-parser/tests/byte_sequences.rs @@ -1,6 +1,9 @@ // cspell: words hexpair rstuvw abcdefghijklmnopqrstuvwyz rstuvw -use cddl_parser::{self, CDDLParser, Parser, Rule}; +use cddl_parser::{ + self, + cddl_test::{CDDLTestParser, Parser, Rule}, +}; #[test] /// Test if the `HEX_PAIR` rule passes properly. @@ -10,12 +13,12 @@ fn check_hexpair() { let not_hex_pairs = vec!["0", " 0", "0 ", "az", "0p"]; for hp in hex_pairs { - let parse = CDDLParser::parse(Rule::HEX_PAIR, hp); + let parse = CDDLTestParser::parse(Rule::HEX_PAIR, hp); assert!(parse.is_ok()); } for hp in not_hex_pairs { - let parse = CDDLParser::parse(Rule::HEX_PAIR, hp); + let parse = CDDLTestParser::parse(Rule::HEX_PAIR, hp); assert!(parse.is_err()); } } @@ -37,12 +40,12 @@ fn check_url_base64() { ]; for test in tests { - let parse = CDDLParser::parse(Rule::URL_BASE64_TEST, test); + let parse = CDDLTestParser::parse(Rule::URL_BASE64_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::URL_BASE64_TEST, test); + let parse = CDDLTestParser::parse(Rule::URL_BASE64_TEST, test); assert!(parse.is_err()); } } @@ -77,12 +80,12 @@ fn check_bytes() { ]; for test in test { - let parse = CDDLParser::parse(Rule::bytes_TEST, test); + let parse = CDDLTestParser::parse(Rule::bytes_TEST, test); assert!(parse.is_ok()); } for test in fail { - let parse = CDDLParser::parse(Rule::bytes_TEST, test); + let parse = CDDLTestParser::parse(Rule::bytes_TEST, test); assert!(parse.is_err()); } } diff --git a/hermes/crates/cbork/cddl-parser/tests/character_sets.rs b/hermes/crates/cbork/cddl-parser/tests/character_sets.rs index 68fa96f53..b713355ef 100644 --- a/hermes/crates/cbork/cddl-parser/tests/character_sets.rs +++ b/hermes/crates/cbork/cddl-parser/tests/character_sets.rs @@ -1,6 +1,9 @@ // cspell: words PCHAR pchar BCHAR bchar SESC sesc SCHAR schar fffd fffe -use cddl_parser::{self, CDDLParser, Parser, Rule}; +use cddl_parser::{ + self, + cddl_test::{CDDLTestParser, Parser, Rule}, +}; #[test] /// Test if the `WHITESPACE` rule passes properly. @@ -10,11 +13,11 @@ fn check_whitespace() { let not_whitespace = "not"; for ws in whitespace { - let parse = CDDLParser::parse(Rule::WHITESPACE, ws); + let parse = CDDLTestParser::parse(Rule::WHITESPACE, ws); assert!(parse.is_ok()); } - let parse = CDDLParser::parse(Rule::WHITESPACE, not_whitespace); + let parse = CDDLTestParser::parse(Rule::WHITESPACE, not_whitespace); assert!(parse.is_err()); } @@ -23,7 +26,7 @@ fn check_whitespace() { fn check_pchar() { for x in ('\u{0}'..='\u{ff}').map(char::from) { let test = format!("{x}"); - let parse = CDDLParser::parse(Rule::PCHAR, &test); + let parse = CDDLTestParser::parse(Rule::PCHAR, &test); if x < ' ' || x == '\u{7f}' { assert!(parse.is_err()); } else { @@ -31,7 +34,7 @@ fn check_pchar() { } } - let parse = CDDLParser::parse(Rule::ASCII_VISIBLE, "\r"); + let parse = CDDLTestParser::parse(Rule::ASCII_VISIBLE, "\r"); assert!(parse.is_err()); } @@ -40,7 +43,7 @@ fn check_pchar() { fn check_bchar() { for x in ('\u{0}'..='\u{ff}').map(char::from) { let test = format!("{x}"); - let parse = CDDLParser::parse(Rule::BCHAR, &test); + let parse = CDDLTestParser::parse(Rule::BCHAR, &test); if x != '\n' && x != '\r' && x < ' ' || x == '\u{27}' || x == '\u{5c}' || x == '\u{7f}' { assert!(parse.is_err()); } else { @@ -48,7 +51,7 @@ fn check_bchar() { } } - let parse = CDDLParser::parse(Rule::ASCII_VISIBLE, "\r"); + let parse = CDDLTestParser::parse(Rule::ASCII_VISIBLE, "\r"); assert!(parse.is_err()); } @@ -57,7 +60,7 @@ fn check_bchar() { fn check_sesc() { for x in (' '..='\u{ff}').map(char::from) { let test = format!("\\{x}"); - let parse = CDDLParser::parse(Rule::SESC, &test); + let parse = CDDLTestParser::parse(Rule::SESC, &test); if x == '\u{7f}' { assert!(parse.is_err()); } else { @@ -65,7 +68,7 @@ fn check_sesc() { } } - let parse = CDDLParser::parse(Rule::ASCII_VISIBLE, "\r"); + let parse = CDDLTestParser::parse(Rule::ASCII_VISIBLE, "\r"); assert!(parse.is_err()); } @@ -74,14 +77,14 @@ fn check_sesc() { fn check_ascii_visible() { for x in (b' '..=b'~').map(char::from) { let test = x.to_string(); - let parse = CDDLParser::parse(Rule::ASCII_VISIBLE, &test); + let parse = CDDLTestParser::parse(Rule::ASCII_VISIBLE, &test); assert!(parse.is_ok()); } - let parse = CDDLParser::parse(Rule::ASCII_VISIBLE, "\r"); + let parse = CDDLTestParser::parse(Rule::ASCII_VISIBLE, "\r"); assert!(parse.is_err()); - let parse = CDDLParser::parse(Rule::ASCII_VISIBLE, "\u{80}"); + let parse = CDDLTestParser::parse(Rule::ASCII_VISIBLE, "\u{80}"); assert!(parse.is_err()); } @@ -91,7 +94,7 @@ fn check_schar_ascii_visible() { let invalids = "\"\\"; for x in (b' '..=b'~').map(char::from) { let test = x.to_string(); - let parse = CDDLParser::parse(Rule::SCHAR_ASCII_VISIBLE, &test); + let parse = CDDLTestParser::parse(Rule::SCHAR_ASCII_VISIBLE, &test); if invalids.contains(x) { assert!(parse.is_err()); } else { @@ -99,10 +102,10 @@ fn check_schar_ascii_visible() { } } - let parse = CDDLParser::parse(Rule::SCHAR_ASCII_VISIBLE, "\r"); + let parse = CDDLTestParser::parse(Rule::SCHAR_ASCII_VISIBLE, "\r"); assert!(parse.is_err()); - let parse = CDDLParser::parse(Rule::SCHAR_ASCII_VISIBLE, "\u{80}"); + let parse = CDDLTestParser::parse(Rule::SCHAR_ASCII_VISIBLE, "\u{80}"); assert!(parse.is_err()); } @@ -112,7 +115,7 @@ fn check_bchar_ascii_visible() { let invalids = "'\\"; for x in (b' '..=b'~').map(char::from) { let test = x.to_string(); - let parse = CDDLParser::parse(Rule::BCHAR_ASCII_VISIBLE, &test); + let parse = CDDLTestParser::parse(Rule::BCHAR_ASCII_VISIBLE, &test); if invalids.contains(x) { assert!(parse.is_err()); } else { @@ -120,28 +123,28 @@ fn check_bchar_ascii_visible() { } } - let parse = CDDLParser::parse(Rule::BCHAR_ASCII_VISIBLE, "\r"); + let parse = CDDLTestParser::parse(Rule::BCHAR_ASCII_VISIBLE, "\r"); assert!(parse.is_err()); - let parse = CDDLParser::parse(Rule::BCHAR_ASCII_VISIBLE, "\u{80}"); + let parse = CDDLTestParser::parse(Rule::BCHAR_ASCII_VISIBLE, "\u{80}"); assert!(parse.is_err()); } #[test] /// Test if the `UNICODE_CHAR` rule passes properly. fn check_unicode() { - let parse = CDDLParser::parse(Rule::UNICODE_CHAR, "\r"); + let parse = CDDLTestParser::parse(Rule::UNICODE_CHAR, "\r"); assert!(parse.is_err()); - let parse = CDDLParser::parse(Rule::UNICODE_CHAR, "\u{80}"); + let parse = CDDLTestParser::parse(Rule::UNICODE_CHAR, "\u{80}"); assert!(parse.is_ok()); - let parse = CDDLParser::parse(Rule::UNICODE_CHAR, "\u{10fffd}"); + let parse = CDDLTestParser::parse(Rule::UNICODE_CHAR, "\u{10fffd}"); assert!(parse.is_ok()); - let parse = CDDLParser::parse(Rule::UNICODE_CHAR, "\u{7ffff}"); + let parse = CDDLTestParser::parse(Rule::UNICODE_CHAR, "\u{7ffff}"); assert!(parse.is_ok()); - let parse = CDDLParser::parse(Rule::UNICODE_CHAR, "\u{10fffe}"); + let parse = CDDLTestParser::parse(Rule::UNICODE_CHAR, "\u{10fffe}"); assert!(parse.is_err()); } diff --git a/hermes/crates/cbork/cddl-parser/tests/comments.rs b/hermes/crates/cbork/cddl-parser/tests/comments.rs index 104c1fd3b..eb3328df2 100644 --- a/hermes/crates/cbork/cddl-parser/tests/comments.rs +++ b/hermes/crates/cbork/cddl-parser/tests/comments.rs @@ -1,4 +1,7 @@ -use cddl_parser::{self, CDDLParser, Parser, Rule}; +use cddl_parser::{ + self, + cddl_test::{CDDLTestParser, Parser, Rule}, +}; #[test] /// Test if the `COMMENT` rule passes properly. @@ -8,16 +11,16 @@ fn check_comment() { let comment3 = ";more\r\n"; let not_comment = "not a comment\n"; - let parse = CDDLParser::parse(Rule::COMMENT, comment1); + let parse = CDDLTestParser::parse(Rule::COMMENT, comment1); assert!(parse.is_ok()); - let parse = CDDLParser::parse(Rule::COMMENT, comment2); + let parse = CDDLTestParser::parse(Rule::COMMENT, comment2); assert!(parse.is_ok()); - let parse = CDDLParser::parse(Rule::COMMENT, comment3); + let parse = CDDLTestParser::parse(Rule::COMMENT, comment3); assert!(parse.is_ok()); - let parse = CDDLParser::parse(Rule::COMMENT, not_comment); + let parse = CDDLTestParser::parse(Rule::COMMENT, not_comment); assert!(parse.is_err()); } @@ -41,12 +44,12 @@ fn check_whitespace_comments() { let fails = vec!["not a comment"]; for test in tests { - let parse = CDDLParser::parse(Rule::COMMENT_TEST, test); + let parse = CDDLTestParser::parse(Rule::COMMENT_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::COMMENT_TEST, test); + let parse = CDDLTestParser::parse(Rule::COMMENT_TEST, test); assert!(parse.is_err()); } } diff --git a/hermes/crates/cbork/cddl-parser/tests/identifiers.rs b/hermes/crates/cbork/cddl-parser/tests/identifiers.rs index 71c31ef8a..dc69d9f13 100644 --- a/hermes/crates/cbork/cddl-parser/tests/identifiers.rs +++ b/hermes/crates/cbork/cddl-parser/tests/identifiers.rs @@ -1,14 +1,17 @@ // cspell: words aname groupsocket typesocket groupsocket -use cddl_parser::{self, CDDLParser, Parser, Rule}; +use cddl_parser::{ + self, + cddl_test::{CDDLTestParser, Parser, Rule}, +}; #[test] /// Check if the name components pass properly. fn check_name_characters() { for x in ('\u{0}'..='\u{ff}').map(char::from) { let test = format!("{x}"); - let parse_start = CDDLParser::parse(Rule::NAME_START, &test); - let parse_end = CDDLParser::parse(Rule::NAME_END, &test); + let parse_start = CDDLTestParser::parse(Rule::NAME_START, &test); + let parse_end = CDDLTestParser::parse(Rule::NAME_END, &test); if x.is_ascii_alphabetic() || x == '@' || x == '_' || x == '$' { assert!(parse_start.is_ok()); @@ -64,12 +67,12 @@ fn check_id() { ]; for test in test { - let parse = CDDLParser::parse(Rule::id_TEST, test); + let parse = CDDLTestParser::parse(Rule::id_TEST, test); assert!(parse.is_ok()); } for test in fail { - let parse = CDDLParser::parse(Rule::id_TEST, test); + let parse = CDDLTestParser::parse(Rule::id_TEST, test); assert!(parse.is_err()); } } diff --git a/hermes/crates/cbork/cddl-parser/tests/literal_values.rs b/hermes/crates/cbork/cddl-parser/tests/literal_values.rs index 62202266e..c2492e76d 100644 --- a/hermes/crates/cbork/cddl-parser/tests/literal_values.rs +++ b/hermes/crates/cbork/cddl-parser/tests/literal_values.rs @@ -1,6 +1,9 @@ // cspell: words xdog intfloat hexfloat xabcp defp rstuvw -use cddl_parser::{self, CDDLParser, Parser, Rule}; +use cddl_parser::{ + self, + cddl_test::{CDDLTestParser, Parser, Rule}, +}; /// Note, the `text`, `bytes` and `id` tests are elsewhere. @@ -21,12 +24,12 @@ fn check_uint() { let fails = vec![" a ", "zz", "0123zzz", "0xdog", "0b777"]; for test in tests { - let parse = CDDLParser::parse(Rule::uint_TEST, test); + let parse = CDDLTestParser::parse(Rule::uint_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::uint_TEST, test); + let parse = CDDLTestParser::parse(Rule::uint_TEST, test); assert!(parse.is_err()); } } @@ -56,12 +59,12 @@ fn check_int() { let fails = vec![" a ", "zz", "0123zzz", "0xdog", "0b777"]; for test in tests { - let parse = CDDLParser::parse(Rule::int_TEST, test); + let parse = CDDLTestParser::parse(Rule::int_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::int_TEST, test); + let parse = CDDLTestParser::parse(Rule::int_TEST, test); assert!(parse.is_err()); } } @@ -92,12 +95,12 @@ fn check_intfloat() { let fails = vec![" a ", "zz", "0123zzz", "0xdog", "0b777"]; for test in tests { - let parse = CDDLParser::parse(Rule::intfloat_TEST, test); + let parse = CDDLTestParser::parse(Rule::intfloat_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::intfloat_TEST, test); + let parse = CDDLTestParser::parse(Rule::intfloat_TEST, test); assert!(parse.is_err()); } } @@ -119,12 +122,12 @@ fn check_hexfloat() { let fails = vec![" a ", "zz", "0123zzz", "0xdog", "0b777"]; for test in tests { - let parse = CDDLParser::parse(Rule::hexfloat_TEST, test); + let parse = CDDLTestParser::parse(Rule::hexfloat_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::hexfloat_TEST, test); + let parse = CDDLTestParser::parse(Rule::hexfloat_TEST, test); assert!(parse.is_err()); } } @@ -163,12 +166,12 @@ fn check_number() { let fails = vec![" a ", "zz", "0123zzz", "0xdog", "0b777"]; for test in tests { - let parse = CDDLParser::parse(Rule::number_TEST, test); + let parse = CDDLTestParser::parse(Rule::number_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::number_TEST, test); + let parse = CDDLTestParser::parse(Rule::number_TEST, test); assert!(parse.is_err()); } } @@ -223,12 +226,12 @@ fn check_value() { let fails = vec![" a ", "zz", "0123zzz", "0xdog", "0b777"]; for test in tests { - let parse = CDDLParser::parse(Rule::value_TEST, test); + let parse = CDDLTestParser::parse(Rule::value_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::value_TEST, test); + let parse = CDDLTestParser::parse(Rule::value_TEST, test); assert!(parse.is_err()); } } diff --git a/hermes/crates/cbork/cddl-parser/tests/text_sequences.rs b/hermes/crates/cbork/cddl-parser/tests/text_sequences.rs index 1cc2e61bf..5fe8ca665 100644 --- a/hermes/crates/cbork/cddl-parser/tests/text_sequences.rs +++ b/hermes/crates/cbork/cddl-parser/tests/text_sequences.rs @@ -1,4 +1,7 @@ -use cddl_parser::{self, CDDLParser, Parser, Rule}; +use cddl_parser::{ + self, + cddl_test::{CDDLTestParser, Parser, Rule}, +}; #[test] /// Test if the `S` rule passes properly. @@ -9,12 +12,12 @@ fn check_s() { let fails = vec![" a ", "zz", " \t d \t", " \t \r \n \t \r\n x"]; for test in tests { - let parse = CDDLParser::parse(Rule::S_TEST, test); + let parse = CDDLTestParser::parse(Rule::S_TEST, test); assert!(parse.is_ok()); } for test in fails { - let parse = CDDLParser::parse(Rule::S_TEST, test); + let parse = CDDLTestParser::parse(Rule::S_TEST, test); assert!(parse.is_err()); } } @@ -27,12 +30,12 @@ fn check_text() { let fail = vec!["", "''", "\"abc\n\""]; for test in test { - let parse = CDDLParser::parse(Rule::text_TEST, test); + let parse = CDDLTestParser::parse(Rule::text_TEST, test); assert!(parse.is_ok()); } for test in fail { - let parse = CDDLParser::parse(Rule::text_TEST, test); + let parse = CDDLTestParser::parse(Rule::text_TEST, test); assert!(parse.is_err()); } }