Skip to content

Commit a7fbf74

Browse files
andimarekbbakerman
authored andcommitted
comments are source characters without line feed and also allow emoji
1 parent eb2f08e commit a7fbf74

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎src/main/antlr/GraphqlCommon.g4‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,18 @@ TripleQuotedStringValue
119119
120120
121121
// Fragments never become a token of their own: they are only used inside other lexer rules
122-
fragment TripleQuotedStringPart : ( EscapedTripleQuote | SourceCharacter )+?;
122+
fragment TripleQuotedStringPart : ( EscapedTripleQuote | ExtendedSourceCharacter )+?;
123123
fragment EscapedTripleQuote : '\\"""';
124-
fragment SourceCharacter :[\u0009\u000A\u000D\u0020-\u{10FFFF}];
125124
126-
Comment: '#' ~[\n\r\u2028\u2029]* -> channel(2);
125+
// this is currently not covered by the spec because we allow all unicode chars
126+
fragment ExtendedSourceCharacter :[\u0009\u000A\u000D\u0020-\u{10FFFF}];
127+
fragment ExtendedSourceCharacterWitoutLineFeed :[\u0009\u000D\u0020-\u{10FFFF}];
128+
129+
// this is the spec definition
130+
// fragment SourceCharacter :[\u0009\u000A\u000D\u0020-\uFFFF];
131+
132+
133+
Comment: '#' ExtendedSourceCharacterWitoutLineFeed* -> channel(2);
127134
128135
fragment EscapedChar : '\\' (["\\/bfnrt] | Unicode) ;
129136
fragment Unicode : 'u' Hex Hex Hex Hex ;

‎src/test/groovy/graphql/parser/ParserTest.groovy‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,22 @@ triple3 : """edge cases \\""" "" " \\"" \\" edge cases"""
751751
e.location.line == 3
752752
e.location.column == 20
753753
}
754+
755+
def "allow emoji in comments"() {
756+
def input = '''
757+
# Represents the 😕 emoji.
758+
{
759+
foo
760+
}
761+
'''
762+
when:
763+
Document document = Parser.parse(input)
764+
OperationDefinition operationDefinition = (document.definitions[0] as OperationDefinition)
765+
766+
767+
then:
768+
operationDefinition.getComments()[0].content == " Represents the 😕 emoji."
769+
}
770+
771+
754772
}

0 commit comments

Comments
 (0)