Skip to content

Commit

Permalink
Improve bare key-value pair lexing
Browse files Browse the repository at this point in the history
This commit provides support for tokenising bare keys as `Name::Label`
without introducing backtracking for non-key strings.
  • Loading branch information
pyrmont committed Jul 10, 2019
1 parent 77dd1b8 commit 04238d0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/rouge/lexers/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ class JSON < RegexLexer
mixin :whitespace
rule %r/{/, Punctuation, :object
rule %r/\[/, Punctuation, :array

rule %r/("[^"]*")(:?)/ do |m|
if m[2] == ":"
groups Name::Label, Punctuation
push :value
else
token Str::Double
end
end

rule(%r//) { push :value }
end
Expand Down

0 comments on commit 04238d0

Please sign in to comment.