diff --git a/script/debug_parser.ts b/script/debug_parser.ts index 92f50701..e62ba77c 100644 --- a/script/debug_parser.ts +++ b/script/debug_parser.ts @@ -14,10 +14,16 @@ const grammarFile = `${parserFolder}/grammar.pegjs`; const helpersFile = `${parserFolder}/helpers.ts`; const chordGrammarFile = './src/parser/chord/base_grammar.pegjs'; const chordSuffixGrammarFile = './src/parser/chord/suffix_grammar.pegjs'; +const whitespaceGrammarFile = './src/parser/whitespace_grammar.pegjs'; +const sectionsGrammarFile = './src/parser/chord_pro/sections_grammar.pegjs'; +const chordDefinitionGrammarFile = './src/parser/chord_definition/grammar.pegjs'; const parserGrammar = fs.readFileSync(grammarFile, 'utf8'); const chordGrammar = skipChordGrammar ? '' : fs.readFileSync(chordGrammarFile); const chordSuffixGrammar = fs.readFileSync(chordSuffixGrammarFile); +const whitespaceGrammar = fs.readFileSync(whitespaceGrammarFile); +const sectionsGrammar = fs.readFileSync(sectionsGrammarFile); +const chordDefinitionGrammar = fs.readFileSync(chordDefinitionGrammarFile); const result = esbuild.buildSync({ bundle: true, @@ -33,6 +39,9 @@ const parserSource = [ parserGrammar, chordGrammar, chordSuffixGrammar, + chordDefinitionGrammar, + sectionsGrammar, + whitespaceGrammar, ].join('\n\n'); async function run() { diff --git a/src/parser/whitespace.grammar b/src/parser/whitespace_grammar.pegjs similarity index 95% rename from src/parser/whitespace.grammar rename to src/parser/whitespace_grammar.pegjs index 240d379d..72392179 100644 --- a/src/parser/whitespace.grammar +++ b/src/parser/whitespace_grammar.pegjs @@ -8,7 +8,7 @@ WhitespaceCharacter = [ \t\n\r] Space "space" - = [ \t]+ + = $([ \t]+) NewLine = CarriageReturn / LineFeed / CarriageReturnLineFeed diff --git a/test/parser/chord_pro_parser.test.ts b/test/parser/chord_pro_parser.test.ts index 7d24d0a5..00fa1dff 100644 --- a/test/parser/chord_pro_parser.test.ts +++ b/test/parser/chord_pro_parser.test.ts @@ -76,6 +76,15 @@ describe('ChordProParser', () => { expect(song.lines[0].items[0]).toBeTag('comment', 'Some {comment}'); }); + it('correctly parses multiple whitespace characters', () => { + const chordSheet = '[C]Let it be '; + const song = new ChordProParser().parse(chordSheet); + const { items } = song.lines[0]; + + expect(items[0]).toBeChordLyricsPair('C', 'Let '); + expect(items[1]).toBeChordLyricsPair('', 'it be '); + }); + it('parses directive with empty value', () => { const song = new ChordProParser().parse('{c: }'); expect(song.lines[0].items[0]).toBeTag('comment', ''); diff --git a/unibuild.ts b/unibuild.ts index 1372d1e5..b2441c97 100755 --- a/unibuild.ts +++ b/unibuild.ts @@ -70,7 +70,7 @@ unibuild((u: Builder) => { 'src/parser/chord_pro/grammar.pegjs', 'src/parser/chord_definition/grammar.pegjs', sectionsGrammar, - 'src/parser/whitespace.grammar', + 'src/parser/whitespace_grammar.pegjs', ], outfile: 'src/parser/chord_pro/peg_parser.ts', build: ({ release }: BuildOptions, ...grammars: string[]) => { @@ -82,7 +82,7 @@ unibuild((u: Builder) => { const chordDefinitionParser = u.asset('chordDefinitionParser', { input: [ 'src/parser/chord_definition/grammar.pegjs', - 'src/parser/whitespace.grammar', + 'src/parser/whitespace_grammar.pegjs', ], outfile: 'src/parser/chord_definition/peg_parser.ts', build: ({ release }: BuildOptions, ...grammars: string[]) => (