mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-15 00:55:22 +00:00
Fix build
This commit is contained in:
parent
cd89c0efc3
commit
1cf14ac807
4 changed files with 50 additions and 42 deletions
|
@ -52,6 +52,7 @@ impl<U> crate::fold::Fold<U> for ConstantOptimizer {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
use rustpython_parser_core::text_size::TextRange;
|
||||||
|
|
||||||
#[cfg(feature = "constant-optimization")]
|
#[cfg(feature = "constant-optimization")]
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -23,7 +23,9 @@ use crate::{
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
|
use crate::text_size::TextRange;
|
||||||
pub(super) use lalrpop_util::ParseError as LalrpopError;
|
pub(super) use lalrpop_util::ParseError as LalrpopError;
|
||||||
|
use rustpython_ast::OptionalRange;
|
||||||
|
|
||||||
/// Parse a full Python program usually consisting of multiple lines.
|
/// Parse a full Python program usually consisting of multiple lines.
|
||||||
///
|
///
|
||||||
|
@ -318,6 +320,11 @@ impl ParseErrorType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub(super) fn optional_range(start: TextSize, end: TextSize) -> OptionalRange<TextRange> {
|
||||||
|
OptionalRange::<TextRange>::new(start, end)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
// See also: https://greentreesnakes.readthedocs.io/en/latest/nodes.html#keyword
|
// See also: https://greentreesnakes.readthedocs.io/en/latest/nodes.html#keyword
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self as ast, Ranged, OptionalRange},
|
ast::{self as ast, Ranged},
|
||||||
lexer::{LexicalError, LexicalErrorType},
|
lexer::{LexicalError, LexicalErrorType},
|
||||||
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
||||||
context::set_context,
|
context::set_context,
|
||||||
string::parse_strings,
|
string::parse_strings,
|
||||||
token::{self, StringKind},
|
token::{self, StringKind},
|
||||||
text_size::TextSize,
|
text_size::TextSize, parser::optional_range
|
||||||
};
|
};
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ grammar;
|
||||||
// For each public entry point, a full parse table is generated.
|
// For each public entry point, a full parse table is generated.
|
||||||
// By having only a single pub function, we reduce this to one.
|
// By having only a single pub function, we reduce this to one.
|
||||||
pub Top: ast::Mod = {
|
pub Top: ast::Mod = {
|
||||||
<start:@L> StartModule <body:Program> <end:@R> => ast::ModModule { body, type_ignores: vec![], range: OptionalRange::new(start, end) }.into(),
|
<start:@L> StartModule <body:Program> <end:@R> => ast::ModModule { body, type_ignores: vec![], range: optional_range(start, end) }.into(),
|
||||||
<start:@L> StartInteractive <body:Program> <end:@R> => ast::ModInteractive { body, range: OptionalRange::new(start, end) }.into(),
|
<start:@L> StartInteractive <body:Program> <end:@R> => ast::ModInteractive { body, range: optional_range(start, end) }.into(),
|
||||||
<start:@L> StartExpression <body:TestList> ("\n")* <end:@R> => ast::ModExpression { body: Box::new(body), range: OptionalRange::new(start, end) }.into()
|
<start:@L> StartExpression <body:TestList> ("\n")* <end:@R> => ast::ModExpression { body: Box::new(body), range: optional_range(start, end) }.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
Program: ast::Suite = {
|
Program: ast::Suite = {
|
||||||
|
@ -371,7 +371,7 @@ MatchCase: ast::MatchCase = {
|
||||||
pattern,
|
pattern,
|
||||||
guard: guard.map(Box::new),
|
guard: guard.map(Box::new),
|
||||||
body,
|
body,
|
||||||
range: OptionalRange::new(start, end)
|
range: optional_range(start, end)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -929,15 +929,15 @@ WithItems: Vec<ast::Withitem> = {
|
||||||
#[inline]
|
#[inline]
|
||||||
WithItemsNoAs: Vec<ast::Withitem> = {
|
WithItemsNoAs: Vec<ast::Withitem> = {
|
||||||
<location:@L> <all:OneOrMore<Test<"all">>> <end_location:@R> => {
|
<location:@L> <all:OneOrMore<Test<"all">>> <end_location:@R> => {
|
||||||
all.into_iter().map(|context_expr| ast::Withitem { context_expr, optional_vars: None, range: OptionalRange::new(location, end_location) }).collect()
|
all.into_iter().map(|context_expr| ast::Withitem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
WithItem<Goal>: ast::Withitem = {
|
WithItem<Goal>: ast::Withitem = {
|
||||||
<location:@L> <context_expr: Test<Goal>> <end_location:@R> if Goal != "as" => ast::Withitem { context_expr, optional_vars: None, range: OptionalRange::new(location, end_location) },
|
<location:@L> <context_expr: Test<Goal>> <end_location:@R> if Goal != "as" => ast::Withitem { context_expr, optional_vars: None, range: optional_range(location, end_location) },
|
||||||
<location:@L> <context_expr:Test<"all">> "as" <vars:Expression<"all">> <end_location:@R> => {
|
<location:@L> <context_expr:Test<"all">> "as" <vars:Expression<"all">> <end_location:@R> => {
|
||||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||||
ast::Withitem { context_expr, optional_vars, range: OptionalRange::new(location, end_location) }
|
ast::Withitem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -966,7 +966,7 @@ Parameters: ast::Arguments = {
|
||||||
kw_defaults: vec![],
|
kw_defaults: vec![],
|
||||||
kwarg: None,
|
kwarg: None,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -991,7 +991,7 @@ ParameterList<ArgType, StarArgType>: ast::Arguments = {
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults,
|
defaults,
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
<location:@L> <param1:ParameterDefs<ArgType>> <kw:("," KwargParameter<ArgType>)> ","? <end_location:@R> =>? {
|
<location:@L> <param1:ParameterDefs<ArgType>> <kw:("," KwargParameter<ArgType>)> ","? <end_location:@R> =>? {
|
||||||
|
@ -1011,7 +1011,7 @@ ParameterList<ArgType, StarArgType>: ast::Arguments = {
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults,
|
defaults,
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
<location:@L> <params:ParameterListStarArgs<ArgType, StarArgType>> ","? <end_location:@R> => {
|
<location:@L> <params:ParameterListStarArgs<ArgType, StarArgType>> ","? <end_location:@R> => {
|
||||||
|
@ -1024,7 +1024,7 @@ ParameterList<ArgType, StarArgType>: ast::Arguments = {
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
<location:@L> <kwarg:KwargParameter<ArgType>> ","? <end_location:@R> => {
|
<location:@L> <kwarg:KwargParameter<ArgType>> ","? <end_location:@R> => {
|
||||||
|
@ -1036,7 +1036,7 @@ ParameterList<ArgType, StarArgType>: ast::Arguments = {
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
kw_defaults: vec![],
|
kw_defaults: vec![],
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1194,7 +1194,7 @@ LambdaDef: ast::Expr = {
|
||||||
kw_defaults: vec![],
|
kw_defaults: vec![],
|
||||||
kwarg: None,
|
kwarg: None,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
))?;
|
))?;
|
||||||
|
@ -1564,7 +1564,7 @@ SingleForComprehension: ast::Comprehension = {
|
||||||
iter,
|
iter,
|
||||||
ifs,
|
ifs,
|
||||||
is_async,
|
is_async,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
52
parser/src/python.rs
generated
52
parser/src/python.rs
generated
|
@ -1,13 +1,13 @@
|
||||||
// auto-generated: "lalrpop 0.20.0"
|
// auto-generated: "lalrpop 0.20.0"
|
||||||
// sha3: dcd27eae3d0dc16a3ba0744e12b96ef7e802b7fe3eff03cbd5e86f6bb02cc325
|
// sha3: 2a588ed2309b95ae978a172dc2a1234d79c6f56440b66bd964f4818b3e021e00
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self as ast, Ranged, OptionalRange},
|
ast::{self as ast, Ranged},
|
||||||
lexer::{LexicalError, LexicalErrorType},
|
lexer::{LexicalError, LexicalErrorType},
|
||||||
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
||||||
context::set_context,
|
context::set_context,
|
||||||
string::parse_strings,
|
string::parse_strings,
|
||||||
token::{self, StringKind},
|
token::{self, StringKind},
|
||||||
text_size::TextSize,
|
text_size::TextSize, parser::optional_range
|
||||||
};
|
};
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
#[allow(unused_extern_crates)]
|
#[allow(unused_extern_crates)]
|
||||||
|
@ -22,13 +22,13 @@ extern crate alloc;
|
||||||
mod __parse__Top {
|
mod __parse__Top {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self as ast, Ranged, OptionalRange},
|
ast::{self as ast, Ranged},
|
||||||
lexer::{LexicalError, LexicalErrorType},
|
lexer::{LexicalError, LexicalErrorType},
|
||||||
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
||||||
context::set_context,
|
context::set_context,
|
||||||
string::parse_strings,
|
string::parse_strings,
|
||||||
token::{self, StringKind},
|
token::{self, StringKind},
|
||||||
text_size::TextSize,
|
text_size::TextSize, parser::optional_range
|
||||||
};
|
};
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
#[allow(unused_extern_crates)]
|
#[allow(unused_extern_crates)]
|
||||||
|
@ -36623,7 +36623,7 @@ fn __action1<
|
||||||
(_, end, _): (TextSize, TextSize, TextSize),
|
(_, end, _): (TextSize, TextSize, TextSize),
|
||||||
) -> ast::Mod
|
) -> ast::Mod
|
||||||
{
|
{
|
||||||
ast::ModModule { body, type_ignores: vec![], range: OptionalRange::new(start, end) }.into()
|
ast::ModModule { body, type_ignores: vec![], range: optional_range(start, end) }.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
@ -36635,7 +36635,7 @@ fn __action2<
|
||||||
(_, end, _): (TextSize, TextSize, TextSize),
|
(_, end, _): (TextSize, TextSize, TextSize),
|
||||||
) -> ast::Mod
|
) -> ast::Mod
|
||||||
{
|
{
|
||||||
ast::ModInteractive { body, range: OptionalRange::new(start, end) }.into()
|
ast::ModInteractive { body, range: optional_range(start, end) }.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
@ -36648,7 +36648,7 @@ fn __action3<
|
||||||
(_, end, _): (TextSize, TextSize, TextSize),
|
(_, end, _): (TextSize, TextSize, TextSize),
|
||||||
) -> ast::Mod
|
) -> ast::Mod
|
||||||
{
|
{
|
||||||
ast::ModExpression { body: Box::new(body), range: OptionalRange::new(start, end) }.into()
|
ast::ModExpression { body: Box::new(body), range: optional_range(start, end) }.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
@ -37615,7 +37615,7 @@ fn __action80<
|
||||||
pattern,
|
pattern,
|
||||||
guard: guard.map(Box::new),
|
guard: guard.map(Box::new),
|
||||||
body,
|
body,
|
||||||
range: OptionalRange::new(start, end)
|
range: optional_range(start, end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38887,7 +38887,7 @@ fn __action153<
|
||||||
) -> Vec<ast::Withitem>
|
) -> Vec<ast::Withitem>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
all.into_iter().map(|context_expr| ast::Withitem { context_expr, optional_vars: None, range: OptionalRange::new(location, end_location) }).collect()
|
all.into_iter().map(|context_expr| ast::Withitem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38938,7 +38938,7 @@ fn __action155<
|
||||||
kw_defaults: vec![],
|
kw_defaults: vec![],
|
||||||
kwarg: None,
|
kwarg: None,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -39124,7 +39124,7 @@ fn __action166<
|
||||||
kw_defaults: vec![],
|
kw_defaults: vec![],
|
||||||
kwarg: None,
|
kwarg: None,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
))?;
|
))?;
|
||||||
|
@ -39555,7 +39555,7 @@ fn __action206<
|
||||||
iter,
|
iter,
|
||||||
ifs,
|
ifs,
|
||||||
is_async,
|
is_async,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39974,7 +39974,7 @@ fn __action240<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults,
|
defaults,
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40006,7 +40006,7 @@ fn __action241<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults,
|
defaults,
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40030,7 +40030,7 @@ fn __action242<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40053,7 +40053,7 @@ fn __action243<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
kw_defaults: vec![],
|
kw_defaults: vec![],
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40198,7 +40198,7 @@ fn __action256<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults,
|
defaults,
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40230,7 +40230,7 @@ fn __action257<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults,
|
defaults,
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40254,7 +40254,7 @@ fn __action258<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
kw_defaults,
|
kw_defaults,
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40277,7 +40277,7 @@ fn __action259<
|
||||||
kwarg,
|
kwarg,
|
||||||
defaults: vec![],
|
defaults: vec![],
|
||||||
kw_defaults: vec![],
|
kw_defaults: vec![],
|
||||||
range: OptionalRange::new(location, end_location)
|
range: optional_range(location, end_location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40371,7 +40371,7 @@ fn __action268<
|
||||||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||||
) -> ast::Withitem
|
) -> ast::Withitem
|
||||||
{
|
{
|
||||||
ast::Withitem { context_expr, optional_vars: None, range: OptionalRange::new(location, end_location) }
|
ast::Withitem { context_expr, optional_vars: None, range: optional_range(location, end_location) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
@ -40386,7 +40386,7 @@ fn __action269<
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||||
ast::Withitem { context_expr, optional_vars, range: OptionalRange::new(location, end_location) }
|
ast::Withitem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40427,7 +40427,7 @@ fn __action273<
|
||||||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||||
) -> ast::Withitem
|
) -> ast::Withitem
|
||||||
{
|
{
|
||||||
ast::Withitem { context_expr, optional_vars: None, range: OptionalRange::new(location, end_location) }
|
ast::Withitem { context_expr, optional_vars: None, range: optional_range(location, end_location) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
@ -40442,7 +40442,7 @@ fn __action274<
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||||
ast::Withitem { context_expr, optional_vars, range: OptionalRange::new(location, end_location) }
|
ast::Withitem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40458,7 +40458,7 @@ fn __action275<
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||||
ast::Withitem { context_expr, optional_vars, range: OptionalRange::new(location, end_location) }
|
ast::Withitem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue