diff options
| -rw-r--r-- | src/parser/conversion/inline.rs | 24 | ||||
| -rw-r--r-- | src/parser/tests.rs | 17 | ||||
| -rw-r--r-- | src/rst.pest | 36 | 
3 files changed, 40 insertions, 37 deletions
| diff --git a/src/parser/conversion/inline.rs b/src/parser/conversion/inline.rs index 94f99b4..79e6f12 100644 --- a/src/parser/conversion/inline.rs +++ b/src/parser/conversion/inline.rs @@ -19,9 +19,9 @@ use super::whitespace_normalize_name;  pub fn convert_inline(pair: Pair<Rule>) -> Result<c::TextOrInlineElement, Error> {  	Ok(match pair.as_rule() { -		Rule::str       		=> pair.as_str().into(), -		Rule::reference 		=> convert_reference(pair)?, -		Rule::substitution_ref 	=> convert_substitution(pair)?.into(), +		Rule::str              => pair.as_str().into(), +		Rule::reference        => convert_reference(pair)?, +		Rule::substitution_ref => convert_substitution_ref(pair)?.into(),  		rule => unimplemented!("unknown rule {:?}", rule),  	})  } @@ -142,17 +142,11 @@ fn convert_reference(pair: Pair<Rule>) -> Result<c::TextOrInlineElement, Error>  	).into())  } -fn convert_substitution(pair: Pair<Rule>) -> Result<e::SubstitutionReference, Error> { -	let concrete = pair.into_inner().next().unwrap(); -	match concrete.as_rule() { -		Rule::substitution_name => { -			let name = whitespace_normalize_name(concrete.as_str()); -			Ok(a::ExtraAttributes::with_extra( -				a::SubstitutionReference { -					refname: vec![at::NameToken(name)] -				} -			)) +fn convert_substitution_ref(pair: Pair<Rule>) -> Result<e::SubstitutionReference, Error> { +	let name = whitespace_normalize_name(pair.as_str()); +	Ok(a::ExtraAttributes::with_extra( +		a::SubstitutionReference { +			refname: vec![at::NameToken(name)]  		} -		_ => unreachable!() -	} +	))  } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index a3df64c..bf9fe22 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -17,6 +17,21 @@ fn plain() {  }  #[test] +fn emph() { +	parses_to! { +		parser: RstParser, +		input: "line *with markup*\n", +		rule: Rule::paragraph, +		tokens: [ +			paragraph(0, 18, [ +				str(0, 5), +				emph(6, 17), +			]) +		] +	}; +} + +#[test]  fn title() {  	parses_to! {  		parser: RstParser, @@ -125,7 +140,7 @@ A |subst| in-line  		tokens: [  			paragraph(0, 17, [  				str(0, 2), -				substitution_ref(2, 9, [ substitution_name(3, 8) ]), +				substitution_name(3, 8),  				str(9, 17),  			]),  			substitution_def(19, 52, [ diff --git a/src/rst.pest b/src/rst.pest index c1bf1b6..34e7bd2 100644 --- a/src/rst.pest +++ b/src/rst.pest @@ -104,18 +104,15 @@ line       =  { !marker ~ inline+ ~ NEWLINE }  blank_line = _{ !marker ~ !inline ~ " "* ~ NEWLINE }  inlines = _{ !marker ~ inline+ ~ ( NEWLINE ~ (PEEK[..] ~ !marker ~ inline+ ~ NEWLINE)+ )? } -inline  = _{ +inline  = _{ inline_special | str } +inline_special = _{      reference      | substitution_ref -    | str -//     link ✓ -//     | str ✓ -//     | endline +    | emph_outer +    | strong_outer +	| literal_outer  //     | ul_or_star_line  //     | space -//     | strong -//     | emph -//     | strike  //     | note_reference  //     | footnote  //     //| citation @@ -127,7 +124,15 @@ inline  = _{  //     | symbol  } -str = { (!(NEWLINE | reference | substitution_ref) ~ ANY)+ } +str = { (!(NEWLINE | inline_special) ~ ANY)+ } + +// simple formatting. TODO: similar to substitution_name, make function or so? +emph_outer    = _{ "*" ~ emph ~ "*" } +emph          =  { (!("*"|" ") ~ ANY)+ ~ (" "+ ~ (!("*"|" ") ~ ANY)+)* } +strong_outer  = _{ "**" ~ strong ~ "**" } +strong        =  { (!("*"|" ") ~ ANY)+ ~ (" "+ ~ (!("*"|" ") ~ ANY)+)* } +literal_outer = _{ "``" ~ literal ~ "``" } +literal       =  { (!("`"|" ") ~ ANY)+ ~ (" "+ ~ (!("`"|" ") ~ ANY)+)* }  // inline links  reference = { reference_target | reference_explicit | reference_auto } @@ -152,7 +157,7 @@ reference_auto = { url_auto | email }  //reference_embedded = { "`" ~ reference_embedded_source ~ "<" ~ absolute_url_with_fragment ~ ">`_" ~ "_"? }  //reference_embedded_source = { ( !("<"|":"|"`") ~ ( " " | nonspacechar | blank_line ) )* } -substitution_ref = { "|" ~ substitution_name ~ "|" } +substitution_ref = _{ "|" ~ substitution_name ~ "|" }  /* URLs as defined by the WHATWG URL standard. */  url = { absolute_url_no_query ~ ("?" ~ url_unit*)? ~ ("#" ~ url_unit*)? } @@ -365,17 +370,6 @@ marker = _{ (bullet_marker | "..") ~ " " }  // star_line = { "****" ~ "*"* | spacechar ~ "*"+ ~ &spacechar }  // ul_line = { "____" ~ "_"* | spacechar ~ "_"+ ~ &spacechar } -// whitespace = { spacechar | NEWLINE } - -// emph = { "*" ~ !whitespace ~ (!"*" ~ inline)+ ~ "*" } -// strong = { "**" ~ !whitespace ~ (!"**" ~ inline)+ ~ "**" } -// strike = { -//     //&{ extension(EXT_STRIKE) } ~ -//     "~~" ~ !whitespace ~ (!"~~" ~ inline)+ ~ "~~" -// } - - -  // empty_title = { "" } | 
