Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "editor")]
use super::Editor;

use super::syntax::{Syntax, TokenType, QUOTES, SEPARATORS};
use super::syntax::{SEPARATORS, Syntax, TokenType};
use std::mem;

#[derive(Default, Debug, PartialEq, PartialOrd, Eq, Ord)]
Expand Down Expand Up @@ -39,6 +39,7 @@ impl Token {
c if syntax.is_special(c.to_string().as_str()) => TokenType::Special,
c if syntax.comment == c.to_string().as_str() => TokenType::Comment(false),
c if syntax.comment_multiline[0] == c.to_string().as_str() => TokenType::Comment(true),
c if syntax.is_quote_symbol(&c) => TokenType::Str(c),
_ => TokenType::from(c),
};
token
Expand Down Expand Up @@ -136,7 +137,7 @@ impl Token {
c if !c.is_alphanumeric() && !SEPARATORS.contains(&c) => {
tokens.extend(self.drain(self.ty));
self.buffer.push(c);
self.ty = if QUOTES.contains(&c) {
self.ty = if syntax.is_quote_symbol(&c) {
Ty::Str(c)
} else {
Ty::Punctuation(c)
Expand Down
3 changes: 3 additions & 0 deletions src/syntax/asm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::syntax::DEFAULT_QUOTES;

use super::Syntax;
use std::collections::BTreeSet;

Expand Down Expand Up @@ -1177,6 +1179,7 @@ impl Syntax {
"ZMM10", "ZMM11", "ZMM12", "ZMM13", "ZMM14", "ZMM15",
// ZMM
]),
quote_symbols: &DEFAULT_QUOTES,
}
}
}
3 changes: 3 additions & 0 deletions src/syntax/lua.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::syntax::DEFAULT_QUOTES;

use super::Syntax;
use std::collections::BTreeSet;

Expand All @@ -17,6 +19,7 @@ impl Syntax {
"boolean", "number", "string", "function", "userdata", "thread", "table",
]),
special: BTreeSet::from(["false", "nil", "true"]),
quote_symbols: &DEFAULT_QUOTES,
}
}
}
14 changes: 12 additions & 2 deletions src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::collections::BTreeSet;
use std::hash::{Hash, Hasher};

pub const SEPARATORS: [char; 1] = ['_'];
pub const QUOTES: [char; 3] = ['\'', '"', '`'];
pub const DEFAULT_QUOTES: [char; 3] = ['\'', '"', '`'];

type MultiLine = bool;
type Float = bool;
Expand Down Expand Up @@ -83,7 +83,6 @@ impl From<char> for TokenType {
fn from(c: char) -> Self {
match c {
c if c.is_whitespace() => TokenType::Whitespace(c),
c if QUOTES.contains(&c) => TokenType::Str(c),
c if c.is_numeric() => TokenType::Numeric(false),
c if c.is_alphabetic() || SEPARATORS.contains(&c) => TokenType::Literal,
c if c.is_ascii_punctuation() => TokenType::Punctuation(c),
Expand All @@ -103,6 +102,7 @@ pub struct Syntax {
pub keywords: BTreeSet<&'static str>,
pub types: BTreeSet<&'static str>,
pub special: BTreeSet<&'static str>,
pub quote_symbols: &'static [char],
}
impl Default for Syntax {
fn default() -> Self {
Expand Down Expand Up @@ -160,6 +160,12 @@ impl Syntax {
..self
}
}
pub fn with_quote_symbols<T: Into<&'static [char]>>(self, quote_symbols: T) -> Self {
Syntax {
quote_symbols: quote_symbols.into(),
..self
}
}

pub fn language(&self) -> &str {
self.language
Expand Down Expand Up @@ -191,6 +197,9 @@ impl Syntax {
self.special.contains(word.to_ascii_uppercase().as_str())
}
}
pub fn is_quote_symbol(&self, c: &char) -> bool {
self.quote_symbols.contains(c)
}
}

impl Syntax {
Expand All @@ -204,6 +213,7 @@ impl Syntax {
keywords: BTreeSet::new(),
types: BTreeSet::new(),
special: BTreeSet::new(),
quote_symbols: &[],
}
}
}
3 changes: 3 additions & 0 deletions src/syntax/python.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::syntax::DEFAULT_QUOTES;

use super::Syntax;
use std::collections::BTreeSet;

Expand Down Expand Up @@ -32,6 +34,7 @@ impl Syntax {
"frozenset",
]),
special: BTreeSet::from(["False", "None", "True"]),
quote_symbols: &DEFAULT_QUOTES,
}
}
}
3 changes: 3 additions & 0 deletions src/syntax/rust.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::syntax::DEFAULT_QUOTES;

use super::Syntax;
use std::collections::BTreeSet;

Expand Down Expand Up @@ -83,6 +85,7 @@ impl Syntax {
"Weak",
]),
special: BTreeSet::from(["Self", "static", "true", "false"]),
quote_symbols: &DEFAULT_QUOTES,
}
}
}
3 changes: 3 additions & 0 deletions src/syntax/shell.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::syntax::DEFAULT_QUOTES;

use super::Syntax;
use std::collections::BTreeSet;

Expand Down Expand Up @@ -36,6 +38,7 @@ impl Syntax {
"alias", "bg", "cd", "command", "false", "fc", "fg", "getopts", "jobs", "kill",
"newgrp", "pwd", "read", "true", "umask", "unalias", "wait",
]),
quote_symbols: &DEFAULT_QUOTES,
}
}
}
3 changes: 3 additions & 0 deletions src/syntax/sql.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::syntax::DEFAULT_QUOTES;

use super::Syntax;
use std::collections::BTreeSet;

Expand Down Expand Up @@ -133,6 +135,7 @@ impl Syntax {
"DATABASE",
]),
special: BTreeSet::from(["PUBLIC"]),
quote_symbols: &DEFAULT_QUOTES,
}
}
}