Jon Parise | 4ce1cb5 | 2024-12-23 09:57:42 +0100 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: graphql |
| 3 | " Maintainer: Jon Parise <jon@indelible.org> |
| 4 | " Filenames: *.graphql *.graphqls *.gql |
| 5 | " URL: https://github.com/jparise/vim-graphql |
| 6 | " License: MIT <https://opensource.org/license/mit> |
| 7 | " Last Change: 2024 Dec 21 |
| 8 | |
| 9 | if !exists('main_syntax') |
| 10 | if exists('b:current_syntax') |
| 11 | finish |
| 12 | endif |
| 13 | let main_syntax = 'graphql' |
| 14 | endif |
| 15 | |
| 16 | syn case match |
| 17 | |
| 18 | syn match graphqlComment "#.*$" contains=@Spell |
| 19 | |
| 20 | syn match graphqlOperator "=" display |
| 21 | syn match graphqlOperator "!" display |
| 22 | syn match graphqlOperator "|" display |
| 23 | syn match graphqlOperator "&" display |
| 24 | syn match graphqlOperator "\M..." display |
| 25 | |
| 26 | syn keyword graphqlBoolean true false |
| 27 | syn keyword graphqlNull null |
| 28 | syn match graphqlNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" display |
| 29 | syn region graphqlString start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ |
| 30 | syn region graphqlString start=+"""+ skip=+\\"""+ end=+"""+ |
| 31 | |
| 32 | syn keyword graphqlKeyword repeatable nextgroup=graphqlKeyword skipwhite |
| 33 | syn keyword graphqlKeyword on nextgroup=graphqlType,graphqlDirectiveLocation skipwhite |
| 34 | |
| 35 | syn keyword graphqlStructure enum scalar type union nextgroup=graphqlType skipwhite |
| 36 | syn keyword graphqlStructure input interface subscription nextgroup=graphqlType skipwhite |
| 37 | syn keyword graphqlStructure implements nextgroup=graphqlType skipwhite |
| 38 | syn keyword graphqlStructure query mutation fragment nextgroup=graphqlName skipwhite |
| 39 | syn keyword graphqlStructure directive nextgroup=graphqlDirective skipwhite |
| 40 | syn keyword graphqlStructure extend nextgroup=graphqlStructure skipwhite |
| 41 | syn keyword graphqlStructure schema nextgroup=graphqlFold skipwhite |
| 42 | |
| 43 | syn match graphqlDirective "\<@\h\w*\>" display |
| 44 | syn match graphqlVariable "\<\$\h\w*\>" display |
| 45 | syn match graphqlName "\<\h\w*\>" display |
| 46 | syn match graphqlType "\<_*\u\w*\>" display |
| 47 | |
| 48 | " https://spec.graphql.org/October2021/#ExecutableDirectiveLocation |
| 49 | syn keyword graphqlDirectiveLocation QUERY MUTATION SUBSCRIPTION FIELD |
| 50 | syn keyword graphqlDirectiveLocation FRAGMENT_DEFINITION FRAGMENT_SPREAD |
| 51 | syn keyword graphqlDirectiveLocation INLINE_FRAGMENT VARIABLE_DEFINITION |
| 52 | " https://spec.graphql.org/October2021/#TypeSystemDirectiveLocation |
| 53 | syn keyword graphqlDirectiveLocation SCHEMA SCALAR OBJECT FIELD_DEFINITION |
| 54 | syn keyword graphqlDirectiveLocation ARGUMENT_DEFINITION INTERFACE UNION |
| 55 | syn keyword graphqlDirectiveLocation ENUM ENUM_VALUE INPUT_OBJECT |
| 56 | syn keyword graphqlDirectiveLocation INPUT_FIELD_DEFINITION |
| 57 | |
| 58 | syn keyword graphqlMetaFields __schema __type __typename |
| 59 | |
| 60 | syn region graphqlFold matchgroup=graphqlBraces start="{" end="}" transparent fold contains=ALLBUT,graphqlStructure |
| 61 | syn region graphqlList matchgroup=graphqlBraces start="\[" end="]" transparent contains=ALLBUT,graphqlDirective,graphqlStructure |
| 62 | |
| 63 | if main_syntax ==# 'graphql' |
| 64 | syn sync minlines=500 |
| 65 | endif |
| 66 | |
| 67 | hi def link graphqlComment Comment |
| 68 | hi def link graphqlOperator Operator |
| 69 | |
| 70 | hi def link graphqlBraces Delimiter |
| 71 | |
| 72 | hi def link graphqlBoolean Boolean |
| 73 | hi def link graphqlNull Keyword |
| 74 | hi def link graphqlNumber Number |
| 75 | hi def link graphqlString String |
| 76 | |
| 77 | hi def link graphqlDirective PreProc |
| 78 | hi def link graphqlDirectiveLocation Special |
| 79 | hi def link graphqlName Identifier |
| 80 | hi def link graphqlMetaFields Special |
| 81 | hi def link graphqlKeyword Keyword |
| 82 | hi def link graphqlStructure Structure |
| 83 | hi def link graphqlType Type |
| 84 | hi def link graphqlVariable Identifier |
| 85 | |
| 86 | let b:current_syntax = 'graphql' |
| 87 | |
| 88 | if main_syntax ==# 'graphql' |
| 89 | unlet main_syntax |
| 90 | endif |