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

Add syntax highlighting for Solidity, Vyper, and Cairo #1806

Open
wants to merge 6 commits into
base: next
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
3 changes: 3 additions & 0 deletions docs/content/documentation/content/syntax-highlighting.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Here is a full list of supported languages and their short names:
- C -> ["c", "h"]
- C# -> ["cs", "csx"]
- C++ -> ["C", "c++", "cc", "cp", "cpp", "cxx", "h", "h++", "hh", "hpp", "hxx", "inl", "ipp"]
- Cairo -> ["cairo"]
- Clojure -> ["clj", "cljc", "cljs", "edn"]
- ClojureC -> ["boot", "clj", "cljc", "cljs", "cljx"]
- CMake -> ["CMakeLists.txt", "cmake"]
Expand Down Expand Up @@ -129,6 +130,7 @@ Here is a full list of supported languages and their short names:
- Sass -> ["sass"]
- Scala -> ["sbt", "sc", "scala"]
- SCSS -> ["scss"]
- Solidity -> ["sol", "solidity"]
- SQL -> ["ddl", "dml", "sql"]
- SQL (Rails) -> ["erbsql", "sql.erb"]
- srt -> ["srt", "subrip"]
Expand All @@ -142,6 +144,7 @@ Here is a full list of supported languages and their short names:
- TypeScript -> ["ts"]
- TypeScriptReact -> ["tsx"]
- VimL -> ["vim"]
- Vyper -> ["vy", "vyper"]
- XML -> ["dtml", "opml", "rng", "rss", "svg", "tld", "xml", "xsd", "xslt"]
- YAML -> ["sublime-syntax", "yaml", "yml"]
- Zig -> ["zig"]
Expand Down
166 changes: 166 additions & 0 deletions sublime/syntaxes/extra/Cairo.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
name: Cairo
file_extensions:
- cairo
scope: source.cairo
contexts:
main:
- include: directives
- include: statements
comment:
- match: '#'
captures:
0: punctuation.definition.comment
push:
- meta_scope: comment.line.number-sign
- match: $
pop: true
- match: TODO
scope: comment.line.number-sign
class-instance:
- match: '[[:upper:]][_$[:alnum:]]+[[:lower:]]+[_$[:alnum:]]+'
scope: support.class.cairo
declaration:
- include: import
directives:
- match: (?<!\w)\s*(%builtins|%lang)\s+
captures:
1: keyword.directive.cairo
expression:
- include: expression-without-identifiers
- include: identifiers
- include: expression-punctuations
expression-operators:
- match: '\%\{|\%\}'
scope: keyword.brackets.python-hints.cairo
- match: (=|!|>|<|\||&|\?|\^|~|\*|\+|\-|\/|\%)
scope: keyword.operator
- match: '(?<![\w$])(cast)(?![\w$])'
scope: keyword.operator.cast.cairo
expression-punctuations:
- include: punctuation-accessor
expression-without-identifiers:
- include: string
- include: comment
- include: literal
- include: function-expression
- include: storages
- include: keywords
- include: parameters
- include: expression-operators
- include: function-call
- include: support-objects
function-call:
- match: '([_$[:alpha:]][_$[:alnum:]]+)\s*(?=\()'
captures:
1: entity.name.function.cairo
push:
- match: (?<=\))
pop: true
- include: string
- include: comment
- include: literal
- include: identifiers
- include: expression-operators
function-expression:
- match: '\s*(func)\s+([_$[:alpha:]][_$[:alnum:]]*)\s*'
captures:
1: storage.type.function.cairo
2: entity.name.function.cairo
push:
- meta_scope: meta.function.expression.cairo
- match: (?<=:)
pop: true
- include: comment
- include: function-implicit
- include: function-params
- match: '->'
scope: keyword.function.return.cairo
function-implicit:
- match: '\{'
push:
- match: '\}'
pop: true
- include: parameters
function-params:
- match: \(
push:
- match: \)
pop: true
- include: parameters
identifiers:
- match: '(?<!\w)([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])'
scope: variable.other.constant.cairo
import:
- match: (?<!\w)\s*(from)\s
captures:
1: keyword.declaration.cairo
push:
- match: \s*(import)\s
captures:
1: keyword.declaration.cairo
pop: true
- include: string
- include: comment
- include: punctuation-accessor
- match: '[_$[:alpha:]][_$[:alnum:]]+'
scope: meta.import.from.location.cairo
keywords:
- match: \b(else|if|in|return|end|assert)\b
scope: keyword.controls.cairo
- match: \b(from|import|func|namespace)\b
scope: keyword.declaration.cairo
- match: ^\s*@(constructor|storage_var|view|external|contract_interface|known_ap_change|event)\s+
scope: keyword.others.cairo
literal:
- include: numeric-literal
numeric-literal:
- match: '\b(?:([0-9]+)|(0x[0-9a-fA-F]+))\b'
scope: constant.numeric.decimal.cairo
parameters:
- include: comment
- include: punctuation-accessor
- match: '(:)\s*([_$[:alpha:]][_$[:alnum:]]+)'
captures:
1: punctuation.separator
2: support.type.cairo
punctuation-accessor:
- match: (\.)|(\*)
captures:
1: punctuation.separator.dot-accessor.cairo
2: keyword.operator
punctuation-semicolon:
- match: ;
scope: punctuation.terminator.statement.cairo
statements:
- include: string
- include: comment
- include: declaration
- include: expression
- include: punctuation-semicolon
storages:
- match: \b(let|const|local|struct|member|alloc_locals)\b
scope: storage.type.cairo
string:
- match: '"'
captures:
0: punctuation.definition.string.begin.cairo
push:
- meta_scope: string.quoted.double.cairo
- match: '"'
captures:
0: punctuation.definition.string.end.cairo
pop: true
- match: "'"
captures:
0: punctuation.definition.string.begin.cairo
push:
- meta_scope: string.quoted.single.cairo
- match: "'"
captures:
0: punctuation.definition.string.end.cairo
pop: true
support-objects:
- include: class-instance
3 changes: 3 additions & 0 deletions sublime/syntaxes/extra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ are converted from the following repos at the following commit:
- Stylus: https://github.com/billymoon/Stylus/tree/30908e3b5757d6cab4bf2ce660ef89b0c614cf62
- Racket: https://gist.githubusercontent.com/sliminality/3f1527f8e910c36b3303346422b03409/raw/9ce1ddd463c9bc97439726fd5f63b1fb3a36419b/Racket.tmLanguage
- TypeScript: https://github.com/microsoft/TypeScript-Sublime-Plugin/commit/a607ddfec90648c1c2f33f8306733f6aec5d2b78
- Solidity: https://github.com/davidhq/SublimeEthereum/commit/65d3905dcc384e1eeb8bc3fe460c12336505edcb
- Vyper: https://github.com/davidhq/SublimeEthereum/commit/65d3905dcc384e1eeb8bc3fe460c12336505edcb
- Cairo: https://github.com/davidhq/SublimeEthereum/commit/65d3905dcc384e1eeb8bc3fe460c12336505edcb

The others, I haven't kept track of the repo/commit.
Loading