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

Fix syntax file extensions and custom color scheme #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
25 changes: 17 additions & 8 deletions auto_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


legacy_syntax_names = {
('\t', 'simple'): 'TSV (Rainbow)',
(',', 'quoted'): 'CSV (Rainbow)'
('\t', 'simple'): ('TSV (Rainbow)', 'tsv'),
(',', 'quoted'): ('CSV (Rainbow)', 'csv'),
}


Expand All @@ -20,17 +20,24 @@ def decode_delim(delim):


def get_syntax_file_basename(delim, policy):
for k, v in legacy_syntax_names.items():
for k, (v, _ext) in legacy_syntax_names.items():
if (delim, policy) == k:
return v + '.sublime-syntax'
return 'Rainbow_CSV_hex_{}_{}.sublime-syntax'.format(encode_delim(delim), filename_policy_map[policy])


def get_syntax_file_ext(delim, policy):
for k, (_v, ext) in legacy_syntax_names.items():
if k == (delim, policy):
return ext
return None


simple_header_template = '''%YAML 1.2
---
name: '{}'
file_extensions: [{}]
scope: text.{}
scope: text.csv.{}


contexts:
Expand All @@ -44,7 +51,7 @@ def get_syntax_file_basename(delim, policy):
---
name: '{}'
file_extensions: [{}]
scope: text.{}
scope: text.csv.{}


contexts:
Expand Down Expand Up @@ -90,7 +97,7 @@ def oniguruma_regular_escape(delim):


def get_syntax_name(delim, policy):
for k, v in legacy_syntax_names.items():
for k, (v, _ext) in legacy_syntax_names.items():
if (delim, policy) == k:
return v
ui_delim = delim.replace('\t', 'tab')
Expand Down Expand Up @@ -144,7 +151,8 @@ def make_standard_context(delim, context_id, num_contexts, indent=' '):
def make_sublime_syntax_simple(delim):
scope = 'rbcsmn' + ''.join([str(ord(d)) for d in delim])
name = get_syntax_name(delim, 'simple')
result = simple_header_template.format(yaml_escape(name), scope, scope)
ext = get_syntax_file_ext(delim, 'simple') or scope
result = simple_header_template.format(yaml_escape(name), ext, scope)
num_contexts = len(rainbow_scope_names)
for context_id in range(num_contexts):
result += '\n'
Expand All @@ -156,7 +164,8 @@ def make_sublime_syntax_standard(delim, policy):
assert policy in ['quoted', 'quoted_rfc']
scope = 'rbcstn' + ''.join([str(ord(d)) for d in delim])
name = get_syntax_name(delim, policy)
result = standard_header_template.format(yaml_escape(name), scope, scope)
ext = get_syntax_file_ext(delim, policy) or scope
result = standard_header_template.format(yaml_escape(name), ext, scope)
if policy == 'quoted':
result += non_rfc_endline_rule
num_contexts = len(rainbow_scope_names)
Expand Down
24 changes: 24 additions & 0 deletions json5/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Python package

on:
push:
pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.12]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run tests
run: python run tests
8 changes: 8 additions & 0 deletions json5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.coverage
.ruff_cache
build
dist
*.pyc
*.pyc.d
*.py,cover
json5.egg-info
12 changes: 12 additions & 0 deletions json5/.gitrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme
;
[subrepo]
remote = https://github.com/dpranke/pyjson5.git
branch = main
commit = 43901a8f45579b6d987245edffd8c8fd5cb6a158
parent = eeab7cf4d42da9e30ba90ae9410aa8cf0b296872
method = merge
cmdver = 0.4.9
Loading