mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-26 13:24:42 +00:00
Avoid allocating vec
s for each statement
This commit is contained in:
parent
851f23668f
commit
726884b287
2 changed files with 19905 additions and 19272 deletions
|
@ -26,32 +26,56 @@ pub Top: ast::Mod = {
|
||||||
};
|
};
|
||||||
|
|
||||||
Program: ast::Suite = {
|
Program: ast::Suite = {
|
||||||
<lines:FileLine*> => {
|
=> vec![],
|
||||||
lines.into_iter().flatten().collect()
|
// Compound statements
|
||||||
|
<mut statements:Program> <next:CompoundStatement> => {
|
||||||
|
statements.push(next);
|
||||||
|
statements
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
|
||||||
// A file line either has a declaration, or an empty newline:
|
// Small statements
|
||||||
FileLine: ast::Suite = {
|
<mut statements:Program> <small:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
|
||||||
Statement,
|
statements.extend(small);
|
||||||
"\n" => vec![],
|
statements.push(last);
|
||||||
|
statements
|
||||||
|
},
|
||||||
|
|
||||||
|
// Empty lines
|
||||||
|
<s:Program> "\n" => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite: ast::Suite = {
|
Suite: ast::Suite = {
|
||||||
SimpleStatement,
|
|
||||||
"\n" Indent <s:Statement+> Dedent => s.into_iter().flatten().collect(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Statement: ast::Suite = {
|
|
||||||
SimpleStatement,
|
|
||||||
<s:CompoundStatement> => vec![s],
|
|
||||||
};
|
|
||||||
|
|
||||||
SimpleStatement: ast::Suite = {
|
|
||||||
<mut statements:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
|
<mut statements:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
|
||||||
statements.push(last);
|
statements.push(last);
|
||||||
statements
|
statements
|
||||||
}
|
},
|
||||||
|
"\n" Indent <s:Statements> Dedent => s,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// One or more statements
|
||||||
|
Statements: Vec<ast::Stmt> = {
|
||||||
|
// First simple statement
|
||||||
|
<mut head:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
|
||||||
|
head.push(last);
|
||||||
|
head
|
||||||
|
},
|
||||||
|
|
||||||
|
// The first compound statement
|
||||||
|
<s:CompoundStatement> => vec![s],
|
||||||
|
|
||||||
|
// Any subsequent compound statements
|
||||||
|
<mut statements:Statements> <next:CompoundStatement> => {
|
||||||
|
statements.push(next);
|
||||||
|
statements
|
||||||
|
},
|
||||||
|
|
||||||
|
// Any subsequent small statements
|
||||||
|
<mut statements:Statements> <small:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
|
||||||
|
statements.extend(small);
|
||||||
|
statements.push(last);
|
||||||
|
statements
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
SmallStatement: ast::Stmt = {
|
SmallStatement: ast::Stmt = {
|
||||||
|
|
39117
parser/src/python.rs
generated
39117
parser/src/python.rs
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue