Skip to content

Commit

Permalink
fix: newline in not allowed in property name
Browse files Browse the repository at this point in the history
  • Loading branch information
PoiScript committed Jun 11, 2024
1 parent 13ebef0 commit 5bc15d8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
20 changes: 19 additions & 1 deletion src/ast/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<PropertyDrawer> {
rowan::ast::support::child(&self.syntax)
}
}

impl Org {
Expand Down
1 change: 0 additions & 1 deletion src/ast/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const nodes = [
first_child: [
["section", "Section"],
["first_headline", "Headline"],
["properties", "PropertyDrawer"],
],
last_child: [["last_headline", "Headline"]],
children: [["headlines", "Headline"]],
Expand Down
3 changes: 0 additions & 3 deletions src/ast/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ impl Document {
pub fn first_headline(&self) -> Option<Headline> {
support::child(&self.syntax)
}
pub fn properties(&self) -> Option<PropertyDrawer> {
support::child(&self.syntax)
}
pub fn last_headline(&self) -> Option<Headline> {
super::last_child(&self.syntax)
}
Expand Down
7 changes: 4 additions & 3 deletions src/syntax/drawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ fn node_property_node(input: Input) -> IResult<Input, GreenElement, ()> {
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)?;
Expand Down

0 comments on commit 5bc15d8

Please sign in to comment.