Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic syntax detection and highlighting #2

Draft
wants to merge 42 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
26100d7
Add filetype detection for TypeQL
agrski Oct 9, 2022
d4f34bf
Add basic tab/indentation settings
agrski Oct 9, 2022
db9a5c4
Add header/manifest to syntax file
agrski Oct 9, 2022
4785a06
Add prelude/syntax check to syntax file
agrski Oct 9, 2022
dcee0a5
Add syntax matching options for case and keyword characters
agrski Oct 9, 2022
1e72feb
Add TypeQL keywords
agrski Oct 9, 2022
d5607fa
Add default highlighting for keyword groups
agrski Oct 9, 2022
5aaf845
Use full-form syntax instead of syn for keyword definitions
agrski Oct 10, 2022
2efc29b
Add Vim fold marker for highlighting section
agrski Oct 10, 2022
a68e8e2
Add syntactic matching & highlighting for comments & TODOs
agrski Oct 10, 2022
4403394
Add syntactic matching & highlighting for string literals
agrski Oct 10, 2022
2700c5a
Add matches & region identifiers for blocks in inference rules
agrski Oct 13, 2022
aaf51fe
Align syntax file header block
agrski Oct 29, 2022
5e2ca66
Add creation metadata to syntax file
agrski Oct 29, 2022
69b1d97
Update link for source of TypeQL grammar
agrski Oct 29, 2022
279239d
Add missing keywords to a couple of syntax groups
agrski Oct 29, 2022
f4363b1
Remove keyword from wrong syntax group
agrski Oct 29, 2022
7e0a2fc
Add keyword group for type var constraints
agrski Oct 29, 2022
341e3a0
Update & rename keyword group for thing-var constraints
agrski Oct 29, 2022
f0c9dee
Update keyword group for operators
agrski Oct 29, 2022
b86593f
Add keyword group for predicates
agrski Oct 29, 2022
dcf29e6
Add keyword group for query aggregations
agrski Oct 29, 2022
477730d
Use consistent alignment for keywords section
agrski Oct 29, 2022
22eaa9b
Reorder keyword groups for logical grouping
agrski Oct 29, 2022
10bce20
Add default highlight for new keyword groups
agrski Oct 29, 2022
af4f813
Split region definition over multiple lines for legibility
agrski Oct 29, 2022
f5d4807
Move Booleans to literals section & rename syntax group
agrski Oct 29, 2022
569ff31
Add match for single-quoted strings
agrski Oct 29, 2022
77634e2
Add syntactic matching & highlighting for integer literals
agrski Oct 29, 2022
061d858
Add syntactic matching & highlighting for floating-point literals
agrski Oct 29, 2022
cb60226
Highlight Booleans as such, not as general constants
agrski Oct 29, 2022
4b9c4f0
Add syntactic matching & highlighting for date & date-time literals
agrski Oct 30, 2022
284728d
Reorder syntax definition sections
agrski Oct 30, 2022
bbfcca0
Separate variable detection to separate section
agrski Oct 30, 2022
3d8f2c3
Add syntactic matching for anonymous variables
agrski Oct 30, 2022
9089cdc
Update syntactic matching for named variables
agrski Oct 30, 2022
c52f7d7
Use consistent alignmnt for highlighting section
agrski Oct 30, 2022
3737281
Order values lexically per keyword group
agrski Oct 30, 2022
0aee33f
Use match for keyword that aliases a Vim syntax option
agrski Oct 30, 2022
492177b
Add TODO comments for syntax concerns
agrski Dec 10, 2023
52742ee
Add placeholder indentation file
agrski Dec 10, 2023
a6efec7
Add notes on how to set up Vim indentation files
agrski Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ftdetect/typedb-tql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
au BufNewFile,BufRead *.tql set filetype=typedb-tql
Empty file removed ftdetect/typeql.vim
Empty file.
3 changes: 3 additions & 0 deletions ftplugin/typedb-tql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set tabstop=4
set softtabstop=4
set shiftwidth=4
Empty file removed ftplugin/typeql.vim
Empty file.
15 changes: 15 additions & 0 deletions indent/typedb-tql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
" Vim indent file
" Language: TypeQL for TypeDB
" Maintainer: agrski <[email protected]>
" Created: 2022 Oct 29
" Last Change: 2022 Oct 29

