language-python icon indicating copy to clipboard operation
language-python copied to clipboard

Implement naming conventions in Python grammar

Open chbk opened this issue 5 years ago • 6 comments

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 and types.
  • 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

  • https://github.com/atom/atom/issues/8430

Related Pull Requests

chbk avatar Nov 22 '19 16:11 chbk

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-py-0
Solarized Dark
solarized-dark-py-1
One Dark
one-dark-py-0
One Dark
one-dark-py-1
Base16 Tomorrow Dark
base16-dark-py-0
Base16 Tomorrow Dark
base16-dark-py-1
Atom Dark
atom-dark-py-0
Atom Dark
atom-dark-py-1
Solarized Light
solarized-light-py-0
Solarized Light
solarized-light-py-1
One Light
one-light-py-0
One Light
one-light-py-1
Base16 Tomorrow Light
base16-light-py-0
Base16 Tomorrow Light
base16-light-py-1
Atom Light
atom-light-py-0
Atom Light
atom-light-py-1

Code snippet:

import lemons as lemonade
from typing import Dict, List

# Welcome to Aperture Science

"\u2661 {cake:02d}"

f"SP{a*9}CE! \n"

r"^Test(?=subject\b)\s[a-z]*"

3 * 1.4 + 12 = 16.2

potato: Dict[int, List] = {
  'mashed': 1,
  'fried': 0
}

class Cube():
  def __init__(self, color):
    my.color = color

class Companion(Cube):
  friend: bool = True

  @classmethod
  def loves_you(cls) -> str:
    return str(cls.friend)

testing: Cube = Cube('pink')

@core.recite
def recipe(red) -> List[str]:
  if red > 0 and True:
    return [
      'fish shaped dirt',
      '3 rhubarb, on fire'
    ]

with open('blue') as portal:
  ...
  portal.write(recipe())

chbk avatar Nov 22 '19 16:11 chbk

Yeah it's a rewrite, difficult to partition into separate commits.

chbk avatar Jan 12 '21 05:01 chbk

Screenshots of different example code in different themes (light/dark/popular/built-in) to show the changes would help a lot for reviewing

jeff-hykin avatar Jan 18 '21 16:01 jeff-hykin

Besides the screenshots above, what would you suggest?

chbk avatar Jan 19 '21 07:01 chbk

Can we merge this?

ThatXliner avatar Mar 28 '21 16:03 ThatXliner

I think this is good to merge

jeff-hykin avatar May 25 '22 15:05 jeff-hykin