2323from specfile .macros import Macros
2424from specfile .sections import Section
2525from specfile .types import SupportsIndex
26- from specfile .utils import UserList , split_conditional_macro_expansion
26+ from specfile .utils import UserList , count_brackets , split_conditional_macro_expansion
2727
2828if TYPE_CHECKING :
2929 from specfile .specfile import Specfile
@@ -489,6 +489,13 @@ def parse(cls, section: Section, context: Optional["Specfile"] = None) -> "Tags"
489489 New instance of `Tags` class.
490490 """
491491
492+ def pop (lines ):
493+ line = lines .pop (0 )
494+ if isinstance (line , str ):
495+ return line , True
496+ else :
497+ return line
498+
492499 def regex_pattern (tag ):
493500 name_regex = get_tag_name_regex (tag )
494501 return rf"^(?P<n>{ name_regex } )(?P<s>\s*:\s*)(?P<v>.+)"
@@ -498,7 +505,8 @@ def regex_pattern(tag):
498505 tag_regexes = [re .compile (regex_pattern (t ), re .IGNORECASE ) for t in TAG_NAMES ]
499506 data = []
500507 buffer : List [str ] = []
501- for line , valid in lines :
508+ while lines :
509+ line , valid = pop (lines )
502510 ws = ""
503511 tokens = re .split (r"([^\S\n]+)$" , line , maxsplit = 1 )
504512 if len (tokens ) > 1 :
@@ -507,10 +515,21 @@ def regex_pattern(tag):
507515 # find out if there is a match for one of the tag regexes
508516 m = next ((m for m in (r .match (line ) for r in tag_regexes ) if m ), None )
509517 if m :
518+ value = m .group ("v" )
519+ if not suffix :
520+ bc , pc = count_brackets (value )
521+ while (bc > 0 or pc > 0 ) and lines :
522+ value += ws
523+ line , _ = pop (lines )
524+ tokens = re .split (r"([^\S\n]+)$" , line , maxsplit = 1 )
525+ if len (tokens ) > 1 :
526+ line , ws , _ = tokens
527+ value += "\n " + line
528+ bc , pc = count_brackets (value )
510529 data .append (
511530 Tag (
512531 m .group ("n" ),
513- m . group ( "v" ) ,
532+ value ,
514533 m .group ("s" ),
515534 Comments .parse (buffer ),
516535 valid ,
@@ -534,8 +553,10 @@ def get_raw_section_data(self) -> List[str]:
534553 result = []
535554 for tag in self .data :
536555 result .extend (tag .comments .get_raw_data ())
537- result .append (
538- f"{ tag ._prefix } { tag .name } { tag ._separator } { tag .value } { tag ._suffix } "
556+ result .extend (
557+ f"{ tag ._prefix } { tag .name } { tag ._separator } { tag .value } { tag ._suffix } " .split (
558+ "\n "
559+ )
539560 )
540561 result .extend (self ._remainder )
541562 return result
0 commit comments