mirror of
https://github.com/mtshiba/pylyzer.git
synced 2025-08-02 21:22:17 +00:00
Update: match the latest erg
This commit is contained in:
parent
058dd01d5e
commit
0ccbd89070
4 changed files with 91 additions and 44 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -253,7 +253,7 @@ checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "els"
|
name = "els"
|
||||||
version = "0.1.13"
|
version = "0.1.13"
|
||||||
source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798"
|
source = "git+https://github.com/erg-lang/erg?branch=main#993bb13bb53dbeb366610cf58d57b3bbcab2b064"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
|
@ -274,7 +274,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_common"
|
name = "erg_common"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798"
|
source = "git+https://github.com/erg-lang/erg?branch=main#993bb13bb53dbeb366610cf58d57b3bbcab2b064"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace-on-stack-overflow",
|
"backtrace-on-stack-overflow",
|
||||||
"hermit-abi",
|
"hermit-abi",
|
||||||
|
@ -285,7 +285,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_compiler"
|
name = "erg_compiler"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798"
|
source = "git+https://github.com/erg-lang/erg?branch=main#993bb13bb53dbeb366610cf58d57b3bbcab2b064"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_parser",
|
"erg_parser",
|
||||||
|
@ -294,7 +294,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_parser"
|
name = "erg_parser"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798"
|
source = "git+https://github.com/erg-lang/erg?branch=main#993bb13bb53dbeb366610cf58d57b3bbcab2b064"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"unicode-xid 0.2.4",
|
"unicode-xid 0.2.4",
|
||||||
|
@ -527,9 +527,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object"
|
name = "object"
|
||||||
version = "0.30.0"
|
version = "0.30.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb"
|
checksum = "8d864c91689fdc196779b98dba0aceac6118594c2df6ee5d943eb6a8df4d107a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl BlockKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Variables are automatically rewritten with `python_compatible_mode`,
|
/// Variables are automatically rewritten with `py_compatible`,
|
||||||
/// but types are rewritten here because they are complex components used inseparably in the Erg system.
|
/// but types are rewritten here because they are complex components used inseparably in the Erg system.
|
||||||
fn escape_name(name: String) -> String {
|
fn escape_name(name: String) -> String {
|
||||||
match &name[..] {
|
match &name[..] {
|
||||||
|
@ -122,7 +122,12 @@ fn op_to_token(op: Operator) -> Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pyloc_to_ergloc(loc: PyLocation, cont_len: usize) -> erg_common::error::Location {
|
pub fn pyloc_to_ergloc(loc: PyLocation, cont_len: usize) -> erg_common::error::Location {
|
||||||
erg_common::error::Location::range(loc.row(), loc.column(), loc.row(), loc.column() + cont_len)
|
erg_common::error::Location::range(
|
||||||
|
loc.row() as u32,
|
||||||
|
loc.column() as u32,
|
||||||
|
loc.row() as u32,
|
||||||
|
(loc.column() + cont_len) as u32,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -322,17 +327,37 @@ impl ASTConverter {
|
||||||
self.names.insert(name.clone(), info);
|
self.names.insert(name.clone(), info);
|
||||||
name
|
name
|
||||||
};
|
};
|
||||||
let token = Token::new(TokenKind::Symbol, cont, loc.row(), loc.column() - 1);
|
let token = Token::new(
|
||||||
|
TokenKind::Symbol,
|
||||||
|
cont,
|
||||||
|
loc.row() as u32,
|
||||||
|
loc.column() as u32 - 1,
|
||||||
|
);
|
||||||
let name = VarName::new(token);
|
let name = VarName::new(token);
|
||||||
let dot = Token::new(TokenKind::Dot, ".", loc.row(), loc.column() - 1);
|
let dot = Token::new(
|
||||||
|
TokenKind::Dot,
|
||||||
|
".",
|
||||||
|
loc.row() as u32,
|
||||||
|
loc.column() as u32 - 1,
|
||||||
|
);
|
||||||
Identifier::new(Some(dot), name)
|
Identifier::new(Some(dot), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: module member mangling
|
// TODO: module member mangling
|
||||||
fn convert_attr_ident(&mut self, name: String, loc: PyLocation) -> Identifier {
|
fn convert_attr_ident(&mut self, name: String, loc: PyLocation) -> Identifier {
|
||||||
let token = Token::new(TokenKind::Symbol, name, loc.row(), loc.column() - 1);
|
let token = Token::new(
|
||||||
|
TokenKind::Symbol,
|
||||||
|
name,
|
||||||
|
loc.row() as u32,
|
||||||
|
loc.column() as u32 - 1,
|
||||||
|
);
|
||||||
let name = VarName::new(token);
|
let name = VarName::new(token);
|
||||||
let dot = Token::new(TokenKind::Dot, ".", loc.row(), loc.column() - 1);
|
let dot = Token::new(
|
||||||
|
TokenKind::Dot,
|
||||||
|
".",
|
||||||
|
loc.row() as u32,
|
||||||
|
loc.column() as u32 - 1,
|
||||||
|
);
|
||||||
Identifier::new(Some(dot), name)
|
Identifier::new(Some(dot), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +416,8 @@ impl ASTConverter {
|
||||||
}
|
}
|
||||||
ExpressionType::Tuple { elements } => {
|
ExpressionType::Tuple { elements } => {
|
||||||
let tmp = fresh_varname();
|
let tmp = fresh_varname();
|
||||||
let tmp_name = VarName::from_str_and_line((&tmp).into(), expr.location.row());
|
let tmp_name =
|
||||||
|
VarName::from_str_and_line((&tmp).into(), expr.location.row() as u32);
|
||||||
let tmp_expr = Expr::Accessor(Accessor::Ident(Identifier::new(
|
let tmp_expr = Expr::Accessor(Accessor::Ident(Identifier::new(
|
||||||
Some(DOT),
|
Some(DOT),
|
||||||
tmp_name.clone(),
|
tmp_name.clone(),
|
||||||
|
@ -401,8 +427,8 @@ impl ASTConverter {
|
||||||
let index = Literal::new(Token::new(
|
let index = Literal::new(Token::new(
|
||||||
TokenKind::NatLit,
|
TokenKind::NatLit,
|
||||||
i.to_string(),
|
i.to_string(),
|
||||||
elem.location.row(),
|
elem.location.row() as u32,
|
||||||
elem.location.column() - 1,
|
elem.location.column() as u32 - 1,
|
||||||
));
|
));
|
||||||
let (param, mut blocks) = self.convert_expr_to_param(elem);
|
let (param, mut blocks) = self.convert_expr_to_param(elem);
|
||||||
let sig = Signature::Var(VarSignature::new(
|
let sig = Signature::Var(VarSignature::new(
|
||||||
|
@ -426,8 +452,8 @@ impl ASTConverter {
|
||||||
let token = Token::new(
|
let token = Token::new(
|
||||||
TokenKind::UBar,
|
TokenKind::UBar,
|
||||||
"_",
|
"_",
|
||||||
expr.location.row(),
|
expr.location.row() as u32,
|
||||||
expr.location.column() - 1,
|
expr.location.column() as u32 - 1,
|
||||||
);
|
);
|
||||||
(
|
(
|
||||||
NonDefaultParamSignature::new(ParamPattern::Discard(token), None),
|
NonDefaultParamSignature::new(ParamPattern::Discard(token), None),
|
||||||
|
@ -461,8 +487,8 @@ impl ASTConverter {
|
||||||
_other => TypeSpec::Infer(Token::new(
|
_other => TypeSpec::Infer(Token::new(
|
||||||
TokenKind::UBar,
|
TokenKind::UBar,
|
||||||
"_",
|
"_",
|
||||||
expr.location.row(),
|
expr.location.row() as u32,
|
||||||
expr.location.column() - 1,
|
expr.location.column() as u32 - 1,
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,8 +513,13 @@ impl ASTConverter {
|
||||||
let last = elems.last().unwrap();
|
let last = elems.last().unwrap();
|
||||||
(last.location.row(), last.location.column())
|
(last.location.row(), last.location.column())
|
||||||
};
|
};
|
||||||
let l_brace = Token::new(l_kind, l_cont, expr_loc.row(), expr_loc.column() - 1);
|
let l_brace = Token::new(
|
||||||
let r_brace = Token::new(r_kind, r_cont, l_end, c_end);
|
l_kind,
|
||||||
|
l_cont,
|
||||||
|
expr_loc.row() as u32,
|
||||||
|
expr_loc.column() as u32 - 1,
|
||||||
|
);
|
||||||
|
let r_brace = Token::new(r_kind, r_cont, l_end as u32, c_end as u32);
|
||||||
(l_brace, r_brace)
|
(l_brace, r_brace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +543,12 @@ impl ASTConverter {
|
||||||
return Expr::Dummy(Dummy::new(vec![]));
|
return Expr::Dummy(Dummy::new(vec![]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let token = Token::new(kind, cont, expr.location.row(), expr.location.column() - 1);
|
let token = Token::new(
|
||||||
|
kind,
|
||||||
|
cont,
|
||||||
|
expr.location.row() as u32,
|
||||||
|
expr.location.column() as u32 - 1,
|
||||||
|
);
|
||||||
Expr::Lit(Literal::new(token))
|
Expr::Lit(Literal::new(token))
|
||||||
}
|
}
|
||||||
ExpressionType::String { value } => {
|
ExpressionType::String { value } => {
|
||||||
|
@ -524,34 +560,34 @@ impl ASTConverter {
|
||||||
let token = Token::new(
|
let token = Token::new(
|
||||||
TokenKind::StrLit,
|
TokenKind::StrLit,
|
||||||
value,
|
value,
|
||||||
expr.location.row(),
|
expr.location.row() as u32,
|
||||||
expr.location.column() - 2,
|
expr.location.column() as u32 - 2,
|
||||||
);
|
);
|
||||||
Expr::Lit(Literal::new(token))
|
Expr::Lit(Literal::new(token))
|
||||||
}
|
}
|
||||||
ExpressionType::False => Expr::Lit(Literal::new(Token::new(
|
ExpressionType::False => Expr::Lit(Literal::new(Token::new(
|
||||||
TokenKind::BoolLit,
|
TokenKind::BoolLit,
|
||||||
"False",
|
"False",
|
||||||
expr.location.row(),
|
expr.location.row() as u32,
|
||||||
expr.location.column() - 1,
|
expr.location.column() as u32 - 1,
|
||||||
))),
|
))),
|
||||||
ExpressionType::True => Expr::Lit(Literal::new(Token::new(
|
ExpressionType::True => Expr::Lit(Literal::new(Token::new(
|
||||||
TokenKind::BoolLit,
|
TokenKind::BoolLit,
|
||||||
"True",
|
"True",
|
||||||
expr.location.row(),
|
expr.location.row() as u32,
|
||||||
expr.location.column() - 1,
|
expr.location.column() as u32 - 1,
|
||||||
))),
|
))),
|
||||||
ExpressionType::None => Expr::Lit(Literal::new(Token::new(
|
ExpressionType::None => Expr::Lit(Literal::new(Token::new(
|
||||||
TokenKind::NoneLit,
|
TokenKind::NoneLit,
|
||||||
"None",
|
"None",
|
||||||
expr.location.row(),
|
expr.location.row() as u32,
|
||||||
expr.location.column() - 1,
|
expr.location.column() as u32 - 1,
|
||||||
))),
|
))),
|
||||||
ExpressionType::Ellipsis => Expr::Lit(Literal::new(Token::new(
|
ExpressionType::Ellipsis => Expr::Lit(Literal::new(Token::new(
|
||||||
TokenKind::EllipsisLit,
|
TokenKind::EllipsisLit,
|
||||||
"Ellipsis",
|
"Ellipsis",
|
||||||
expr.location.row(),
|
expr.location.row() as u32,
|
||||||
expr.location.column() - 1,
|
expr.location.column() as u32 - 1,
|
||||||
))),
|
))),
|
||||||
ExpressionType::IfExpression { test, body, orelse } => {
|
ExpressionType::IfExpression { test, body, orelse } => {
|
||||||
let block = self.convert_expr(*body);
|
let block = self.convert_expr(*body);
|
||||||
|
@ -861,7 +897,7 @@ impl ASTConverter {
|
||||||
let call_ident = Identifier::new(Some(DOT), VarName::from_static("__call__"));
|
let call_ident = Identifier::new(Some(DOT), VarName::from_static("__call__"));
|
||||||
let params = Params::new(vec![], None, vec![], None);
|
let params = Params::new(vec![], None, vec![], None);
|
||||||
let class_ident =
|
let class_ident =
|
||||||
Identifier::public_with_line(DOT, self.namespace.last().unwrap().into(), line);
|
Identifier::public_with_line(DOT, self.namespace.last().unwrap().into(), line as u32);
|
||||||
let class_spec = TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(SimpleTypeSpec::new(
|
let class_spec = TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(SimpleTypeSpec::new(
|
||||||
class_ident,
|
class_ident,
|
||||||
ConstArgs::empty(),
|
ConstArgs::empty(),
|
||||||
|
@ -1038,8 +1074,10 @@ impl ASTConverter {
|
||||||
}
|
}
|
||||||
ExpressionType::Tuple { elements } => {
|
ExpressionType::Tuple { elements } => {
|
||||||
let tmp = fresh_varname();
|
let tmp = fresh_varname();
|
||||||
let tmp_name =
|
let tmp_name = VarName::from_str_and_line(
|
||||||
VarName::from_str_and_line((&tmp).into(), stmt.location.row());
|
(&tmp).into(),
|
||||||
|
stmt.location.row() as u32,
|
||||||
|
);
|
||||||
let tmp_ident = Identifier::new(Some(DOT), tmp_name);
|
let tmp_ident = Identifier::new(Some(DOT), tmp_name);
|
||||||
let tmp_expr = Expr::Accessor(Accessor::Ident(tmp_ident.clone()));
|
let tmp_expr = Expr::Accessor(Accessor::Ident(tmp_ident.clone()));
|
||||||
let sig = Signature::Var(VarSignature::new(
|
let sig = Signature::Var(VarSignature::new(
|
||||||
|
@ -1057,8 +1095,8 @@ impl ASTConverter {
|
||||||
let index = Literal::new(Token::new(
|
let index = Literal::new(Token::new(
|
||||||
TokenKind::NatLit,
|
TokenKind::NatLit,
|
||||||
i.to_string(),
|
i.to_string(),
|
||||||
elem.location.row(),
|
elem.location.row() as u32,
|
||||||
elem.location.column() - 1,
|
elem.location.column() as u32 - 1,
|
||||||
));
|
));
|
||||||
let (param, mut blocks) = self.convert_expr_to_param(elem);
|
let (param, mut blocks) = self.convert_expr_to_param(elem);
|
||||||
let sig = Signature::Var(VarSignature::new(
|
let sig = Signature::Var(VarSignature::new(
|
||||||
|
@ -1309,8 +1347,8 @@ impl ASTConverter {
|
||||||
let mod_name = Expr::Lit(Literal::new(Token::new(
|
let mod_name = Expr::Lit(Literal::new(Token::new(
|
||||||
TokenKind::StrLit,
|
TokenKind::StrLit,
|
||||||
cont,
|
cont,
|
||||||
stmt.location.row(),
|
stmt.location.row() as u32,
|
||||||
stmt.location.column() - 1,
|
stmt.location.column() as u32 - 1,
|
||||||
)));
|
)));
|
||||||
let args = Args::new(vec![PosArg::new(mod_name)], vec![], None);
|
let args = Args::new(vec![PosArg::new(mod_name)], vec![], None);
|
||||||
let call = import_acc.call_expr(args);
|
let call = import_acc.call_expr(args);
|
||||||
|
@ -1351,8 +1389,8 @@ impl ASTConverter {
|
||||||
let mod_name = Expr::Lit(Literal::new(Token::new(
|
let mod_name = Expr::Lit(Literal::new(Token::new(
|
||||||
TokenKind::StrLit,
|
TokenKind::StrLit,
|
||||||
cont,
|
cont,
|
||||||
stmt.location.row(),
|
stmt.location.row() as u32,
|
||||||
stmt.location.column() - 1,
|
stmt.location.column() as u32 - 1,
|
||||||
)));
|
)));
|
||||||
let args = Args::new(vec![PosArg::new(mod_name)], vec![], None);
|
let args = Args::new(vec![PosArg::new(mod_name)], vec![], None);
|
||||||
let call = import_acc.call_expr(args);
|
let call = import_acc.call_expr(args);
|
||||||
|
|
|
@ -2,10 +2,12 @@ use erg_common::config::ErgConfig;
|
||||||
use erg_common::error::{ErrorCore, ErrorKind, MultiErrorDisplay};
|
use erg_common::error::{ErrorCore, ErrorKind, MultiErrorDisplay};
|
||||||
use erg_common::style::{BLUE, GREEN, RED, RESET, YELLOW};
|
use erg_common::style::{BLUE, GREEN, RED, RESET, YELLOW};
|
||||||
use erg_common::traits::{Runnable, Stream};
|
use erg_common::traits::{Runnable, Stream};
|
||||||
|
use erg_common::Str;
|
||||||
use erg_compiler::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArtifact};
|
use erg_compiler::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArtifact};
|
||||||
use erg_compiler::context::ModuleContext;
|
use erg_compiler::context::ModuleContext;
|
||||||
use erg_compiler::erg_parser::ast::AST;
|
use erg_compiler::erg_parser::ast::AST;
|
||||||
use erg_compiler::error::{CompileError, CompileErrors};
|
use erg_compiler::error::{CompileError, CompileErrors};
|
||||||
|
use erg_compiler::global::SharedCompilerResource;
|
||||||
use erg_compiler::lower::ASTLowerer;
|
use erg_compiler::lower::ASTLowerer;
|
||||||
use py2erg::dump_decl_er;
|
use py2erg::dump_decl_er;
|
||||||
use py2erg::{CheckStatus, ShadowingMode};
|
use py2erg::{CheckStatus, ShadowingMode};
|
||||||
|
@ -53,6 +55,13 @@ impl Runnable for PythonAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Buildable for PythonAnalyzer {
|
impl Buildable for PythonAnalyzer {
|
||||||
|
fn inherit(cfg: ErgConfig, shared: SharedCompilerResource) -> Self {
|
||||||
|
let mod_name = Str::rc(cfg.input.file_stem());
|
||||||
|
Self {
|
||||||
|
cfg: cfg.copy(),
|
||||||
|
checker: ASTLowerer::new_with_cache(cfg, mod_name, shared),
|
||||||
|
}
|
||||||
|
}
|
||||||
fn build(&mut self, code: String, mode: &str) -> Result<CompleteArtifact, IncompleteArtifact> {
|
fn build(&mut self, code: String, mode: &str) -> Result<CompleteArtifact, IncompleteArtifact> {
|
||||||
self.analyze(code, mode)
|
self.analyze(code, mode)
|
||||||
}
|
}
|
||||||
|
@ -83,7 +92,7 @@ impl PythonAnalyzer {
|
||||||
err.to_string(),
|
err.to_string(),
|
||||||
0,
|
0,
|
||||||
ErrorKind::SyntaxError,
|
ErrorKind::SyntaxError,
|
||||||
erg_common::error::Location::Line(err.location.row()),
|
erg_common::error::Location::Line(err.location.row() as u32),
|
||||||
);
|
);
|
||||||
let err = CompileError::new(core, self.cfg.input.clone(), "".into());
|
let err = CompileError::new(core, self.cfg.input.clone(), "".into());
|
||||||
IncompleteArtifact::new(None, CompileErrors::from(err), CompileErrors::empty())
|
IncompleteArtifact::new(None, CompileErrors::from(err), CompileErrors::empty())
|
||||||
|
|
|
@ -22,8 +22,8 @@ fn filter_error(_ctx: &ModuleContext, error: CompileError) -> Option<CompileErro
|
||||||
// exclude doc strings
|
// exclude doc strings
|
||||||
ErrorKind::UnusedWarning => {
|
ErrorKind::UnusedWarning => {
|
||||||
let code = error.input.reread_lines(
|
let code = error.input.reread_lines(
|
||||||
error.core.loc.ln_begin().unwrap(),
|
error.core.loc.ln_begin().unwrap_or(1) as usize,
|
||||||
error.core.loc.ln_end().unwrap(),
|
error.core.loc.ln_end().unwrap_or(1) as usize,
|
||||||
);
|
);
|
||||||
if code[0].trim().starts_with("\"\"\"") {
|
if code[0].trim().starts_with("\"\"\"") {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue