Skip to content

Commit 76656cb

Browse files
committed
started working on stirng escape sequences
1 parent 3026eee commit 76656cb

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ license = "MIT"
66
repository = "https://github.com/mendelsshop/umpl"
77
keywords = ["umpl", "umpl-lang"]
88
categories = ["language", "lang"]
9-
description = "Umple is a a meme language that is a mix of c like languages and lisp like languages."
9+
description = "Umpl is a a meme language that is a mix of c like languages and lisp like languages."
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

src/lexer.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,67 @@ impl Lexer {
121121
if self.peek() == '\n' {
122122
self.line += 1;
123123
}
124-
self.advance();
124+
// check for escape sequence \` \n \\ \t \r \a \b \f \v \e \Xhh \0ooo \Uhhhhhhhh
125+
if self.peek() == '\\' {
126+
self.source.remove(self.current);
127+
if self.peek() == '`' {
128+
self.advance();
129+
} else if self.peek() == 'n' {
130+
self.source.remove(self.current);
131+
self.source.insert(self.current, '\n');
132+
self.advance();
133+
self.line += 1;
134+
} else if self.peek() == '\\' {
135+
self.source.remove(self.current);
136+
self.source.insert(self.current, '\\');
137+
self.advance();
138+
} else if self.peek() == 't' {
139+
self.source.remove(self.current);
140+
self.source.insert(self.current, '\t');
141+
self.advance();
142+
} else if self.peek() == 'r' {
143+
self.source.remove(self.current);
144+
self.source.insert(self.current, '\r');
145+
self.advance();
146+
} else if self.peek() == 'a' {
147+
self.source.remove(self.current);
148+
self.source.insert(self.current, '\x07');
149+
self.advance();
150+
} else if self.peek() == 'b' {
151+
self.source.remove(self.current);
152+
self.source.insert(self.current, '\x08');
153+
self.advance();
154+
} else if self.peek() == 'f' {
155+
self.source.remove(self.current);
156+
self.source.insert(self.current, '\x0C');
157+
self.advance();
158+
} else if self.peek() == 'v' {
159+
self.source.remove(self.current);
160+
self.source.insert(self.current, '\x0b');
161+
self.advance();
162+
} else if self.peek() == 'e' {
163+
self.source.remove(self.current);
164+
self.source.insert(self.current, '\x1b');
165+
self.advance();
166+
} else if self.peek() == 'X' {
167+
todo!();
168+
} else if self.peek() == 'O' {
169+
todo!();
170+
} else if self.peek() == 'U' {
171+
todo!();
172+
} else {
173+
error::error(self.line, format!("unknown escape sequence {}", self.peek()));
174+
}
175+
} else {
176+
self.advance();
177+
}
178+
179+
// self.advance();
125180
}
126181
if self.is_at_end() {
127182
error::error(self.line, "unterminated string");
128183
}
184+
// println!("{}", self.get_text());
129185
self.advance();
130186
self.start += 1;
131187
self.current -= 1;

umpl_examples/simple.umpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
create num with 1
22
(( multiply 0xA6.A7 6 66 (minus 5)))>
3-
create str with ((multiply `ff\n ` 5.76))>
4-
((plus str ` ` 5 ` ` true ` ` hempty))>
3+
create str with ((multiply `ff\n` 5.76))>
4+
((plus str `` 5 ` ` true ` ` hempty))>
55
((not true))>
66
(5)>
77
((and(eq true true) true))>
@@ -13,7 +13,7 @@ create str with ((multiply `ff\n ` 5.76))>
1313
(4)>>
1414
create str with `df`
1515
(str)>
16-
(`fdff`)>
16+
(`fdff\a `)>
1717
((multiplywith str 5))<
1818
(str)>>
1919
((addwith str 5))<

0 commit comments

Comments
 (0)