Skip to content

Commit

Permalink
NamedType rule (graphql#97)
Browse files Browse the repository at this point in the history
This builds on graphql#89 and graphql#90 to create a more specific parser rule and parser state for NamedType. This makes it easier to builds tools on top of codemirror-graphql which do interesting things when the names of types are encountered, such as jump-to-docs or hover cards.
  • Loading branch information
leebyron committed Jan 18, 2017
1 parent 48574bf commit 7704ca4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/utils/Rules.js
Expand Up @@ -129,7 +129,7 @@ export const ParseRules = {
],
TypeCondition: [
word('on'),
type('atom'),
'NamedType',
],
// Variables could be parsed in cases where only Const is expected by spec.
Value(token) {
Expand Down Expand Up @@ -162,11 +162,12 @@ export const ParseRules = {
ObjectValue: [ p('{'), list('ObjectField'), p('}') ],
ObjectField: [ name('attribute'), p(':'), 'Value' ],
Type(token) {
return token.value === '[' ? 'ListType' : 'NamedType';
return token.value === '[' ? 'ListType' : 'NonNullType';
},
// NonNullType has been merged into ListType and NamedType to simplify.
// NonNullType has been merged into ListType to simplify.
ListType: [ p('['), 'Type', p(']'), opt(p('!')) ],
NamedType: [ name('atom'), opt(p('!')) ],
NonNullType: [ 'NamedType', opt(p('!')) ],
NamedType: [ type('atom') ],
Directive: [ p('@', 'meta'), name('meta'), opt('Arguments') ],
// GraphQL schema language
SchemaDef: [
Expand All @@ -187,7 +188,7 @@ export const ParseRules = {
list('FieldDef'),
p('}'),
],
Implements: [ word('implements'), list(name('atom')) ],
Implements: [ word('implements'), list('NamedType') ],
FieldDef: [
name('property'),
opt('ArgumentsDef'),
Expand Down Expand Up @@ -218,7 +219,7 @@ export const ParseRules = {
p('='),
list('UnionMember', p('|'))
],
UnionMember: [ name('atom') ],
UnionMember: [ 'NamedType' ],
EnumDef: [
word('enum'),
name('atom'),
Expand Down Expand Up @@ -273,7 +274,8 @@ function type(style) {
style,
match: token => token.kind === 'Name',
update(state, token) {
state.prevState.type = token.value;
state.name = token.value;
state.prevState.prevState.type = token.value;
}
};
}

0 comments on commit 7704ca4

Please sign in to comment.