diff --git a/lib/rouge/lexers/toml.rb b/lib/rouge/lexers/toml.rb index 21339f3605..f931e26898 100644 --- a/lib/rouge/lexers/toml.rb +++ b/lib/rouge/lexers/toml.rb @@ -48,7 +48,10 @@ class TOML < RegexLexer state :content do mixin :basic + rule %r/"""/, Str, :mdq rule %r/"/, Str, :dq + rule %r/'''/, Str, :msq + rule %r/'/, Str, :sq mixin :esc_str rule %r/\,/, Punctuation rule %r/\[/, Punctuation, :array @@ -56,8 +59,28 @@ class TOML < RegexLexer state :dq do rule %r/"/, Str, :pop! + rule %r/\n/, Error, :pop! + mixin :esc_str + rule %r/[^\\"\n]+/, Str + end + + state :mdq do + rule %r/"""/, Str, :pop! mixin :esc_str rule %r/[^\\"]+/, Str + rule %r/"+/, Str + end + + state :sq do + rule %r/'/, Str, :pop! + rule %r/\n/, Error, :pop! + rule %r/[^'\n]+/, Str + end + + state :msq do + rule %r/'''/, Str, :pop! + rule %r/[^']+/, Str + rule %r/'+/, Str end state :esc_str do diff --git a/spec/visual/samples/toml b/spec/visual/samples/toml index 0928d3a5f4..0bf59e1459 100644 --- a/spec/visual/samples/toml +++ b/spec/visual/samples/toml @@ -38,6 +38,45 @@ funky = "I'm a string. \"You can quote me\". Tab \t newline \n you get it." right = "C:\\Users\\nodejs\\templates" wrong = "C:\Users\nodejs\templates" # note: doesn't produce a valid path +# What you see is what you get - no escapes +winpath = 'C:\Users\nodejs\templates' +winpath2 = '\\ServerX\admin$\system32\' +quoted = 'Tom "Dubs" Preston-Werner' +regex = '<\i\c*\s*>' +wrong = 'no multiline - but rest of lex is okay + +# multiline +regex2 = '''I [dw]on't need \d{2} apples''' +lines = ''' +The first newline is +trimmed in raw strings. + All other whitespace + is preserved. +''' + +str4 = """Here are two quotation marks: "". Simple enough.""" +# str5 = """Here are three quotation marks: """.""" # INVALID +str5 = """Here are three quotation marks: ""\".""" +str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\".""" + +# "This," she said, "is just a pointless statement." +str7 = """"This," she said, "is just a pointless statement.""" +# The following strings are byte-for-byte equivalent: +str1 = "The quick brown fox jumps over the lazy dog." + +str2 = """ +The quick brown \ + + + fox jumps over \ + the lazy dog.""" + +str3 = """\ + The quick brown \ + fox jumps over \ + the lazy dog.\ + """ + # Test file for TOML # Only this one tries to emulate a TOML file written by a user of the kind of parser writers probably hate # This part you'll really hate