Skip to content

Commit

Permalink
Merge pull request rouge-ruby#1012 from dblessing/fix_graphql_multili…
Browse files Browse the repository at this point in the history
…ne_str_992

GraphQL: Support for multiline strings
  • Loading branch information
dblessing committed Oct 9, 2018
2 parents 54f062b + d59a7a2 commit e957c74
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/rouge/lexers/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class GraphQL < RegexLexer
rule /\bunion\b/, Keyword, :union_definition

mixin :basic

# Markdown descriptions
rule /(""")(.*?)(""")/m do |m|
token Str::Double, m[1]
delegate Markdown, m[2]
token Str::Double, m[3]
end
end

state :basic do
Expand Down Expand Up @@ -227,6 +234,9 @@ class GraphQL < RegexLexer
}
}

# Multiline strings
rule /""".*?"""/m, Str::Double

rule /\$#{name}\b/, &pop_unless_list[Name::Variable]
rule /\b(?:true|false|null)\b/, &pop_unless_list[Keyword::Constant]
rule /[+-]?[0-9]+\.[0-9]+(?:[eE][+-]?[0-9]+)?/, &pop_unless_list[Num::Float]
Expand Down
25 changes: 24 additions & 1 deletion spec/visual/samples/graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
"""
Decimal number serialized as string.

Should match regexp: `/^[+-]?[0-9]+(\.[0-9]+)$/`

Format:
`<sign>`? `<digit>`+ ( `.` `<digit>`+ )?

Example:
- `"1000"`
- `"0.00000001"`
- `"-10"`
- `"+1"`

This is invalid:
- `".01"` *missing preceding zero*
- `"1,000.00"` *invalid character*
- `"1e-10"` *exponential form is not allowed*
"""

# Most code copied from https://github.com/rmosolgo/language-graphql/blob/master/spec/fixtures/example.graphql
fragment on AnalysisImage @relay(plural: true) {
extension
Expand Down Expand Up @@ -46,7 +66,10 @@ query
queryName(
$float: f = 123.011e-1, $float: f = 123.00, $float: f = 123e+20
$boolean: b ! = true, $boolean: b = false
$String: s = "Some string \" \\ \/ \b \f \r \r and the rest"
$String: s = """Multiline
string
here
"""
$enum: e = aaaa, $enum: e = AAAA_AA
$list : [ String!, Boolean!, ID, Int, Float ] ! = ["aaa", 1 , aFlag]
$object: o = {
Expand Down

0 comments on commit e957c74

Please sign in to comment.