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 official filetype support for ChucK (.ck) #13886

Closed
gacallea opened this issue Jan 18, 2024 · 11 comments · Fixed by #13888 or neovim/neovim#27096
Closed

add official filetype support for ChucK (.ck) #13886

gacallea opened this issue Jan 18, 2024 · 11 comments · Fixed by #13888 or neovim/neovim#27096

Comments

@gacallea
Copy link
Contributor

gacallea commented Jan 18, 2024

Is your feature request about something that is currently impossible or hard to do? Please describe the problem.

Nothing impossible, just nice to have included.

Describe the solution you'd like

Adding something like this? Not sure how vim defines filetypes:

au BufRead,BufNewFile *.ck setfiletype chuck

Describe alternatives you've considered

At the moment I'm using ftdetect/chuck.vim

au BufRead,BufNewFile *.ck setfiletype chuck

Additional context

ChucK as a language, filetype, and extension has existed since 2002. It would be nice to have native support.

Also, I opened a feature request with NerdFonts for the logo to be included: ryanoasis/nerd-fonts#1479

@chrisbra
Copy link
Member

Thanks. I have created #13888 to detect the filetype. However there won't be any filetype, syntax or indent scripts. I'll leave that for later for someone who actually knows the language and can contribute those things

@gacallea
Copy link
Contributor Author

Thanks. I have created #13888 to detect the filetype. However there won't be any filetype, syntax or indent scripts. I'll leave that for later for someone who actually knows the language and can contribute those things

