Support additional text on the same lines as section headings.
This commit is contained in:
@ -35,6 +35,7 @@ type
|
||||
case kind: ChordChartNodeKind
|
||||
of ccnkSection:
|
||||
sectionName*: string
|
||||
remainingSectionLine*: Option[string]
|
||||
sectionContents*: seq[ChordChartNode]
|
||||
of ccnkLine:
|
||||
line*: seq[ChordChartNode]
|
||||
@ -267,12 +268,13 @@ proc parseMetadata(ctx: var ParserContext): ChordChartMetadata =
|
||||
|
||||
const KNOWN_SECTION_NAMES = [
|
||||
"chorus", "verse", "bridge", "breakdown", "vamp", "intstrumental",
|
||||
"interlude", "intro", "outtro", "ending", "end", "tag"
|
||||
"interlude", "intro", "outtro", "ending", "end", "tag", "prechorus",
|
||||
"pre-chorus", "pre chorus"
|
||||
]
|
||||
|
||||
let SECTION_LINE_PAT = re(
|
||||
"^((" & # case insensitive
|
||||
"((?i)" & KNOWN_SECTION_NAMES.join("|") & ")" & # known names
|
||||
"^((" & "((?i)" & # case insensitive
|
||||
KNOWN_SECTION_NAMES.join("|") & ")" & # known names
|
||||
"|[[:upper:]]{3,}" & # all upper-case words
|
||||
") ?\\d*)" & # numeric suffix (Verse 2)
|
||||
|
||||
@ -422,12 +424,14 @@ proc parseBody(ctx: var ParserContext): seq[ChordChartNode] =
|
||||
let captures = m.get.captures.toSeq
|
||||
ctx.curSection = ChordChartNode(
|
||||
kind: ccnkSection,
|
||||
sectionName: if captures[0].isSome: captures[0].get.strip
|
||||
else: raise ctx.makeError("unknown error parsing section header: " & line),
|
||||
sectionName:
|
||||
if captures[0].isSome: captures[0].get.strip
|
||||
else: raise ctx.makeError("unknown error parsing section header: " & line),
|
||||
remainingSectionLine:
|
||||
if captures[3].isSome: some(captures[3].get.strip)
|
||||
else: none[string](),
|
||||
sectionContents: @[])
|
||||
result.add(ctx.curSection)
|
||||
if captures[3].isSome:
|
||||
ctx.curSection.sectionContents &= ctx.parseLineParts(captures[3].get)
|
||||
continue
|
||||
|
||||
else:
|
||||
|
Reference in New Issue
Block a user