Skip to content

Commit

Permalink
Add syntax highlighting file.
Browse files Browse the repository at this point in the history
Plugin now imports 'math' module into the default expression namespace, for convenience.
Add test CSV (not programmatically validated in any way).
  • Loading branch information
wadetb committed Nov 28, 2014
1 parent 87d128d commit dd51c5a
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 0 deletions.
45 changes: 45 additions & 0 deletions AdvancedCSV.YAML-tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Advanced CSV
fileTypes: [csv]
scopeName: text.advanced_csv
uuid: 7ce133ea-e34b-47d9-a03c-341293337c88

patterns:
- name: meta.quoted.advanced_csv
begin: (\")
end: (\")
captures:
'1': {name: string.quoted.double.advanced_csv}
patterns:
- include: '$self'

- name: meta.range.advanced_csv
begin: (\[([+-]?\d*)(\:)?([+-]?\d*)(\,)?([+-]?\d*)(\:)?([+-]?\d*)\])?\s*([<>v^])?\s*(=)
beginCaptures:
'1': {name: keyword.operator.advanced_csv} # range
'2': {name: constant.numeric.formula.advanced_csv} # row_begin
'4': {name: constant.numeric.formula.advanced_csv} # row_end
'6': {name: constant.numeric.formula.advanced_csv} # col_begin
'8': {name: constant.numeric.formula.advanced_csv} # col_end
'9': {name: keyword.operator.advanced_csv} # direction
'10': {name: keyword.operator.advanced_csv} # equals
end: (?=(\")|$)
patterns:
- include: source.python

- name: meta.number.advanced_csv
match: (?<=^|,|\s|\")([0-9.eE+-]+)(?=$|,|\s|\")
captures:
'1': {name: constant.numeric.advanced_csv}

- name: meta.nonnumber.advanced_csv
match: (?<=^|,|\s|\")([^, \t\"]+)(?=$|,|\s|\")
captures:
'1': {name: storage.type.advanced_csv}

- name: meta.delimiter.advanced_csv
match: (\,)
captures:
'1': {name: keyword.operator.advanced_csv}

137 changes: 137 additions & 0 deletions AdvancedCSV.tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>csv</string>
</array>
<key>name</key>
<string>Advanced CSV</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(\")</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>string.quoted.double.advanced_csv</string>
</dict>
</dict>
<key>end</key>
<string>(\")</string>
<key>name</key>
<string>meta.quoted.advanced_csv</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(\[([+-]?\d*)(\:)?([+-]?\d*)(\,)?([+-]?\d*)(\:)?([+-]?\d*)\])?\s*([&lt;&gt;v^])?\s*(=)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.advanced_csv</string>
</dict>
<key>10</key>
<dict>
<key>name</key>
<string>keyword.operator.advanced_csv</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>constant.numeric.formula.advanced_csv</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>constant.numeric.formula.advanced_csv</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>constant.numeric.formula.advanced_csv</string>
</dict>
<key>8</key>
<dict>
<key>name</key>
<string>constant.numeric.formula.advanced_csv</string>
</dict>
<key>9</key>
<dict>
<key>name</key>
<string>keyword.operator.advanced_csv</string>
</dict>
</dict>
<key>end</key>
<string>(?=(\")|$)</string>
<key>name</key>
<string>meta.range.advanced_csv</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.python</string>
</dict>
</array>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>constant.numeric.advanced_csv</string>
</dict>
</dict>
<key>match</key>
<string>(?&lt;=^|,|\s|\")([0-9.eE+-]+)(?=$|,|\s|\")</string>
<key>name</key>
<string>meta.number.advanced_csv</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>storage.type.advanced_csv</string>
</dict>
</dict>
<key>match</key>
<string>(?&lt;=^|,|\s|\")([^, \t\"]+)(?=$|,|\s|\")</string>
<key>name</key>
<string>meta.nonnumber.advanced_csv</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.advanced_csv</string>
</dict>
</dict>
<key>match</key>
<string>(\,)</string>
<key>name</key>
<string>meta.delimiter.advanced_csv</string>
</dict>
</array>
<key>scopeName</key>
<string>text.advanced_csv</string>
<key>uuid</key>
<string>7ce133ea-e34b-47d9-a03c-341293337c88</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions csvplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sublime_plugin

import re, sys, os
from math import *

directory = os.path.dirname(os.path.realpath(__file__))
sys.path.append(directory)
Expand Down
12 changes: 12 additions & 0 deletions test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
hello ,col0,sdfadfasdf,col1,328000822119.0 ,1.7320508075688772
aa ,bb , ,c ,328000822119.0 ,1.7320508075688772
1 ,2 , ,3 ,328000822119.0 ,1.7320508075688772
4 ,3 , ,2 ,0.01e10
",a "" ",b , ,c ,.45
'asd' , , , ,125.0
, , ,0.45,[0:3]=m[:].sum()
, , , ,"[0:3,+1:+2]=sqrt(3)", ,
, , , ,12


,

0 comments on commit dd51c5a

Please sign in to comment.