thanks! I do have a syntax (that I didn't write) but it's from 8 years ago and I'm unsure it's complete. Should I share anyway?

@gacallea
Copy link
Contributor Author

Just in case, I'm sharing the syntax I have and the link to the API reference where all terms are present. Since the syntax file is 8y old, this API reference may help complete it: https://chuck.cs.princeton.edu/doc/reference/

if exists("b:current_syntax")
    finish
endif

syntax keyword chuckBoolean true false maybe
syntax keyword chuckBoolean null NULL
highlight link chuckBoolean Boolean

syntax match chuckComment "\v//.*$"
syntax region  chuckComment start="/\*"  end="\*/"
highlight link chuckComment Comment

syntax keyword chuckConditional if else
highlight link chuckConditional Conditional

syntax keyword chuckKeyword fun function
syntax keyword chuckKeyword return
syntax keyword chuckKeyword const
syntax keyword chuckKeyword new
syntax keyword chuckKeyword now
syntax keyword chuckKeyword pi
syntax keyword chuckKeyword me
syntax keyword chuckKeyword samp ms second minute hour day week
syntax keyword chuckKeyword repeat break continue
syntax keyword chuckKeyword class extends public private static pure this
syntax keyword chuckKeyword spork
syntax keyword chuckKeyword cherr chout
highlight link chuckKeyword Keyword


syntax keyword chuckOperator => @=> =^
syntax keyword chuckOperator + - * /
syntax keyword chuckOperator %
syntax keyword chuckOperator "&&" "||" == != >=
syntax keyword chuckOperator & + ^
syntax keyword chuckOperator ++ --
syntax keyword chuckOperator ! + -
syntax keyword chuckOperator <<< >>>
highlight link chuckOperator Operator

syntax keyword chuckRepeat while until for do
highlight link chuckRepeat Repeat

syntax keyword chuckType int float time dur void string
syntax keyword chuckType array ugen complex polar
syntax keyword chuckType Object Event UGen
highlight link chuckType Type


syntax keyword chuckBuiltinUGen adc blackhole dac
syntax keyword chuckBuiltinUGen Gain
syntax keyword chuckBuiltinUGen Noise Impulse Step
syntax keyword chuckBuiltinUGen Phasor Osc SinOsc PulseOsc SqrOsc TriOsc SawOsc
syntax keyword chuckBuiltinUGen Gen5 Gen7 Gen9 Gen10 Gen17
syntax keyword chuckBuiltinUGen CurveTable WarpTable
syntax keyword chuckBuiltinUGen BiQuad OneZero TwoZero OnePole TwoPole PoleZero
syntax keyword chuckBuiltinUGen Filter LPF HPF BPF BRF ResonZ Dynamics
syntax keyword chuckBuiltinUGen HalfRect FullRect ZeroX
syntax keyword chuckBuiltinUGen SndBuf
syntax keyword chuckBuiltinUGen Mix2 Pan2
syntax keyword chuckBuiltinUGen StkInstrument BandedWG
syntax keyword chuckBuiltinUGen BlowBotl BlowHole Bowed Brass Clarinet Flute
syntax keyword chuckBuiltinUGen Mandolin ModalBar Moog Saxofony Shakers
syntax keyword chuckBuiltinUGen Sitar StifKarp VoicForm
syntax keyword chuckBuiltinUGen FM BeeThree FMVoices HevyMetl PercFlut Rhodey TubeBell Wurley
syntax keyword chuckBuiltinUGen Delay DelayA DelayL Echo
syntax keyword chuckBuiltinUGen Envelope ADSR
syntax keyword chuckBuiltinUGen JCRev NRev PRCRev
syntax keyword chuckBuiltinUGen Chorus Modulate PitShift SubNoise Blit BlitSaw BlitSquare
syntax keyword chuckBuiltinUGen WvIn WaveLoop WvOut
syntax keyword chuckBuiltinUGen GenX LiSa Dyno
syntax keyword chuckBuiltinUGen Chugen Chubgraph
highlight link chuckBuiltinUGen Structure

syntax keyword chuckBuiltinUAna UAna UAnaBlob Windowing
syntax keyword chuckBuiltinUAna FFT IFFT DCT IDCT
syntax keyword chuckBuiltinUAna Centroid Flux RMS RollOff
syntax keyword chuckBuiltinUAna Flip pilF
highlight link chuckBuiltinUAna Structure

syntax keyword chuckChugin ABSaturator AmbPan Bitcrusher Elliptic ExpDelay FIR
syntax keyword chuckChugin FluidSynth GVerb KasFilter Ladspa MagicSine Mesh2D
syntax keyword chuckChugin Multicomb Overdrive PanN PitchTrack PowerADSR Sigmund
syntax keyword chuckChugin Spectacle WinFuncEnv
highlight link chuckChugin Structure

syntax keyword chuckEvent OscRecv OscSend OscEvent OscOut OscIn OscMsg
syntax keyword chuckEvent MidiIn MidiOut MidiMsg
syntax keyword chuckEvent KBHit Hid HidMsg
highlight link chuckEvent Special

syntax keyword chuckIO Machine RegEx FileIO SerialIO StringTokenizer ConsoleInput
highlight link chuckIO Special

syntax keyword chuckLib Math Std
highlight link chuckLib Special


syntax match chuckNumber /\%(\i\|\$\)\@<![-]\?\d\+/ display
highlight link chuckNumber Number

syntax match chuckHex /\<0[xX]\x\+[lL]\=\>/ display
highlight link chuckHex Number

syntax match chuckFloat /\%(\i\|\$\)\@<![-]\?\%(\d*\.\d\+\|\d\+\.\)/ display
highlight link chuckFloat Float

syntax region chuckString start=/"/ end=/"/ display
highlight link chuckString String

let b:current_syntax = "chuck"

@chrisbra
Copy link
Member

Well, don't expect us to complete a syntax script for a language we are not using. There is no author mentioned in your syntax script (the default header with metadata, like version, maintainer, etc missing). I am a bit unsure if we can distribute it as is for Vim however, without an author/maintainer who has given us the permission to distribute this file with Vim.

@gacallea
Copy link
Contributor Author

sorry about that. here's the link to the author vim plugin where the syntax is from: https://github.com/wilsaj/chuck.vim -- my apologies. didn't mean to steal/avoid credits.

@gacallea
Copy link
Contributor Author

ps: since I'm also writing a plugin where the syntax is used, it's my intention to complete it once I get around other blocking stuff. it is my very first plugin and for now syntax update is TODO.

chrisbra added a commit that referenced this issue Jan 19, 2024
closes #13886

Signed-off-by: Christian Brabandt <cb@256bit.org>
clason added a commit to clason/neovim that referenced this issue Jan 20, 2024
runtime(filetype): detect *.ck files as Chuck filetype (vim/vim#13888)

closes vim/vim#13886

vim/vim@27a4632

Co-authored-by: Christian Brabandt <cb@256bit.org>
clason added a commit to neovim/neovim that referenced this issue Jan 21, 2024
runtime(filetype): detect *.ck files as Chuck filetype (vim/vim#13888)

closes vim/vim#13886

vim/vim@27a4632

Co-authored-by: Christian Brabandt <cb@256bit.org>
@gacallea
Copy link
Contributor Author

gacallea commented Jan 21, 2024

@chrisbra thanks that was quick!

Now, I got no answer from the syntax author yet. I'm about to try do it myself starting from the API.

  • Is there a doc/tutorial you suggest to follow?
  • Should I open a new issue once that's done? reopen this one?

Please and thank you

@gacallea
Copy link
Contributor Author

gacallea commented Jan 21, 2024

Hi @chrisbra :)

it wasn't too hard! Here's one I compiled by using the sources referenced in the syntax itself. Let me know if I should open a separate issue or add anything for licensing/using this. Cheers!

" Vim syntax file
" Language: ChucK
" Maintainer: Andrea Callea
" Latest Revision: 21 January 2024

" Sources used for this syntax
" https://chuck.cs.princeton.edu/doc/language/
" https://chuck.cs.princeton.edu/doc/reference/

if exists("b:current_syntax")
  finish
endif

syntax keyword chuckPrimitiveType int float time dur void vec3 vec4
highlight link chuckPrimitiveType Type

syntax keyword chuckComplexType complex polar
highlight link chuckComplexType Type

syntax keyword chuckReferenceType Object Event UGen array string
highlight link chuckReferenceType Type

syntax keyword chuckBoolean true false maybe
syntax keyword chuckBoolean null NULL
highlight link chuckBoolean Boolean

syntax keyword chuckOperator => @=> =^
syntax keyword chuckOperator + - * /
syntax keyword chuckOperator %
syntax keyword chuckOperator "&&" "||" == !=
syntax keyword chuckOperator >  >=  <  <=
syntax keyword chuckOperator >>  <<  &  |  "^"
syntax keyword chuckOperator ++ --
syntax keyword chuckOperator ! + - new @
syntax keyword chuckOperator <<< >>>
highlight link chuckOperator Operator

syntax keyword chuckConditional if else
highlight link chuckConditional Conditional

syntax keyword chuckRepeat while do until for each
highlight link chuckRepeat Repeat

syntax keyword chuckTimeAndDuration samp ms second minute hour day week
syntax keyword chuckTimeAndDuration now later
highlight link chuckTimeAndDuration Keyword

" these may need some additional keywords I missed, for a future review
syntax keyword chuckKeyword dac adc
syntax keyword chuckKeyword fun function
syntax keyword chuckKeyword return
syntax keyword chuckKeyword const
syntax keyword chuckKeyword new
syntax keyword chuckKeyword pi
syntax keyword chuckKeyword me
syntax keyword chuckKeyword repeat break continue
syntax keyword chuckKeyword class extends public private static pure this
syntax keyword chuckKeyword spork
syntax keyword chuckKeyword cherr chout
highlight link chuckKeyword Keyword

syntax keyword chuckBaseClasses Shred Math Machine Std
highlight link chuckBaseClasses Special

syntax keyword chuckBasicUGen Gain Impulse Step SndBuf SndBuf2
syntax keyword chuckBasicUGen ADSR Envelope Delay DelayL DelayA Echo
syntax keyword chuckBasicUGen Noise CNoise Osc SinOsc TriOsc SawOsc PulseOsc SqrOsc
syntax keyword chuckBasicUGen Phasor HalfRect FullRect
syntax keyword chuckBasicUGen Chugraph Chugen UGen_Multi UGen_Stereo Mix2 Pan2
highlight link chuckBasicUGen Structure

syntax keyword chuckFilterUGen FilterBasic LPF HPF BPF BRF BiQuad ResonZ
syntax keyword chuckFilterUGen OnePole OneZero TwoPole TwoZero PoleZero
highlight link chuckFilterUGen Structure

syntax keyword chuckSTKUGen JCRev NRev PRCRev
syntax keyword chuckSTKUGen Chorus Modulate PitShift SubNoise
syntax keyword chuckSTKUGen BLT Blit BlitSaw BlitSquare FilterStk
syntax keyword chuckSTKUGen WvIn WaveLoop WvOut WvOut2 StkInstrument
syntax keyword chuckSTKUGen BandedWG BlowBotl BlowHole
syntax keyword chuckSTKUGen Bowed Brass Clarinet Flute Mandolin
syntax keyword chuckSTKUGen ModalBar Moog Saxofony Shakers Sitar StifKarp
syntax keyword chuckSTKUGen VoicForm KrstlChr FM BeeThree FMVoices
syntax keyword chuckSTKUGen HevyMetl HnkyTonk FrencHrn PercFlut Rhodey TubeBell Wurley
highlight link chuckSTKUGen Structure

syntax keyword chuckAdvancedUGen LiSa LiSa2 LiSa6 LiSa8 LiSa10
syntax keyword chuckAdvancedUGen LiSa16 GenX Gen5 Gen7 Gen9 Gen10 Gen17
syntax keyword chuckAdvancedUGen CurveTable WarpTable Dyno
highlight link chuckAdvancedUGen Structure

syntax keyword chuckChugin ABSaturator AmbPan3 Bitcrusher Elliptic ExpDelay ExpEnv FIR
syntax keyword chuckChugin FoldbackSaturator GVerb KasFilter MagicSine Mesh2D
syntax keyword chuckChugin Multicomb Pan4 Pan8 Pan16 PitchTrack PowerADSR RegEx
syntax keyword chuckChugin Sigmund Spectacle WinFuncEnv WPDiodeLadder WPKorg35
highlight link chuckChugin Structure

syntax keyword chuckUnitAnalyzer UAna UAnaBlob Windowing
syntax keyword chuckUnitAnalyzer FFT IFFT DCT IDCT
syntax keyword chuckUnitAnalyzer Centroid Flux RMS RollOff
syntax keyword chuckUnitAnalyzer Flip UnFlip XCorr
syntax keyword chuckUnitAnalyzer Chroma Kurtosis MFCC SFM ZeroX AutoCorr FeatureCollector
highlight link chuckUnitAnalyzer Structure

syntax keyword chuckChAI MLP KNN KNN2 HMM SVM Word2Vec PCA Wekinator AI
highlight link chuckChAI Structure

syntax keyword chuckInputOutput IO FileIO OscIn OscOut OscMsg
syntax keyword chuckInputOutput Hid HidMsg KBHit SerialIO
syntax keyword chuckInputOutput MidiIn MidiOut MidiMsg MidiFileIn
highlight link chuckInputOutput Special

syntax keyword chuckUtilities CKDoc StringTokenizer ConsoleInput
highlight link chuckUtilities Special

syntax match chuckComment "\v//.*$"
syntax region  chuckComment start="/\*"  end="\*/"
highlight link chuckComment Comment

syntax match chuckNumber /\%(\i\|\$\)\@<![-]\?\d\+/ display
highlight link chuckNumber Number

syntax match chuckHex /\<0[xX]\x\+[lL]\=\>/ display
highlight link chuckHex Number

syntax match chuckFloat /\%(\i\|\$\)\@<![-]\?\%(\d*\.\d\+\|\d\+\.\)/ display
highlight link chuckFloat Float

syntax region chuckString start=/"/ end=/"/ display
highlight link chuckString String

let b:current_syntax = "chuck"

@dkearns
Copy link
Contributor

dkearns commented Jan 21, 2024

Thanks for the addition. A PR is a bit easier to review and possibly for @chrisbra to commit.

  • None of the chuckOperator group will match as it's all defined with :syn-keyword which only allows the characters defined by the iskeyword option. See :help syn-iskeyword. You'll need to use :syn-match instead.

  • You'll also need to come up with some way to disambiguate the new keyword from the new operator, if they're not the same thing.

  • Apparently string escape sequences are supported so you'll need to skip at least \" when looking for the end pattern match of a string. There's lots of examples in the distributed syntax files. See: https://chuck.cs.princeton.edu/doc/examples/string/escape.ck

  • The :highlight commands need the default argument.

  • I don't think this is considered a strict requirement by anybody but the :highlight commands are usually grouped together at the end of the file rather than after the syntax group definition. E.g., https://github.com/vim/vim/blob/master/runtime/syntax/a2ps.vim

  • Changing "Latest Revision" header to "Last Change: 2024 Jan 24" matches the majority of distributed files and makes searching the repo a little easier in some instances.

  • Could you please also add yourself to https://github.com/vim/vim/blob/master/.github/CODEOWNERS?

@gacallea
Copy link
Contributor Author

thanks @dkearns :) will fix those now! my first syntax file, gotta have some mistakes :D

@gacallea
Copy link
Contributor Author

hi @dkearns I fixed the issues and I forked the repo. I'm reading CONTRIBUTING and related links but I cannot find PR policies. I see that conventional commits are used but can't find if I need rebasing or else. A doc would help me avoid mistakes. Cheers :)

glepnir pushed a commit to glepnir/neovim that referenced this issue Mar 31, 2024
runtime(filetype): detect *.ck files as Chuck filetype (vim/vim#13888)

closes vim/vim#13886

vim/vim@27a4632

Co-authored-by: Christian Brabandt <cb@256bit.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants