Skip to content

Commit

Permalink
First commit of syntax files.
Browse files Browse the repository at this point in the history
  • Loading branch information
thom committed Aug 11, 2017
1 parent 8864742 commit 9a82149
Show file tree
Hide file tree
Showing 11 changed files with 3,265 additions and 0 deletions.
11 changes: 11 additions & 0 deletions metadata/Comments.YAML-tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# [PackageDev] target_format: plist, ext: tmPreferences
name: Comments
scope: source.sql
settings:
shellVariables:
- name: TM_COMMENT_START
value: '--'
- name: TM_COMMENT_START_2
value: '/*'
- name: TM_COMMENT_END_2
value: '*/'
34 changes: 34 additions & 0 deletions metadata/Comments.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>name</key>
<string>Comments</string>
<key>scope</key>
<string>source.sql.oracle, source.plsql</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string>--</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_START_2</string>
<key>value</key>
<string>/*</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_END_2</string>
<key>value</key>
<string>*/</string>
</dict>
</array>
</dict>
</dict>
</plist>
26 changes: 26 additions & 0 deletions metadata/Indent.YAML-tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# [PackageDev] target_format: plist, ext: tmPreferences
name: Indent
scope: source.sql
settings:
increaseIndentPattern: >-
(?ix)^(
(\s|,)* \b(
select|from|(group|connect|order|pivot|having)\s+by|
case (?! .*\b(end)\b)
)\b .*
|
.*\(\s*
)$
decreaseIndentPattern: >-
(?ix)^(
\s* \b(
select|from|(group|connect|order|pivot|having)\s+by|
end
)\b .*
|
\s* \) .*
)$
bracketIndentNextLinePattern: >-
(?ix)^\s* \b(
when|then|else
)\b \s*$
35 changes: 35 additions & 0 deletions metadata/Indent.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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>name</key>
<string>Indent</string>
<key>scope</key>
<string>source.sql</string>
<key>settings</key>
<dict>
<key>bracketIndentNextLinePattern</key>
<string>(?ix)^\s* \b(
when|then|else
)\b \s*$</string>
<key>decreaseIndentPattern</key>
<string>(?ix)^(
\s* \b(
select|from|connect\s+by|
end
)\b .*
|
\s* \) .*
)$</string>
<key>increaseIndentPattern</key>
<string>(?ix)^(
(\s|,)* \b(
select|from|connect\s+by|
case (?! .*\b(end)\b)
)\b .*
|
.*\(\s*
)$</string>
</dict>
</dict>
</plist>
6 changes: 6 additions & 0 deletions metadata/Symbol List.YAML-tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# [PackageDev] target_format: plist, ext: tmPreferences
name: Symbol List
scope: >-
source.sql entity.name.subquery
settings:
showInSymbolList: '1'
15 changes: 15 additions & 0 deletions metadata/Symbol List.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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>name</key>
<string>Symbol List</string>
<key>scope</key>
<string>source.sql entity.name.subquery</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<string>1</string>
</dict>
</dict>
</plist>
82 changes: 82 additions & 0 deletions syntaxes/macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from YAMLMacros.lib.syntax import meta, expect, pop_on, stack

def meta_set(scope):
return [
{ 'meta_scope': scope },
{ 'clear_scopes': 1 },
{ 'match': r'', 'pop': True },
]

def expect_keyword(match, scope="keyword.other.sql"):
return expect(word(match), scope)

def expect_identifier(scope):
return [
{ 'match': r'{{unquoted_identifier}}', 'scope': scope, 'pop': True },
{
'match': r'(")([^"]+)(")',
'scope': 'string.quoted.double.sql',
'captures': {
'1': 'punctuation.definition.string.begin.sql',
'2': scope,
'3': 'punctuation.definition.string.end.sql',
},
'pop': True,
},

{ 'match': r'(?=\S)', 'pop': True },
]

def expect_in_parens(contents):
return [
{
'match': r'\(',
'scope': 'punctuation.section.group.begin.sql',
'set': [
expect(r'\)', 'punctuation.section.group.end.sql'),
contents,
],
},
{ 'match': r'(?=\S)', 'pop': True },
]

def end(keyword=None):
if bool(keyword):
next_context = expect_keyword(keyword, 'keyword.control.sql')
else:
next_context = expect_identifier('variable.other.label.sql')

return {
'match': word('END'),
'scope': 'keyword.control.sql',
'set': next_context,
}

def word(match):
return r'(?i)\b(?:%s)\b' % match

def word_ahead(match):
return r'(?i)\b(?=(?:%s)\b)' % match

def empty_context(*args):
return [ { 'match':'', 'pop': True } ]

def all(*contexts):
return [
{ 'include': context } for context in contexts
]

def heredoc(start, end):
return {
'match': r"(?i)q\'%s" % start,
'scope': 'punctuation.definition.string.begin.sql',
'set': [
{ 'meta_include_prototype': False },
{ 'meta_scope': 'string.quoted.heredoc.sql' },
{
'match': r"%s\'" % end,
'scope': 'punctuation.definition.string.end.sql',
'pop': True,
},
],
}
Loading

0 comments on commit 9a82149

Please sign in to comment.