diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-08-30 15:00:18 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-09-07 11:07:17 +0200 |
| commit | 0d12f2ab23177642eef2e6bb9c583cdd0c743b33 (patch) | |
| tree | 03a88594081dcf360d0d880167feb1debca970e6 /src/parse/tokens.rs | |
| parent | 0cb876ebf9138c1ee3b3c87165952a73569ffb28 (diff) | |
[WIP] Label and reference syntax
Diffstat (limited to 'src/parse/tokens.rs')
| -rw-r--r-- | src/parse/tokens.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs index be107f3c..e004dd37 100644 --- a/src/parse/tokens.rs +++ b/src/parse/tokens.rs @@ -148,8 +148,10 @@ impl<'s> Tokens<'s> { '*' if !self.in_word() => NodeKind::Star, '_' if !self.in_word() => NodeKind::Underscore, '`' => self.raw(), - '$' => self.math(), '=' => NodeKind::Eq, + '$' => self.math(), + '<' => self.label(), + '@' => self.reference(), c if c == '.' || c.is_ascii_digit() => self.numbering(start, c), // Plain text. @@ -277,7 +279,9 @@ impl<'s> Tokens<'s> { // Parenthesis and hashtag. '[' | ']' | '{' | '}' | '#' | // Markup. - '~' | '\'' | '"' | '*' | '_' | '`' | '$' | '=' | '-' | '.' => { + '~' | '-' | '.' | ':' | + '\'' | '"' | '*' | '_' | '`' | '$' | '=' | + '<' | '>' | '@' => { self.s.expect(c); NodeKind::Escape(c) } @@ -453,6 +457,29 @@ impl<'s> Tokens<'s> { } } + fn label(&mut self) -> NodeKind { + let label = self.s.eat_while(is_id_continue); + if self.s.eat_if('>') { + if !label.is_empty() { + NodeKind::Label(label.into()) + } else { + NodeKind::Error(SpanPos::Full, "label cannot be empty".into()) + } + } else { + self.terminated = false; + NodeKind::Error(SpanPos::End, "expected closing angle bracket".into()) + } + } + + fn reference(&mut self) -> NodeKind { + let label = self.s.eat_while(is_id_continue); + if !label.is_empty() { + NodeKind::Ref(label.into()) + } else { + NodeKind::Error(SpanPos::Full, "label cannot be empty".into()) + } + } + fn ident(&mut self, start: usize) -> NodeKind { self.s.eat_while(is_id_continue); match self.s.from(start) { |
