Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix #4157: handle error in case of unsupported format #4474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 47 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
eb5dd55
Fix clippy issues for rust 1.67 (#4478)
DimitrisJim Jan 31, 2023
1d0cb29
feat: allow not set SIGINT handler
discord9 Jan 6, 2023
844ff75
feat: impl Detail option for not set SIG_INT
discord9 Jan 31, 2023
3a08ff1
use qualname in `TypeErrors` for functions (#4476)
nicku12345 Feb 1, 2023
29e322b
Match on ascii start/continuation characters before calling functions.
DimitrisJim Jan 29, 2023
516c41d
Don't call is_emoji_presentation for each invocation of consume_normal
DimitrisJim Jan 29, 2023
a3eb988
Add initial capacities, use u32s for indents/spaces.
DimitrisJim Jan 29, 2023
6ba8191
Eat for comma.
DimitrisJim Jan 30, 2023
4c37307
Hint that the unwrap should always succeed.
DimitrisJim Feb 1, 2023
2cb6634
use workspace dependencies
youknowone Feb 6, 2023
2ce349d
Bump openssl-src from 111.24.0+1.1.1s to 111.25.0+1.1.1t
dependabot[bot] Feb 8, 2023
01380bf
Move NewLineHandler inline, don't check each character twice.
DimitrisJim Feb 6, 2023
8ef74d6
Document lexer.
DimitrisJim Feb 7, 2023
0d3ff4d
Try to fix mac build
youknowone Jan 22, 2023
c682063
update libffi
youknowone Jan 22, 2023
1f9a48f
bump up openssl and libffi
youknowone Jan 22, 2023
600a3da
skip run rust tests for macOS CI
youknowone Feb 9, 2023
585d8f2
Simplify examples/call_between_rust_and_python
youknowone Feb 9, 2023
a7ebb80
Skip linking ssl on mac runner.
DimitrisJim Feb 9, 2023
4c96416
Use entire range for generators-as-arguments
charliermarsh Feb 10, 2023
c1defc1
Add test_generator_expression_argument
youknowone Feb 10, 2023
37b4e97
Refactor: Join string and string_parser.
DimitrisJim Feb 11, 2023
deca153
Document parser crate.
DimitrisJim Feb 7, 2023
595897c
fix the typos
howjmay Feb 12, 2023
e53e891
Add tests, some comments, to function.rs.
DimitrisJim Feb 11, 2023
9fc54fd
extra_tests/snippets/{builtins => builtin_eval}.py
youknowone Feb 13, 2023
a8d63ff
remove duplicated tests from tests/stdlib_math.py
youknowone Feb 13, 2023
1b6d45d
Remove completed TODO
youknowone Feb 13, 2023
6871964
wrap_index without abs
youknowone Jun 10, 2022
6731150
optimize str.(l|r)strip
youknowone Feb 13, 2023
0c7324e
Fix aarch64 compatibility for sqlite.
jonathanslenders Feb 13, 2023
c45bcfa
Fix str.join with str subclass
youknowone Feb 13, 2023
96178a1
Add co_freevars to code object
minhrongcon2000 Feb 16, 2023
9ac6e99
Fix code linting
minhrongcon2000 Feb 16, 2023
c5a629b
Add co_cellvars to code object
howjmay Feb 15, 2023
1755f04
Fix unexpected success in test_future.
DimitrisJim Feb 16, 2023
390c8da
Use nix for more things
coolreader18 Feb 9, 2023
8bac26f
Tidy up ssl a little
coolreader18 Feb 16, 2023
39ddc50
Run cargo-update
coolreader18 Feb 16, 2023
59c7536
PyObjectRef::downcast_exact returns PyRefExact
youknowone Feb 14, 2023
c97d504
Add description for PyRefExact
youknowone Feb 16, 2023
ef5ba76
Optimize Py<PyDict>::to_attributes() to reuse PyRefExact
xiaozhiyan Feb 16, 2023
b1f41c1
Optimize bytes-like (l|r)strip (#4500)
dannasman Feb 17, 2023
900f49a
narrow publicity of BytesInner::elements
youknowone Feb 17, 2023
ad0b15e
remove unnecessary to_vec()
dannasman Feb 17, 2023
5b17bd6
Handle panic in case of unsupported format in chrono
itsankitkp Jan 27, 2023
d4a6d39
feat! add test case for unsupported time format
itsankitkp Jan 31, 2023
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
Prev Previous commit
Next Next commit
Move NewLineHandler inline, don't check each character twice.
  • Loading branch information
DimitrisJim authored and itsankitkp committed Feb 19, 2023
commit 01380bfd671ab02d24b7f0ae94d0fb225904ee6e
146 changes: 59 additions & 87 deletions 146 compiler/parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ where
*self.window.last_mut().expect("never empty") = next;
next
}

fn change_first(&mut self, ch: char) {
*self.window.first_mut().expect("never empty") = Some(ch);
}
}

impl<T, const N: usize, Idx> Index<Idx> for CharWindow<T, N>
Expand All @@ -135,7 +131,6 @@ where

pub struct Lexer<T: Iterator<Item = char>> {
window: CharWindow<T, 3>,

at_begin_of_line: bool,
nesting: usize, // Amount of parenthesis
indentations: Indentations,
Expand All @@ -160,60 +155,7 @@ pub fn make_tokenizer_located(
source: &str,
start_location: Location,
) -> impl Iterator<Item = LexResult> + '_ {
let nlh = NewlineHandler::new(source.chars());
Lexer::new(nlh, start_location)
}

// The newline handler is an iterator which collapses different newline
// types into \n always.
pub struct NewlineHandler<T: Iterator<Item = char>> {
window: CharWindow<T, 2>,
}

impl<T> NewlineHandler<T>
where
T: Iterator<Item = char>,
{
pub fn new(source: T) -> Self {
let mut nlh = NewlineHandler {
window: CharWindow::new(source),
};
nlh.shift();
nlh.shift();
nlh
}

fn shift(&mut self) -> Option<char> {
let result = self.window[0];
self.window.slide();
result
}
}

impl<T> Iterator for NewlineHandler<T>
where
T: Iterator<Item = char>,
{
type Item = char;

fn next(&mut self) -> Option<Self::Item> {
// Collapse \r\n into \n
loop {
match self.window[..2] {
[Some('\r'), Some('\n')] => {
// Windows EOL into \n
self.shift();
}
[Some('\r'), _] => {
// MAC EOL into \n
self.window.change_first('\n');
}
_ => break,
}
}

self.shift()
}
Lexer::new(source.chars(), start_location)
}

impl<T> Lexer<T>
Expand Down Expand Up @@ -446,10 +388,9 @@ where
fn lex_comment(&mut self) -> LexResult {
let start_pos = self.get_pos();
let mut value = String::new();
value.push(self.next_char().unwrap());
loop {
match self.window[0] {
Some('\n') | None => {
Some('\n' | '\r') | None => {
let end_pos = self.get_pos();
return Ok((start_pos, Tok::Comment(value), end_pos));
}
Expand Down Expand Up @@ -487,7 +428,6 @@ where
continue;
}
}

if c == '\n' && !triple_quoted {
return Err(LexicalError {
error: LexicalErrorType::OtherError(
Expand Down Expand Up @@ -613,7 +553,7 @@ where
spaces = 0;
tabs = 0;
}
Some('\n') => {
Some('\n' | '\r') => {
// Empty line!
self.next_char();
spaces = 0;
Expand Down Expand Up @@ -1059,7 +999,7 @@ where
}
}
}
'\n' => {
'\n' | '\r' => {
let tok_start = self.get_pos();
self.next_char();
let tok_end = self.get_pos();
Expand All @@ -1082,13 +1022,16 @@ where
}
'\\' => {
self.next_char();
if let Some('\n') = self.window[0] {
self.next_char();
} else {
return Err(LexicalError {
error: LexicalErrorType::LineContinuationError,
location: self.get_pos(),
});
match self.window[0] {
Some('\n' | '\r') => {
self.next_char();
}
_ => {
return Err(LexicalError {
error: LexicalErrorType::LineContinuationError,
location: self.get_pos(),
})
}
}

if self.window[0].is_none() {
Expand Down Expand Up @@ -1136,12 +1079,22 @@ where

/// Helper function to go to the next character coming up.
fn next_char(&mut self) -> Option<char> {
let c = self.window[0];
let mut c = self.window[0];
self.window.slide();
if c == Some('\n') {
self.location.newline();
} else {
self.location.go_right();
match c {
Some('\n') => {
self.location.newline();
}
Some('\r') => {
if self.window[0] == Some('\n') {
self.window.slide();
}
self.location.newline();
c = Some('\n');
}
_ => {
self.location.go_right();
}
}
c
}
Expand Down Expand Up @@ -1189,7 +1142,7 @@ where

#[cfg(test)]
mod tests {
use super::{make_tokenizer, NewlineHandler, StringKind, Tok};
use super::{make_tokenizer, StringKind, Tok};
use num_bigint::BigInt;

const WINDOWS_EOL: &str = "\r\n";
Expand All @@ -1201,16 +1154,6 @@ mod tests {
lexer.map(|x| x.unwrap().1).collect()
}

#[test]
fn test_newline_processor() {
// Escape \ followed by \n (by removal):
let src = "b\\\r\n";
assert_eq!(4, src.len());
let nlh = NewlineHandler::new(src.chars());
let x: Vec<char> = nlh.collect();
assert_eq!(vec!['b', '\\', '\n'], x);
}

fn stok(s: &str) -> Tok {
Tok::String {
value: s.to_owned(),
Expand Down Expand Up @@ -1645,4 +1588,33 @@ mod tests {
let tokens = lex_source(source);
assert_eq!(tokens, vec![stok(r"\N{EN SPACE}"), Tok::Newline])
}

macro_rules! test_triple_quoted {
($($name:ident: $eol:expr,)*) => {
$(
#[test]
fn $name() {
let source = format!("\"\"\"{0} test string{0} \"\"\"", $eol);
let tokens = lex_source(&source);
assert_eq!(
tokens,
vec![
Tok::String {
value: "\n test string\n ".to_owned(),
kind: StringKind::String,
triple_quoted: true,
},
Tok::Newline,
]
)
}
)*
}
}

test_triple_quoted! {
test_triple_quoted_windows_eol: WINDOWS_EOL,
test_triple_quoted_mac_eol: MAC_EOL,
test_triple_quoted_unix_eol: UNIX_EOL,
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.