Skip to content

Instantly share code, notes, and snippets.

@tomaash
Last active February 5, 2021 16:19
Show Gist options
  • Save tomaash/43b10f57877bab1c76b01d0dcfbe889d to your computer and use it in GitHub Desktop.
Save tomaash/43b10f57877bab1c76b01d0dcfbe889d to your computer and use it in GitHub Desktop.
IRO grammar of Pulsar language
#################################################################
## Iro
################################################################
##
## * Press Ctrl + '+'/'-' To Zoom in
## * Press Ctrl + S to save and recalculate...
## * Documents are saved to web storage.
## * Only one save slot supported.
## * Matches cannot span lines.
## * Unicode chars must be defined in \u0000 to \uffff format.
## * All matches must be contained by a single group ( ... )
## * Look behinds not permitted, (?<= or (?<!
## * Look forwards are permitted (?= or (?!
## * Constants are defined as __my_const = (......)
## * The \= format allows unescaped regular expressions
## * Constants referenced by match \= $${__my_const}
## * Constants can reference other constants
## * You are free to delete all the default scopes.
## * Twitter : ainslec , Web: http://eeyo.io/iro
##
################################################################
name = pulsar
file_extensions [] = pulsar;
################################################################
## Styles
################################################################
styles [] {
.comment : style {
color = #aaa
italic = true
textmate_scope = comment.block
}
// .keyword : style {
// color = cyan
// textmate_scope = constant.language
// }
.id : style {
color = red
bold = true
textmate_scope = variable
}
.flow_name : style {
color = #4589FF
bold = true
textmate_scope = constant.language
}
.function_call : style {
color = #008141
bold = true
textmate_scope = support.function
}
.method_call : style {
color = #874CE6
bold = true
textmate_scope = support.method
}
.numeric : style {
color = #009E9E
textmate_scope = constant.numeric
}
.punctuation : style {
color = cyan
textmate_scope = punctuation
}
.punctuation_paren : style {
color = cyan
textmate_scope = punctuation.definition.paren
}
.punctuation_substitution : style {
color = #B28600
textmate_scope = punctuation.definition.substitution
}
.punctuation_flow : style {
color = #B28600
textmate_scope = punctuation.definition.flow
}
.escaped_text : style {
color = light_green
background_color = #241
textmate_scope = string.punctuation
}
.quoted_text : style {
color = #D23031
textmate_scope = string.quoted.double
}
.quote : style {
color = #D23031
textmate_scope = string.quoted.double
}
.text : style {
color = white
bold = true
textmate_scope = text.raw
}
// .illegal : style {
// color = white
// background_color = red
// ace_scope = invalid
// textmate_scope = invalid
// pygments_scope = Generic.Error
// }
}
contexts [] {
##############################################
## Main Context - Entry point context
##############################################
main : context {
: include "multi_line_comment" ;
: include "substitution";
: include "flow";
: pattern {
regex \= ([^\s])
styles [] = .text;
}
}
flow : context {
: inline_push {
regex \= ({\[)
styles = .punctuation_flow
: pop {
regex = ((?:/)?]})
styles = .punctuation_flow
}
: include "flow_attrs";
}
}
flow_attrs : context {
: pattern {
regex \= \b(let|set|var|global|map|to|for|in|traverse|into|source|switch|case|default|inject|context|if|elseif|else|import|return|emit|log|code)\b
styles [] = .flow_name;
}
// : pattern {
// regex \= \b(context|print|in)\b
// styles [] = .keyword;
// }
: include "expression" ;
: include "multi_line_comment";
}
substitution: context {
: inline_push {
uid = uid_substitution
regex \= ({{)
styles [] = .punctuation_substitution;
: pop {
regex \= (}})
styles [] = .punctuation_substitution;
}
: include "expression" ;
: include "multi_line_comment";
}
}
numeric : context {
: pattern {
regex \= (\b\d+\.?\d+)
styles [] = .numeric;
}
}
// language_literals : context {
// : pattern {
// regex \= \b(true|false|nil|self)\b
// styles [] = .flow_name;
// }
// }
function_call : context {
: inline_push {
uid = uid_function_call
regex \= (@[a-z_][a-zA-Z0-9_\.]*\b)(?:\s*)(\()
styles[] = .function_call, .punctuation_paren;
:pop {
regex \= (\))
styles[] = .punctuation_paren;
}
: include "expression";
// : pattern {
// regex \= (,)
// uid = uid_function_comma
// styles[] = .punctuation;
// }
}
}
expression : context {
uid = uid_expression
// : include "language_literals";
: include "method_call";
// : include "transformer_value";
: pattern {
regex \= (\b[a-zA-Z_][a-zA-Z0-9_]*\b)
styles [] = .id;
}
: include "numeric" ;
: include "quoted_string";
: include "function_call";
}
method_call : context {
: inline_push {
uid = uid_transformer_call
regex \= (\.[a-zA-Z][a-zA-Z0-9_]*\b)(?:\s*)(\()
//default_style = .illegal
styles[] = .method_call, .punctuation;
:pop {
regex \= (\))
styles[] = .punctuation;
}
: include "expression";
: pattern {
regex \= (,)
uid = uid_function_comma
styles[] = .punctuation;
}
}
}
// transformer_value : context {
// : pattern {
// uid = uid_transformer_value
// regex \= (\.[a-zA-Z][a-zA-Z0-9_]*\b)
// //default_style = .illegal
// styles[] = .transformer_call;
// }
// }
## TODO: see .capitalized's braces aren't colored.
quoted_string : context {
: inline_push {
regex \= (")
styles [] = .quote;
: pop {
regex \= (")
styles [] = .quote;
}
: pattern {
regex \= (\\(?:\\|"))
styles [] = .escaped_text;
}
: pattern {
regex \= ([^"\\]+)
styles [] = .quoted_text;
}
}
}
multi_line_comment : context {
description = multiline
: inline_push {
regex \= ({\*)
styles [] = .comment;
default_style = .comment
: pop {
regex \= (\*})
styles [] = .comment;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment