pub fn term_to_constraint(&self, term: Spanned<Term>) -> Result<Spanned<hir::Constraint>> {
        // Handle range constraints.
        match term.value {
            Term::Range(..) => {
                return Ok(self.term_to_range(term)?.map(|r| hir::Constraint::Range(r)))
            }
            _ => (),
        };

        // Unpack the optional element constraint on array constraints.
        let (term, elem) = match term.value {
            Term::RangeSuffix(subterm, con) | Term::SuffixParen(subterm, con) => {
                (*subterm, Some(*con))
            }
            _ => (term, None),
        };

        // Otherwise handle the array and record constraint cases.
        match term.value {
            Term::Paren(terms) => {
                let any_records = terms.iter().any(|t| match t.value {
                    Term::SuffixParen(..) => true,
                    _ => false,
                });
                if any_records && elem.is_none() {
                    self.term_to_record_constraint(term.span, terms)
                        .map(|t| t.map_into())
                } else {
                    self.term_to_array_constraint(term.span, terms, elem)
                        .map(|t| t.map_into())
                }
            }
            _ => {
                self.emit(
                    DiagBuilder2::error(format!(
                        "`{}` is not a valid constraint",
                        term.span.extract()
                    ))
                    .span(term.span)
                    .add_note(
                        "Did you mean a range constraint (`range ...`) or an array or record \
                         constraint (`(...)`)? See IEEE 1076-2008 section 6.3.",
                    ),
                );
                debugln!("It is a {:#?}", term);
                return Err(());
            }
        }
    }
/// Map a term to a constraint.
Map a term to a constraint.
Map a term to a constraint .
pub fn term_to_constraint(&self, term: Spanned<Term>) -> Result<Spanned<hir::Constraint>> {
        // Handle range constraints.
        match term.value {
            Term::Range(..) => {
                return Ok(self.term_to_range(term)?.map(|r| hir::Constraint::Range(r)))
            }
            _ => (),
        };
        // Unpack the optional element constraint on array constraints.
        let (term, elem) = match term.value {
            Term::RangeSuffix(subterm, con) | Term::SuffixParen(subterm, con) => {
                (*subterm, Some(*con))
            }
            _ => (term, None),
        };
        // Otherwise handle the array and record constraint cases.
        match term.value {
            Term::Paren(terms) => {
                let any_records = terms.iter().any(|t| match t.value {
                    Term::SuffixParen(..) => true,
                    _ => false,
                });
                if any_records && elem.is_none() {
                    self.term_to_record_constraint(term.span, terms)
                        .map(|t| t.map_into())
                } else {
                    self.term_to_array_constraint(term.span, terms, elem)
                        .map(|t| t.map_into())
                }
            }
            _ => {
                self.emit(
                    DiagBuilder2::error(format!(
                        "`{}` is not a valid constraint",
                        term.span.extract()
                    ))
                    .span(term.span)
                    .add_note(
                        "Did you mean a range constraint (`range ...`) or an array or record \
                         constraint (`(...)`)? See IEEE 1076-2008 section 6.3.",
                    ),
                );
                debugln!("It is a {:#?}", term);
                return Err(());
            }
        }
    }
pub fn term_to_constraint ( & self , term : Spanned < Term > ) -> Result < Spanned < hir :: Constraint > > { // Handle range constraints. match term . value { Term :: Range ( .. ) => { return Ok ( self . term_to_range ( term ) ? . map ( | r | hir :: Constraint :: Range ( r ) ) ) } _ => ( ) , } ; // Unpack the optional element constraint on array constraints. let ( term , elem ) = match term . value { Term :: RangeSuffix ( subterm , con ) | Term :: SuffixParen ( subterm , con ) => { ( * subterm , Some ( * con ) ) } _ => ( term , None ) , } ; // Otherwise handle the array and record constraint cases. match term . value { Term :: Paren ( terms ) => { let any_records = terms . iter ( ) . any ( | t | match t . value { Term :: SuffixParen ( .. ) => true , _ => false , } ) ; if any_records && elem . is_none ( ) { self . term_to_record_constraint ( term . span , terms ) . map ( | t | t . map_into ( ) ) } else { self . term_to_array_constraint ( term . span , terms , elem ) . map ( | t | t . map_into ( ) ) } } _ => { self . emit ( DiagBuilder2 :: error ( format ! ( " " term span extract ( ) ) ) . span ( term . span ) . add_note ( " \
 " , ) , ) ; debugln ! ( " " term ) ; return Err ( ( ) ) ; } } }
Map a term to a constraint.
Map a term to a constraint .
&self
term
Spanned<Term>
&self
term
Spanned<Term>