diff options
| author | Philipp A | 2020-09-06 22:30:19 +0200 | 
|---|---|---|
| committer | Philipp A | 2020-09-07 00:28:39 +0200 | 
| commit | c80468a8f917079189c8cd111556f9752085e3e4 (patch) | |
| tree | 62408e2ea52c38fbdf6f6d213cfa8ddb4a0e8131 | |
| parent | 4de128cf7924ad3c0c81dfc52701ace16b010749 (diff) | |
| download | rust-rst-c80468a8f917079189c8cd111556f9752085e3e4.tar.bz2 | |
Don’t parse literal content
| -rw-r--r-- | document_tree/src/elements.rs | 2 | ||||
| -rw-r--r-- | parser/src/conversion/inline.rs | 2 | ||||
| -rw-r--r-- | parser/src/rst.pest | 4 | ||||
| -rw-r--r-- | parser/src/simplify.rs | 4 | ||||
| -rw-r--r-- | parser/src/tests.rs | 19 | 
5 files changed, 24 insertions, 7 deletions
| diff --git a/document_tree/src/elements.rs b/document_tree/src/elements.rs index 26bccf6..1db0a24 100644 --- a/document_tree/src/elements.rs +++ b/document_tree/src/elements.rs @@ -257,7 +257,7 @@ impl_elems!(  	//inline elements  	(Emphasis,              TextOrInlineElement) -	(Literal,               TextOrInlineElement) +	(Literal,               String)  	(Reference,             TextOrInlineElement; +)  	(Strong,                TextOrInlineElement)  	(FootnoteReference,     TextOrInlineElement; +) diff --git a/parser/src/conversion/inline.rs b/parser/src/conversion/inline.rs index 6094714..82a74e7 100644 --- a/parser/src/conversion/inline.rs +++ b/parser/src/conversion/inline.rs @@ -25,7 +25,7 @@ pub fn convert_inline(pair: Pair<Rule>) -> Result<c::TextOrInlineElement, Error>  		Rule::substitution_name => convert_substitution_ref(pair)?.into(),  		Rule::emph              => e::Emphasis::with_children(convert_inlines(pair)?).into(),  		Rule::strong            => e::Strong::with_children(convert_inlines(pair)?).into(), -		Rule::literal           => e::Literal::with_children(convert_inlines(pair)?).into(), +		Rule::literal           => e::Literal::with_children(vec![pair.as_str().to_owned()]).into(),  		rule => unimplemented!("unknown rule {:?}", rule),  	})  } diff --git a/parser/src/rst.pest b/parser/src/rst.pest index cf0d42e..322ad08 100644 --- a/parser/src/rst.pest +++ b/parser/src/rst.pest @@ -135,7 +135,7 @@ str = { (!(NEWLINE | inline_special) ~ ANY)+ }  // simple formatting  inline_nested = _{ inline_special | str_nested }  str_nested    =  { word_nested ~ ( " "+ ~ word_nested)* } -// TODO: allow ` in emph and * in literal +// TODO: allow ` in emph  word_nested   = _{ (!(NEWLINE | " " | inline_special | "*" | "`") ~ ANY)+ }  emph_outer    = _{ "*" ~ emph ~ "*" } @@ -143,7 +143,7 @@ emph          =  { (!("*"|" ") ~ inline_nested)+ ~ (" "+ ~ (!("*"|" ") ~ inline_  strong_outer  = _{ "**" ~ strong ~ "**" }  strong        =  { (!("*"|" ") ~ inline_nested)+ ~ (" "+ ~ (!("*"|" ") ~ inline_nested)+)* }  literal_outer = _{ "``" ~ literal ~ "``" } -literal       =  { (!("`"|" ") ~ inline_nested)+ ~ (" "+ ~ (!("`"|" ") ~ inline_nested)+)* } +literal       =  { (!"``" ~ ANY)+ }  // inline links  reference = { reference_target | reference_explicit | reference_auto } diff --git a/parser/src/simplify.rs b/parser/src/simplify.rs index 7974991..4c254af 100644 --- a/parser/src/simplify.rs +++ b/parser/src/simplify.rs @@ -325,7 +325,7 @@ impl ResolvableRefs for c::TextOrInlineElement {  			String(_) => {},  			Emphasis(e) => sub_pop(&**e, refs),  			Strong(e) => sub_pop(&**e, refs), -			Literal(e) => sub_pop(&**e, refs), +			Literal(_) => {},  			Reference(e) => sub_pop(&**e, refs),  			FootnoteReference(e) => sub_pop(&**e, refs),  			CitationReference(e) => sub_pop(&**e, refs), @@ -352,7 +352,7 @@ impl ResolvableRefs for c::TextOrInlineElement {  			String(e) => String(e),  			Emphasis(e) => sub_res(*e, refs).into(),  			Strong(e) => sub_res(*e, refs).into(), -			Literal(e) => sub_res(*e, refs).into(), +			Literal(e) => Literal(e),  			Reference(mut e) => {  				if e.extra().refuri.is_none() {  					if let Some(uri) = refs.target_url(&e.extra().refname) { diff --git a/parser/src/tests.rs b/parser/src/tests.rs index 79438e0..504d13b 100644 --- a/parser/src/tests.rs +++ b/parser/src/tests.rs @@ -111,7 +111,7 @@ fn inline_code_literal_with_underscore() {          input: "``NAME_WITH_UNDERSCORE``",          rule: Rule::inline,          tokens: [ -            literal(2, 22, [str_nested(2, 22)]), +            literal(2, 22),          ]      };  } @@ -218,6 +218,23 @@ A |subst| in-line  	};  } +#[test] +fn substitution_in_literal() { +	parses_to! { +		parser: RstParser, +		input: "Just ``|code|``, really ``*code* |only|``", +		rule: Rule::document, +		tokens: [ +			paragraph(0, 41, [ +				str(0, 5), +				literal(7, 13), +				str(15, 24), +				literal(26, 39), +			]), +		] +	}; +} +  #[allow(clippy::cognitive_complexity)]  #[test] | 
