summaryrefslogtreecommitdiff
path: root/src/syntax/highlight.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax/highlight.rs')
-rw-r--r--src/syntax/highlight.rs272
1 files changed, 136 insertions, 136 deletions
diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs
index 7c0b4ac1..526d1302 100644
--- a/src/syntax/highlight.rs
+++ b/src/syntax/highlight.rs
@@ -6,7 +6,7 @@ use std::ops::Range;
use syntect::highlighting::{Color, FontStyle, Highlighter, Style, Theme};
use syntect::parsing::Scope;
-use super::{parse, NodeKind, SyntaxNode};
+use super::{parse, SyntaxKind, SyntaxNode};
/// Highlight source text into a standalone HTML document.
pub fn highlight_html(text: &str, theme: &Theme) -> String {
@@ -194,170 +194,170 @@ impl Category {
i: usize,
) -> Option<Category> {
match child.kind() {
- NodeKind::LineComment => Some(Category::Comment),
- NodeKind::BlockComment => Some(Category::Comment),
- NodeKind::Space { .. } => None,
-
- NodeKind::LeftBrace => Some(Category::Bracket),
- NodeKind::RightBrace => Some(Category::Bracket),
- NodeKind::LeftBracket => Some(Category::Bracket),
- NodeKind::RightBracket => Some(Category::Bracket),
- NodeKind::LeftParen => Some(Category::Bracket),
- NodeKind::RightParen => Some(Category::Bracket),
- NodeKind::Comma => Some(Category::Punctuation),
- NodeKind::Semicolon => Some(Category::Punctuation),
- NodeKind::Colon => Some(Category::Punctuation),
- NodeKind::Star => match parent.kind() {
- NodeKind::Strong => None,
+ SyntaxKind::LineComment => Some(Category::Comment),
+ SyntaxKind::BlockComment => Some(Category::Comment),
+ SyntaxKind::Space { .. } => None,
+
+ SyntaxKind::LeftBrace => Some(Category::Bracket),
+ SyntaxKind::RightBrace => Some(Category::Bracket),
+ SyntaxKind::LeftBracket => Some(Category::Bracket),
+ SyntaxKind::RightBracket => Some(Category::Bracket),
+ SyntaxKind::LeftParen => Some(Category::Bracket),
+ SyntaxKind::RightParen => Some(Category::Bracket),
+ SyntaxKind::Comma => Some(Category::Punctuation),
+ SyntaxKind::Semicolon => Some(Category::Punctuation),
+ SyntaxKind::Colon => Some(Category::Punctuation),
+ SyntaxKind::Star => match parent.kind() {
+ SyntaxKind::Strong => None,
_ => Some(Category::Operator),
},
- NodeKind::Underscore => match parent.kind() {
- NodeKind::Script => Some(Category::MathOperator),
+ SyntaxKind::Underscore => match parent.kind() {
+ SyntaxKind::Script => Some(Category::MathOperator),
_ => None,
},
- NodeKind::Dollar => Some(Category::MathDelimiter),
- NodeKind::Plus => Some(match parent.kind() {
- NodeKind::EnumItem => Category::ListMarker,
+ SyntaxKind::Dollar => Some(Category::MathDelimiter),
+ SyntaxKind::Plus => Some(match parent.kind() {
+ SyntaxKind::EnumItem => Category::ListMarker,
_ => Category::Operator,
}),
- NodeKind::Minus => Some(match parent.kind() {
- NodeKind::ListItem => Category::ListMarker,
+ SyntaxKind::Minus => Some(match parent.kind() {
+ SyntaxKind::ListItem => Category::ListMarker,
_ => Category::Operator,
}),
- NodeKind::Slash => Some(match parent.kind() {
- NodeKind::DescItem => Category::ListMarker,
- NodeKind::Frac => Category::MathOperator,
+ SyntaxKind::Slash => Some(match parent.kind() {
+ SyntaxKind::DescItem => Category::ListMarker,
+ SyntaxKind::Frac => Category::MathOperator,
_ => Category::Operator,
}),
- NodeKind::Hat => Some(Category::MathOperator),
- NodeKind::Amp => Some(Category::MathOperator),
- NodeKind::Dot => Some(Category::Punctuation),
- NodeKind::Eq => match parent.kind() {
- NodeKind::Heading => None,
+ SyntaxKind::Hat => Some(Category::MathOperator),
+ SyntaxKind::Amp => Some(Category::MathOperator),
+ SyntaxKind::Dot => Some(Category::Punctuation),
+ SyntaxKind::Eq => match parent.kind() {
+ SyntaxKind::Heading => None,
_ => Some(Category::Operator),
},
- NodeKind::EqEq => Some(Category::Operator),
- NodeKind::ExclEq => Some(Category::Operator),
- NodeKind::Lt => Some(Category::Operator),
- NodeKind::LtEq => Some(Category::Operator),
- NodeKind::Gt => Some(Category::Operator),
- NodeKind::GtEq => Some(Category::Operator),
- NodeKind::PlusEq => Some(Category::Operator),
- NodeKind::HyphEq => Some(Category::Operator),
- NodeKind::StarEq => Some(Category::Operator),
- NodeKind::SlashEq => Some(Category::Operator),
- NodeKind::Dots => Some(Category::Operator),
- NodeKind::Arrow => Some(Category::Operator),
-
- NodeKind::Not => Some(Category::Keyword),
- NodeKind::And => Some(Category::Keyword),
- NodeKind::Or => Some(Category::Keyword),
- NodeKind::None => Some(Category::KeywordLiteral),
- NodeKind::Auto => Some(Category::KeywordLiteral),
- NodeKind::Let => Some(Category::Keyword),
- NodeKind::Set => Some(Category::Keyword),
- NodeKind::Show => Some(Category::Keyword),
- NodeKind::If => Some(Category::Keyword),
- NodeKind::Else => Some(Category::Keyword),
- NodeKind::For => Some(Category::Keyword),
- NodeKind::In => Some(Category::Keyword),
- NodeKind::While => Some(Category::Keyword),
- NodeKind::Break => Some(Category::Keyword),
- NodeKind::Continue => Some(Category::Keyword),
- NodeKind::Return => Some(Category::Keyword),
- NodeKind::Import => Some(Category::Keyword),
- NodeKind::Include => Some(Category::Keyword),
- NodeKind::From => Some(Category::Keyword),
-
- NodeKind::Markup { .. } => match parent.kind() {
- NodeKind::DescItem
+ SyntaxKind::EqEq => Some(Category::Operator),
+ SyntaxKind::ExclEq => Some(Category::Operator),
+ SyntaxKind::Lt => Some(Category::Operator),
+ SyntaxKind::LtEq => Some(Category::Operator),
+ SyntaxKind::Gt => Some(Category::Operator),
+ SyntaxKind::GtEq => Some(Category::Operator),
+ SyntaxKind::PlusEq => Some(Category::Operator),
+ SyntaxKind::HyphEq => Some(Category::Operator),
+ SyntaxKind::StarEq => Some(Category::Operator),
+ SyntaxKind::SlashEq => Some(Category::Operator),
+ SyntaxKind::Dots => Some(Category::Operator),
+ SyntaxKind::Arrow => Some(Category::Operator),
+
+ SyntaxKind::Not => Some(Category::Keyword),
+ SyntaxKind::And => Some(Category::Keyword),
+ SyntaxKind::Or => Some(Category::Keyword),
+ SyntaxKind::None => Some(Category::KeywordLiteral),
+ SyntaxKind::Auto => Some(Category::KeywordLiteral),
+ SyntaxKind::Let => Some(Category::Keyword),
+ SyntaxKind::Set => Some(Category::Keyword),
+ SyntaxKind::Show => Some(Category::Keyword),
+ SyntaxKind::If => Some(Category::Keyword),
+ SyntaxKind::Else => Some(Category::Keyword),
+ SyntaxKind::For => Some(Category::Keyword),
+ SyntaxKind::In => Some(Category::Keyword),
+ SyntaxKind::While => Some(Category::Keyword),
+ SyntaxKind::Break => Some(Category::Keyword),
+ SyntaxKind::Continue => Some(Category::Keyword),
+ SyntaxKind::Return => Some(Category::Keyword),
+ SyntaxKind::Import => Some(Category::Keyword),
+ SyntaxKind::Include => Some(Category::Keyword),
+ SyntaxKind::From => Some(Category::Keyword),
+
+ SyntaxKind::Markup { .. } => match parent.kind() {
+ SyntaxKind::DescItem
if parent
.children()
- .take_while(|child| child.kind() != &NodeKind::Colon)
- .find(|c| matches!(c.kind(), NodeKind::Markup { .. }))
+ .take_while(|child| child.kind() != &SyntaxKind::Colon)
+ .find(|c| matches!(c.kind(), SyntaxKind::Markup { .. }))
.map_or(false, |ident| std::ptr::eq(ident, child)) =>
{
Some(Category::ListTerm)
}
_ => None,
},
- NodeKind::Text(_) => None,
- NodeKind::Linebreak => Some(Category::Escape),
- NodeKind::Escape(_) => Some(Category::Escape),
- NodeKind::Shorthand(_) => Some(Category::Shorthand),
- NodeKind::SmartQuote { .. } => Some(Category::SmartQuote),
- NodeKind::Strong => Some(Category::Strong),
- NodeKind::Emph => Some(Category::Emph),
- NodeKind::Raw(_) => Some(Category::Raw),
- NodeKind::Link(_) => Some(Category::Link),
- NodeKind::Label(_) => Some(Category::Label),
- NodeKind::Ref(_) => Some(Category::Ref),
- NodeKind::Heading => Some(Category::Heading),
- NodeKind::ListItem => Some(Category::ListItem),
- NodeKind::EnumItem => Some(Category::ListItem),
- NodeKind::EnumNumbering(_) => Some(Category::ListMarker),
- NodeKind::DescItem => Some(Category::ListItem),
- NodeKind::Math => Some(Category::Math),
- NodeKind::Atom(_) => None,
- NodeKind::Script => None,
- NodeKind::Frac => None,
- NodeKind::Align => None,
-
- NodeKind::Ident(_) => match parent.kind() {
- NodeKind::Markup { .. } => Some(Category::Interpolated),
- NodeKind::Math => Some(Category::Interpolated),
- NodeKind::FuncCall => Some(Category::Function),
- NodeKind::MethodCall if i > 0 => Some(Category::Function),
- NodeKind::Closure if i == 0 => Some(Category::Function),
- NodeKind::SetRule => Some(Category::Function),
- NodeKind::ShowRule
+ SyntaxKind::Text(_) => None,
+ SyntaxKind::Linebreak => Some(Category::Escape),
+ SyntaxKind::Escape(_) => Some(Category::Escape),
+ SyntaxKind::Shorthand(_) => Some(Category::Shorthand),
+ SyntaxKind::SmartQuote { .. } => Some(Category::SmartQuote),
+ SyntaxKind::Strong => Some(Category::Strong),
+ SyntaxKind::Emph => Some(Category::Emph),
+ SyntaxKind::Raw(_) => Some(Category::Raw),
+ SyntaxKind::Link(_) => Some(Category::Link),
+ SyntaxKind::Label(_) => Some(Category::Label),
+ SyntaxKind::Ref(_) => Some(Category::Ref),
+ SyntaxKind::Heading => Some(Category::Heading),
+ SyntaxKind::ListItem => Some(Category::ListItem),
+ SyntaxKind::EnumItem => Some(Category::ListItem),
+ SyntaxKind::EnumNumbering(_) => Some(Category::ListMarker),
+ SyntaxKind::DescItem => Some(Category::ListItem),
+ SyntaxKind::Math => Some(Category::Math),
+ SyntaxKind::Atom(_) => None,
+ SyntaxKind::Script => None,
+ SyntaxKind::Frac => None,
+ SyntaxKind::Align => None,
+
+ SyntaxKind::Ident(_) => match parent.kind() {
+ SyntaxKind::Markup { .. } => Some(Category::Interpolated),
+ SyntaxKind::Math => Some(Category::Interpolated),
+ SyntaxKind::FuncCall => Some(Category::Function),
+ SyntaxKind::MethodCall if i > 0 => Some(Category::Function),
+ SyntaxKind::Closure if i == 0 => Some(Category::Function),
+ SyntaxKind::SetRule => Some(Category::Function),
+ SyntaxKind::ShowRule
if parent
.children()
.rev()
- .skip_while(|child| child.kind() != &NodeKind::Colon)
- .find(|c| matches!(c.kind(), NodeKind::Ident(_)))
+ .skip_while(|child| child.kind() != &SyntaxKind::Colon)
+ .find(|c| matches!(c.kind(), SyntaxKind::Ident(_)))
.map_or(false, |ident| std::ptr::eq(ident, child)) =>
{
Some(Category::Function)
}
_ => None,
},
- NodeKind::Bool(_) => Some(Category::KeywordLiteral),
- NodeKind::Int(_) => Some(Category::Number),
- NodeKind::Float(_) => Some(Category::Number),
- NodeKind::Numeric(_, _) => Some(Category::Number),
- NodeKind::Str(_) => Some(Category::String),
- NodeKind::CodeBlock => None,
- NodeKind::ContentBlock => None,
- NodeKind::Parenthesized => None,
- NodeKind::Array => None,
- NodeKind::Dict => None,
- NodeKind::Named => None,
- NodeKind::Keyed => None,
- NodeKind::Unary => None,
- NodeKind::Binary => None,
- NodeKind::FieldAccess => None,
- NodeKind::FuncCall => None,
- NodeKind::MethodCall => None,
- NodeKind::Args => None,
- NodeKind::Spread => None,
- NodeKind::Closure => None,
- NodeKind::Params => None,
- NodeKind::LetBinding => None,
- NodeKind::SetRule => None,
- NodeKind::ShowRule => None,
- NodeKind::Conditional => None,
- NodeKind::WhileLoop => None,
- NodeKind::ForLoop => None,
- NodeKind::ForPattern => None,
- NodeKind::ModuleImport => None,
- NodeKind::ImportItems => None,
- NodeKind::ModuleInclude => None,
- NodeKind::LoopBreak => None,
- NodeKind::LoopContinue => None,
- NodeKind::FuncReturn => None,
-
- NodeKind::Error(_, _) => Some(Category::Error),
+ SyntaxKind::Bool(_) => Some(Category::KeywordLiteral),
+ SyntaxKind::Int(_) => Some(Category::Number),
+ SyntaxKind::Float(_) => Some(Category::Number),
+ SyntaxKind::Numeric(_, _) => Some(Category::Number),
+ SyntaxKind::Str(_) => Some(Category::String),
+ SyntaxKind::CodeBlock => None,
+ SyntaxKind::ContentBlock => None,
+ SyntaxKind::Parenthesized => None,
+ SyntaxKind::Array => None,
+ SyntaxKind::Dict => None,
+ SyntaxKind::Named => None,
+ SyntaxKind::Keyed => None,
+ SyntaxKind::Unary => None,
+ SyntaxKind::Binary => None,
+ SyntaxKind::FieldAccess => None,
+ SyntaxKind::FuncCall => None,
+ SyntaxKind::MethodCall => None,
+ SyntaxKind::Args => None,
+ SyntaxKind::Spread => None,
+ SyntaxKind::Closure => None,
+ SyntaxKind::Params => None,
+ SyntaxKind::LetBinding => None,
+ SyntaxKind::SetRule => None,
+ SyntaxKind::ShowRule => None,
+ SyntaxKind::Conditional => None,
+ SyntaxKind::WhileLoop => None,
+ SyntaxKind::ForLoop => None,
+ SyntaxKind::ForPattern => None,
+ SyntaxKind::ModuleImport => None,
+ SyntaxKind::ImportItems => None,
+ SyntaxKind::ModuleInclude => None,
+ SyntaxKind::LoopBreak => None,
+ SyntaxKind::LoopContinue => None,
+ SyntaxKind::FuncReturn => None,
+
+ SyntaxKind::Error(_, _) => Some(Category::Error),
}
}