Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for inline tables to TOML lexer #1359

Merged
merged 1 commit into from Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/rouge/lexers/toml.rb
Expand Up @@ -17,6 +17,12 @@ class TOML < RegexLexer
rule %r/\s+/, Text
rule %r/#.*?$/, Comment
rule %r/(true|false)/, Keyword::Constant

rule %r/(\S+)(\s*)(=)(\s*)(\{)/ do |m|
groups Name::Namespace, Text, Operator, Text, Punctuation
push :inline
end

rule %r/(?<!=)\s*\[[\S]+\]/, Name::Namespace

rule %r/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date
Expand All @@ -33,7 +39,6 @@ class TOML < RegexLexer
groups Name::Property, Text, Punctuation
push :value
end

end

state :value do
Expand Down Expand Up @@ -63,6 +68,16 @@ class TOML < RegexLexer
mixin :content
rule %r/\]/, Punctuation, :pop!
end

state :inline do
mixin :content

rule %r/(#{identifier})(\s*)(=)/ do
groups Name::Property, Text, Punctuation
end

rule %r/\}/, Punctuation, :pop!
end
end
end
end
3 changes: 3 additions & 0 deletions spec/visual/samples/toml
Expand Up @@ -62,3 +62,6 @@ test_string = "You'll hate me after this - #" # " Annoying, isn't it?
]

東京都 = 123

name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }