Skip to content

Commit

Permalink
Fix CSV file extensions and syntax scopes
Browse files Browse the repository at this point in the history
Changes the syntax scope to `text.csv.*`, e.g. `text.csv.rbcstn44`
instead of the unusual `text.rbcstn44`. (What is a "rbcstn44" file,
anyway?)

Also sets the file extensions, allowing the FileIcons package to work.

Closes #34
  • Loading branch information
parasyte authored and mechatroner committed Sep 1, 2024
1 parent e2732a5 commit e7dc99f
Show file tree
Hide file tree
Showing 40 changed files with 58 additions and 49 deletions.
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
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_table_names_path():
return table_names_path_cached


legacy_syntax_names_inv = {v + '.sublime-syntax': k for k, v in auto_syntax.legacy_syntax_names.items()}
legacy_syntax_names_inv = {v + '.sublime-syntax': k for k, (v, _ext) in auto_syntax.legacy_syntax_names.items()}


def ensure_syntax_file(delim, policy):
Expand Down
4 changes: 2 additions & 2 deletions pregenerated_grammars/CSV (Rainbow).sublime-syntax
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%YAML 1.2
---
name: 'CSV (Rainbow)'
file_extensions: [rbcstn44]
scope: text.rbcstn44
file_extensions: [csv]
scope: text.csv.rbcstn44


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV Simple'
file_extensions: [rbcsmn32]
scope: text.rbcsmn32
scope: text.csv.rbcsmn32


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ! Simple'
file_extensions: [rbcsmn33]
scope: text.rbcsmn33
scope: text.csv.rbcsmn33


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV " Simple'
file_extensions: [rbcsmn34]
scope: text.rbcsmn34
scope: text.csv.rbcsmn34


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV # Simple'
file_extensions: [rbcsmn35]
scope: text.rbcsmn35
scope: text.csv.rbcsmn35


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV $ Simple'
file_extensions: [rbcsmn36]
scope: text.rbcsmn36
scope: text.csv.rbcsmn36


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV % Simple'
file_extensions: [rbcsmn37]
scope: text.rbcsmn37
scope: text.csv.rbcsmn37


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV & Simple'
file_extensions: [rbcsmn38]
scope: text.rbcsmn38
scope: text.csv.rbcsmn38


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV '' Simple'
file_extensions: [rbcsmn39]
scope: text.rbcsmn39
scope: text.csv.rbcsmn39


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ( Simple'
file_extensions: [rbcsmn40]
scope: text.rbcsmn40
scope: text.csv.rbcsmn40


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ) Simple'
file_extensions: [rbcsmn41]
scope: text.rbcsmn41
scope: text.csv.rbcsmn41


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV * Simple'
file_extensions: [rbcsmn42]
scope: text.rbcsmn42
scope: text.csv.rbcsmn42


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV + Simple'
file_extensions: [rbcsmn43]
scope: text.rbcsmn43
scope: text.csv.rbcsmn43


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV , Simple'
file_extensions: [rbcsmn44]
scope: text.rbcsmn44
scope: text.csv.rbcsmn44


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV , RFC'
file_extensions: [rbcstn44]
scope: text.rbcstn44
scope: text.csv.rbcstn44


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV - Simple'
file_extensions: [rbcsmn45]
scope: text.rbcsmn45
scope: text.csv.rbcsmn45


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV . Simple'
file_extensions: [rbcsmn46]
scope: text.rbcsmn46
scope: text.csv.rbcsmn46


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV / Simple'
file_extensions: [rbcsmn47]
scope: text.rbcsmn47
scope: text.csv.rbcsmn47


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV : Simple'
file_extensions: [rbcsmn58]
scope: text.rbcsmn58
scope: text.csv.rbcsmn58


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ; Simple'
file_extensions: [rbcsmn59]
scope: text.rbcsmn59
scope: text.csv.rbcsmn59


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ; Standard'
file_extensions: [rbcstn59]
scope: text.rbcstn59
scope: text.csv.rbcstn59


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ; RFC'
file_extensions: [rbcstn59]
scope: text.rbcstn59
scope: text.csv.rbcstn59


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV < Simple'
file_extensions: [rbcsmn60]
scope: text.rbcsmn60
scope: text.csv.rbcsmn60


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV = Simple'
file_extensions: [rbcsmn61]
scope: text.rbcsmn61
scope: text.csv.rbcsmn61


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV > Simple'
file_extensions: [rbcsmn62]
scope: text.rbcsmn62
scope: text.csv.rbcsmn62


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ? Simple'
file_extensions: [rbcsmn63]
scope: text.rbcsmn63
scope: text.csv.rbcsmn63


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV @ Simple'
file_extensions: [rbcsmn64]
scope: text.rbcsmn64
scope: text.csv.rbcsmn64


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV [ Simple'
file_extensions: [rbcsmn91]
scope: text.rbcsmn91
scope: text.csv.rbcsmn91


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV \ Simple'
file_extensions: [rbcsmn92]
scope: text.rbcsmn92
scope: text.csv.rbcsmn92


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ] Simple'
file_extensions: [rbcsmn93]
scope: text.rbcsmn93
scope: text.csv.rbcsmn93


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ^ Simple'
file_extensions: [rbcsmn94]
scope: text.rbcsmn94
scope: text.csv.rbcsmn94


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV _ Simple'
file_extensions: [rbcsmn95]
scope: text.rbcsmn95
scope: text.csv.rbcsmn95


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV ` Simple'
file_extensions: [rbcsmn96]
scope: text.rbcsmn96
scope: text.csv.rbcsmn96


contexts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
name: 'Rainbow CSV { Simple'
file_extensions: [rbcsmn123]
scope: text.rbcsmn123
scope: text.csv.rbcsmn123


contexts:
Expand Down
Loading

0 comments on commit e7dc99f

Please sign in to comment.