fn load_source(source: Source, kb: &mut KnowledgeBase) -> PolarResult<Vec<Diagnostic>> {
            if let Some(ref filename) = source.filename {
                kb.add_source(filename, &source.src)?;
            }
            // TODO(gj): we still bomb out at the first ParseError.
            let mut lines = parser::parse_lines(source)?;
            lines.reverse();
            let mut diagnostics = vec![];
            while let Some(line) = lines.pop() {
                match line {
                    parser::Line::Rule(rule) => {
                        diagnostics.append(&mut check_singletons(&rule, kb));
                        diagnostics.append(&mut check_ambiguous_precedence(&rule));
                        let rule = rewrite_rule(rule, kb);
                        kb.add_rule(rule);
                    }
                    parser::Line::Query(term) => {
                        kb.inline_queries.push(term);
                    }
                    parser::Line::RuleType(rule_type) => {
                        // make sure rule_type doesn't have anything that needs to be rewritten in the head
                        let rule_type = rewrite_rule(rule_type, kb);
                        if !matches!(
                            rule_type.body.value(),
                            Value::Expression(
                                Operation {
                                    operator: Operator::And,
                                    args
                                }
                            ) if args.is_empty()
                        ) {
                            diagnostics.push(Diagnostic::Error(
                                ValidationError::InvalidRuleType {
                                    rule_type,
                                    msg: "Rule types cannot contain dot lookups.".into(),
                                }
                                .into(),
                            ));
                        } else {
                            kb.add_rule_type(rule_type);
                        }
                    }
                    parser::Line::ResourceBlock {
                        keyword,
                        resource,
                        productions,
                    } => {
                        let (block, mut errors) =
                            resource_block_from_productions(keyword, resource, productions);
                        errors.append(&mut block.add_to_kb(kb));
                        diagnostics.extend(errors.into_iter().map(Into::into));
                    }
                }
            }
            Ok(diagnostics)
        }
// Separate function so that errors returned with `?` are captured.
Separate function so that errors returned with `?` are captured.
Separate function so that errors returned with ` ? ` are captured .
fn load_source(source: Source, kb: &mut KnowledgeBase) -> PolarResult<Vec<Diagnostic>> {
            if let Some(ref filename) = source.filename {
                kb.add_source(filename, &source.src)?;
            }
            // TODO(gj): we still bomb out at the first ParseError.
            let mut lines = parser::parse_lines(source)?;
            lines.reverse();
            let mut diagnostics = vec![];
            while let Some(line) = lines.pop() {
                match line {
                    parser::Line::Rule(rule) => {
                        diagnostics.append(&mut check_singletons(&rule, kb));
                        diagnostics.append(&mut check_ambiguous_precedence(&rule));
                        let rule = rewrite_rule(rule, kb);
                        kb.add_rule(rule);
                    }
                    parser::Line::Query(term) => {
                        kb.inline_queries.push(term);
                    }
                    parser::Line::RuleType(rule_type) => {
                        // make sure rule_type doesn't have anything that needs to be rewritten in the head
                        let rule_type = rewrite_rule(rule_type, kb);
                        if !matches!(
                            rule_type.body.value(),
                            Value::Expression(
                                Operation {
                                    operator: Operator::And,
                                    args
                                }
                            ) if args.is_empty()
                        ) {
                            diagnostics.push(Diagnostic::Error(
                                ValidationError::InvalidRuleType {
                                    rule_type,
                                    msg: "Rule types cannot contain dot lookups.".into(),
                                }
                                .into(),
                            ));
                        } else {
                            kb.add_rule_type(rule_type);
                        }
                    }
                    parser::Line::ResourceBlock {
                        keyword,
                        resource,
                        productions,
                    } => {
                        let (block, mut errors) =
                            resource_block_from_productions(keyword, resource, productions);
                        errors.append(&mut block.add_to_kb(kb));
                        diagnostics.extend(errors.into_iter().map(Into::into));
                    }
                }
            }
            Ok(diagnostics)
        }
fn load_source ( source : Source , kb : & mut KnowledgeBase ) -> PolarResult < Vec < Diagnostic > > { if let Some ( ref filename ) = source . filename { kb . add_source ( filename , & source . src ) ? ; } // TODO(gj): we still bomb out at the first ParseError. let mut lines = parser :: parse_lines ( source ) ? ; lines . reverse ( ) ; let mut diagnostics = vec ! [ ] ; while let Some ( line ) = lines . pop ( ) { match line { parser :: Line :: Rule ( rule ) => { diagnostics . append ( & mut check_singletons ( & rule , kb ) ) ; diagnostics . append ( & mut check_ambiguous_precedence ( & rule ) ) ; let rule = rewrite_rule ( rule , kb ) ; kb . add_rule ( rule ) ; } parser :: Line :: Query ( term ) => { kb . inline_queries . push ( term ) ; } parser :: Line :: RuleType ( rule_type ) => { // make sure rule_type doesn't have anything that needs to be rewritten in the head let rule_type = rewrite_rule ( rule_type , kb ) ; if ! matches ! ( rule_type body value ( ) Value Expression ( Operation { operator Operator And args } ) if args is_empty ( ) ) { diagnostics . push ( Diagnostic :: Error ( ValidationError :: InvalidRuleType { rule_type , msg : " " . into ( ) , } . into ( ) , ) ) ; } else { kb . add_rule_type ( rule_type ) ; } } parser :: Line :: ResourceBlock { keyword , resource , productions , } => { let ( block , mut errors ) = resource_block_from_productions ( keyword , resource , productions ) ; errors . append ( & mut block . add_to_kb ( kb ) ) ; diagnostics . extend ( errors . into_iter ( ) . map ( Into :: into ) ) ; } } } Ok ( diagnostics ) }
Separate function so that errors returned with `?` are captured.
Separate function so that errors returned with ` ? ` are captured .
source
Source
kb
&mut KnowledgeBase
source
Source
kb
&mut KnowledgeBase