Loading tools/pdl/src/ast.rs +10 −5 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ pub type FileId = usize; /// Stores the source file contents for reference. pub type SourceDatabase = files::SimpleFiles<String, String>; #[derive(Debug, Copy, Clone, Serialize, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Default, Copy, Clone, Serialize, PartialEq, Eq, PartialOrd, Ord)] pub struct SourceLocation { /// Byte offset into the file (counted from zero). pub offset: usize, Loading @@ -22,7 +22,7 @@ pub struct SourceLocation { pub column: usize, } #[derive(Debug, Clone, Serialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)] pub struct SourceRange { pub file: FileId, pub start: SourceLocation, Loading @@ -36,7 +36,7 @@ pub struct Comment { pub text: String, } #[derive(Debug, Serialize)] #[derive(Debug, PartialEq, Eq, Serialize)] #[serde(rename_all = "snake_case")] pub enum EndiannessValue { LittleEndian, Loading Loading @@ -164,7 +164,7 @@ pub struct Grammar { pub version: String, pub file: FileId, pub comments: Vec<Comment>, pub endianness: Option<Endianness>, pub endianness: Endianness, pub declarations: Vec<Decl>, } Loading Loading @@ -227,7 +227,12 @@ impl Grammar { Grammar { version: "1,0".to_owned(), comments: vec![], endianness: None, // The endianness is mandatory, so this default value will // be updated while parsing. endianness: Endianness { loc: SourceRange::default(), value: EndiannessValue::LittleEndian, }, declarations: vec![], file, } Loading tools/pdl/src/parser.rs +19 −4 Original line number Diff line number Diff line Loading @@ -130,7 +130,7 @@ declaration = _{ grammar = { SOI ~ endianness_declaration? ~ endianness_declaration ~ declaration* ~ EOI } Loading Loading @@ -439,9 +439,7 @@ fn parse_grammar(root: Node<'_>, context: &Context) -> Result<ast::Grammar, Stri let loc = node.as_loc(context); let rule = node.as_rule(); match rule { Rule::endianness_declaration => { grammar.endianness = Some(parse_endianness(node, context)?) } Rule::endianness_declaration => grammar.endianness = parse_endianness(node, context)?, Rule::checksum_declaration => { let mut children = node.children(); let id = parse_identifier(&mut children)?; Loading Loading @@ -539,3 +537,20 @@ pub fn parse_file( })?; parse_inline(sources, name, source) } #[cfg(test)] mod test { use super::*; #[test] fn endianness_is_set() { // The grammar starts out with a placeholder little-endian // value. This tests that we update it while parsing. let mut db = ast::SourceDatabase::new(); let grammar = parse_inline(&mut db, String::from("stdin"), String::from(" big_endian_packets ")) .unwrap(); assert_eq!(grammar.endianness.value, ast::EndiannessValue::BigEndian); assert_ne!(grammar.endianness.loc, ast::SourceRange::default()); } } tools/pdl/src/pdl.pest +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ declaration = _{ grammar = { SOI ~ endianness_declaration? ~ endianness_declaration ~ declaration* ~ EOI } Loading
tools/pdl/src/ast.rs +10 −5 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ pub type FileId = usize; /// Stores the source file contents for reference. pub type SourceDatabase = files::SimpleFiles<String, String>; #[derive(Debug, Copy, Clone, Serialize, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Default, Copy, Clone, Serialize, PartialEq, Eq, PartialOrd, Ord)] pub struct SourceLocation { /// Byte offset into the file (counted from zero). pub offset: usize, Loading @@ -22,7 +22,7 @@ pub struct SourceLocation { pub column: usize, } #[derive(Debug, Clone, Serialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)] pub struct SourceRange { pub file: FileId, pub start: SourceLocation, Loading @@ -36,7 +36,7 @@ pub struct Comment { pub text: String, } #[derive(Debug, Serialize)] #[derive(Debug, PartialEq, Eq, Serialize)] #[serde(rename_all = "snake_case")] pub enum EndiannessValue { LittleEndian, Loading Loading @@ -164,7 +164,7 @@ pub struct Grammar { pub version: String, pub file: FileId, pub comments: Vec<Comment>, pub endianness: Option<Endianness>, pub endianness: Endianness, pub declarations: Vec<Decl>, } Loading Loading @@ -227,7 +227,12 @@ impl Grammar { Grammar { version: "1,0".to_owned(), comments: vec![], endianness: None, // The endianness is mandatory, so this default value will // be updated while parsing. endianness: Endianness { loc: SourceRange::default(), value: EndiannessValue::LittleEndian, }, declarations: vec![], file, } Loading
tools/pdl/src/parser.rs +19 −4 Original line number Diff line number Diff line Loading @@ -130,7 +130,7 @@ declaration = _{ grammar = { SOI ~ endianness_declaration? ~ endianness_declaration ~ declaration* ~ EOI } Loading Loading @@ -439,9 +439,7 @@ fn parse_grammar(root: Node<'_>, context: &Context) -> Result<ast::Grammar, Stri let loc = node.as_loc(context); let rule = node.as_rule(); match rule { Rule::endianness_declaration => { grammar.endianness = Some(parse_endianness(node, context)?) } Rule::endianness_declaration => grammar.endianness = parse_endianness(node, context)?, Rule::checksum_declaration => { let mut children = node.children(); let id = parse_identifier(&mut children)?; Loading Loading @@ -539,3 +537,20 @@ pub fn parse_file( })?; parse_inline(sources, name, source) } #[cfg(test)] mod test { use super::*; #[test] fn endianness_is_set() { // The grammar starts out with a placeholder little-endian // value. This tests that we update it while parsing. let mut db = ast::SourceDatabase::new(); let grammar = parse_inline(&mut db, String::from("stdin"), String::from(" big_endian_packets ")) .unwrap(); assert_eq!(grammar.endianness.value, ast::EndiannessValue::BigEndian); assert_ne!(grammar.endianness.loc, ast::SourceRange::default()); } }
tools/pdl/src/pdl.pest +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ declaration = _{ grammar = { SOI ~ endianness_declaration? ~ endianness_declaration ~ declaration* ~ EOI }