refactor: utils macros
This commit is contained in:
parent
93ed18602a
commit
75362bd2a8
16 changed files with 70 additions and 91 deletions
|
|
@ -11,7 +11,7 @@ impl Block {
|
|||
|
||||
let args = eol!(src);
|
||||
let name = until_while!(src, 8, |c| c == b' ' || c == b'\n', |c: u8| c
|
||||
.is_ascii_alphabetic());
|
||||
.is_ascii_alphabetic())?;
|
||||
// TODO: ignore case match
|
||||
let content = src.find(&format!("\n#+END_{}", &src[8..name]))?;
|
||||
let end = eol!(src, content + 1);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ impl DynBlock {
|
|||
|
||||
let args = eol!(src);
|
||||
let name = until_while!(src, 9, |c| c == b' ' || c == b'\n', |c: u8| c
|
||||
.is_ascii_alphabetic());
|
||||
.is_ascii_alphabetic())?;
|
||||
// TODO: ignore case matching
|
||||
let content = src.find("\n#+END:")?;
|
||||
let end = eol!(src, content + 1);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ impl FnDef {
|
|||
pub fn parse(src: &str) -> Option<(&str, &str, usize)> {
|
||||
starts_with!(src, "[fn:");
|
||||
|
||||
let label = until_while!(src, 4, b']', valid_label);
|
||||
let label = until_while!(src, 4, b']', valid_label)?;
|
||||
|
||||
if label == 4 {
|
||||
return None;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ impl Keyword {
|
|||
starts_with!(src, "#+");
|
||||
}
|
||||
|
||||
let key = until_while!(src, 2, b':', |c: u8| c.is_ascii_uppercase() || c == b'_');
|
||||
let key = until_while!(src, 2, b':', |c: u8| c.is_ascii_uppercase() || c == b'_')?;
|
||||
|
||||
// includes the eol character
|
||||
let end = src.find('\n').map(|i| i + 1).unwrap_or_else(|| src.len());
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ pub struct Rule;
|
|||
impl Rule {
|
||||
pub fn parse(src: &str) -> Option<usize> {
|
||||
let end = eol!(src);
|
||||
let leading = until_while!(src, 0, b'-', |c| c == b' ' || c == b'\t');
|
||||
let leading = until_while!(src, 0, b'-', |c| c == b' ' || c == b'\t')?;
|
||||
if src[leading..end].chars().all(|c| c == '-') && end - leading > 4 {
|
||||
Some(end)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue