Making a grammar with Tree-Sitter, need a little help


#1

Hi!

I’m writing a grammar that uses Tree-Sitter, I’ve got the very basics down, and now I’m trying to use the compiled parser node-gyp spits out with Atom.

id: 'fortios'
name: 'FortiOS CLI'
type: 'tree-sitter'
parser: 'sitter-fortigate'
legacyScopeName: 'source.fortios'
scopeName: 'source.fortios'


folds: [
  {
    start: {index: 1, type: 'identifier'}
    end: {index: -1, type: ')'}
  }
]

scopes:
  'program': 'source.tree'
  'heading_name': 'markup.heading'
  'eq_divider': 'constant.other.symbol'
  'dash_divider': 'constant.other.symbol'
  'group > "("': 'markup.string'
  'group > ")"': 'markup.string'

The above is my grammars/fortios.cson

When I reload Atom, or close and reopen it I get:

[Enter steps to reproduce:]

Atom: 1.30.0-beta1 x64
Electron: 2.0.5
OS: Mac OS X 10.13.6
Thrown From: language-fortigate-sitter package 0.0.0

Stack Trace

Failed to load a language-fortigate-sitter package grammar

At Cannot read property 'length' of undefined in /Users/xorkle/.atom/packages/language-fortigate-sitter/grammars/fortios.cson

TypeError: Cannot read property 'length' of undefined
    at GrammarRegistry.getGrammarPathScore (/Applications/Atom Beta.app/Contents/Resources/app/src/grammar-registry.js:252:41)
    at GrammarRegistry.getGrammarScore (/Applications/Atom Beta.app/Contents/Resources/app/src/grammar-registry.js:211:28)
    at grammarScoresByBuffer.forEach (/Applications/Atom Beta.app/Contents/Resources/app/src/grammar-registry.js:358:34)
    at Map.forEach (<anonymous>)
    at GrammarRegistry.grammarAddedOrUpdated (/Applications/Atom Beta.app/Contents/Resources/app/src/grammar-registry.js:349:38)
    at GrammarRegistry.addGrammar (/Applications/Atom Beta.app/Contents/Resources/app/src/grammar-registry.js:444:18)
    at TreeSitterGrammar.activate (/Applications/Atom Beta.app/Contents/Resources/app/src/tree-sitter-grammar.js:78:45)
    at grammarRegistry.readGrammar (/Applications/Atom Beta.app/Contents/Resources/app/src/package.js:617:53)
    at CSON.readFile (/Applications/Atom Beta.app/Contents/Resources/app/src/grammar-registry.js:506:15)
    at /Applications/Atom Beta.app/Contents/Resources/app/node_modules/season/lib/cson.js:223:65
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
  at /packages/language-fortigate-sitter/grammars/fortios.cson:1:1

Commands

     -1:18.2.0 core:select-all (input.hidden-input)
     -1:17.7.0 core:copy (input.hidden-input)

Non-Core Packages

atom-clock 0.1.16 
autocomplete-emojis 2.5.0 
busy-signal 1.4.3 
city-lights-syntax 1.1.8 
city-lights-ui 1.5.3 
hey-pane 1.1.0 
highlight-bad-chars 1.2.0 
Hydrogen 2.5.1 
intentions 1.1.5 
language-csv 1.1.2 
language-fortigate 0.3.0 
language-fortigate-sitter 0.0.0 
linter 2.2.0 
linter-rubocop 2.2.3 
linter-ui-default 1.7.1 
tablr 1.8.3 
teletype 0.13.3 

To me it seems like I’m missing something out of fortios.cson?

If that’s not the case I’ll publish the entire project I have so far and link it here.

Thanks!


#2

You’re missing file types; it doesn’t have the length of the (undefined) fileTypes array.


#3

Argh, thanks!

I seem to be causing Atom to crash entirely, I’ll get some debug logs soon.

Thanks!


#4

Below is the macOS crash report:

