Files
c3c/resources/editor_plugins/iro/c3.iro
Christoffer Lerno c149f14a1f Added iro grammar.
2021-07-20 15:01:04 +02:00

378 lines
8.5 KiB
Plaintext

name = C3
file_extensions [] = c3;
################################################################
## Constants
################################################################
__CONSTANT \= (_*[A-Z][A-Za-z0-9_]*)
__IDENT \= _*[a-z][A-Za-z0-9_]*
__TYPE \= _*[A-Z][A-Za-z0-9_]*[a-z][A-Za-z0-9_]*
__SCOPE \= ([a-z]+::)*
__USERTYPE \= _*[A-Z][A-Za-z0-9_]*[a-z][A-Za-z0-9_]*
__BUILTIN_TYPE \= void|float|half|double|quad|long|ulong|int|short|char|uint|ushort|ichar|usize|isize|iptr|uptr|iptrdiff|uptrdiff
################################################################
## Styles
################################################################
styles [] {
.comment : style {
color = #5F5A60
italic = true
ace_scope = comment
textmate_scope = comment
pygments_scope = Comment
}
.type : style {
color = #AE81FF
pygments_scope = Name.Class
textmate_scope = entity.name.type
}
.string : style {
color = #E6DB74
pygments_scope = String.Double
textmate_scope = string.quoted.double
}
.escaped_text : style {
color = #AE81FF
pygments_scope = String.Escape
}
.function_decl : style {
color = #A6E22E
pygments_scope = Name.Entity
}
.declare : style {
color = #66D9EF
pygments_scope = Keyword.Declaration
}
.function_call : style {
color = #66D9EF
pygments_scope = Name.Function
}
.type_builtin : style {
color = #f92672
ace_scope = keyword
textmate_scope = keyword
pygments_scope = Keyword.Type
}
.keyword_constant : style
{
color = #f92672
ace_scope = keyword
textmate_scope = keyword
pygments_scope = Keyword.Constant
}
.keyword : style {
color = #f92672
ace_scope = keyword
textmate_scope = keyword
pygments_scope = Keyword
}
.constant : style {
color = #AE81FF
textmate_scope = constant
pygments_scope = Name.Constant
}
.numeric : style {
color = #AE81FF
ace_scope = constant.numeric
textmate_scope = constant.numeric
pygments_scope = Number
}
.punctuation : style {
color = #FD971F
ace_scope = punctuation
textmate_scope = punctuation
pygments_scope = Punctuation
}
.compile_time : style {
color = #908B25
pygments_scope = Keyword.Pseudo
}
.variable : style {
color = #f8f8f2
background_color = #272822
pygments_scope = Name
}
.text : style {
color = #f8f8f2
background_color = #272822
ace_scope = text
textmate_scope = text
pygments_scope = String
}
.illegal : style {
color = white
background_color = red
ace_scope = invalid
textmate_scope = invalid
pygments_scope = Generic.Error
}
}
#################################################
## Parse contexts
#################################################
contexts [] {
top_level : context {
: include "parens";
: include "comment";
: include "constants";
: include "ct_keywords";
: include "decls";
: include "path";
: include "type";
: include "keywords";
: include "storage";
: include "call";
: include "identifier";
: include "kw_operators";
: include "operators";
: pattern {
regex \= ([\.\;])
styles [] = .punctuation;
}
: pattern {
regex \= ([\@])
styles [] = .keyword;
}
}
builtin_constants : context {
: pattern {
regex \= (true|false|null)
styles [] = .keyword_constant;
}
}
constants : context {
: pattern {
regex \= ($${__CONSTANT})
styles [] = .constant;
}
}
type : context {
: pattern {
regex \= ($${__SCOPE})?($${__USERTYPE})
styles [] = .type;
}
: pattern {
regex \= ($${__BUILTIN_TYPE})
styles [] = .type_builtin;
}
}
path : context {
: pattern {
regex \= ([a-z][a-z_0-9]*)(\s*)(::)
styles [] = .text, .text, .keyword;
}
}
call : context {
: pattern {
regex \= ($${__IDENT}\s*)(\()
styles [] = .function_call, .text;
}
}
keywords : context {
: pattern {
regex \= (import|for|foreach|return|else|if|default|switch|while|do|module|assert|distinct|break|nextcase|case|continue|defer)
styles [] = .keyword;
}
}
ct_keywords : context {
: pattern {
regex \= (\$[a-zA-Z][a-z_A-Z0-9]*)
styles [] = .compile_time;
}
}
storage : context {
: pattern {
regex \= (const|extern|static|private)
styles [] = .keyword;
}
}
identifier : context {
: pattern {
regex \= ($${__IDENT})
styles [] = .variable;
}
}
operators : context {
: pattern {
regex \= ([\*\=\/\%\<\>\,\:\^\&\!\|\~])
styles [] = .text;
}
}
kw_operators : context {
: pattern {
regex \= ([\+\-])
styles [] = .text;
}
}
parens : context {
: pattern {
regex \= ([\[\]\(\)\{\}])
styles [] = .text;
}
}
decls : context
{
: pattern {
regex \= (func\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
styles [] = .declare, .text, .text, .type, .type_builtin, .function_decl;
}
: pattern {
regex \= (func\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
styles [] = .declare, .text, .text, .type, .type_builtin, .function_decl;
}
: pattern {
regex \= (enum|struct|errtype|union)(\s+)($${__USERTYPE})
styles[] = .declare, .text, .function_decl;
}
: pattern {
regex \= (struct|union|define)
styles[] = .declare;
}
}
nested_comment : context {
: inline_push {
regex \= (/\*)
styles [] = .comment;
: pop {
regex \= (.*\*/)
styles [] = .comment;
}
: include "nested_comment";
}
}
comment : context {
: pattern {
regex \= (//.*)
styles [] = .comment;
}
: include "nested_comment";
}
main : context {
: include "top_level";
: pattern {
regex \= (define|extern|if|module|import|func|struct|while|do|return|union|errtype)
styles [] = .keyword;
}
: include "numeric" ;
: inline_push {
regex \= (\{)
styles [] = .punctuation;
: pop {
regex \= (\})
styles [] = .punctuation;
}
: include "main" ;
}
: pattern {
regex \= (;)
styles [] = .punctuation;
}
: inline_push {
regex \= (\")
styles [] = .punctuation;
: pop {
regex \= (\")
styles [] = .punctuation;
}
: pattern {
regex \= (\\(?:\\|"))
styles [] = .escaped_text;
}
: pattern {
regex \= ([^"\\]+)
styles [] = .string;
}
}
: include "multi_line_comment" ;
: pattern {
regex \= (//.*)
styles [] = .comment;
}
: pattern {
regex \= ([^\s])
styles [] = .illegal;
}
}
#################################################
## End of Contexts
#################################################
###########################################
## Numeric Context
###########################################
numeric : context {
: pattern {
regex \= (\b\d+)
styles [] = .numeric;
}
}
###########################################
## Multi Line Comment Context
###########################################
multi_line_comment : context {
description = multiline
: inline_push {
regex \= (/\*)
styles [] = .comment;
default_style = .comment
: pop {
regex \= (\*/)
styles [] = .comment;
}
}
}
}