1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use crate::error::{RableError, Result};
use super::Lexer;
impl Lexer {
/// Reads contents of a single-quoted string (after the opening `'`).
pub(super) fn read_single_quoted(&mut self, value: &mut String) -> Result<()> {
loop {
match self.advance_char() {
Some('\'') => {
value.push('\'');
return Ok(());
}
Some(c) => value.push(c),
None => {
return Err(RableError::matched_pair(
"unterminated single quote",
self.pos,
self.line,
));
}
}
}
}
/// Reads contents of an ANSI-C quoted string `$'...'` (after the opening `'`).
/// Unlike regular single quotes, `\` is an escape character here.
pub(super) fn read_ansi_c_quoted(&mut self, value: &mut String) -> Result<()> {
loop {
match self.peek_char() {
Some('\'') => {
self.advance_char();
value.push('\'');
return Ok(());
}
Some('\\') => {
self.advance_char();
value.push('\\');
if let Some(next) = self.advance_char() {
value.push(next);
}
}
Some(c) => {
self.advance_char();
value.push(c);
}
None => {
return Err(RableError::matched_pair(
"unterminated ANSI-C quote",
self.pos,
self.line,
));
}
}
}
}
/// Reads contents of a double-quoted string (after the opening `"`).
pub(super) fn read_double_quoted(&mut self, value: &mut String) -> Result<()> {
loop {
match self.peek_char() {
Some('"') => {
self.advance_char();
value.push('"');
return Ok(());
}
Some('\\') => {
self.advance_char();
// Line continuation: \<newline> is removed in double quotes
if self.peek_char() == Some('\n') {
self.advance_char();
} else {
value.push('\\');
if let Some(next) = self.advance_char() {
value.push(next);
}
}
}
Some('$') => {
self.read_dollar(value)?;
}
Some('`') => {
self.advance_char();
value.push('`');
self.read_backtick(value)?;
}
Some(c) => {
self.advance_char();
value.push(c);
}
None => {
return Err(RableError::matched_pair(
"unterminated double quote",
self.pos,
self.line,
));
}
}
}
}
}