Process:               Atom Beta Helper [61416]
Path:                  /Applications/Atom Beta.app/Contents/Frameworks/Atom Beta Helper.app/Contents/MacOS/Atom Beta Helper
Identifier:            Atom Beta Helper
Parent Process:        Atom Beta [59320]
Responsible:           Atom Beta [59320]
75  com.github.electron.framework 	0x000000010e2e908c atom::NodeBindings::UvRunOnce() + 172
79  com.github.electron.framework 	0x000000010e2e94e4 base::internal::Invoker<base::internal::BindState<void (atom::NodeBindings::*)(), base::WeakPtr<atom::NodeBindings> >, void ()>::Run(base::internal::BindStateBase*) + 20
103 com.github.electron.framework 	0x000000010e1adf44 AtomMain + 68
104 com.github.atom.helper        	0x000000010e1a0f26 main + 38
2   com.github.electron.framework 	0x000000010e2e8f40 atom::NodeBindings::EmbedThreadRunner(void*) + 48
       0x10e1a0000 -        0x10e1a0ff7 +com.github.atom.helper (0) <9264FDB0-6B74-3B13-A2C4-871CC03949BF> /Applications/Atom Beta.app/Contents/Frameworks/Atom Beta Helper.app/Contents/MacOS/Atom Beta Helper
       0x10e1ac000 -        0x112463f27 +com.github.electron.framework (0) <1EA6A07B-1AB0-3258-96FD-DF5E910E054E> /Applications/Atom Beta.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework
       0x112add000 -        0x112af8fff +com.github.Squirrel (1.0 - 1) <E4398068-33D3-3A00-9DBE-5ACC9B022501> /Applications/Atom Beta.app/Contents/Frameworks/Squirrel.framework/Versions/A/Squirrel
       0x112b1d000 -        0x112b80ff7 +org.reactivecocoa.ReactiveCocoa (1.0 - 1) <701B20DE-3ADD-3643-B52A-E05744C30DB3> /Applications/Atom Beta.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/ReactiveCocoa
       0x112bfe000 -        0x112c12fff +org.mantle.Mantle (1.0 - ???) <31915DD6-48E6-3706-A076-C9D4CE17F4F6> /Applications/Atom Beta.app/Contents/Frameworks/Mantle.framework/Versions/A/Mantle
       0x112c2b000 -        0x113aa7fff +libnode.dylib (0) <E2F96842-1586-383D-86C4-342FACFF05A6> /Applications/Atom Beta.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib
       0x113d53000 -        0x113fc0fe7 +libffmpeg.dylib (0) <B8B8A195-ADAF-3003-8F62-B9D1C788605D> /Applications/Atom Beta.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libffmpeg.dylib
       0x1157c6000 -        0x1157c6fff +cached-run-in-this-context.node (???) <2E84176A-5F96-398A-BCE5-62CB51D3599C> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/cached-run-in-this-context/build/Release/cached-run-in-this-context.node
       0x11b375000 -        0x11b376fff +scrollbar-style-observer.node (???) <E53E5319-FEC3-3608-ADC5-2E689BBFF851> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/scrollbar-style/build/Release/scrollbar-style-observer.node
       0x11b3ce000 -        0x11b3d2ff7 +pathwatcher.node (???) <0C62EC84-ADCE-3DC0-9161-0D20AAE0D10F> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/pathwatcher/build/Release/pathwatcher.node
       0x11b3db000 -        0x11b3dcfff +tree_sitter_embedded_template_binding.node (???) <193D1860-B807-3FEF-9B02-D6B392EA1A86> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-embedded-template/build/Release/tree_sitter_embedded_template_binding.node
       0x11b3e0000 -        0x11b3e5fff +tree_sitter_html_binding.node (???) <DB51F7B3-6522-3A65-A3AF-22C0DC58A35A> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-html/build/Release/tree_sitter_html_binding.node
       0x11c39f000 -        0x11c43dfff +superstring.node (???) <6CAFB9FA-23E3-3C62-9569-3AA66FB789F0> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/superstring/build/Release/superstring.node
       0x11d255000 -        0x11d2a6ff7 +onig_scanner.node (???) <A31255FF-9B1D-30DE-9C62-379D5B3930DD> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/oniguruma/build/Release/onig_scanner.node
       0x11d2bd000 -        0x11d2c4ff7 +tree_sitter_c_binding.node (???) <D0F76F00-DABA-3670-BB89-5FFB5F21CEBA> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-c/build/Release/tree_sitter_c_binding.node
       0x11d369000 -        0x11d374ff7 +tree_sitter_cpp_binding.node (???) <CEF08FFB-DC11-3CCF-8999-FD1FDC9AFF99> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-cpp/build/Release/tree_sitter_cpp_binding.node
       0x11d542000 -        0x11d548ff7 +tree_sitter_go_binding.node (???) <EF2B7DB3-BC42-3F28-A41F-7E9A7D76056D> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-go/build/Release/tree_sitter_go_binding.node
       0x11d5e8000 -        0x11d5f4ff7 +tree_sitter_javascript_binding.node (???) <29A1F913-F69E-376F-8E66-8974B121B8DE> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-javascript/build/Release/tree_sitter_javascript_binding.node
       0x11d70e000 -        0x11d716ff7 +tree_sitter_python_binding.node (???) <B4DE0361-4FC7-3293-BB05-1656683EFE22> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-python/build/Release/tree_sitter_python_binding.node
       0x11d7eb000 -        0x11d807fff +tree_sitter_ruby_binding.node (???) <BBEB59F8-9E51-354F-933F-58484852C797> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-ruby/build/Release/tree_sitter_ruby_binding.node
       0x11de79000 -        0x11de82fff +tree_sitter_bash_binding.node (???) <9FCCFC43-AA77-3866-A41A-1D03AE928716> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-bash/build/Release/tree_sitter_bash_binding.node
       0x11dfcd000 -        0x11dfd1fff +keytar.node (???) <1C14EF65-BDC5-32BD-91D3-794C79824D80> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/keytar/build/Release/keytar.node
       0x122e10000 -        0x122e24fff +tree_sitter_typescript_binding.node (???) <20853236-7694-3CA4-B932-69D51D9000C3> /Applications/Atom Beta.app/Contents/Resources/app.asar.unpacked/node_modules/tree-sitter-typescript/build/Release/tree_sitter_typescript_binding.node

https://xorkle.com/i/rfWBjpDhsA.zip is both the Atom package and the tree-sitter grammar. Very barebones just to get something working.