This commit is contained in:
Slug 2025-12-04 11:23:42 +09:00 committed by GitHub
commit fe27ffb0b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 53 additions and 23 deletions

View file

@ -27,6 +27,6 @@ fn main() -> std::io::Result<()> {
} else {
true
};
println!("cargo:rustc-env=CASE_SENSITIVE={}", case_sensitive);
println!("cargo:rustc-env=CASE_SENSITIVE={case_sensitive}");
Ok(())
}

View file

@ -1982,8 +1982,8 @@ pub enum GuardClause {
impl NestedDisplay for GuardClause {
fn fmt_nest(&self, f: &mut std::fmt::Formatter<'_>, _level: usize) -> std::fmt::Result {
match self {
GuardClause::Condition(cond) => write!(f, "{}", cond),
GuardClause::Bind(bind) => write!(f, "{}", bind),
GuardClause::Condition(cond) => write!(f, "{cond}"),
GuardClause::Bind(bind) => write!(f, "{bind}"),
}
}
}

View file

@ -642,14 +642,14 @@ impl CodeObj {
write!(instrs, "{arg} ({})", self.cellvars[arg]).unwrap();
}
Opcode308::JUMP_ABSOLUTE => {
write!(instrs, "{arg} (to {})", arg).unwrap();
write!(instrs, "{arg} (to {arg})").unwrap();
}
Opcode308::JUMP_FORWARD => {
write!(instrs, "{arg} (to {})", idx + arg + 2).unwrap();
}
// REVIEW: *2?
Opcode308::POP_JUMP_IF_FALSE | Opcode308::POP_JUMP_IF_TRUE => {
write!(instrs, "{arg} (to {})", arg).unwrap();
write!(instrs, "{arg} (to {arg})").unwrap();
}
Opcode308::BINARY_ADD
| Opcode308::BINARY_SUBTRACT
@ -690,14 +690,14 @@ impl CodeObj {
write!(instrs, "{arg} ({})", self.cellvars[arg]).unwrap();
}
Opcode309::JUMP_ABSOLUTE => {
write!(instrs, "{arg} (to {})", arg).unwrap();
write!(instrs, "{arg} (to {arg})").unwrap();
}
Opcode309::JUMP_FORWARD => {
write!(instrs, "{arg} (to {})", idx + arg + 2).unwrap();
}
// REVIEW: *2?
Opcode309::POP_JUMP_IF_FALSE | Opcode309::POP_JUMP_IF_TRUE => {
write!(instrs, "{arg} (to {})", arg).unwrap();
write!(instrs, "{arg} (to {arg})").unwrap();
}
Opcode309::BINARY_ADD
| Opcode309::BINARY_SUBTRACT

View file

@ -183,12 +183,12 @@ pub fn try_v_enum(s: Set<ValueObj>) -> Result<Type, Set<ValueObj>> {
}
pub fn v_enum(s: Set<ValueObj>) -> Type {
try_v_enum(s).unwrap_or_else(|set| panic!("not homogeneous: {}", set))
try_v_enum(s).unwrap_or_else(|set| panic!("not homogeneous: {set}"))
}
pub fn t_enum(s: Set<Type>) -> Type {
try_v_enum(s.into_iter().map(ValueObj::builtin_type).collect())
.unwrap_or_else(|set| panic!("not homogeneous: {}", set))
.unwrap_or_else(|set| panic!("not homogeneous: {set}"))
}
pub fn t_singleton(t: Type) -> Type {

View file

@ -451,7 +451,7 @@ impl LimitedDisplay for SubrType {
}
write!(f, "*")?;
if let Some(name) = var_params.name() {
write!(f, "{}: ", name)?;
write!(f, "{name}: ")?;
}
var_params.typ().limited_fmt(f, limit - 1)?;
}

View file

@ -2172,19 +2172,19 @@ impl NestedDisplay for Call {
if i != 0 {
write!(f, ", ")?;
}
write!(f, "{}", arg)?;
write!(f, "{arg}")?;
}
if let Some(rest) = self.args.var_args.as_ref() {
if !self.args.pos_args().is_empty() {
write!(f, ", ")?;
}
write!(f, "*{}", rest)?;
write!(f, "*{rest}")?;
}
for (i, kw_arg) in self.args.kw_args().iter().enumerate() {
if i != 0 || !self.args.pos_args().is_empty() || self.args.var_args.is_some() {
write!(f, ", ")?;
}
write!(f, "{}", kw_arg)?;
write!(f, "{kw_arg}")?;
}
write!(f, ")")
} else {
@ -3204,7 +3204,7 @@ impl NestedDisplay for ConstApp {
fn fmt_nest(&self, f: &mut std::fmt::Formatter<'_>, level: usize) -> std::fmt::Result {
writeln!(f, "{}", self.obj)?;
if let Some(attr_name) = &self.attr_name {
writeln!(f, "{}", attr_name)?;
writeln!(f, "{attr_name}")?;
}
writeln!(f, "(")?;
self.args.fmt_nest(f, level + 1)?;
@ -4459,11 +4459,11 @@ impl fmt::Display for VarName {
#[pymethods]
impl VarName {
pub fn __repr__(&self) -> String {
format!("VarName({})", self)
format!("VarName({self})")
}
pub fn __str__(&self) -> String {
format!("VarName({})", self)
format!("VarName({self})")
}
#[staticmethod]
@ -4733,11 +4733,11 @@ impl From<Identifier> for Expr {
#[pymethods]
impl Identifier {
pub fn __repr__(&self) -> String {
format!("Identifier({})", self)
format!("Identifier({self})")
}
pub fn __str__(&self) -> String {
format!("Identifier({})", self)
format!("Identifier({self})")
}
pub fn is_const(&self) -> bool {
@ -5263,11 +5263,11 @@ impl VarSignature {
}
pub fn __repr__(&self) -> String {
format!("VarSignature({})", self)
format!("VarSignature({self})")
}
pub fn __str__(&self) -> String {
format!("VarSignature({})", self)
format!("VarSignature({self})")
}
}
@ -5722,8 +5722,8 @@ pub enum GuardClause {
impl NestedDisplay for GuardClause {
fn fmt_nest(&self, f: &mut std::fmt::Formatter<'_>, _level: usize) -> std::fmt::Result {
match self {
Self::Condition(cond) => write!(f, "{}", cond),
Self::Bind(def) => write!(f, "{}", def),
Self::Condition(cond) => write!(f, "{cond}"),
Self::Bind(def) => write!(f, "{def}"),
}
}
}

View file

@ -175,6 +175,23 @@ impl LexError {
))
}
pub fn parenthesize_error(errno: usize, loc: Location, got: &str) -> Self {
let msg = switch_lang!(
"japanese" => "不適切な閉じ括弧があります",
"simplified_chinese" => "存在不匹配的右括号",
"traditional_chinese" => "存在不匹配的右括號",
"english" => "unmatched closing parenthesis found",
);
let got = StyledStr::new(got, Some(ERR), Some(ATTR));
let hint = switch_lang!(
"japanese" => format!("この{}は対応する開き括弧がないため、削除するか開き括弧を追加してください", got),
"simplified_chinese" => format!("{}缺少对应的左括号,请删除或添加左括号", got),
"traditional_chinese" => format!("{}缺少對應的左括號,請刪除或添加左括號", got),
"english" => format!("{} has no matching opening parenthesis - either remove it or add an opening parenthesis", got),
);
Self::syntax_error(errno, loc, msg, Some(hint))
}
pub fn expect_next_line_error(errno: usize, loc: Location, caused: &str) -> Self {
Self::new(ErrorCore::new(
vec![SubMessage::ambiguous_new(

View file

@ -2050,6 +2050,13 @@ impl Parser {
debug_exit_info!(self);
return Err(());
}
Some(t) if t.is(RParen) => {
let err = ParseError::parenthesize_error(line!() as usize, t.loc(), ")");
self.errs.push(err);
self.next_expr();
debug_exit_info!(self);
return Err(());
}
_ => {
if stack.len() <= 1 {
break;

View file

@ -84,6 +84,11 @@ fn parse_invalid_class_definition() -> Result<(), ()> {
expect_failure("tests/invalid_class_definition.er", 0, 7)
}
#[test]
fn parse_missing_paren() -> Result<(), ()> {
expect_failure("tests/unmatched_paren.er", 0, 1)
}
#[test]
fn parse_warns() -> Result<(), ()> {
expect_success("tests/warns.er", 1)

View file

@ -0,0 +1 @@
func a, b) = a + b

View file

@ -454,7 +454,7 @@ impl PackageManagerRunner {
{
Ok(out) => ExitStatus::new(out.status.code().unwrap_or(0), 0, 0),
Err(err) => {
eprintln!("Error: {}", err);
eprintln!("Error: {err}");
ExitStatus::ERR1
}
}