From 5bc15d80ffdf11b87cc5344f6c8ad24673551e2c Mon Sep 17 00:00:00 2001 From: PoiScript Date: Tue, 11 Jun 2024 15:16:11 +0800 Subject: [PATCH] fix: newline in not allowed in property name --- src/ast/document.rs | 20 +++++++++++++++++++- src/ast/generate.js | 1 - src/ast/generated.rs | 3 --- src/syntax/drawer.rs | 7 ++++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/ast/document.rs b/src/ast/document.rs index ab190ee..f248769 100644 --- a/src/ast/document.rs +++ b/src/ast/document.rs @@ -2,7 +2,7 @@ use rowan::ast::AstNode; use crate::Org; -use super::{Document, Keyword}; +use super::{Document, Keyword, PropertyDrawer}; impl Document { /// Returns an iterator of keywords in zeroth section @@ -55,6 +55,24 @@ impl Document { Some(s) }) } + + /// Returns top-level properties drawer + /// + /// ```rust + /// use orgize::{Org, ast::Document}; + /// + /// let org = Org::parse(r#":PROPERTIES: + /// :ID: 20220718T085035.042592 + /// :END: + /// #+TITLE: Complete Computing"#); + /// + /// let properties = org.document().properties().unwrap(); + /// assert_eq!(properties.to_hash_map().len(), 1); + /// assert_eq!(properties.get("ID").unwrap(), "20220718T085035.042592"); + /// ``` + pub fn properties(&self) -> Option { + rowan::ast::support::child(&self.syntax) + } } impl Org { diff --git a/src/ast/generate.js b/src/ast/generate.js index 26cfd82..81bbc4f 100644 --- a/src/ast/generate.js +++ b/src/ast/generate.js @@ -6,7 +6,6 @@ const nodes = [ first_child: [ ["section", "Section"], ["first_headline", "Headline"], - ["properties", "PropertyDrawer"], ], last_child: [["last_headline", "Headline"]], children: [["headlines", "Headline"]], diff --git a/src/ast/generated.rs b/src/ast/generated.rs index a34d493..1bfd489 100644 --- a/src/ast/generated.rs +++ b/src/ast/generated.rs @@ -57,9 +57,6 @@ impl Document { pub fn first_headline(&self) -> Option { support::child(&self.syntax) } - pub fn properties(&self) -> Option { - support::child(&self.syntax) - } pub fn last_headline(&self) -> Option { super::last_child(&self.syntax) } diff --git a/src/syntax/drawer.rs b/src/syntax/drawer.rs index aee47e0..a44cbb0 100644 --- a/src/syntax/drawer.rs +++ b/src/syntax/drawer.rs @@ -109,9 +109,10 @@ fn node_property_node(input: Input) -> IResult { let (input, ws1) = space0(input)?; let (input, colon1) = colon_token(input)?; let (input, (colon2, name)) = map( - verify(take_while1(|c| c != ' ' && c != '\t'), |i: &Input| { - i.ends_with(':') - }), + verify( + take_while1(|c| c != ' ' && c != '\t' && c != '\n' && c != '\r'), + |i: &Input| i.ends_with(':'), + ), |input: Input| input.take_split(input.len() - 1), )(input)?; let (input, ws2) = space1(input)?;