Add ast::Dummy

This commit is contained in:
Shunsuke Shibayama 2022-12-11 23:43:36 +09:00
parent 34eb413456
commit 03319d1c8c
4 changed files with 95 additions and 7 deletions

View file

@ -1166,6 +1166,29 @@ impl Locational for Block {
impl_stream_for_wrapper!(Block, Expr);
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Dummy(Vec<Expr>);
impl NestedDisplay for Dummy {
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result {
fmt_lines(self.0.iter(), f, level)
}
}
impl_display_from_nested!(Dummy);
impl Locational for Dummy {
fn loc(&self) -> Location {
if self.0.is_empty() {
Location::Unknown
} else {
Location::concat(self.0.first().unwrap(), self.0.last().unwrap())
}
}
}
impl_stream_for_wrapper!(Dummy, Expr);
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct ConstLocal {
pub symbol: Token,
@ -3532,7 +3555,7 @@ pub enum Expr {
PatchDef(PatchDef),
AttrDef(AttrDef),
/// for mapping to Python AST
Dummy(Block),
Dummy(Dummy),
}
impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef, Dummy);

View file

@ -14,9 +14,9 @@ use erg_common::{enum_unwrap, get_hash, log, set};
use crate::ast::{
Accessor, Args, Array, ArrayComprehension, ArrayTypeSpec, ArrayWithLength, AttrDef, BinOp,
Block, Call, ClassAttr, ClassAttrs, ClassDef, ConstExpr, DataPack, Def, DefBody, DefId, Dict,
Expr, Identifier, KeyValue, KwArg, Lambda, LambdaSignature, Literal, Methods, MixedRecord,
Module, NonDefaultParamSignature, NormalArray, NormalDict, NormalRecord, NormalSet,
NormalTuple, ParamPattern, ParamRecordAttr, Params, PatchDef, PosArg, Record,
Dummy, Expr, Identifier, KeyValue, KwArg, Lambda, LambdaSignature, Literal, Methods,
MixedRecord, Module, NonDefaultParamSignature, NormalArray, NormalDict, NormalRecord,
NormalSet, NormalTuple, ParamPattern, ParamRecordAttr, Params, PatchDef, PosArg, Record,
RecordAttrOrIdent, RecordAttrs, Set as astSet, SetWithLength, Signature, SubrSignature, Tuple,
TupleTypeSpec, TypeAppArgs, TypeBoundSpecs, TypeSpec, TypeSpecWithOp, UnaryOp, VarName,
VarPattern, VarRecordAttr, VarSignature,
@ -301,7 +301,7 @@ impl Desugarer {
for chunk in exprs.into_iter() {
chunks.push(desugar(chunk));
}
Expr::Dummy(Block::new(chunks))
Expr::Dummy(Dummy::new(chunks))
}
}
}