Add and, or type parsing

This commit is contained in:
Shunsuke Shibayama 2022-10-02 11:53:15 +09:00
parent 05c434781b
commit a4f0ad4024
2 changed files with 23 additions and 3 deletions

View file

@ -366,7 +366,7 @@ impl Context {
/// assert supertype_of(Bool, Bool) /// assert supertype_of(Bool, Bool)
/// ``` /// ```
/// This function does not consider the nominal subtype relation. /// This function does not consider the nominal subtype relation.
/// Use `rec_full_supertype_of` for complete judgement. /// Use `supertype_of` for complete judgement.
/// 単一化、評価等はここでは行わない、スーパータイプになる可能性があるかだけ判定する /// 単一化、評価等はここでは行わない、スーパータイプになる可能性があるかだけ判定する
/// ので、lhsが(未連携)型変数の場合は単一化せずにtrueを返す /// ので、lhsが(未連携)型変数の場合は単一化せずにtrueを返す
pub(crate) fn structural_supertype_of(&self, lhs: &Type, rhs: &Type) -> bool { pub(crate) fn structural_supertype_of(&self, lhs: &Type, rhs: &Type) -> bool {

View file

@ -2121,8 +2121,8 @@ impl Parser {
Ok(bounds) Ok(bounds)
} }
fn convert_type_arg_to_bound(&mut self, _arg: PosArg) -> ParseResult<TypeBoundSpec> { fn convert_type_arg_to_bound(&mut self, arg: PosArg) -> ParseResult<TypeBoundSpec> {
match _arg.expr { match arg.expr {
Expr::TypeAsc(tasc) => { Expr::TypeAsc(tasc) => {
let lhs = self let lhs = self
.convert_rhs_to_sig(*tasc.expr) .convert_rhs_to_sig(*tasc.expr)
@ -2529,6 +2529,26 @@ impl Parser {
.map_err(|_| self.stack_dec())?; .map_err(|_| self.stack_dec())?;
self.level -= 1; self.level -= 1;
Ok(TypeSpec::Interval { op, lhs, rhs }) Ok(TypeSpec::Interval { op, lhs, rhs })
} else if bin.op.kind == TokenKind::AndOp {
let mut args = bin.args.into_iter();
let lhs = self
.convert_rhs_to_type_spec(*args.next().unwrap())
.map_err(|_| self.stack_dec())?;
let rhs = self
.convert_rhs_to_type_spec(*args.next().unwrap())
.map_err(|_| self.stack_dec())?;
self.level -= 1;
Ok(TypeSpec::and(lhs, rhs))
} else if bin.op.kind == TokenKind::OrOp {
let mut args = bin.args.into_iter();
let lhs = self
.convert_rhs_to_type_spec(*args.next().unwrap())
.map_err(|_| self.stack_dec())?;
let rhs = self
.convert_rhs_to_type_spec(*args.next().unwrap())
.map_err(|_| self.stack_dec())?;
self.level -= 1;
Ok(TypeSpec::or(lhs, rhs))
} else { } else {
self.level -= 1; self.level -= 1;
let err = ParseError::simple_syntax_error(line!() as usize, bin.loc()); let err = ParseError::simple_syntax_error(line!() as usize, bin.loc());