Skip to content

Commit

Permalink
Update syntax with Snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed Oct 14, 2017
1 parent 5e0f65d commit d460e15
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 4 deletions.
54 changes: 54 additions & 0 deletions Indentation Rules.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Indentation Rules</string>
<key>scope</key>
<string>source.odin</string>
<key>settings</key>
<dict>
<key>decreaseIndentPattern</key>
<string>(?x)
^ # start of line
(.*\*/)? # skip comments if present
( # three possibilities
\s* \} # whitespace and a closing curly brace
( # capture:
[^}{"']* \{ # anything other than curly braces or quotes, then open curly
)? # (optional)
[;\s]*? # any whitespace or semicolons
|
(?:\s* (case).*:) # case statements pop back one indent
|
(?: \) (?&lt;! \( ) ) # closing braces not preceded by opening braces
)
(//.*|/\*.*\*/\s*)? # skip any comments (optional)
$ # end of line
</string>
<key>increaseIndentPattern</key>
<string>(?x)
^
(?: .* \*/ )? # skip any comments
(?:
(.* \{ [^}"'\n]*) # lines containing an open curly but no quotes or close curly
| # OR
(?:\s* (case).*:) # case statements
| # OR
(.* \( [^)"'\n]*) # lines containing an open brace but no quotes or close brace
)
(//.*|/\*.*\*/\s*)? # skip any comments (optional)
$
</string>
<!--
<key>indentNextLinePattern</key>
<string>(?x)^
(?! .* [;:{}] # do not indent when line ends with ;, :, {, or }
\s* (//|/[*] .* [*]/ \s* $) # …account for potential trailing comment
)
</string>
-->
<key>unIndentedLinePattern</key>
<string>^\s*((/\*|\*/|//|import\b.*|export\b.*|(using\s+import)\b.*).*)?$</string>
</dict>
</dict>
</plist>
8 changes: 4 additions & 4 deletions Odin.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ contexts:
keywords:
- match: \b(import|export|foreign|foreign_library|foreign_system_library)\b
scope: keyword.control.odin
- match: \b(if|else|when|for|in|defer|match|return|const)\b
- match: \b(if|else|when|for|in|defer|switch|return)\b
scope: keyword.control.odin
- match: \b(fallthrough|break|continue|case|vector|static|dynamic|atomic)\b
- match: \b(fallthrough|break|continue|case|vector|static|dynamic)\b
scope: keyword.control.odin
- match: \b(using|do)\b
scope: keyword.control.odin
Expand All @@ -75,7 +75,7 @@ contexts:
scope: constant.numeric.odin
- match: '---'
scope: constant.numeric.odin
- match: \b(var|let|type|macro|struct|enum|union|map|bit_field)\b
- match: \b(type|macro|struct|enum|union|map|bit_field)\b
scope: storage.type.odin
- match: \b(cast|transmute)\b
scope: keyword.function.odin
Expand All @@ -98,7 +98,7 @@ contexts:
- match: ({{identifier}})\s*[!]?\s*[\(]
captures:
1: support.function.odin
- match: '\b({{identifier}})\s*[:]\s*[:]\s*(struct|union|enum|)'
- match: '\b({{identifier}})\s*[:]\s*[:]\s*(struct|union|enum|bit_field)'
captures:
1: meta.type.odin entity.name.type.odin
2: storage.type.odin
Expand Down
8 changes: 8 additions & 0 deletions Snippets/For Loop.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[for ${2:i} in ${3:0}..${1:count} {
$0
}]]></content>
<tabTrigger>for</tabTrigger>
<scope>source.odin</scope>
<description>For Loop</description>
</snippet>
8 changes: 8 additions & 0 deletions Snippets/If Statement.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[if ${1:condition} {
$0
}]]></content>
<tabTrigger>if</tabTrigger>
<scope>source.odin</scope>
<description>If Statement</description>
</snippet>
8 changes: 8 additions & 0 deletions Snippets/Struct.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[struct {
${0:var: vartype,}
}]]></content>
<tabTrigger>st</tabTrigger>
<scope>source.odin</scope>
<description>Struct</description>
</snippet>
9 changes: 9 additions & 0 deletions Snippets/Switch Statement.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<snippet>
<content><![CDATA[switch ${2:condition} {
case ${3:expr}:
$0
}]]></content>
<tabTrigger>switch</tabTrigger>
<scope>source.odin</scope>
<description>Switch Statement</description>
</snippet>
8 changes: 8 additions & 0 deletions Snippets/When Statement.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[when ${1:condition} {
$0
}]]></content>
<tabTrigger>when</tabTrigger>
<scope>source.odin</scope>
<description>When Statement</description>
</snippet>
6 changes: 6 additions & 0 deletions Snippets/export.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[export $2"${1:name}"]]></content>
<tabTrigger>exp</tabTrigger>
<scope>source.odin</scope>
<description>Export</description>
</snippet>
6 changes: 6 additions & 0 deletions Snippets/import.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<snippet>
<content><![CDATA[import $2"${1:name}"]]></content>
<tabTrigger>imp</tabTrigger>
<scope>source.odin</scope>
<description>Import</description>
</snippet>
8 changes: 8 additions & 0 deletions Snippets/main().sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[main :: proc() {
$0
}]]></content>
<tabTrigger>main</tabTrigger>
<scope>source.odin</scope>
<description>main()</description>
</snippet>
8 changes: 8 additions & 0 deletions Snippets/proc.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<snippet>
<content><![CDATA[${1:proc_name} :: proc($2)$3 {
$0
}]]></content>
<tabTrigger>proc</tabTrigger>
<scope>source.odin</scope>
<description>Function</description>
</snippet>

0 comments on commit d460e15

Please sign in to comment.