Update cspell for compiler

This commit is contained in:
Jeong YunWon 2023-03-16 21:27:02 +09:00
parent ef38eb6b1a
commit f9b5469642
27 changed files with 158 additions and 213 deletions

View file

@ -48,10 +48,10 @@ impl<'a> Unparser<'a> {
} }
fn unparse_expr<U>(&mut self, ast: &Expr<U>, level: u8) -> fmt::Result { fn unparse_expr<U>(&mut self, ast: &Expr<U>, level: u8) -> fmt::Result {
macro_rules! opprec { macro_rules! op_prec {
($opty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => { ($op_ty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => {
match $x { match $x {
$(<$enu>::$var => (opprec!(@space $opty, $op), precedence::$prec),)* $(<$enu>::$var => (op_prec!(@space $op_ty, $op), precedence::$prec),)*
} }
}; };
(@space bin, $op:literal) => { (@space bin, $op:literal) => {
@ -72,7 +72,7 @@ impl<'a> Unparser<'a> {
} }
match &ast.node { match &ast.node {
ExprKind::BoolOp { op, values } => { 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, { group_if!(prec, {
let mut first = true; let mut first = true;
for val in values { for val in values {
@ -89,8 +89,8 @@ impl<'a> Unparser<'a> {
}) })
} }
ExprKind::BinOp { left, op, right } => { ExprKind::BinOp { left, op, right } => {
let rassoc = matches!(op, Operator::Pow); let right_associative = matches!(op, Operator::Pow);
let (op, prec) = opprec!( let (op, prec) = op_prec!(
bin, bin,
op, op,
Operator, Operator,
@ -109,13 +109,13 @@ impl<'a> Unparser<'a> {
FloorDiv("//", TERM), FloorDiv("//", TERM),
); );
group_if!(prec, { group_if!(prec, {
self.unparse_expr(left, prec + rassoc as u8)?; self.unparse_expr(left, prec + right_associative as u8)?;
self.p(op)?; self.p(op)?;
self.unparse_expr(right, prec + !rassoc as u8)?; self.unparse_expr(right, prec + !right_associative as u8)?;
}) })
} }
ExprKind::UnaryOp { op, operand } => { ExprKind::UnaryOp { op, operand } => {
let (op, prec) = opprec!( let (op, prec) = op_prec!(
un, un,
op, op,
crate::Unaryop, crate::Unaryop,
@ -131,8 +131,8 @@ impl<'a> Unparser<'a> {
} }
ExprKind::Lambda { args, body } => { ExprKind::Lambda { args, body } => {
group_if!(precedence::TEST, { group_if!(precedence::TEST, {
let npos = args.args.len() + args.posonlyargs.len(); let pos = args.args.len() + args.posonlyargs.len();
self.p(if npos > 0 { "lambda " } else { "lambda" })?; self.p(if pos > 0 { "lambda " } else { "lambda" })?;
self.unparse_args(args)?; self.unparse_args(args)?;
write!(self, ": {}", **body)?; write!(self, ": {}", **body)?;
}) })
@ -260,7 +260,7 @@ impl<'a> Unparser<'a> {
[], [],
) = (&**args, &**keywords) ) = (&**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_expr(elt, precedence::TEST)?;
self.unparse_comp(generators)?; self.unparse_comp(generators)?;
} else { } else {
@ -287,7 +287,7 @@ impl<'a> Unparser<'a> {
conversion, conversion,
format_spec, format_spec,
} => self.unparse_formatted(value, *conversion, format_spec.as_deref())?, } => 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 } => { ExprKind::Constant { value, kind } => {
if let Some(kind) = kind { if let Some(kind) = kind {
self.p(kind)?; self.p(kind)?;
@ -490,7 +490,7 @@ impl<'a> Unparser<'a> {
unreachable!() unreachable!()
} }
} }
ExprKind::JoinedStr { values } => self.unparse_joinedstr(values, is_spec), ExprKind::JoinedStr { values } => self.unparse_joined_str(values, is_spec),
ExprKind::FormattedValue { ExprKind::FormattedValue {
value, value,
conversion, conversion,
@ -505,7 +505,7 @@ impl<'a> Unparser<'a> {
self.p(&s) self.p(&s)
} }
fn unparse_joinedstr<U>(&mut self, values: &[Expr<U>], is_spec: bool) -> fmt::Result { fn unparse_joined_str<U>(&mut self, values: &[Expr<U>], is_spec: bool) -> fmt::Result {
if is_spec { if is_spec {
self.unparse_fstring_body(values, is_spec) self.unparse_fstring_body(values, is_spec)
} else { } else {

View file

@ -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. //! implements bytecode structure.
use crate::{marshal, Location}; use crate::{marshal, Location};
@ -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)] #[derive(Copy, Clone, Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct OpArg(pub u32); pub struct OpArg(pub u32);
@ -156,7 +156,7 @@ impl OpArg {
OpArg(0) 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] #[inline]
pub fn instr_size(self) -> usize { 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 (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 { pub trait OpArgType: Copy {
fn from_oparg(x: u32) -> Option<Self>; fn from_op_arg(x: u32) -> Option<Self>;
fn to_oparg(self) -> u32; fn to_op_arg(self) -> u32;
} }
impl OpArgType for u32 { impl OpArgType for u32 {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(x) Some(x)
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self self
} }
} }
impl OpArgType for bool { impl OpArgType for bool {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(x != 0) Some(x != 0)
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self as u32 self as u32
} }
} }
macro_rules! oparg_enum { macro_rules! op_arg_enum {
($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $discr:literal,)* }) => { ($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $value:literal,)* }) => {
$(#[$attr])* $(#[$attr])*
$vis enum $name { $vis enum $name {
$($(#[$var_attr])* $var = $discr,)* $($(#[$var_attr])* $var = $value,)*
} }
impl OpArgType for $name { impl OpArgType for $name {
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self as u32 self as u32
} }
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(match u8::try_from(x).ok()? { Some(match u8::try_from(x).ok()? {
$($discr => Self::$var,)* $($value => Self::$var,)*
_ => return None, _ => return None,
}) })
} }
@ -261,7 +261,7 @@ impl<T: OpArgType> Arg<T> {
} }
#[inline] #[inline]
pub fn new(arg: T) -> (Self, OpArg) { pub fn new(arg: T) -> (Self, OpArg) {
(Self(PhantomData), OpArg(arg.to_oparg())) (Self(PhantomData), OpArg(arg.to_op_arg()))
} }
#[inline] #[inline]
pub fn new_single(arg: T) -> (Self, OpArgByte) pub fn new_single(arg: T) -> (Self, OpArgByte)
@ -276,13 +276,13 @@ impl<T: OpArgType> Arg<T> {
} }
#[inline(always)] #[inline(always)]
pub fn try_get(self, arg: OpArg) -> Option<T> { pub fn try_get(self, arg: OpArg) -> Option<T> {
T::from_oparg(arg.0) T::from_op_arg(arg.0)
} }
#[inline(always)] #[inline(always)]
/// # Safety /// # Safety
/// T::from_oparg(self) must succeed /// T::from_op_arg(self) must succeed
pub unsafe fn get_unchecked(self, arg: OpArg) -> T { 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, Some(t) => t,
None => std::hint::unreachable_unchecked(), None => std::hint::unreachable_unchecked(),
} }
@ -310,11 +310,11 @@ pub struct Label(pub u32);
impl OpArgType for Label { impl OpArgType for Label {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(Label(x)) Some(Label(x))
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self.0 self.0
} }
} }
@ -325,7 +325,7 @@ impl fmt::Display for Label {
} }
} }
oparg_enum!( op_arg_enum!(
/// Transforms a value prior to formatting it. /// Transforms a value prior to formatting it.
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -344,11 +344,11 @@ oparg_enum!(
impl TryFrom<usize> for ConversionFlag { impl TryFrom<usize> for ConversionFlag {
type Error = usize; type Error = usize;
fn try_from(b: usize) -> Result<Self, Self::Error> { fn try_from(b: usize) -> Result<Self, Self::Error> {
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. /// The kind of Raise that occurred.
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -634,11 +634,11 @@ bitflags! {
} }
impl OpArgType for MakeFunctionFlags { impl OpArgType for MakeFunctionFlags {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(unsafe { MakeFunctionFlags::from_bits_unchecked(x as u8) }) Some(unsafe { MakeFunctionFlags::from_bits_unchecked(x as u8) })
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self.bits().into() self.bits().into()
} }
} }
@ -793,7 +793,7 @@ impl<C: Constant> BorrowedConstant<'_, C> {
} }
} }
oparg_enum!( op_arg_enum!(
/// The possible comparison operators /// The possible comparison operators
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -809,7 +809,7 @@ oparg_enum!(
} }
); );
oparg_enum!( op_arg_enum!(
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
pub enum TestOperator { pub enum TestOperator {
@ -822,7 +822,7 @@ oparg_enum!(
} }
); );
oparg_enum!( op_arg_enum!(
/// The possible Binary operators /// The possible Binary operators
/// # Examples /// # Examples
/// ///
@ -850,7 +850,7 @@ oparg_enum!(
} }
); );
oparg_enum!( op_arg_enum!(
/// The possible unary operators /// The possible unary operators
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -870,12 +870,12 @@ pub struct UnpackExArgs {
impl OpArgType for UnpackExArgs { impl OpArgType for UnpackExArgs {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
let [before, after, ..] = x.to_le_bytes(); let [before, after, ..] = x.to_le_bytes();
Some(Self { before, after }) Some(Self { before, after })
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
u32::from_le_bytes([self.before, self.after, 0, 0]) u32::from_le_bytes([self.before, self.after, 0, 0])
} }
} }
@ -925,20 +925,20 @@ impl<C: Constant> CodeObject<C> {
pub fn arg_names(&self) -> Arguments<C::Name> { pub fn arg_names(&self) -> Arguments<C::Name> {
let nargs = self.arg_count as usize; let nargs = self.arg_count as usize;
let nkwargs = self.kwonlyarg_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 posonlyargs = &self.varnames[..self.posonlyarg_count as usize];
let args = &self.varnames[..nargs]; 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 = if self.flags.contains(CodeFlags::HAS_VARARGS) {
let vararg = &self.varnames[varargspos]; let vararg = &self.varnames[varargs_pos];
varargspos += 1; varargs_pos += 1;
Some(vararg) Some(vararg)
} else { } else {
None None
}; };
let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) { let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) {
Some(&self.varnames[varargspos]) Some(&self.varnames[varargs_pos])
} else { } else {
None None
}; };
@ -968,7 +968,7 @@ impl<C: Constant> CodeObject<C> {
fn display_inner( fn display_inner(
&self, &self,
f: &mut fmt::Formatter, f: &mut fmt::Formatter,
expand_codeobjects: bool, expand_code_objects: bool,
level: usize, level: usize,
) -> fmt::Result { ) -> fmt::Result {
let label_targets = self.label_targets(); let label_targets = self.label_targets();
@ -1007,14 +1007,14 @@ impl<C: Constant> CodeObject<C> {
write!(f, "{arrow} {offset:offset_digits$} ")?; write!(f, "{arrow} {offset:offset_digits$} ")?;
// instruction // instruction
instruction.fmt_dis(arg, f, self, expand_codeobjects, 21, level)?; instruction.fmt_dis(arg, f, self, expand_code_objects, 21, level)?;
writeln!(f)?; writeln!(f)?;
} }
Ok(()) Ok(())
} }
/// Recursively display this CodeObject /// 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<C>); struct Display<'a, C: Constant>(&'a CodeObject<C>);
impl<C: Constant> fmt::Display for Display<'_, C> { impl<C: Constant> fmt::Display for Display<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -1287,7 +1287,7 @@ impl Instruction {
arg: OpArg, arg: OpArg,
f: &mut fmt::Formatter, f: &mut fmt::Formatter,
ctx: &impl InstrDisplayContext, ctx: &impl InstrDisplayContext,
expand_codeobjects: bool, expand_code_objects: bool,
pad: usize, pad: usize,
level: usize, level: usize,
) -> fmt::Result { ) -> fmt::Result {
@ -1295,26 +1295,26 @@ impl Instruction {
($variant:ident) => { ($variant:ident) => {
write!(f, stringify!($variant)) write!(f, stringify!($variant))
}; };
($variant:ident, $map:ident = $argmarker:expr) => {{ ($variant:ident, $map:ident = $arg_marker:expr) => {{
let arg = $argmarker.get(arg); let arg = $arg_marker.get(arg);
write!(f, "{:pad$}({}, {})", stringify!($variant), arg, $map(arg)) write!(f, "{:pad$}({}, {})", stringify!($variant), arg, $map(arg))
}}; }};
($variant:ident, $argmarker:expr) => { ($variant:ident, $arg_marker:expr) => {
write!(f, "{:pad$}({})", stringify!($variant), $argmarker.get(arg)) write!(f, "{:pad$}({})", stringify!($variant), $arg_marker.get(arg))
}; };
($variant:ident, ?$argmarker:expr) => { ($variant:ident, ?$arg_marker:expr) => {
write!( write!(
f, f,
"{:pad$}({:?})", "{:pad$}({:?})",
stringify!($variant), stringify!($variant),
$argmarker.get(arg) $arg_marker.get(arg)
) )
}; };
} }
let varname = |i: u32| ctx.get_varname(i as usize); let varname = |i: u32| ctx.get_varname(i as usize);
let name = |i: u32| ctx.get_name(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 { match self {
ImportName { idx } => w!(ImportName, name = idx), ImportName { idx } => w!(ImportName, name = idx),
@ -1324,17 +1324,17 @@ impl Instruction {
LoadFast(idx) => w!(LoadFast, varname = idx), LoadFast(idx) => w!(LoadFast, varname = idx),
LoadNameAny(idx) => w!(LoadNameAny, name = idx), LoadNameAny(idx) => w!(LoadNameAny, name = idx),
LoadGlobal(idx) => w!(LoadGlobal, name = idx), LoadGlobal(idx) => w!(LoadGlobal, name = idx),
LoadDeref(idx) => w!(LoadDeref, cellname = idx), LoadDeref(idx) => w!(LoadDeref, cell_name = idx),
LoadClassDeref(idx) => w!(LoadClassDeref, cellname = idx), LoadClassDeref(idx) => w!(LoadClassDeref, cell_name = idx),
StoreFast(idx) => w!(StoreFast, varname = idx), StoreFast(idx) => w!(StoreFast, varname = idx),
StoreLocal(idx) => w!(StoreLocal, name = idx), StoreLocal(idx) => w!(StoreLocal, name = idx),
StoreGlobal(idx) => w!(StoreGlobal, 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), DeleteFast(idx) => w!(DeleteFast, varname = idx),
DeleteLocal(idx) => w!(DeleteLocal, name = idx), DeleteLocal(idx) => w!(DeleteLocal, name = idx),
DeleteGlobal(idx) => w!(DeleteGlobal, name = idx), DeleteGlobal(idx) => w!(DeleteGlobal, name = idx),
DeleteDeref(idx) => w!(DeleteDeref, cellname = idx), DeleteDeref(idx) => w!(DeleteDeref, cell_name = idx),
LoadClosure(i) => w!(LoadClosure, cellname = i), LoadClosure(i) => w!(LoadClosure, cell_name = i),
Subscript => w!(Subscript), Subscript => w!(Subscript),
StoreSubscript => w!(StoreSubscript), StoreSubscript => w!(StoreSubscript),
DeleteSubscript => w!(DeleteSubscript), DeleteSubscript => w!(DeleteSubscript),
@ -1343,7 +1343,7 @@ impl Instruction {
LoadConst { idx } => { LoadConst { idx } => {
let value = ctx.get_constant(idx.get(arg) as usize); let value = ctx.get_constant(idx.get(arg) as usize);
match value.borrow_constant() { match value.borrow_constant() {
BorrowedConstant::Code { code } if expand_codeobjects => { BorrowedConstant::Code { code } if expand_code_objects => {
write!(f, "{:pad$}({:?}):", "LoadConst", code)?; write!(f, "{:pad$}({:?}):", "LoadConst", code)?;
code.display_inner(f, true, level + 1)?; code.display_inner(f, true, level + 1)?;
Ok(()) Ok(())
@ -1434,7 +1434,7 @@ pub trait InstrDisplayContext {
fn get_constant(&self, i: usize) -> &Self::Constant; fn get_constant(&self, i: usize) -> &Self::Constant;
fn get_name(&self, i: usize) -> &str; fn get_name(&self, i: usize) -> &str;
fn get_varname(&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<C: Constant> InstrDisplayContext for CodeObject<C> { impl<C: Constant> InstrDisplayContext for CodeObject<C> {
@ -1448,7 +1448,7 @@ impl<C: Constant> InstrDisplayContext for CodeObject<C> {
fn get_varname(&self, i: usize) -> &str { fn get_varname(&self, i: usize) -> &str {
self.varnames[i].as_ref() self.varnames[i].as_ref()
} }
fn get_cellname(&self, i: usize) -> &str { fn get_cell_name(&self, i: usize) -> &str {
self.cellvars self.cellvars
.get(i) .get(i)
.unwrap_or_else(|| &self.freevars[i - self.cellvars.len()]) .unwrap_or_else(|| &self.freevars[i - self.cellvars.len()])

View file

@ -241,6 +241,7 @@ where
lxr.window.slide(); lxr.window.slide();
lxr.window.slide(); lxr.window.slide();
// TODO: Handle possible mismatch between BOM and explicit encoding declaration. // TODO: Handle possible mismatch between BOM and explicit encoding declaration.
// spell-checker:ignore feff
if let Some('\u{feff}') = lxr.window[0] { if let Some('\u{feff}') = lxr.window[0] {
lxr.window.slide(); lxr.window.slide();
} }
@ -1085,7 +1086,7 @@ where
} }
} }
' ' | '\t' | '\x0C' => { ' ' | '\t' | '\x0C' => {
// Skip whitespaces // Skip white-spaces
self.next_char(); self.next_char();
while let Some(' ' | '\t' | '\x0C') = self.window[0] { while let Some(' ' | '\t' | '\x0C') = self.window[0] {
self.next_char(); self.next_char();
@ -1327,7 +1328,7 @@ mod tests {
lexer.map(|x| x.unwrap().1).collect() lexer.map(|x| x.unwrap().1).collect()
} }
fn stok(s: &str) -> Tok { fn str_tok(s: &str) -> Tok {
Tok::String { Tok::String {
value: s.to_owned(), value: s.to_owned(),
kind: StringKind::String, kind: StringKind::String,
@ -1335,7 +1336,7 @@ mod tests {
} }
} }
fn raw_stok(s: &str) -> Tok { fn raw_str_tok(s: &str) -> Tok {
Tok::String { Tok::String {
value: s.to_owned(), value: s.to_owned(),
kind: StringKind::RawString, kind: StringKind::RawString,
@ -1434,13 +1435,13 @@ mod tests {
#[test] #[test]
fn test_assignment() { fn test_assignment() {
let source = r"avariable = 99 + 2-0"; let source = r"a_variable = 99 + 2-0";
let tokens = lex_source(source); let tokens = lex_source(source);
assert_eq!( assert_eq!(
tokens, tokens,
vec![ vec![
Tok::Name { Tok::Name {
name: String::from("avariable"), name: String::from("a_variable"),
}, },
Tok::Equal, Tok::Equal,
Tok::Int { Tok::Int {
@ -1663,13 +1664,13 @@ mod tests {
vec![ vec![
Tok::Lpar, Tok::Lpar,
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
stok("a"), str_tok("a"),
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
stok("b"), str_tok("b"),
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
stok("c"), str_tok("c"),
stok("d"), str_tok("d"),
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
Tok::Rpar, Tok::Rpar,
Tok::Newline, Tok::Newline,
@ -1716,15 +1717,15 @@ mod tests {
assert_eq!( assert_eq!(
tokens, tokens,
vec![ vec![
stok("double"), str_tok("double"),
stok("single"), str_tok("single"),
stok(r"can\'t"), str_tok(r"can\'t"),
stok(r#"\\\""#), str_tok(r#"\\\""#),
stok(r"\t\r\n"), str_tok(r"\t\r\n"),
stok(r"\g"), str_tok(r"\g"),
raw_stok(r"raw\'"), raw_str_tok(r"raw\'"),
stok(r"\420"), str_tok(r"\420"),
stok(r"\200\0a"), str_tok(r"\200\0a"),
Tok::Newline, Tok::Newline,
] ]
); );
@ -1740,7 +1741,7 @@ mod tests {
assert_eq!( assert_eq!(
tokens, tokens,
vec![ vec![
stok("abc\\\ndef"), str_tok("abc\\\ndef"),
Tok::Newline, Tok::Newline,
] ]
) )
@ -1759,7 +1760,7 @@ mod tests {
fn test_escape_unicode_name() { fn test_escape_unicode_name() {
let source = r#""\N{EN SPACE}""#; let source = r#""\N{EN SPACE}""#;
let tokens = lex_source(source); 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 { macro_rules! test_triple_quoted {

View file

@ -433,14 +433,14 @@ class Foo(A, B):
} }
#[test] #[test]
fn test_parse_boolop_or() { fn test_parse_bool_op_or() {
let source = "x or y"; let source = "x or y";
let parse_ast = parse_expression(source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_boolop_and() { fn test_parse_bool_op_and() {
let source = "x and y"; let source = "x and y";
let parse_ast = parse_expression(source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
@ -513,10 +513,10 @@ with (0 as a, 1 as b,): pass
#[test] #[test]
fn test_star_index() { fn test_star_index() {
let source = "\ let source = "\
array_slice = array[0, *idxs, -1] array_slice = array[0, *indexes, -1]
array[0, *idxs, -1] = array_slice array[0, *indexes, -1] = array_slice
array[*idxs_to_select, *idxs_to_select] array[*indexes_to_select, *indexes_to_select]
array[3:5, *idxs_to_select] array[3:5, *indexes_to_select]
"; ";
let parse_ast = parse_program(source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);

View file

@ -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,
},
},
]

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/function.rs source: compiler/parser/src/function.rs
assertion_line: 165
expression: parse_ast expression: parse_ast
--- ---
Ok( Ok(

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/function.rs source: compiler/parser/src/function.rs
assertion_line: 165
expression: parse_ast expression: parse_ast
--- ---
Ok( Ok(

View file

@ -1,5 +1,5 @@
--- ---
source: parser/src/parser.rs source: compiler/parser/src/parser.rs
expression: parse_ast expression: parse_ast
--- ---
[] []

View file

@ -11,7 +11,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -43,7 +43,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -73,7 +73,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 32, column: 35,
}, },
), ),
custom: (), custom: (),
@ -106,7 +106,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 28, column: 31,
}, },
), ),
custom: (), custom: (),
@ -119,12 +119,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 28, column: 31,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs", id: "indexes",
ctx: Load, ctx: Load,
}, },
}, },
@ -134,12 +134,12 @@ expression: parse_ast
Located { Located {
location: Location { location: Location {
row: 1, row: 1,
column: 30, column: 33,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 32, column: 35,
}, },
), ),
custom: (), custom: (),
@ -148,12 +148,12 @@ expression: parse_ast
operand: Located { operand: Located {
location: Location { location: Location {
row: 1, row: 1,
column: 31, column: 34,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 32, column: 35,
}, },
), ),
custom: (), custom: (),
@ -184,7 +184,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -198,7 +198,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 19, column: 22,
}, },
), ),
custom: (), custom: (),
@ -228,7 +228,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 18, column: 21,
}, },
), ),
custom: (), custom: (),
@ -261,7 +261,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 14, column: 17,
}, },
), ),
custom: (), custom: (),
@ -274,12 +274,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 14, column: 17,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs", id: "indexes",
ctx: Load, ctx: Load,
}, },
}, },
@ -289,12 +289,12 @@ expression: parse_ast
Located { Located {
location: Location { location: Location {
row: 2, row: 2,
column: 16, column: 19,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 18, column: 21,
}, },
), ),
custom: (), custom: (),
@ -303,12 +303,12 @@ expression: parse_ast
operand: Located { operand: Located {
location: Location { location: Location {
row: 2, row: 2,
column: 17, column: 20,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 18, column: 21,
}, },
), ),
custom: (), custom: (),
@ -332,12 +332,12 @@ expression: parse_ast
value: Located { value: Located {
location: Location { location: Location {
row: 2, row: 2,
column: 22, column: 25,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -357,7 +357,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 39, column: 45,
}, },
), ),
custom: (), custom: (),
@ -370,7 +370,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 39, column: 45,
}, },
), ),
custom: (), custom: (),
@ -400,7 +400,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 38, column: 44,
}, },
), ),
custom: (), custom: (),
@ -414,7 +414,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 21, column: 24,
}, },
), ),
custom: (), custom: (),
@ -427,12 +427,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 21, column: 24,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs_to_select", id: "indexes_to_select",
ctx: Load, ctx: Load,
}, },
}, },
@ -442,12 +442,12 @@ expression: parse_ast
Located { Located {
location: Location { location: Location {
row: 3, row: 3,
column: 23, column: 26,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 38, column: 44,
}, },
), ),
custom: (), custom: (),
@ -455,17 +455,17 @@ expression: parse_ast
value: Located { value: Located {
location: Location { location: Location {
row: 3, row: 3,
column: 24, column: 27,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 38, column: 44,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs_to_select", id: "indexes_to_select",
ctx: Load, ctx: Load,
}, },
}, },
@ -489,7 +489,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 27, column: 30,
}, },
), ),
custom: (), custom: (),
@ -502,7 +502,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 27, column: 30,
}, },
), ),
custom: (), custom: (),
@ -532,7 +532,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 26, column: 29,
}, },
), ),
custom: (), custom: (),
@ -604,7 +604,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 26, column: 29,
}, },
), ),
custom: (), custom: (),
@ -617,12 +617,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 26, column: 29,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs_to_select", id: "indexes_to_select",
ctx: Load, ctx: Load,
}, },
}, },

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 698
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 706
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 714
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 690
expression: "parse_fstring(\"\").unwrap()" expression: "parse_fstring(\"\").unwrap()"
--- ---
[] []

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 669
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 766
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 677
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 759
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 685
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 773
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 780
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 787
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -27,7 +27,7 @@ where
{ {
pub fn new(lexer: I, mode: Mode) -> Self { pub fn new(lexer: I, mode: Mode) -> Self {
Self { Self {
underlying: lexer.multipeek(), underlying: lexer.multipeek(), // spell-checker:ignore multipeek
start_of_line: matches!(mode, Mode::Interactive | Mode::Module), start_of_line: matches!(mode, Mode::Interactive | Mode::Module),
} }
} }

View file

@ -179,7 +179,7 @@ impl<'a> StringParser<'a> {
let mut expression = String::new(); let mut expression = String::new();
let mut spec = None; let mut spec = None;
let mut delims = Vec::new(); let mut delimiters = Vec::new();
let mut conversion = ConversionFlag::None; let mut conversion = ConversionFlag::None;
let mut self_documenting = false; let mut self_documenting = false;
let mut trailing_seq = String::new(); let mut trailing_seq = String::new();
@ -194,7 +194,7 @@ impl<'a> StringParser<'a> {
expression.push('='); expression.push('=');
self.next_char(); self.next_char();
} }
'!' if delims.is_empty() && self.peek() != Some(&'=') => { '!' if delimiters.is_empty() && self.peek() != Some(&'=') => {
if expression.trim().is_empty() { if expression.trim().is_empty() {
return Err(FStringError::new(EmptyExpression, self.get_pos()).into()); 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 // match a python 3.8 self documenting expression
// format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}' // format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}'
'=' if self.peek() != Some(&'=') && delims.is_empty() => { '=' if self.peek() != Some(&'=') && delimiters.is_empty() => {
self_documenting = true; self_documenting = true;
} }
':' if delims.is_empty() => { ':' if delimiters.is_empty() => {
let parsed_spec = self.parse_spec(nested)?; let parsed_spec = self.parse_spec(nested)?;
spec = Some(Box::new(self.expr(ExprKind::JoinedStr { spec = Some(Box::new(self.expr(ExprKind::JoinedStr {
@ -236,10 +236,10 @@ impl<'a> StringParser<'a> {
} }
'(' | '{' | '[' => { '(' | '{' | '[' => {
expression.push(ch); expression.push(ch);
delims.push(ch); delimiters.push(ch);
} }
')' => { ')' => {
let last_delim = delims.pop(); let last_delim = delimiters.pop();
match last_delim { match last_delim {
Some('(') => { Some('(') => {
expression.push(ch); expression.push(ch);
@ -257,7 +257,7 @@ impl<'a> StringParser<'a> {
} }
} }
']' => { ']' => {
let last_delim = delims.pop(); let last_delim = delimiters.pop();
match last_delim { match last_delim {
Some('[') => { Some('[') => {
expression.push(ch); expression.push(ch);
@ -274,8 +274,8 @@ impl<'a> StringParser<'a> {
} }
} }
} }
'}' if !delims.is_empty() => { '}' if !delimiters.is_empty() => {
let last_delim = delims.pop(); let last_delim = delimiters.pop();
match last_delim { match last_delim {
Some('{') => { Some('{') => {
expression.push(ch); expression.push(ch);
@ -800,7 +800,7 @@ mod tests {
} }
#[test] #[test]
fn test_fstring_parse_selfdocumenting_base() { fn test_fstring_parse_self_documenting_base() {
let src = "{user=}"; let src = "{user=}";
let parse_ast = parse_fstring(src).unwrap(); let parse_ast = parse_fstring(src).unwrap();
@ -808,7 +808,7 @@ mod tests {
} }
#[test] #[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 src = "mix {user=} with text and {second=}";
let parse_ast = parse_fstring(src).unwrap(); let parse_ast = parse_fstring(src).unwrap();
@ -816,7 +816,7 @@ mod tests {
} }
#[test] #[test]
fn test_fstring_parse_selfdocumenting_format() { fn test_fstring_parse_self_documenting_format() {
let src = "{user=:>10}"; let src = "{user=:>10}";
let parse_ast = parse_fstring(src).unwrap(); let parse_ast = parse_fstring(src).unwrap();
@ -877,14 +877,14 @@ mod tests {
} }
#[test] #[test]
fn test_parse_fstring_selfdoc_prec_space() { fn test_parse_fstring_self_doc_prec_space() {
let source = "{x =}"; let source = "{x =}";
let parse_ast = parse_fstring(source).unwrap(); let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_fstring_selfdoc_trailing_space() { fn test_parse_fstring_self_doc_trailing_space() {
let source = "{x= }"; let source = "{x= }";
let parse_ast = parse_fstring(source).unwrap(); let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
@ -979,7 +979,7 @@ mod tests {
#[test] #[test]
fn test_escape_char_in_byte_literal() { fn test_escape_char_in_byte_literal() {
// backslash does not escape // 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, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }