mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-19 03:38:13 +01:00
Made the x_1
notation possible.
This commit is contained in:
parent
0ab31c18cb
commit
c6f60748e2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*/target
|
||||
kalk/Cargo.lock
|
||||
kalk_cli/test
|
||||
|
@ -140,12 +140,22 @@ impl<'a> Lexer<'a> {
|
||||
fn next_identifier(&mut self) -> Token {
|
||||
let start = self.index;
|
||||
let mut end = start;
|
||||
let letter_reg = regex::Regex::new(r"[A-z']").unwrap();
|
||||
let letter_reg = regex::Regex::new(r"[A-z'_]").unwrap();
|
||||
let mut value = String::new();
|
||||
|
||||
while is_valid_identifier(self.peek()) {
|
||||
let c = *self.peek().unwrap();
|
||||
|
||||
// If the current character is an underscore, expect a number next.
|
||||
// This is to allow the notation like the following: x_1
|
||||
if c == '_' {
|
||||
self.advance();
|
||||
let num = self.next_number_literal().value;
|
||||
value.push('_');
|
||||
value.push_str(&num.trim_end()); // Trim, since the number_literal function allows whitespace, which identifiers should not contain.
|
||||
break;
|
||||
}
|
||||
|
||||
// Only allow identifiers with a special character to have *one* character. No more.
|
||||
// Break the loop if it isn't the first run and the current character is a special character.
|
||||
if end - start > 0 && !letter_reg.is_match(&c.to_string()) {
|
||||
|
@ -54,9 +54,9 @@ impl Highlighter for LineHighlighter {
|
||||
fn highlight<'l>(&self, line: &'l str, _: usize) -> Cow<'l, str> {
|
||||
let mut coloured = line.to_string();
|
||||
|
||||
let reg = Regex::new(r"([A-z]+|[\+-/\*\^!])").unwrap();
|
||||
let reg = Regex::new(r"(([^0-9\.,\(\)=\+-/\*\^!_]+(_\d+)?)|[\+-/\*\^!])").unwrap();
|
||||
let unit = Regex::new(r"(deg|rad)").unwrap();
|
||||
let identifier = Regex::new(r"[^0-9\.,\(\)=\+-/\*\^!]+").unwrap();
|
||||
let identifier = Regex::new(r"[^0-9\.,\(\)=\+-/\*\^!_]+(_\d+)?").unwrap();
|
||||
let op = Regex::new(r"[\+-/\*\^!]+").unwrap();
|
||||
|
||||
coloured = reg
|
||||
|
Loading…
Reference in New Issue
Block a user