Simplify parser module structure, add several syntax elements
This commit is contained in:
parent
070b5b7448
commit
e3d5686c7b
11 changed files with 348 additions and 186 deletions
43
src/syntax/content/parser/token/code.rs
Normal file
43
src/syntax/content/parser/token/code.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use crate::{
|
||||
syntax::content::{Parseable, Lexeme},
|
||||
};
|
||||
|
||||
pub struct Code {
|
||||
text: String,
|
||||
sticky: bool,
|
||||
}
|
||||
|
||||
impl Parseable for Code {
|
||||
fn probe(lexeme: &Lexeme) -> bool {
|
||||
let chars = lexeme.split_chars();
|
||||
|
||||
if let Some(first_char) = chars.first()
|
||||
&& let Some(last_char) = chars.last()
|
||||
{
|
||||
*first_char == '`' && *last_char == '`'
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn lex(lexeme: &Lexeme) -> Code {
|
||||
let sticky = [
|
||||
",", ".", ":", ";", "!", "?", "/", "(", ")", "%", "*", "&", r#"""#,
|
||||
"'",
|
||||
];
|
||||
|
||||
Code {
|
||||
text: lexeme.text().replace("`", ""),
|
||||
sticky: sticky.contains(&lexeme.next.as_str()),
|
||||
}
|
||||
}
|
||||
|
||||
fn render(&self) -> String {
|
||||
let space = if self.sticky {
|
||||
String::new()
|
||||
} else {
|
||||
String::from(" ")
|
||||
};
|
||||
format!("<code>{}</code>{space}", self.text)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue