Skip to content

Commit

Permalink
Add support for inline tables to TOML lexer (#1359)
Browse files Browse the repository at this point in the history
The current TOML lexer does not support inline tables. This commit fixes
that by adding a new `:inline` state.
  • Loading branch information
pyrmont committed Nov 20, 2019
1 parent 3da22f9 commit b8b955c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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 }

0 comments on commit b8b955c

Please sign in to comment.