Skip to content

Commit d072797

Browse files
committed
📝 grammar contributing docs 🌹
1 parent 5dfdd68 commit d072797

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/grammar.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
# CSON Grammar
1+
# CSON grammar
2+
3+
Atom works with a CSON grammar. We generate this from Microsoft supported grammar files. This is the code https://github.com/TypeStrong/atom-typescript/blob/master/scripts/grammar.js run using `npm run build` that updates our grammar file.
4+
5+
For grammar issues go here : https://github.com/Microsoft/TypeScript-TmLanguage/issues and link back to us if you want us to pull from upstream :rose:.
6+
7+
# CSON Grammar Docs
28
What is meant by `name` and `captures`
39
https://discuss.atom.io/t/grammar-understanding-captures-vs-name/14783
410

511
Generally the best docs:
612
http://manual.macromates.com/en/language_grammars.html
713

814
# Dynamic Grammar
15+
16+
> Warning : :warning: This feature is now legacy but has some good learning
17+
918
We used dynamic (code driven) grammar initially. Following are the lessons still worth sharing but we are using the CSON grammar now.
1019

1120
I am using `atom` and `first-mate` interchangeably here. There isn't a documented way of creating a grammar from *code*. We found a hacky way by reading a *lot of source code*. Please look at `typeScriptGrammar.ts`. Basically you inherit from `Grammar` and let that do the heavy lifting. Then all you need is to return `AtomTokens` from `tokenizeLine`. The way the atom grammar works is that they will store the returned `ruleSet` for any line and call `tokenizeLine` for the next line passing in that `ruleSet`. As soon as you edit a line all the following lines are invalidated and `tokenizeLine` is called for them again. This works beautifully with the `ts.createClassifier` which is a quick syntactic classifier provided by the TS language service. It only depends on a `finalLexState` (e.g. did the previous line have a continuing multiline comment) and that is what we store in the `ruleSet`.

0 commit comments

Comments
 (0)