slurmulon / bach

:musical_score: Semantic music notation
http://codebach.tech
MIT License
8 stars 0 forks source link

Nested quotes are broken #16

Closed slurmulon closed 3 years ago

slurmulon commented 5 years ago

Users should be able to nest single quotes inside of double quotes (or vice-versa). Right now this causes a syntax error during parsing

Parse error at line 1, column 16:
@Title = "1960's Memphis Soul Bar Blues Backing Track [Bb - 110 BPM]"
               ^
Expected one of:
!Play
@
#":[a-zA-Z0-9]+"
{
[
(
#"[0-9]+"
#"#[a-fA-F0-9xX]{6}"
#"['|\"](.*?)[\"|']"
#"(`|~|Note|Scale|Chord|Mode|Triad)"
slava92 commented 5 years ago

Hi Erik, The BNF rule for "string" has to explicitly express that it starts and ends with the same character - either single or double quote. Something along this line:

modified   resources/grammar.bnf
@@ -20,7 +20,7 @@ meta       = [<empty>] <'@'> #'(Audio|Instrument|Time|Tempo|Key|Delay|Link|Title
 keyword    = [<empty>] #'(`|~|Note|Scale|Chord|Mode|Triad)' [<empty>]
 play       = [<empty>] <'!Play'> [<empty>] elem
 meter      = [<empty>] number <'|'> number [<empty>]
-string     = #'[\'|\"](.*?)[\"|\']'
+string     = #'(?:\'([^\']*?)\'|\"([^\"]*?)\")'
 word       = #'[a-zA-Z]+'
 number     = #'[0-9]+'
 color      = #'#[a-fA-F0-9xX]{6}'

Cheers

slurmulon commented 5 years ago

@slava92 Oh awesome, thanks for the tip/fix!

Also sorry for the extreme delay, I'm terrible with Github notifications sometimes :face_with_head_bandage: