Skip to content

Instantly share code, notes, and snippets.

@staticfloat
Created August 28, 2012 23:36
Show Gist options
  • Select an option

  • Save staticfloat/3505330 to your computer and use it in GitHub Desktop.

Select an option

Save staticfloat/3505330 to your computer and use it in GitHub Desktop.
{ scopeName = 'source.julia';
firstLineMatch = '^#!/usr/bin/env\s+julia\s*$';
fileTypes = ( 'j', 'jl', 'jul', 'julia' );
foldingStartMarker = '^\s*(?:if|while|for|begin|function|macro|module|type|let)\b(?!.*\bend\b).*$';
foldingStopMarker = '^\s*(?:end)\b.*$';
patterns = (
{ include = '#function_decl'; },
{ include = '#function_call'; },
{ include = '#type_decl'; },
{ include = '#keyword'; },
{ include = '#operator'; },
{ include = '#number'; },
{ include = '#string'; },
{ include = '#comment'; },
);
repository = {
comment = {
patterns = (
{ name = 'comment.line.number-sign.julia';
match = '(?<!\$)(#)(?!\{).*$\n?';
captures = { 1 = { name = 'punctuation.definition.comment.julia'; }; };
},
);
};
bracket = {
patterns = (
{ name = 'keyword.bracket.julia';
match = '(?:\(|\)|\[|\]|\{|\}|,)';
},
);
};
function_call = {
patterns = (
{ name = 'meta.function.julia';
begin = '[a-zA-Z0-9_]+\w*\(';
end = "\)(('|(\.'))*\.?')?";
endCaptures = { 1 = { name = 'keyword.operator.transposed-func.julia'; }; };
patterns = ( { include = '$self'; } );
},
);
};
function_decl = {
patterns = (
{ name = 'meta.function.julia';
begin = '(function)\w*([a-zA-Z0-9_]+)\w*\(';
end = '\)';
beginCaptures = {
1 = { name = 'keyword.other.julia'; };
2 = { name = 'entity.name.function.julia'; };
};
patterns = ( { include = '$self'; } );
},
);
};
keyword = {
patterns = (
{ name = 'support.type.julia';
match = '\b(Range1?|NDRange|Tuple|Real|Vector|Array|AbstractArray|ObjectIdDict|Dict|WeakKeyDict|EnvHash|LineIterator|String|IntSet|FDSet|Set|Task|ASCIIString|UTF8String|Bool|Int(8|16|32|64)?|Uint(8|16|32|64)?|Float(32|64)?|Complex(64|128)?)\b';
},
{ name = 'support.constant.julia';
match = '\b(std(out|err|in)_stream)\b';
},
{ name = 'support.function.julia';
match = '\b(?:exit|whos|edit|load|isa?|is(equal|less)|typeof|n?tuple|uid|hash|finalizer|co(py|nvert)|promote|sub|type(min|max)|real(min|max)|sizeof|eps|promote_type|method_exists|applicable|invoke|start|done|next|isempty|numel|length|contains|reduce|m(ax|in)|sum|prod|anyp?|allp?|countp?|map|ref|assign|has|get|d(el|el_all)|add|intset|choose|union|p(ush|op)|enqueue|shift|insert|del|grow|append!?|str(len|cat|ing|chr)|cstring|(l|r)pad|split|join|ch(op|omp)|ind2chr|chr2ind|open|memio|fdio|flush|close|with_output_stream|write|read|position|s(eek|kip)|current_output_stream|set_current_output_stream|show(all)?|print(ln)?|dump|read(all|line|until|lines)|each_line|dlm(read|write)|csv(read|write)|div|fld|mod|sinc?|cosc?|sinh?|cosh?|tanh?|a(sin|cos|tan|tan2)|sech?|c(sc|ot)h?|a(cos|sin|tan|sec|csc|cot)h?|hypot|log|log2|log10|log1p|logb|ilobg|exp2?|expm1|ldexp|ceil|floor|trunc|round|i(ceil|floor|trunc|round|part)|fpart|m(in|ax)|clamp|abs2?|copysign|sign|signbit|pow|sqrt|cbrt|erfc?|gamma|lgamma|lfact|bessel(j0|j1|y1|y0)|real|imag|conj|angle|cis|binomial|factorial|gcd|lcm|nextpow2|powermod|eps|bin|hex|dec|oct|int2str|parse_int|bool|u?int(8|16|32|64)|float(32|64)|char|safe_char|complex|is(complex|real)|bswap|num2hex|hex2num|one|zero|is(denormal|finite|nan)|nextfloat|prevfloat|integer_valued|real_valued|exponent|mantissa|rand(f|i|bit|bool|n|g|chi2|exp)|srand|ndimds|size|eltype|numel|nnz|strides?|ref|cell|zeros|ones|trues|falses|fill!?|reshape|copy|similar|empty|reinterpret|eye|linspace|sub|slicedim|assign|cat|vcat|hcat|hvcat|flip(dim|pud|plr)|circshift|findn?|i?permute|squeeze|dot|cross|norm|chol|lu|qr|eig|svd|tri(u|l)|diagm?|rank|cond|trace|det|inv|repmat|kron|linreg|sort(r|perm)?!?|issorted|nthperm!?|rand(perm|cycle)|shuffle!?|reverse!?|select!?|mean|std|median|histc?|i?fft(2|3|n|shift)|deconv|conv|xcorr|addprocs_(local|ssh|sge)|nprocs|myid|remote_call|wait|fetch|remote_call_(wait|fetch)|put|take|d(array|zeros|ones|fill|randn?|cell|istribute)|localize|changedist|myindexes|owner|procs|distdim|system|get(hostname|ipaddr|cwd|pid)|setcwd|t(ime|ic|oc|oq)|dl(open|sym)|error|throw|strerror|assert|yieldto|current_task|istaskdone|consume|produce|make_scheduled|yield|tls)\b';
},
{ name = 'keyword.other.julia';
match = '\b(?:function|type|macro|quote|abstract|bitstype|typealias|module|new)\b';
},
{ name = 'keyword.control.julia';
match = '\b(?:if|else|elseif|while|for|begin|let|end|do|try|catch|return|break|continue)\b';
},
{ name = 'storage.modifier.variable.julia';
match = '\b(?:global|local|const|export|import)\b';
},
{ name = 'support.macro.julia';
match = '@\w+\b';
},
);
};
number = {
patterns = (
{ name = 'constant.numeric.julia';
match = '((\b0(x|X)[0-9a-fA-F]*)|((\b[0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]*)?(im)?|\bInf(32)?\b|\bNaN(32)?\b)';
},
);
};
operator = {
patterns = (
{ name = 'keyword.operator.update.julia';
match = '(?:=|:=|\+=|-=|\*=|/=|//=|\.//=|\.\*=|\\=|\.\\=|^=|\.^=|%=|\|=|&=|\$=|<<=|>>=)';
},
{ name = 'keyword.operator.ternary.julia';
match = '(?:\?|:)';
},
{ name = 'keyword.operator.boolean.julia';
match = '(?:\|\||&&|!)';
},
{ name = 'keyword.operator.arrow.julia';
match = '(?:->|<-|-->)';
},
{ name = 'keyword.operator.relation.julia';
match = '(?:>|<|>=|<=|==|!=|\.>|\.<|\.>=|\.>=|\.==|\.!=|\.=|\.!|<:|:>)';
},
{ name = 'keyword.operator.range.julia';
match = '(?::)';
},
{ name = 'keyword.operator.shift.julia';
match = '(?:<<|>>)';
},
{ name = 'keyword.operator.bitwise.julia';
match = '(?:\||\&|~)';
},
{ name = 'keyword.operator.arithmetic.julia';
match = '(?:\+|-|\*|\.\*|/|\./|//|\.//|%|\.%|\\|\.\\|\^|\.\^)';
},
{ name = 'keyword.operator.isa.julia';
match = '(?:::)';
},
{ name = 'keyword.operator.dots.julia';
match = '(?:\.(?=[a-zA-Z])|\.\.+)';
},
{ match = "\w+(((\.')|')*\.?')";
captures = { 1 = { name = 'keyword.operator.transpose.julia'; }; };
},
{ name = 'test-square';
begin = '\[';
end = "\](((\.')|')*\.?')";
endCaptures = { 1 = { name = 'keyword.operator.transpose.julia'; }; };
patterns = ( { include = '$self'; } );
},
{ name = 'test-parens';
begin = '\(';
end = "\)(((\.')|')*\.?')";
endCaptures = { 1 = { name = 'keyword.operator.transpose.julia'; }; };
patterns = ( { include = '$self'; } );
},
);
};
string = {
patterns = (
{ name = 'string.quoted.single.julia';
begin = "'";
end = "'";
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.julia'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.julia'; }; };
patterns = ( { include = '#string_escaped_char'; } );
},
{ name = 'string.quoted.double.julia';
begin = '"';
end = '"';
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.julia'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.julia'; }; };
patterns = ( { include = '#string_escaped_char'; } );
},
{ name = 'string.quoted.custom-double.julia';
begin = '\b\w+"';
end = '"\w*';
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.julia'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.julia'; }; };
patterns = ( { include = '#string_custom_escaped_char'; } );
},
{ name = 'string.quoted.double.julia';
begin = '`';
end = '`';
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.julia'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.julia'; }; };
patterns = ( { include = '#string_escaped_char'; } );
},
);
};
string_custom_escaped_char = {
patterns = (
{ name = 'constant.character.escape.julia';
match = '\\"';
},
);
};
string_escaped_char = {
patterns = (
{ name = 'constant.character.escape.julia';
match = '\\(\\|[0-3]\d{,2}|[4-7]\d?|x[a-fA-F0-9]{,2}|u[a-fA-F0-9]{,4}|U[a-fA-F0-9]{,8}|.)';
},
);
};
type_decl = {
patterns = (
{ name = 'meta.type.julia';
match = '(type)\s+([a-zA-Z0-9_]+)(\s*(<:)\s*[.a-zA-Z0-9_:]+)?';
captures = {
1 = { name = 'keyword.control.type.julia'; };
2 = { name = 'entity.name.type.julia'; };
3 = { name = 'entity.other.inherited-class.julia'; };
4 = { name = 'punctuation.separator.inheritance.julia'; };
};
},
{ name = 'other.typed-variable.julia';
match = '([a-zA-Z0-9_]+)(::[a-zA-Z0-9_]+)';
captures = { 2 = { name = 'support.type.julia'; }; };
comments = "Matches a typed variable, such as 'id::String'";
},
);
};
};
}
{ name = 'test-square';
begin = '\[';
end = "\](((\.')|')*\.?')";
endCaptures = { 1 = { name = 'keyword.operator.transpose.julia'; }; };
patterns = ( { include = '$self'; } );
},
{ name = 'test-parens';
begin = '\(';
end = "\)(((\.')|')*\.?')";
endCaptures = { 1 = { name = 'keyword.operator.transpose.julia'; }; };
patterns = ( { include = '$self'; } );
},
# Test matrix notation
[1,sin(pi),2]'
[1,sin(pi),2].'
[1,sin(pi),2]'.'
# Test subexp notation
(1, sin(pi), 2)'
(1, sin(pi), 2).'
(1, sin(pi), 2)'.'
# This doesn't work, the square bracket consumes the rest of the file
(this is a [test agdgjl] )'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment