@@ -110,16 +110,15 @@ pub fn parse(
110110
111111 let base_sel = scraper:: selector:: Selector :: parse ( "html>head>base" ) . unwrap ( ) ;
112112
113- if let Some ( base_el) = doc. select ( & base_sel) . next ( ) {
114- if let Some ( base_href) = base_el. attr ( "href" ) {
115- base =
116- Iri :: parse ( base_href. to_string ( ) ) . map_err ( |source| Error :: IriParseError {
117- source,
118- iri : base_href. to_string ( ) ,
119- } ) ?;
120-
121- trace ! ( "<base> found: {base}" ) ;
122- }
113+ if let Some ( base_el) = doc. select ( & base_sel) . next ( )
114+ && let Some ( base_href) = base_el. attr ( "href" )
115+ {
116+ base = Iri :: parse ( base_href. to_string ( ) ) . map_err ( |source| Error :: IriParseError {
117+ source,
118+ iri : base_href. to_string ( ) ,
119+ } ) ?;
120+
121+ trace ! ( "<base> found: {base}" ) ;
123122 }
124123
125124 let eval_context = EvaluationContext :: new ( base) ;
@@ -174,9 +173,7 @@ impl ListMapping {
174173 pub fn except_for ( & self , other : & ListMapping ) -> Self {
175174 let mut lists = self . lists . clone ( ) ;
176175 lists. retain ( |key, _| !other. lists . contains_key ( key) ) ;
177- Self {
178- lists : lists. into ( ) ,
179- }
176+ Self { lists }
180177 }
181178}
182179
@@ -282,7 +279,7 @@ impl<'b> LocalScope<'b> {
282279 }
283280 }
284281
285- fn empty_curie ( & self ) -> oxrdf:: NamedNodeRef {
282+ fn empty_curie ( & self ) -> oxrdf:: NamedNodeRef < ' _ > {
286283 oxrdf:: NamedNodeRef :: new_unchecked ( self . eval_context . base . as_str ( ) )
287284 }
288285
@@ -779,7 +776,7 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
779776 // instantiated on the current element, use the list as follows:
780777 }
781778 S :: OutputList ( subject, list_mapping) => {
782- if let Some ( list_mapping) = Rc :: try_unwrap ( list_mapping) . ok ( ) {
779+ if let Ok ( list_mapping) = Rc :: try_unwrap ( list_mapping) {
783780 // 14. (cont)
784781 for ( iri, list) in list_mapping. into_inner ( ) . lists . iter ( ) {
785782 // “If there are zero items in the list associated with the IRI, generate the following triple:
@@ -834,11 +831,11 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
834831 trace ! (
835832 "{}{}{} {attrs}" ,
836833 ancestor_stack. join( ">" ) ,
837- ancestor_stack
838- . is_empty ( )
839- . not ( )
840- . then_some ( ">" )
841- . unwrap_or_default ( ) ,
834+ if ancestor_stack. is_empty ( ) . not ( ) {
835+ ">"
836+ } else {
837+ Default :: default ( )
838+ } ,
842839 el. name( )
843840 ) ;
844841 }
@@ -955,7 +952,7 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
955952 }
956953 }
957954
958- let handle_safecurie_or_curie_or_iri_s =
955+ let _handle_safecurie_or_curie_or_iri_s =
959956 |value : Option < & str > | -> Option < Vec < NamedOrBlankNode > > {
960957 Some ( local. safecuri_or_curie_or_iri_s ( value?) )
961958 } ;
@@ -1084,7 +1081,7 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
10841081 . or_else ( || src. map ( NamedOrBlankNode :: from) )
10851082 . map ( |x| Rc :: new ( oxrdf:: Subject :: from ( x) ) ) ;
10861083
1087- let new_subject : Rc < oxrdf:: Subject > ;
1084+ let _new_subject : Rc < oxrdf:: Subject > ;
10881085
10891086 //5.
10901087 // “If the current element contains no @rel or @rev attribute,
@@ -1112,12 +1109,9 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
11121109 local. new_subject = Some ( Rc :: new ( local. empty_curie ( ) . into ( ) ) ) ;
11131110 }
11141111 // “otherwise, if parent object is present, new subject is set to the value of parent object.
1115- else if eval_context. parent_object . is_some ( ) {
1116- trace ! (
1117- "- Using parent object as new subject: {}" ,
1118- eval_context. parent_object. as_ref( ) . unwrap( )
1119- ) ;
1120- local. new_subject = eval_context. parent_object . clone ( ) ;
1112+ else if let Some ( parent_obj) = & eval_context. parent_object {
1113+ trace ! ( "- Using parent object as new subject: {}" , parent_obj) ;
1114+ local. new_subject = Some ( parent_obj. clone ( ) ) ;
11211115 }
11221116
11231117 // “If @typeof is present then typed resource is set to the resource obtained from
@@ -1282,7 +1276,7 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
12821276 // “by using the resource from @resource, if present, obtained according to the section on CURIE and IRI Processing;
12831277 // otherwise, by using the IRI from @href, if present, obtained according to the section on CURIE and IRI Processing;
12841278 // otherwise, by using the IRI from @src, if present, obtained according to the section on CURIE and IRI Processing;
1285- local. current_object_resource = Some ( Rc :: new ( resource_iri. clone ( ) . into ( ) ) ) ;
1279+ local. current_object_resource = Some ( Rc :: new ( resource_iri. clone ( ) ) ) ;
12861280 trace ! (
12871281 "- Using @resource/@href/@src as current object resource: {}" ,
12881282 local. current_object_resource. as_ref( ) . unwrap( )
@@ -1335,12 +1329,12 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
13351329 // 8.
13361330 // “If in any of the previous steps a new subject
13371331 // was set to a non-null value different from the parent object;
1338- if let Some ( ns) = & local. new_subject {
1339- if Some ( ns) != eval_context. parent_object . as_ref ( ) {
1340- // “The list mapping taken from the evaluation context is set to a new, empty mapping.
1341- trace ! ( "- Setting new list mapping" ) ;
1342- local . list_mappings = Default :: default ( ) ;
1343- }
1332+ if let Some ( ns) = & local. new_subject
1333+ && Some ( ns) != eval_context. parent_object . as_ref ( )
1334+ {
1335+ // “The list mapping taken from the evaluation context is set to a new, empty mapping.
1336+ trace ! ( "- Setting new list mapping" ) ;
1337+ local . list_mappings = Default :: default ( ) ;
13441338 }
13451339
13461340 // 9.
@@ -1539,7 +1533,7 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
15391533 oxrdf:: LiteralRef :: new_typed_literal ( & content_val, datatype) . into ( )
15401534 }
15411535 }
1542- Some ( NamedOrBlankNode :: BlankNode ( blank_node ) ) => todo ! ( ) ,
1536+ Some ( NamedOrBlankNode :: BlankNode ( _blank_node ) ) => todo ! ( ) ,
15431537 }
15441538 } else if let Some ( otherwise_datatype) = otherwise_datatype {
15451539 // [html-rdfa] extension #9
@@ -1614,47 +1608,47 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
16141608 // 12.
16151609 // “If the skip element flag is 'false', and new subject was set to a non-null value,
16161610 // then any incomplete triples within the current context should be completed:
1617- if !local. skip_element {
1618- if let Some ( new_subject) = & local. new_subject {
1619- // “The list of incomplete triples from the current evaluation context
1620- // (not the local list of incomplete triples) will contain zero or more predicate
1621- // IRIs. This list is iterated over and each of the predicates is used with parent
1622- // subject and new subject to generate a triple or add a new element to the local
1623- // list mapping. Note that at each level there are two lists of incomplete triples;
1624- // one for the current processing level (which is passed to each child element in
1625- // the previous step), and one that was received as part of the evaluation context.
1626- // It is the latter that is used in processing during this step .
1627- for incomplete in eval_context . incomplete_triples . iter ( ) {
1628- // “Note that each incomplete triple has a direction value that is used to determine
1629- // what will become the subject, and what will become the object, of each generated triple:
1630- match incomplete {
1631- // “If direction is 'none',
1632- // the new subject is added to the list from the iterated incomplete triple.
1633- IncompleteTriple :: List ( name , list ) => list
1634- . borrow_mut ( )
1635- . push ( Rc :: new ( new_subject . as_ref ( ) . clone ( ) . into ( ) ) ) ,
1636- // “If direction is 'forward' then the following triple is generated:
1637- IncompleteTriple :: Forward ( predicate ) => {
1638- self . emit_output ( TripleRef :: new (
1639- // subject = parent subject
1640- eval_context . parent_subject . as_ref ( ) ,
1641- // predicate = the predicate from the iterated incomplete triple
1642- predicate. as_ref ( ) ,
1643- // object = new subject
1644- new_subject . as_ref ( ) ,
1645- ) ) ;
1646- }
1647- // “If direction is 'reverse' then this is the triple generated:
1648- IncompleteTriple :: Reverse ( predicate ) => {
1649- self . emit_output ( TripleRef :: new (
1650- // subject = new subject
1651- new_subject . as_ref ( ) ,
1652- // predicate = the predicate from the iterated incomplete triple
1653- predicate. as_ref ( ) ,
1654- // object = parent subject
1655- eval_context . parent_subject . as_ref ( ) ,
1656- ) ) ;
1657- }
1611+ if !local. skip_element
1612+ && let Some ( new_subject) = & local. new_subject
1613+ {
1614+ // “The list of incomplete triples from the current evaluation context
1615+ // (not the local list of incomplete triples) will contain zero or more predicate
1616+ // IRIs. This list is iterated over and each of the predicates is used with parent
1617+ // subject and new subject to generate a triple or add a new element to the local
1618+ // list mapping. Note that at each level there are two lists of incomplete triples;
1619+ // one for the current processing level (which is passed to each child element in
1620+ // the previous step), and one that was received as part of the evaluation context .
1621+ // It is the latter that is used in processing during this step.
1622+ for incomplete in eval_context . incomplete_triples . iter ( ) {
1623+ // “Note that each incomplete triple has a direction value that is used to determine
1624+ // what will become the subject, and what will become the object, of each generated triple:
1625+ match incomplete {
1626+ // “If direction is 'none',
1627+ // the new subject is added to the list from the iterated incomplete triple.
1628+ IncompleteTriple :: List ( _name , list ) => list
1629+ . borrow_mut ( )
1630+ . push ( Rc :: new ( new_subject . as_ref ( ) . clone ( ) . into ( ) ) ) ,
1631+ // “If direction is 'forward' then the following triple is generated:
1632+ IncompleteTriple :: Forward ( predicate ) => {
1633+ self . emit_output ( TripleRef :: new (
1634+ // subject = parent subject
1635+ eval_context . parent_subject . as_ref ( ) ,
1636+ // predicate = the predicate from the iterated incomplete triple
1637+ predicate . as_ref ( ) ,
1638+ // object = new subject
1639+ new_subject . as_ref ( ) ,
1640+ ) ) ;
1641+ }
1642+ // “If direction is 'reverse' then this is the triple generated:
1643+ IncompleteTriple :: Reverse ( predicate ) => {
1644+ self . emit_output ( TripleRef :: new (
1645+ // subject = new subject
1646+ new_subject . as_ref ( ) ,
1647+ // predicate = the predicate from the iterated incomplete triple
1648+ predicate . as_ref ( ) ,
1649+ // object = parent subject
1650+ eval_context . parent_subject . as_ref ( ) ,
1651+ ) ) ;
16581652 }
16591653 }
16601654 }
0 commit comments