if exists("b:did_indent")
finish
endif
let b:did_indent = 1

" https://psy.swansea.ac.uk/staff/carter/vim/vim_indent.htm
"
" define -> dedent to start of line
" , -> ensure indented to one level beyond last keyword = 1 indent
88 changes: 88 additions & 0 deletions syntax/typedb-tql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
" Vim syntax file
" Language: TypeQL for TypeDB
" Maintainer: agrski <[email protected]>
" Created: 2022 Oct 09
" Last Change: 2022 Oct 29

" Based on the ANTLR grammar defined for TypeQL:
" https://github.com/vaticle/typeql/blob/fd78c825e87058293290d4801834593823a329a8/grammar/TypeQL.g4

" TODO - make sure to capture of all the below
" https://github.com/vaticle/typeql/blob/master/grammar/TypeQL.g4

" Prelude {{{1
if exists("b:current_syntax")
finish
endif

" Syntax matching options {{{1
syntax case match

setlocal iskeyword+=!

" INPUT TOKEN PATTERNS
" 0x[0-9a-f]+
" (labels... again rules to apply)
"
" Add matches for various regions

" Keywords {{{1
syntax keyword typedbTqlNativeType attribute entity relation role rule thing
syntax keyword typedbTqlDataType boolean datetime double long string
syntax keyword typedbTqlTypeVarConstraint abstract as @key owns plays regex relates sub sub! then type when
syntax keyword typedbTqlThingVarConstraint has iid is isa isa! value
syntax keyword typedbTqlQueryCmd compute define delete get insert match undefine
syntax keyword typedbTqlQueryModifier asc desc limit offset sort
syntax keyword typedbTqlAggregateCmd count group max mean median min std sum
syntax keyword typedbTqlOperator not or
syntax keyword typedbTqlPredicate != < <= = > >= like
syntax match typedbTqlPredicate /contains/

" Comments {{{1
syntax keyword typedbTqlTodo contained FIXME NOTE TODO XXX
syntax match typedbTqlComment /#.*$/ contains=typedbTqlTodo

" Literals {{{1
syntax keyword typedbTqlBoolean false true
syntax match typedbTqlString /".*"/
syntax match typedbTqlString /'.*'/
syntax match typedbTqlLong /\v(\+|-)?[0-9]+/
syntax match typedbTqlDouble /\v(\+|-)?[0-9]+\.[0-9]+/
syntax match typedbTqlDate /\v([0-9]{4}|(\+|-)[0-9]+)-[0-1][0-9]-[0-3][0-9]/
syntax match typedbTqlDateTime /\v([0-9]{4}|(\+|-)[0-9]+)-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9](:[0-6][0-9](\.[0-9]{1,3})?)?/

" Variables {{{1
syntax match typedbTqlVar /\$_/
syntax match typedbTqlVar /\$[a-zA-Z0-9][a-zA-Z0-9_-]*/

" Blocks {{{1
syntax match typedbTqlBlockDelimiter /[{}()]/ contained
syntax region typedbTqlBlock
\ start='{'
\ end='}'
\ contains=typedbTqlVar,typedbTqlThingVarConstraint,typedbTqlBlockDelimiter
\ fold transparent

" Default highlighting {{{1
highlight default link typedbTqlNativeType Identifier
highlight default link typedbTqlDataType Type
highlight default link typedbTqlTypeVarConstraint Statement
highlight default link typedbTqlThingVarConstraint Operator
highlight default link typedbTqlQueryCmd Statement
highlight default link typedbTqlQueryModifier Statement
highlight default link typedbTqlAggregateCmd Statement
highlight default link typedbTqlOperator Operator
highlight default link typedbTqlPredicate Operator

highlight default link typedbTqlTodo Todo
highlight default link typedbTqlComment Comment

highlight default link typedbTqlVar Identifier
highlight default link typedbTqlBlockDelimiter Structure

highlight default link typedbTqlBoolean Boolean
highlight default link typedbTqlString String
highlight default link typedbTqlLong Number
highlight default link typedbTqlDouble Float
highlight default link typedbTqlDate Constant
highlight default link typedbTqlDateTime Constant
Empty file removed syntax/typeql.vim
Empty file.