summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/mod.rs8
-rw-r--r--src/syntax/parsing.rs30
-rw-r--r--src/syntax/tokens.rs6
3 files changed, 39 insertions, 5 deletions
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs
index 8596a618..620a929e 100644
--- a/src/syntax/mod.rs
+++ b/src/syntax/mod.rs
@@ -100,7 +100,6 @@ pub enum Decoration {
/// ^^^
/// ```
ValidFuncName,
-
/// An invalid function name:
/// ```typst
/// [blabla]
@@ -114,6 +113,13 @@ pub enum Decoration {
/// ^^^^^
/// ```
ArgumentKey,
+
+ /// Italic.
+ Italic,
+ /// Bold.
+ Bold,
+ /// Monospace.
+ Monospace,
}
impl dyn Model {
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs
index 1526a5cb..d24985a6 100644
--- a/src/syntax/parsing.rs
+++ b/src/syntax/parsing.rs
@@ -375,6 +375,7 @@ mod tests {
Space as S, Newline as N,
ToggleItalic as Italic, ToggleBolder as Bold, ToggleMonospace as Mono,
};
+ use Decoration::*;
pub use Expr::{Number as Num, Bool};
pub fn Id(text: &str) -> Expr { Expr::Ident(Ident(text.to_string())) }
@@ -421,9 +422,32 @@ mod tests {
};
}
+ /// Test whether the given string yields the given decorations.
+ macro_rules! d {
+ ($s:expr => [$(($sl:tt:$sc:tt, $el:tt:$ec:tt, $d:expr)),* $(,)?]) => {
+ let ctx = ParseContext { scope: &scope() };
+ let decos = parse(Position::ZERO, $s, ctx).feedback.decos;
+
+ let expected = vec![
+ $(Spanned {
+ v: $d,
+ span: Span {
+ start: Position { line: $sl, column: $sc },
+ end: Position { line: $el, column: $ec },
+ },
+ }),*
+ ];
+
+ if decos != expected {
+ fail($s, decos, expected);
+ }
+ };
+ }
+
fn scope() -> Scope {
let mut scope = Scope::new::<DebugFn>();
scope.add::<DebugFn>("f");
+ scope.add::<DebugFn>("n");
scope.add::<DebugFn>("box");
scope
}
@@ -552,4 +576,10 @@ mod tests {
(0:21, 0:21, "expected closing bracket"),
]);
}
+
+ #[test]
+ fn parse_decos() {
+ d!("*Technische Universität Berlin* [n]\n [n]"
+ => [(0:33, 0:34, ValidFuncName), (1:33, 1:34, ValidFuncName)]);
+ }
}
diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs
index 7b52f655..f4ea5daf 100644
--- a/src/syntax/tokens.rs
+++ b/src/syntax/tokens.rs
@@ -403,15 +403,13 @@ impl<'s> Tokens<'s> {
fn eat(&mut self) -> Option<char> {
let c = self.iter.next()?;
- let len = c.len_utf8();
-
- self.index += len;
+ self.index += c.len_utf8();
if is_newline_char(c) && !(c == '\r' && self.peek() == Some('\n')) {
self.position.line += 1;
self.position.column = 0;
} else {
- self.position.column += len;
+ self.position.column += 1;
}
Some(c)