Skip to content

Commit

Permalink
json-doc: Add support for ellipsis (...) in json.
Browse files Browse the repository at this point in the history
In documentation it is often helpful to be able to omit details not currently
relevant. In contrast to a comment, this syntax is allowed between a comma and
the end of an object. This allows for more uniform usage when omitting details
at the end of an object.
  • Loading branch information
Martin Hostettler committed Mar 3, 2015
1 parent 263a9c0 commit 18a2786
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rouge/lexers/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,20 @@ class JSONDOC < JSON

prepend :root do
mixin :comments
rule /(\.\.\.)/, Comment::Single
end

prepend :object_key_initial do
mixin :comments
rule /(\.\.\.)/, Comment::Single
end

prepend :object_key do
mixin :comments
rule /(\.\.\.)/ do
token Comment::Single
goto :object_key_initial
end
end

state :comments do
Expand Down
15 changes: 15 additions & 0 deletions spec/visual/samples/json-doc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
"postalCode": "10021",
"country": "US"
},
"ellipsis": {
"object": { ... },
...
"list": [ ... ],
"locations": {
...
"city": "New York",
...
"postalCode": "10021",
...
},
"key": ...,
...
},
"comments": { // comments
"key": "value", // in
"list": [
Expand All @@ -18,6 +32,7 @@
"emptyObject": { // comment
}
},
...
"errors": {
"object": { "a", "b" }
},
Expand Down

0 comments on commit 18a2786

Please sign in to comment.