Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Implement naming conventions in JavaScript and Regex grammars #690

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chbk
Copy link

@chbk chbk commented Jan 12, 2021

Description of the Change

This is a rewrite of the Tree-sitter grammar to implement naming conventions for syntax scopes.

Benefits

  • Many new scopes added to make the grammar explicit and exhaustive.
  • Notable improvements on punctuation, types, and regex patterns.
  • Highlighting to be consistent with other languages.

Possible Drawbacks

Some new scopes to be added to themes. The changes aim to facilitate theme development, filling the template is enough to ensure coherent highlighting across languages, instead of painfully creating styling rules for every language separately.

Applicable Issues

Related Pull Requests

@chbk
Copy link
Author

chbk commented Jan 12, 2021

Preview of the changes with Atom's default syntax themes:

Without naming conventions
(current Tree-sitter grammar)
With naming conventions in
theme and Tree-sitter grammar
Solarized Dark
solarized-dark-js-0
Solarized Dark
solarized-dark-js-1
One Dark
one-dark-js-0
One Dark
one-dark-js-1
Base16 Tomorrow Dark
base16-dark-js-0
Base16 Tomorrow Dark
base16-dark-js-1
Atom Dark
atom-dark-js-0
Atom Dark
atom-dark-js-1
Solarized Light
solarized-light-js-0
Solarized Light
solarized-light-js-1
One Light
one-light-js-0
One Light
one-light-js-1
Base16 Tomorrow Light
base16-light-js-0
Base16 Tomorrow Light
base16-light-js-1
Atom Light
atom-light-js-0
Atom Light
atom-light-js-1

Code snippet:

import * as empire from 'galaxy'

class Terminus extends empire.Planet {
  static hologram() {
    return super.psychohistory
  }
  get plan() {
    return (
      <div class={this.axiom + 1}>
        <Council speaker="first"/>
      </div>
    )
  }
}

vault = Terminus.hologram(true)
cleonII = new empire.Trantor.Ruler()

@future
function seldonCrisis(...years) {
  let riddle = "a circle has"
  riddle += `${years[0]} no end`
  console.log(riddle)
  return [...arguments]
}

if (magnifico === undefined) {
  let search = Infinity
}

robotics.map(law =>
  law.replace(/^H(?:.*\w)\n$/i, "0")
)

/** @type {number} */
const PARSEC = 2.06265 * 1e5

export function *travel() {
  yield {
    distance: 16204 * PARSEC,
    destination: "star's end"
  }
}

icecream17 added a commit to icecream17/pulsar that referenced this pull request Oct 2, 2022
The non-tree sitter version is almost completely copied so nothing to say there.

There are some inconsistencies/missing operators in the tree-sitter version, for example:
- `this`
- `new.target`
- `import.meta`
- The keyword.operator order looks more wrong the more I look at it but that's for another day because of the possible scope regularity change in the future: atom/language-javascript#690
- btw atom/language-javascript#691 looks good to me I should probably do that

Even though tree-sitter will have some above changes I added the new operators (`** **= ?? &&= ||= ??= void`) anyway.
Well `void` is not new it's just missing.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators for a list of operators. Of course while the comma is technically an operator, hopefully it's used more to separate elements in arrays or properties in objects.

Also `delete` is an operator not control.
@icecream17 icecream17 mentioned this pull request Oct 2, 2022
3 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant