From 70f8e04af3eecfff4a52720ca35594f502def58c Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 16 Mar 2023 21:27:02 +0900 Subject: [PATCH] Update cspell for compiler --- ast/src/unparse.rs | 30 ++--- codegen/src/compile.rs | 102 +++++++-------- codegen/src/ir.rs | 17 +-- ...pile__tests__nested_double_async_with.snap | 4 +- codegen/src/symboltable.rs | 22 ++-- core/src/bytecode.rs | 116 +++++++++--------- core/src/location.rs | 2 +- parser/build.rs | 2 +- parser/src/lexer.rs | 41 ++++--- parser/src/parser.rs | 12 +- ...python_parser__context__tests__assign.snap | 42 ------- ...unction__tests__function_kw_only_args.snap | 1 - ...__function_kw_only_args_with_defaults.snap | 1 - ...er__parser__tests__parse_bool_op_and.snap} | 0 ...ser__parser__tests__parse_bool_op_or.snap} | 0 ...on_parser__parser__tests__parse_empty.snap | 2 +- ...hon_parser__parser__tests__star_index.snap | 78 ++++++------ ..._fstring_parse_self_documenting_base.snap} | 1 - ...ing_parse_self_documenting_base_more.snap} | 1 - ...string_parse_self_documenting_format.snap} | 1 - ...r__string__tests__parse_empty_fstring.snap | 1 - ..._parser__string__tests__parse_fstring.snap | 1 - ...__string__tests__parse_fstring_equals.snap | 1 - ...ing__tests__parse_fstring_nested_spec.snap | 1 - ...ring__tests__parse_fstring_not_equals.snap | 1 - ..._tests__parse_fstring_not_nested_spec.snap | 1 - ...s__parse_fstring_self_doc_prec_space.snap} | 1 - ...arse_fstring_self_doc_trailing_space.snap} | 1 - ...ring__tests__parse_fstring_yield_expr.snap | 1 - parser/src/soft_keywords.rs | 2 +- parser/src/string.rs | 30 ++--- src/lib.rs | 2 +- 32 files changed, 234 insertions(+), 284 deletions(-) delete mode 100644 parser/src/snapshots/rustpython_parser__context__tests__assign.snap rename parser/src/snapshots/{rustpython_parser__parser__tests__parse_boolop_and.snap => rustpython_parser__parser__tests__parse_bool_op_and.snap} (100%) rename parser/src/snapshots/{rustpython_parser__parser__tests__parse_boolop_or.snap => rustpython_parser__parser__tests__parse_bool_op_or.snap} (100%) rename parser/src/snapshots/{rustpython_parser__string__tests__fstring_parse_selfdocumenting_base.snap => rustpython_parser__string__tests__fstring_parse_self_documenting_base.snap} (98%) rename parser/src/snapshots/{rustpython_parser__string__tests__fstring_parse_selfdocumenting_base_more.snap => rustpython_parser__string__tests__fstring_parse_self_documenting_base_more.snap} (99%) rename parser/src/snapshots/{rustpython_parser__string__tests__fstring_parse_selfdocumenting_format.snap => rustpython_parser__string__tests__fstring_parse_self_documenting_format.snap} (99%) rename parser/src/snapshots/{rustpython_parser__string__tests__parse_fstring_selfdoc_prec_space.snap => rustpython_parser__string__tests__parse_fstring_self_doc_prec_space.snap} (98%) rename parser/src/snapshots/{rustpython_parser__string__tests__parse_fstring_selfdoc_trailing_space.snap => rustpython_parser__string__tests__parse_fstring_self_doc_trailing_space.snap} (98%) diff --git a/ast/src/unparse.rs b/ast/src/unparse.rs index b8b3420..081c2a9 100644 --- a/ast/src/unparse.rs +++ b/ast/src/unparse.rs @@ -48,10 +48,10 @@ impl<'a> Unparser<'a> { } fn unparse_expr(&mut self, ast: &Expr, level: u8) -> fmt::Result { - macro_rules! opprec { - ($opty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => { + macro_rules! op_prec { + ($op_ty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => { match $x { - $(<$enu>::$var => (opprec!(@space $opty, $op), precedence::$prec),)* + $(<$enu>::$var => (op_prec!(@space $op_ty, $op), precedence::$prec),)* } }; (@space bin, $op:literal) => { @@ -72,7 +72,7 @@ impl<'a> Unparser<'a> { } match &ast.node { ExprKind::BoolOp { op, values } => { - let (op, prec) = opprec!(bin, op, Boolop, And("and", AND), Or("or", OR)); + let (op, prec) = op_prec!(bin, op, Boolop, And("and", AND), Or("or", OR)); group_if!(prec, { let mut first = true; for val in values { @@ -89,8 +89,8 @@ impl<'a> Unparser<'a> { }) } ExprKind::BinOp { left, op, right } => { - let rassoc = matches!(op, Operator::Pow); - let (op, prec) = opprec!( + let right_associative = matches!(op, Operator::Pow); + let (op, prec) = op_prec!( bin, op, Operator, @@ -109,13 +109,13 @@ impl<'a> Unparser<'a> { FloorDiv("//", TERM), ); group_if!(prec, { - self.unparse_expr(left, prec + rassoc as u8)?; + self.unparse_expr(left, prec + right_associative as u8)?; self.p(op)?; - self.unparse_expr(right, prec + !rassoc as u8)?; + self.unparse_expr(right, prec + !right_associative as u8)?; }) } ExprKind::UnaryOp { op, operand } => { - let (op, prec) = opprec!( + let (op, prec) = op_prec!( un, op, crate::Unaryop, @@ -131,8 +131,8 @@ impl<'a> Unparser<'a> { } ExprKind::Lambda { args, body } => { group_if!(precedence::TEST, { - let npos = args.args.len() + args.posonlyargs.len(); - self.p(if npos > 0 { "lambda " } else { "lambda" })?; + let pos = args.args.len() + args.posonlyargs.len(); + self.p(if pos > 0 { "lambda " } else { "lambda" })?; self.unparse_args(args)?; write!(self, ": {}", **body)?; }) @@ -260,7 +260,7 @@ impl<'a> Unparser<'a> { [], ) = (&**args, &**keywords) { - // make sure a single genexp doesn't get double parens + // make sure a single genexpr doesn't get double parens self.unparse_expr(elt, precedence::TEST)?; self.unparse_comp(generators)?; } else { @@ -287,7 +287,7 @@ impl<'a> Unparser<'a> { conversion, format_spec, } => self.unparse_formatted(value, *conversion, format_spec.as_deref())?, - ExprKind::JoinedStr { values } => self.unparse_joinedstr(values, false)?, + ExprKind::JoinedStr { values } => self.unparse_joined_str(values, false)?, ExprKind::Constant { value, kind } => { if let Some(kind) = kind { self.p(kind)?; @@ -490,7 +490,7 @@ impl<'a> Unparser<'a> { unreachable!() } } - ExprKind::JoinedStr { values } => self.unparse_joinedstr(values, is_spec), + ExprKind::JoinedStr { values } => self.unparse_joined_str(values, is_spec), ExprKind::FormattedValue { value, conversion, @@ -505,7 +505,7 @@ impl<'a> Unparser<'a> { self.p(&s) } - fn unparse_joinedstr(&mut self, values: &[Expr], is_spec: bool) -> fmt::Result { + fn unparse_joined_str(&mut self, values: &[Expr], is_spec: bool) -> fmt::Result { if is_spec { self.unparse_fstring_body(values, is_spec) } else { diff --git a/codegen/src/compile.rs b/codegen/src/compile.rs index f92e3b1..4d94096 100644 --- a/codegen/src/compile.rs +++ b/codegen/src/compile.rs @@ -189,14 +189,14 @@ macro_rules! emit { ($c:expr, Instruction::$op:ident { $arg:ident$(,)? }$(,)?) => { $c.emit_arg($arg, |x| Instruction::$op { $arg: x }) }; - ($c:expr, Instruction::$op:ident { $arg:ident : $argval:expr $(,)? }$(,)?) => { - $c.emit_arg($argval, |x| Instruction::$op { $arg: x }) + ($c:expr, Instruction::$op:ident { $arg:ident : $arg_val:expr $(,)? }$(,)?) => { + $c.emit_arg($arg_val, |x| Instruction::$op { $arg: x }) }; - ($c:expr, Instruction::$op:ident( $argval:expr $(,)? )$(,)?) => { - $c.emit_arg($argval, Instruction::$op) + ($c:expr, Instruction::$op:ident( $arg_val:expr $(,)? )$(,)?) => { + $c.emit_arg($arg_val, Instruction::$op) }; ($c:expr, Instruction::$op:ident$(,)?) => { - $c.emit_noarg(Instruction::$op) + $c.emit_no_arg(Instruction::$op) }; } @@ -331,7 +331,7 @@ impl Compiler { cache: impl FnOnce(&mut ir::CodeInfo) -> &mut IndexSet, ) -> bytecode::NameIdx { let name = self.mangle(name); - let cache = cache(self.current_codeinfo()); + let cache = cache(self.current_code_info()); cache .get_index_of(name.as_ref()) .unwrap_or_else(|| cache.insert_full(name.into_owned()).0) @@ -821,7 +821,7 @@ impl Compiler { Some(v) => { if self.ctx.func == FunctionContext::AsyncFunction && self - .current_codeinfo() + .current_code_info() .flags .contains(bytecode::CodeFlags::IS_GENERATOR) { @@ -929,12 +929,12 @@ impl Compiler { ); } - let mut funcflags = bytecode::MakeFunctionFlags::empty(); + let mut func_flags = bytecode::MakeFunctionFlags::empty(); if have_defaults { - funcflags |= bytecode::MakeFunctionFlags::DEFAULTS; + func_flags |= bytecode::MakeFunctionFlags::DEFAULTS; } if !args.kw_defaults.is_empty() { - funcflags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS; + func_flags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS; } self.push_output( @@ -954,15 +954,15 @@ impl Compiler { } if let Some(name) = args.vararg.as_deref() { - self.current_codeinfo().flags |= bytecode::CodeFlags::HAS_VARARGS; + self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARARGS; self.varname(&name.node.arg)?; } if let Some(name) = args.kwarg.as_deref() { - self.current_codeinfo().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS; + self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS; self.varname(&name.node.arg)?; } - Ok(funcflags) + Ok(func_flags) } fn prepare_decorators(&mut self, decorator_list: &[ast::Expr]) -> CompileResult<()> { @@ -1133,8 +1133,8 @@ impl Compiler { // Create bytecode for this function: self.prepare_decorators(decorator_list)?; - let mut funcflags = self.enter_function(name, args)?; - self.current_codeinfo() + let mut func_flags = self.enter_function(name, args)?; + self.current_code_info() .flags .set(bytecode::CodeFlags::IS_COROUTINE, is_async); @@ -1157,7 +1157,7 @@ impl Compiler { let (doc_str, body) = split_doc(body); - self.current_codeinfo() + self.current_code_info() .constants .insert_full(ConstantData::None); @@ -1210,7 +1210,7 @@ impl Compiler { } if num_annotations > 0 { - funcflags |= bytecode::MakeFunctionFlags::ANNOTATIONS; + func_flags |= bytecode::MakeFunctionFlags::ANNOTATIONS; emit!( self, Instruction::BuildMap { @@ -1220,7 +1220,7 @@ impl Compiler { } if self.build_closure(&code) { - funcflags |= bytecode::MakeFunctionFlags::CLOSURE; + func_flags |= bytecode::MakeFunctionFlags::CLOSURE; } self.emit_constant(ConstantData::Code { @@ -1231,7 +1231,7 @@ impl Compiler { }); // Turn code object into function object: - emit!(self, Instruction::MakeFunction(funcflags)); + emit!(self, Instruction::MakeFunction(func_flags)); emit!(self, Instruction::Duplicate); self.load_docstring(doc_str); @@ -1388,10 +1388,10 @@ impl Compiler { self.qualified_path.append(global_path_prefix.as_mut()); self.ctx = prev_ctx; - let mut funcflags = bytecode::MakeFunctionFlags::empty(); + let mut func_flags = bytecode::MakeFunctionFlags::empty(); if self.build_closure(&code) { - funcflags |= bytecode::MakeFunctionFlags::CLOSURE; + func_flags |= bytecode::MakeFunctionFlags::CLOSURE; } self.emit_constant(ConstantData::Code { @@ -1402,7 +1402,7 @@ impl Compiler { }); // Turn code object into function object: - emit!(self, Instruction::MakeFunction(funcflags)); + emit!(self, Instruction::MakeFunction(func_flags)); self.emit_constant(ConstantData::Str { value: name.to_owned(), @@ -1417,7 +1417,7 @@ impl Compiler { } fn load_docstring(&mut self, doc_str: Option) { - // TODO: __doc__ must be default None and no bytecodes unless it is Some + // TODO: __doc__ must be default None and no bytecode unless it is Some // Duplicate top of stack (the function or class object) // Doc string value: @@ -1603,12 +1603,12 @@ impl Compiler { &mut self, left: &ast::Expr, ops: &[ast::Cmpop], - vals: &[ast::Expr], + exprs: &[ast::Expr], ) -> CompileResult<()> { assert!(!ops.is_empty()); - assert_eq!(vals.len(), ops.len()); + assert_eq!(exprs.len(), ops.len()); let (last_op, mid_ops) = ops.split_last().unwrap(); - let (last_val, mid_vals) = vals.split_last().unwrap(); + let (last_val, mid_exprs) = exprs.split_last().unwrap(); use bytecode::ComparisonOperator::*; use bytecode::TestOperator::*; @@ -1626,7 +1626,7 @@ impl Compiler { }; // a == b == c == d - // compile into (pseudocode): + // compile into (pseudo code): // result = a == b // if result: // result = b == c @@ -1636,7 +1636,7 @@ impl Compiler { // initialize lhs outside of loop self.compile_expression(left)?; - let end_blocks = if mid_vals.is_empty() { + let end_blocks = if mid_exprs.is_empty() { None } else { let break_block = self.new_block(); @@ -1645,7 +1645,7 @@ impl Compiler { }; // for all comparisons except the last (as the last one doesn't need a conditional jump) - for (op, val) in mid_ops.iter().zip(mid_vals) { + for (op, val) in mid_ops.iter().zip(mid_exprs) { self.compile_expression(val)?; // store rhs for the next comparison in chain emit!(self, Instruction::Duplicate); @@ -2206,7 +2206,7 @@ impl Compiler { let prev_ctx = self.ctx; let name = "".to_owned(); - let mut funcflags = self.enter_function(&name, args)?; + let mut func_flags = self.enter_function(&name, args)?; self.ctx = CompileContext { loop_data: Option::None, @@ -2214,7 +2214,7 @@ impl Compiler { func: FunctionContext::Function, }; - self.current_codeinfo() + self.current_code_info() .constants .insert_full(ConstantData::None); @@ -2222,14 +2222,14 @@ impl Compiler { emit!(self, Instruction::ReturnValue); let code = self.pop_code_object(); if self.build_closure(&code) { - funcflags |= bytecode::MakeFunctionFlags::CLOSURE; + func_flags |= bytecode::MakeFunctionFlags::CLOSURE; } self.emit_constant(ConstantData::Code { code: Box::new(code), }); self.emit_constant(ConstantData::Str { value: name }); // Turn code object into function object: - emit!(self, Instruction::MakeFunction(funcflags)); + emit!(self, Instruction::MakeFunction(func_flags)); self.ctx = prev_ctx; } @@ -2345,24 +2345,24 @@ impl Compiler { fn compile_keywords(&mut self, keywords: &[ast::Keyword]) -> CompileResult<()> { let mut size = 0; let groupby = keywords.iter().group_by(|e| e.node.arg.is_none()); - for (is_unpacking, subkeywords) in &groupby { + for (is_unpacking, sub_keywords) in &groupby { if is_unpacking { - for keyword in subkeywords { + for keyword in sub_keywords { self.compile_expression(&keyword.node.value)?; size += 1; } } else { - let mut subsize = 0; - for keyword in subkeywords { + let mut sub_size = 0; + for keyword in sub_keywords { if let Some(name) = &keyword.node.arg { self.emit_constant(ConstantData::Str { value: name.to_owned(), }); self.compile_expression(&keyword.node.value)?; - subsize += 1; + sub_size += 1; } } - emit!(self, Instruction::BuildMap { size: subsize }); + emit!(self, Instruction::BuildMap { size: sub_size }); size += 1; } } @@ -2634,9 +2634,9 @@ impl Compiler { self.ctx = prev_ctx; - let mut funcflags = bytecode::MakeFunctionFlags::empty(); + let mut func_flags = bytecode::MakeFunctionFlags::empty(); if self.build_closure(&code) { - funcflags |= bytecode::MakeFunctionFlags::CLOSURE; + func_flags |= bytecode::MakeFunctionFlags::CLOSURE; } // List comprehension code: @@ -2650,7 +2650,7 @@ impl Compiler { }); // Turn code object into function object: - emit!(self, Instruction::MakeFunction(funcflags)); + emit!(self, Instruction::MakeFunction(func_flags)); // Evaluate iterated item: self.compile_expression(&generators[0].iter)?; @@ -2694,7 +2694,7 @@ impl Compiler { }); } - fn emit_noarg(&mut self, ins: Instruction) { + fn emit_no_arg(&mut self, ins: Instruction) { self._emit(ins, OpArg::null(), ir::BlockIdx::NULL) } @@ -2710,29 +2710,29 @@ impl Compiler { // fn block_done() fn emit_constant(&mut self, constant: ConstantData) { - let info = self.current_codeinfo(); + let info = self.current_code_info(); let idx = info.constants.insert_full(constant).0.to_u32(); self.emit_arg(idx, |idx| Instruction::LoadConst { idx }) } - fn current_codeinfo(&mut self) -> &mut ir::CodeInfo { + fn current_code_info(&mut self) -> &mut ir::CodeInfo { self.code_stack.last_mut().expect("no code on stack") } fn current_block(&mut self) -> &mut ir::Block { - let info = self.current_codeinfo(); + let info = self.current_code_info(); &mut info.blocks[info.current_block] } fn new_block(&mut self) -> ir::BlockIdx { - let code = self.current_codeinfo(); + let code = self.current_code_info(); let idx = ir::BlockIdx(code.blocks.len().to_u32()); code.blocks.push(ir::Block::default()); idx } fn switch_to_block(&mut self, block: ir::BlockIdx) { - let code = self.current_codeinfo(); + let code = self.current_code_info(); let prev = code.current_block; assert_eq!( code.blocks[block].next, @@ -2762,7 +2762,7 @@ impl Compiler { } fn mark_generator(&mut self) { - self.current_codeinfo().flags |= bytecode::CodeFlags::IS_GENERATOR + self.current_code_info().flags |= bytecode::CodeFlags::IS_GENERATOR } } @@ -2882,7 +2882,7 @@ mod tests { ($value:expr) => { insta::assert_snapshot!( insta::internals::AutoName, - $value.display_expand_codeobjects().to_string(), + $value.display_expand_code_objects().to_string(), stringify!($value) ) }; @@ -2925,7 +2925,7 @@ if (True and False) or (False and True): for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')): with self.subTest(type=type(stop_exc)): try: - async with woohoo(): + async with egg(): raise stop_exc except Exception as ex: self.assertIs(ex, stop_exc) diff --git a/codegen/src/ir.rs b/codegen/src/ir.rs index 2658028..dc7e2e7 100644 --- a/codegen/src/ir.rs +++ b/codegen/src/ir.rs @@ -45,6 +45,7 @@ pub struct InstructionInfo { pub location: Location, } +// spell-checker:ignore petgraph // TODO: look into using petgraph for handling blocks and stuff? it's heavier than this, but it // might enable more analysis/optimizations #[derive(Debug)] @@ -223,12 +224,12 @@ impl CodeInfo { fn max_stackdepth(&self) -> u32 { let mut maxdepth = 0u32; let mut stack = Vec::with_capacity(self.blocks.len()); - let mut startdepths = vec![u32::MAX; self.blocks.len()]; - startdepths[0] = 0; + let mut start_depths = vec![u32::MAX; self.blocks.len()]; + start_depths[0] = 0; stack.push(BlockIdx(0)); const DEBUG: bool = false; 'process_blocks: while let Some(block) = stack.pop() { - let mut depth = startdepths[block.idx()]; + let mut depth = start_depths[block.idx()]; if DEBUG { eprintln!("===BLOCK {}===", block.0); } @@ -266,14 +267,14 @@ impl CodeInfo { if target_depth > maxdepth { maxdepth = target_depth } - stackdepth_push(&mut stack, &mut startdepths, i.target, target_depth); + stackdepth_push(&mut stack, &mut start_depths, i.target, target_depth); } depth = new_depth; if instr.unconditional_branch() { continue 'process_blocks; } } - stackdepth_push(&mut stack, &mut startdepths, block.next, depth); + stackdepth_push(&mut stack, &mut start_depths, block.next, depth); } if DEBUG { eprintln!("DONE: {maxdepth}"); @@ -293,7 +294,7 @@ impl InstrDisplayContext for CodeInfo { fn get_varname(&self, i: usize) -> &str { self.varname_cache[i].as_ref() } - fn get_cellname(&self, i: usize) -> &str { + fn get_cell_name(&self, i: usize) -> &str { self.cellvar_cache .get_index(i) .unwrap_or_else(|| &self.freevar_cache[i - self.cellvar_cache.len()]) @@ -303,11 +304,11 @@ impl InstrDisplayContext for CodeInfo { fn stackdepth_push( stack: &mut Vec, - startdepths: &mut [u32], + start_depths: &mut [u32], target: BlockIdx, depth: u32, ) { - let block_depth = &mut startdepths[target.idx()]; + let block_depth = &mut start_depths[target.idx()]; if *block_depth == u32::MAX || depth > *block_depth { *block_depth = depth; stack.push(target); diff --git a/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap b/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap index 0563b38..dcc6f4c 100644 --- a/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap +++ b/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap @@ -1,6 +1,6 @@ --- source: compiler/codegen/src/compile.rs -expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with woohoo():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")" +expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with egg():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")" --- 1 0 SetupLoop 1 LoadNameAny (0, StopIteration) @@ -26,7 +26,7 @@ expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyn 3 20 SetupExcept (40) - 4 21 LoadNameAny (6, woohoo) + 4 21 LoadNameAny (6, egg) 22 CallFunctionPositional(0) 23 BeforeAsyncWith 24 GetAwaitable diff --git a/codegen/src/symboltable.rs b/codegen/src/symboltable.rs index f2a7c42..258d357 100644 --- a/codegen/src/symboltable.rs +++ b/codegen/src/symboltable.rs @@ -16,7 +16,7 @@ use rustpython_ast as ast; use rustpython_compiler_core::Location; use std::{borrow::Cow, fmt}; -/// Captures all symbols in the current scope, and has a list of subscopes in this scope. +/// Captures all symbols in the current scope, and has a list of sub-scopes in this scope. #[derive(Clone)] pub struct SymbolTable { /// The name of this symbol table. Often the name of the class or function. @@ -25,7 +25,7 @@ pub struct SymbolTable { /// The type of symbol table pub typ: SymbolTableType, - /// The line number in the sourcecode where this symboltable begins. + /// The line number in the source code where this symboltable begins. pub line_number: usize, // Return True if the block is a nested class or function @@ -34,7 +34,7 @@ pub struct SymbolTable { /// A set of symbols present on this scope level. pub symbols: IndexMap, - /// A list of subscopes in the order as found in the + /// A list of sub-scopes in the order as found in the /// AST nodes. pub sub_tables: Vec, } @@ -107,7 +107,7 @@ bitflags! { // this is required to correct the scope in the analysis. const ASSIGNED_IN_COMPREHENSION = 0x040; // indicates that the symbol is used a bound iterator variable. We distinguish this case - // from normal assignment to detect unallowed re-assignment to iterator variables. + // from normal assignment to detect disallowed re-assignment to iterator variables. const ITER = 0x080; /// indicates that the symbol is a free variable in a class method from the scope that the /// class is defined in, e.g.: @@ -531,7 +531,7 @@ enum SymbolUsage { AnnotationAssigned, Parameter, AnnotationParameter, - AssignedNamedExprInCompr, + AssignedNamedExprInComprehension, Iter, } @@ -741,7 +741,7 @@ impl SymbolTableBuilder { Import { names } | ImportFrom { names, .. } => { for name in names { if let Some(alias) = &name.node.asname { - // `import mymodule as myalias` + // `import my_module as my_alias` self.register_name(alias, SymbolUsage::Imported, location)?; } else { // `import module` @@ -1042,7 +1042,11 @@ impl SymbolTableBuilder { if let Name { id, .. } = &target.node { let table = self.tables.last().unwrap(); if table.typ == SymbolTableType::Comprehension { - self.register_name(id, SymbolUsage::AssignedNamedExprInCompr, location)?; + self.register_name( + id, + SymbolUsage::AssignedNamedExprInComprehension, + location, + )?; } else { // omit one recursion. When the handling of an store changes for // Identifiers this needs adapted - more forward safe would be @@ -1256,7 +1260,7 @@ impl SymbolTableBuilder { SymbolUsage::Assigned => { flags.insert(SymbolFlags::ASSIGNED); } - SymbolUsage::AssignedNamedExprInCompr => { + SymbolUsage::AssignedNamedExprInComprehension => { flags.insert(SymbolFlags::ASSIGNED | SymbolFlags::ASSIGNED_IN_COMPREHENSION); } SymbolUsage::Global => { @@ -1273,7 +1277,7 @@ impl SymbolTableBuilder { // and even more checking // it is not allowed to assign to iterator variables (by named expressions) if flags.contains(SymbolFlags::ITER | SymbolFlags::ASSIGNED) - /*&& symbol.is_assign_namedexpr_in_comprehension*/ + /*&& symbol.is_assign_named_expr_in_comprehension*/ { return Err(SymbolTableError { error: diff --git a/core/src/bytecode.rs b/core/src/bytecode.rs index c01c4b8..a522d3f 100644 --- a/core/src/bytecode.rs +++ b/core/src/bytecode.rs @@ -1,4 +1,4 @@ -//! Implement python as a virtual machine with bytecodes. This module +//! Implement python as a virtual machine with bytecode. This module //! implements bytecode structure. use crate::{marshal, Location}; @@ -85,7 +85,7 @@ impl ConstantBag for BasicBag { } /// Primary container of a single code object. Each python function has -/// a codeobject. Also a module has a codeobject. +/// a code object. Also a module has a code object. #[derive(Clone)] pub struct CodeObject { pub instructions: Box<[CodeUnit]>, @@ -147,7 +147,7 @@ impl fmt::Debug for OpArgByte { } } -/// a full 32-bit oparg, including any possible ExtendedArg extension +/// a full 32-bit op_arg, including any possible ExtendedArg extension #[derive(Copy, Clone, Debug)] #[repr(transparent)] pub struct OpArg(pub u32); @@ -156,7 +156,7 @@ impl OpArg { OpArg(0) } - /// Returns how many CodeUnits a instruction with this oparg will be encoded as + /// Returns how many CodeUnits a instruction with this op_arg will be encoded as #[inline] pub fn instr_size(self) -> usize { (self.0 > 0xff) as usize + (self.0 > 0xff_ff) as usize + (self.0 > 0xff_ff_ff) as usize + 1 @@ -204,46 +204,46 @@ impl OpArgState { } pub trait OpArgType: Copy { - fn from_oparg(x: u32) -> Option; - fn to_oparg(self) -> u32; + fn from_op_arg(x: u32) -> Option; + fn to_op_arg(self) -> u32; } impl OpArgType for u32 { #[inline(always)] - fn from_oparg(x: u32) -> Option { + fn from_op_arg(x: u32) -> Option { Some(x) } #[inline(always)] - fn to_oparg(self) -> u32 { + fn to_op_arg(self) -> u32 { self } } impl OpArgType for bool { #[inline(always)] - fn from_oparg(x: u32) -> Option { + fn from_op_arg(x: u32) -> Option { Some(x != 0) } #[inline(always)] - fn to_oparg(self) -> u32 { + fn to_op_arg(self) -> u32 { self as u32 } } -macro_rules! oparg_enum { - ($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $discr:literal,)* }) => { +macro_rules! op_arg_enum { + ($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $value:literal,)* }) => { $(#[$attr])* $vis enum $name { - $($(#[$var_attr])* $var = $discr,)* + $($(#[$var_attr])* $var = $value,)* } impl OpArgType for $name { - fn to_oparg(self) -> u32 { + fn to_op_arg(self) -> u32 { self as u32 } - fn from_oparg(x: u32) -> Option { + fn from_op_arg(x: u32) -> Option { Some(match u8::try_from(x).ok()? { - $($discr => Self::$var,)* + $($value => Self::$var,)* _ => return None, }) } @@ -261,7 +261,7 @@ impl Arg { } #[inline] pub fn new(arg: T) -> (Self, OpArg) { - (Self(PhantomData), OpArg(arg.to_oparg())) + (Self(PhantomData), OpArg(arg.to_op_arg())) } #[inline] pub fn new_single(arg: T) -> (Self, OpArgByte) @@ -276,13 +276,13 @@ impl Arg { } #[inline(always)] pub fn try_get(self, arg: OpArg) -> Option { - T::from_oparg(arg.0) + T::from_op_arg(arg.0) } #[inline(always)] /// # Safety - /// T::from_oparg(self) must succeed + /// T::from_op_arg(self) must succeed pub unsafe fn get_unchecked(self, arg: OpArg) -> T { - match T::from_oparg(arg.0) { + match T::from_op_arg(arg.0) { Some(t) => t, None => std::hint::unreachable_unchecked(), } @@ -310,11 +310,11 @@ pub struct Label(pub u32); impl OpArgType for Label { #[inline(always)] - fn from_oparg(x: u32) -> Option { + fn from_op_arg(x: u32) -> Option { Some(Label(x)) } #[inline(always)] - fn to_oparg(self) -> u32 { + fn to_op_arg(self) -> u32 { self.0 } } @@ -325,7 +325,7 @@ impl fmt::Display for Label { } } -oparg_enum!( +op_arg_enum!( /// Transforms a value prior to formatting it. #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u8)] @@ -344,11 +344,11 @@ oparg_enum!( impl TryFrom for ConversionFlag { type Error = usize; fn try_from(b: usize) -> Result { - u32::try_from(b).ok().and_then(Self::from_oparg).ok_or(b) + u32::try_from(b).ok().and_then(Self::from_op_arg).ok_or(b) } } -oparg_enum!( +op_arg_enum!( /// The kind of Raise that occurred. #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u8)] @@ -634,11 +634,11 @@ bitflags! { } impl OpArgType for MakeFunctionFlags { #[inline(always)] - fn from_oparg(x: u32) -> Option { + fn from_op_arg(x: u32) -> Option { Some(unsafe { MakeFunctionFlags::from_bits_unchecked(x as u8) }) } #[inline(always)] - fn to_oparg(self) -> u32 { + fn to_op_arg(self) -> u32 { self.bits().into() } } @@ -793,7 +793,7 @@ impl BorrowedConstant<'_, C> { } } -oparg_enum!( +op_arg_enum!( /// The possible comparison operators #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(u8)] @@ -809,7 +809,7 @@ oparg_enum!( } ); -oparg_enum!( +op_arg_enum!( #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(u8)] pub enum TestOperator { @@ -822,7 +822,7 @@ oparg_enum!( } ); -oparg_enum!( +op_arg_enum!( /// The possible Binary operators /// # Examples /// @@ -850,7 +850,7 @@ oparg_enum!( } ); -oparg_enum!( +op_arg_enum!( /// The possible unary operators #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(u8)] @@ -870,12 +870,12 @@ pub struct UnpackExArgs { impl OpArgType for UnpackExArgs { #[inline(always)] - fn from_oparg(x: u32) -> Option { + fn from_op_arg(x: u32) -> Option { let [before, after, ..] = x.to_le_bytes(); Some(Self { before, after }) } #[inline(always)] - fn to_oparg(self) -> u32 { + fn to_op_arg(self) -> u32 { u32::from_le_bytes([self.before, self.after, 0, 0]) } } @@ -925,20 +925,20 @@ impl CodeObject { pub fn arg_names(&self) -> Arguments { let nargs = self.arg_count as usize; let nkwargs = self.kwonlyarg_count as usize; - let mut varargspos = nargs + nkwargs; + let mut varargs_pos = nargs + nkwargs; let posonlyargs = &self.varnames[..self.posonlyarg_count as usize]; let args = &self.varnames[..nargs]; - let kwonlyargs = &self.varnames[nargs..varargspos]; + let kwonlyargs = &self.varnames[nargs..varargs_pos]; let vararg = if self.flags.contains(CodeFlags::HAS_VARARGS) { - let vararg = &self.varnames[varargspos]; - varargspos += 1; + let vararg = &self.varnames[varargs_pos]; + varargs_pos += 1; Some(vararg) } else { None }; let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) { - Some(&self.varnames[varargspos]) + Some(&self.varnames[varargs_pos]) } else { None }; @@ -968,7 +968,7 @@ impl CodeObject { fn display_inner( &self, f: &mut fmt::Formatter, - expand_codeobjects: bool, + expand_code_objects: bool, level: usize, ) -> fmt::Result { let label_targets = self.label_targets(); @@ -1007,14 +1007,14 @@ impl CodeObject { write!(f, "{arrow} {offset:offset_digits$} ")?; // instruction - instruction.fmt_dis(arg, f, self, expand_codeobjects, 21, level)?; + instruction.fmt_dis(arg, f, self, expand_code_objects, 21, level)?; writeln!(f)?; } Ok(()) } /// Recursively display this CodeObject - pub fn display_expand_codeobjects(&self) -> impl fmt::Display + '_ { + pub fn display_expand_code_objects(&self) -> impl fmt::Display + '_ { struct Display<'a, C: Constant>(&'a CodeObject); impl fmt::Display for Display<'_, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -1287,7 +1287,7 @@ impl Instruction { arg: OpArg, f: &mut fmt::Formatter, ctx: &impl InstrDisplayContext, - expand_codeobjects: bool, + expand_code_objects: bool, pad: usize, level: usize, ) -> fmt::Result { @@ -1295,26 +1295,26 @@ impl Instruction { ($variant:ident) => { write!(f, stringify!($variant)) }; - ($variant:ident, $map:ident = $argmarker:expr) => {{ - let arg = $argmarker.get(arg); + ($variant:ident, $map:ident = $arg_marker:expr) => {{ + let arg = $arg_marker.get(arg); write!(f, "{:pad$}({}, {})", stringify!($variant), arg, $map(arg)) }}; - ($variant:ident, $argmarker:expr) => { - write!(f, "{:pad$}({})", stringify!($variant), $argmarker.get(arg)) + ($variant:ident, $arg_marker:expr) => { + write!(f, "{:pad$}({})", stringify!($variant), $arg_marker.get(arg)) }; - ($variant:ident, ?$argmarker:expr) => { + ($variant:ident, ?$arg_marker:expr) => { write!( f, "{:pad$}({:?})", stringify!($variant), - $argmarker.get(arg) + $arg_marker.get(arg) ) }; } let varname = |i: u32| ctx.get_varname(i as usize); let name = |i: u32| ctx.get_name(i as usize); - let cellname = |i: u32| ctx.get_cellname(i as usize); + let cell_name = |i: u32| ctx.get_cell_name(i as usize); match self { ImportName { idx } => w!(ImportName, name = idx), @@ -1324,17 +1324,17 @@ impl Instruction { LoadFast(idx) => w!(LoadFast, varname = idx), LoadNameAny(idx) => w!(LoadNameAny, name = idx), LoadGlobal(idx) => w!(LoadGlobal, name = idx), - LoadDeref(idx) => w!(LoadDeref, cellname = idx), - LoadClassDeref(idx) => w!(LoadClassDeref, cellname = idx), + LoadDeref(idx) => w!(LoadDeref, cell_name = idx), + LoadClassDeref(idx) => w!(LoadClassDeref, cell_name = idx), StoreFast(idx) => w!(StoreFast, varname = idx), StoreLocal(idx) => w!(StoreLocal, name = idx), StoreGlobal(idx) => w!(StoreGlobal, name = idx), - StoreDeref(idx) => w!(StoreDeref, cellname = idx), + StoreDeref(idx) => w!(StoreDeref, cell_name = idx), DeleteFast(idx) => w!(DeleteFast, varname = idx), DeleteLocal(idx) => w!(DeleteLocal, name = idx), DeleteGlobal(idx) => w!(DeleteGlobal, name = idx), - DeleteDeref(idx) => w!(DeleteDeref, cellname = idx), - LoadClosure(i) => w!(LoadClosure, cellname = i), + DeleteDeref(idx) => w!(DeleteDeref, cell_name = idx), + LoadClosure(i) => w!(LoadClosure, cell_name = i), Subscript => w!(Subscript), StoreSubscript => w!(StoreSubscript), DeleteSubscript => w!(DeleteSubscript), @@ -1343,7 +1343,7 @@ impl Instruction { LoadConst { idx } => { let value = ctx.get_constant(idx.get(arg) as usize); match value.borrow_constant() { - BorrowedConstant::Code { code } if expand_codeobjects => { + BorrowedConstant::Code { code } if expand_code_objects => { write!(f, "{:pad$}({:?}):", "LoadConst", code)?; code.display_inner(f, true, level + 1)?; Ok(()) @@ -1434,7 +1434,7 @@ pub trait InstrDisplayContext { fn get_constant(&self, i: usize) -> &Self::Constant; fn get_name(&self, i: usize) -> &str; fn get_varname(&self, i: usize) -> &str; - fn get_cellname(&self, i: usize) -> &str; + fn get_cell_name(&self, i: usize) -> &str; } impl InstrDisplayContext for CodeObject { @@ -1448,7 +1448,7 @@ impl InstrDisplayContext for CodeObject { fn get_varname(&self, i: usize) -> &str { self.varnames[i].as_ref() } - fn get_cellname(&self, i: usize) -> &str { + fn get_cell_name(&self, i: usize) -> &str { self.cellvars .get(i) .unwrap_or_else(|| &self.freevars[i - self.cellvars.len()]) @@ -1491,7 +1491,7 @@ pub mod frozen_lib { } impl> FrozenCodeObject { - /// Decode a frozen codeobject + /// Decode a frozen code object #[inline] pub fn decode( &self, diff --git a/core/src/location.rs b/core/src/location.rs index a6e7d39..3384139 100644 --- a/core/src/location.rs +++ b/core/src/location.rs @@ -1,7 +1,7 @@ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -/// Sourcecode location. +/// Source code location. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Location { diff --git a/parser/build.rs b/parser/build.rs index e693601..1ef1d53 100644 --- a/parser/build.rs +++ b/parser/build.rs @@ -112,7 +112,7 @@ fn gen_phf(out_dir: &Path) { .entry("False", "Tok::False") .entry("None", "Tok::None") .entry("True", "Tok::True") - // moreso "standard" keywords + // more so "standard" keywords .entry("and", "Tok::And") .entry("as", "Tok::As") .entry("assert", "Tok::Assert") diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index 45f5ca8..38b1d53 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -241,6 +241,7 @@ where lxr.window.slide(); lxr.window.slide(); // TODO: Handle possible mismatch between BOM and explicit encoding declaration. + // spell-checker:ignore feff if let Some('\u{feff}') = lxr.window[0] { lxr.window.slide(); } @@ -1085,7 +1086,7 @@ where } } ' ' | '\t' | '\x0C' => { - // Skip whitespaces + // Skip white-spaces self.next_char(); while let Some(' ' | '\t' | '\x0C') = self.window[0] { self.next_char(); @@ -1327,7 +1328,7 @@ mod tests { lexer.map(|x| x.unwrap().1).collect() } - fn stok(s: &str) -> Tok { + fn str_tok(s: &str) -> Tok { Tok::String { value: s.to_owned(), kind: StringKind::String, @@ -1335,7 +1336,7 @@ mod tests { } } - fn raw_stok(s: &str) -> Tok { + fn raw_str_tok(s: &str) -> Tok { Tok::String { value: s.to_owned(), kind: StringKind::RawString, @@ -1434,13 +1435,13 @@ mod tests { #[test] fn test_assignment() { - let source = r"avariable = 99 + 2-0"; + let source = r"a_variable = 99 + 2-0"; let tokens = lex_source(source); assert_eq!( tokens, vec![ Tok::Name { - name: String::from("avariable"), + name: String::from("a_variable"), }, Tok::Equal, Tok::Int { @@ -1663,13 +1664,13 @@ mod tests { vec![ Tok::Lpar, Tok::NonLogicalNewline, - stok("a"), + str_tok("a"), Tok::NonLogicalNewline, - stok("b"), + str_tok("b"), Tok::NonLogicalNewline, Tok::NonLogicalNewline, - stok("c"), - stok("d"), + str_tok("c"), + str_tok("d"), Tok::NonLogicalNewline, Tok::Rpar, Tok::Newline, @@ -1716,15 +1717,15 @@ mod tests { assert_eq!( tokens, vec![ - stok("double"), - stok("single"), - stok(r"can\'t"), - stok(r#"\\\""#), - stok(r"\t\r\n"), - stok(r"\g"), - raw_stok(r"raw\'"), - stok(r"\420"), - stok(r"\200\0a"), + str_tok("double"), + str_tok("single"), + str_tok(r"can\'t"), + str_tok(r#"\\\""#), + str_tok(r"\t\r\n"), + str_tok(r"\g"), + raw_str_tok(r"raw\'"), + str_tok(r"\420"), + str_tok(r"\200\0a"), Tok::Newline, ] ); @@ -1740,7 +1741,7 @@ mod tests { assert_eq!( tokens, vec![ - stok("abc\\\ndef"), + str_tok("abc\\\ndef"), Tok::Newline, ] ) @@ -1759,7 +1760,7 @@ mod tests { fn test_escape_unicode_name() { let source = r#""\N{EN SPACE}""#; let tokens = lex_source(source); - assert_eq!(tokens, vec![stok(r"\N{EN SPACE}"), Tok::Newline]) + assert_eq!(tokens, vec![str_tok(r"\N{EN SPACE}"), Tok::Newline]) } macro_rules! test_triple_quoted { diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 6376e04..b9c0bc0 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -433,14 +433,14 @@ class Foo(A, B): } #[test] - fn test_parse_boolop_or() { + fn test_parse_bool_op_or() { let source = "x or y"; let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] - fn test_parse_boolop_and() { + fn test_parse_bool_op_and() { let source = "x and y"; let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); @@ -513,10 +513,10 @@ with (0 as a, 1 as b,): pass #[test] fn test_star_index() { let source = "\ -array_slice = array[0, *idxs, -1] -array[0, *idxs, -1] = array_slice -array[*idxs_to_select, *idxs_to_select] -array[3:5, *idxs_to_select] +array_slice = array[0, *indexes, -1] +array[0, *indexes, -1] = array_slice +array[*indexes_to_select, *indexes_to_select] +array[3:5, *indexes_to_select] "; let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); diff --git a/parser/src/snapshots/rustpython_parser__context__tests__assign.snap b/parser/src/snapshots/rustpython_parser__context__tests__assign.snap deleted file mode 100644 index a9fe441..0000000 --- a/parser/src/snapshots/rustpython_parser__context__tests__assign.snap +++ /dev/null @@ -1,42 +0,0 @@ ---- -source: compiler/parser/src/context.rs -expression: parse_ast ---- -[ - Located { - location: Location { - row: 1, - column: 1, - }, - custom: (), - node: Assign { - targets: [ - Located { - location: Location { - row: 1, - column: 1, - }, - custom: (), - node: Name { - id: "x", - ctx: Store, - }, - }, - ], - value: Located { - location: Location { - row: 1, - column: 5, - }, - custom: (), - node: Constant { - value: Int( - 1, - ), - kind: None, - }, - }, - type_comment: None, - }, - }, -] diff --git a/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args.snap b/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args.snap index bfb7074..2b990fa 100644 --- a/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args.snap +++ b/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/function.rs -assertion_line: 165 expression: parse_ast --- Ok( diff --git a/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args_with_defaults.snap b/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args_with_defaults.snap index 2004bbe..08fa27e 100644 --- a/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args_with_defaults.snap +++ b/parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args_with_defaults.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/function.rs -assertion_line: 165 expression: parse_ast --- Ok( diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_bool_op_and.snap similarity index 100% rename from parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap rename to parser/src/snapshots/rustpython_parser__parser__tests__parse_bool_op_and.snap diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_bool_op_or.snap similarity index 100% rename from parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap rename to parser/src/snapshots/rustpython_parser__parser__tests__parse_bool_op_or.snap diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_empty.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_empty.snap index 64d89c1..17be8fe 100644 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_empty.snap +++ b/parser/src/snapshots/rustpython_parser__parser__tests__parse_empty.snap @@ -1,5 +1,5 @@ --- -source: parser/src/parser.rs +source: compiler/parser/src/parser.rs expression: parse_ast --- [] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__star_index.snap b/parser/src/snapshots/rustpython_parser__parser__tests__star_index.snap index 6aed23b..897edb2 100644 --- a/parser/src/snapshots/rustpython_parser__parser__tests__star_index.snap +++ b/parser/src/snapshots/rustpython_parser__parser__tests__star_index.snap @@ -11,7 +11,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 33, + column: 36, }, ), custom: (), @@ -43,7 +43,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 33, + column: 36, }, ), custom: (), @@ -73,7 +73,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 32, + column: 35, }, ), custom: (), @@ -106,7 +106,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 28, + column: 31, }, ), custom: (), @@ -119,12 +119,12 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 28, + column: 31, }, ), custom: (), node: Name { - id: "idxs", + id: "indexes", ctx: Load, }, }, @@ -134,12 +134,12 @@ expression: parse_ast Located { location: Location { row: 1, - column: 30, + column: 33, }, end_location: Some( Location { row: 1, - column: 32, + column: 35, }, ), custom: (), @@ -148,12 +148,12 @@ expression: parse_ast operand: Located { location: Location { row: 1, - column: 31, + column: 34, }, end_location: Some( Location { row: 1, - column: 32, + column: 35, }, ), custom: (), @@ -184,7 +184,7 @@ expression: parse_ast end_location: Some( Location { row: 2, - column: 33, + column: 36, }, ), custom: (), @@ -198,7 +198,7 @@ expression: parse_ast end_location: Some( Location { row: 2, - column: 19, + column: 22, }, ), custom: (), @@ -228,7 +228,7 @@ expression: parse_ast end_location: Some( Location { row: 2, - column: 18, + column: 21, }, ), custom: (), @@ -261,7 +261,7 @@ expression: parse_ast end_location: Some( Location { row: 2, - column: 14, + column: 17, }, ), custom: (), @@ -274,12 +274,12 @@ expression: parse_ast end_location: Some( Location { row: 2, - column: 14, + column: 17, }, ), custom: (), node: Name { - id: "idxs", + id: "indexes", ctx: Load, }, }, @@ -289,12 +289,12 @@ expression: parse_ast Located { location: Location { row: 2, - column: 16, + column: 19, }, end_location: Some( Location { row: 2, - column: 18, + column: 21, }, ), custom: (), @@ -303,12 +303,12 @@ expression: parse_ast operand: Located { location: Location { row: 2, - column: 17, + column: 20, }, end_location: Some( Location { row: 2, - column: 18, + column: 21, }, ), custom: (), @@ -332,12 +332,12 @@ expression: parse_ast value: Located { location: Location { row: 2, - column: 22, + column: 25, }, end_location: Some( Location { row: 2, - column: 33, + column: 36, }, ), custom: (), @@ -357,7 +357,7 @@ expression: parse_ast end_location: Some( Location { row: 3, - column: 39, + column: 45, }, ), custom: (), @@ -370,7 +370,7 @@ expression: parse_ast end_location: Some( Location { row: 3, - column: 39, + column: 45, }, ), custom: (), @@ -400,7 +400,7 @@ expression: parse_ast end_location: Some( Location { row: 3, - column: 38, + column: 44, }, ), custom: (), @@ -414,7 +414,7 @@ expression: parse_ast end_location: Some( Location { row: 3, - column: 21, + column: 24, }, ), custom: (), @@ -427,12 +427,12 @@ expression: parse_ast end_location: Some( Location { row: 3, - column: 21, + column: 24, }, ), custom: (), node: Name { - id: "idxs_to_select", + id: "indexes_to_select", ctx: Load, }, }, @@ -442,12 +442,12 @@ expression: parse_ast Located { location: Location { row: 3, - column: 23, + column: 26, }, end_location: Some( Location { row: 3, - column: 38, + column: 44, }, ), custom: (), @@ -455,17 +455,17 @@ expression: parse_ast value: Located { location: Location { row: 3, - column: 24, + column: 27, }, end_location: Some( Location { row: 3, - column: 38, + column: 44, }, ), custom: (), node: Name { - id: "idxs_to_select", + id: "indexes_to_select", ctx: Load, }, }, @@ -489,7 +489,7 @@ expression: parse_ast end_location: Some( Location { row: 4, - column: 27, + column: 30, }, ), custom: (), @@ -502,7 +502,7 @@ expression: parse_ast end_location: Some( Location { row: 4, - column: 27, + column: 30, }, ), custom: (), @@ -532,7 +532,7 @@ expression: parse_ast end_location: Some( Location { row: 4, - column: 26, + column: 29, }, ), custom: (), @@ -604,7 +604,7 @@ expression: parse_ast end_location: Some( Location { row: 4, - column: 26, + column: 29, }, ), custom: (), @@ -617,12 +617,12 @@ expression: parse_ast end_location: Some( Location { row: 4, - column: 26, + column: 29, }, ), custom: (), node: Name { - id: "idxs_to_select", + id: "indexes_to_select", ctx: Load, }, }, diff --git a/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_base.snap b/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_base.snap similarity index 98% rename from parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_base.snap rename to parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_base.snap index cca26ad..125c6af 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_base.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_base.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 698 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_base_more.snap b/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_base_more.snap similarity index 99% rename from parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_base_more.snap rename to parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_base_more.snap index c425d67..14a2034 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_base_more.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_base_more.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 706 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_format.snap b/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_format.snap similarity index 99% rename from parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_format.snap rename to parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_format.snap index c402ed6..c7f6288 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_selfdocumenting_format.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__fstring_parse_self_documenting_format.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 714 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_empty_fstring.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_empty_fstring.snap index 073ac42..94515b9 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_empty_fstring.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_empty_fstring.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 690 expression: "parse_fstring(\"\").unwrap()" --- [] diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring.snap index 10b6f3a..4355fd7 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 669 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_equals.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_equals.snap index 194061c..c8c2052 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_equals.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_equals.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 766 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_nested_spec.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_nested_spec.snap index 96ec3e7..6154948 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_nested_spec.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_nested_spec.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 677 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_equals.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_equals.snap index cbfe435..029b5ee 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_equals.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_equals.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 759 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_nested_spec.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_nested_spec.snap index 2adc5a4..8b26d29 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_nested_spec.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_not_nested_spec.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 685 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_selfdoc_prec_space.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_self_doc_prec_space.snap similarity index 98% rename from parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_selfdoc_prec_space.snap rename to parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_self_doc_prec_space.snap index 16d62ea..f48f688 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_selfdoc_prec_space.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_self_doc_prec_space.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 773 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_selfdoc_trailing_space.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_self_doc_trailing_space.snap similarity index 98% rename from parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_selfdoc_trailing_space.snap rename to parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_self_doc_trailing_space.snap index 16171f2..e1ced21 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_selfdoc_trailing_space.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_self_doc_trailing_space.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 780 expression: parse_ast --- [ diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_yield_expr.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_yield_expr.snap index e3a9ff7..9022388 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_yield_expr.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_yield_expr.snap @@ -1,6 +1,5 @@ --- source: compiler/parser/src/string.rs -assertion_line: 787 expression: parse_ast --- [ diff --git a/parser/src/soft_keywords.rs b/parser/src/soft_keywords.rs index b7b034f..c670fd1 100644 --- a/parser/src/soft_keywords.rs +++ b/parser/src/soft_keywords.rs @@ -27,7 +27,7 @@ where { pub fn new(lexer: I, mode: Mode) -> Self { Self { - underlying: lexer.multipeek(), + underlying: lexer.multipeek(), // spell-checker:ignore multipeek start_of_line: matches!(mode, Mode::Interactive | Mode::Module), } } diff --git a/parser/src/string.rs b/parser/src/string.rs index 0cd03df..14f5ce1 100644 --- a/parser/src/string.rs +++ b/parser/src/string.rs @@ -179,7 +179,7 @@ impl<'a> StringParser<'a> { let mut expression = String::new(); let mut spec = None; - let mut delims = Vec::new(); + let mut delimiters = Vec::new(); let mut conversion = ConversionFlag::None; let mut self_documenting = false; let mut trailing_seq = String::new(); @@ -194,7 +194,7 @@ impl<'a> StringParser<'a> { expression.push('='); self.next_char(); } - '!' if delims.is_empty() && self.peek() != Some(&'=') => { + '!' if delimiters.is_empty() && self.peek() != Some(&'=') => { if expression.trim().is_empty() { return Err(FStringError::new(EmptyExpression, self.get_pos()).into()); } @@ -223,11 +223,11 @@ impl<'a> StringParser<'a> { // match a python 3.8 self documenting expression // format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}' - '=' if self.peek() != Some(&'=') && delims.is_empty() => { + '=' if self.peek() != Some(&'=') && delimiters.is_empty() => { self_documenting = true; } - ':' if delims.is_empty() => { + ':' if delimiters.is_empty() => { let parsed_spec = self.parse_spec(nested)?; spec = Some(Box::new(self.expr(ExprKind::JoinedStr { @@ -236,10 +236,10 @@ impl<'a> StringParser<'a> { } '(' | '{' | '[' => { expression.push(ch); - delims.push(ch); + delimiters.push(ch); } ')' => { - let last_delim = delims.pop(); + let last_delim = delimiters.pop(); match last_delim { Some('(') => { expression.push(ch); @@ -257,7 +257,7 @@ impl<'a> StringParser<'a> { } } ']' => { - let last_delim = delims.pop(); + let last_delim = delimiters.pop(); match last_delim { Some('[') => { expression.push(ch); @@ -274,8 +274,8 @@ impl<'a> StringParser<'a> { } } } - '}' if !delims.is_empty() => { - let last_delim = delims.pop(); + '}' if !delimiters.is_empty() => { + let last_delim = delimiters.pop(); match last_delim { Some('{') => { expression.push(ch); @@ -800,7 +800,7 @@ mod tests { } #[test] - fn test_fstring_parse_selfdocumenting_base() { + fn test_fstring_parse_self_documenting_base() { let src = "{user=}"; let parse_ast = parse_fstring(src).unwrap(); @@ -808,7 +808,7 @@ mod tests { } #[test] - fn test_fstring_parse_selfdocumenting_base_more() { + fn test_fstring_parse_self_documenting_base_more() { let src = "mix {user=} with text and {second=}"; let parse_ast = parse_fstring(src).unwrap(); @@ -816,7 +816,7 @@ mod tests { } #[test] - fn test_fstring_parse_selfdocumenting_format() { + fn test_fstring_parse_self_documenting_format() { let src = "{user=:>10}"; let parse_ast = parse_fstring(src).unwrap(); @@ -877,14 +877,14 @@ mod tests { } #[test] - fn test_parse_fstring_selfdoc_prec_space() { + fn test_parse_fstring_self_doc_prec_space() { let source = "{x =}"; let parse_ast = parse_fstring(source).unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] - fn test_parse_fstring_selfdoc_trailing_space() { + fn test_parse_fstring_self_doc_trailing_space() { let source = "{x= }"; let parse_ast = parse_fstring(source).unwrap(); insta::assert_debug_snapshot!(parse_ast); @@ -979,7 +979,7 @@ mod tests { #[test] fn test_escape_char_in_byte_literal() { // backslash does not escape - let source = r##"b"omkmok\Xaa""##; + let source = r##"b"omkmok\Xaa""##; // spell-checker:ignore omkmok let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } diff --git a/src/lib.rs b/src/lib.rs index 27c1587..9c38408 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ fn error_from_parse(error: parser::ParseError, source: &str) -> CompileError { CompileError::from(error, source) } -/// Compile a given sourcecode into a bytecode object. +/// Compile a given source code into a bytecode object. pub fn compile( source: &str, mode: compile::Mode,