Skip to content
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
14 changes: 14 additions & 0 deletions prototypes/sema.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{
"include": "#comment"
},
{
"include": "#regex"
},
{
"include": "#string"
},
Expand Down Expand Up @@ -50,6 +53,17 @@
}
],
"repository": {
"regex": {
"name": "string.regexp.sema",
"begin": "#\"",
"end": "\"",
"patterns": [
{
"name": "string.regexp.sema",
"match": "\\\\."
}
]
},
"block-comment": {
"name": "comment.block.sema",
"begin": "#\\|",
Expand Down
14 changes: 14 additions & 0 deletions static/sema.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{
"include": "#comment"
},
{
"include": "#regex"
},
{
"include": "#string"
},
Expand Down Expand Up @@ -50,6 +53,17 @@
}
],
"repository": {
"regex": {
"name": "string.regexp.sema",
"begin": "#\"",
"end": "\"",
"patterns": [
{
"name": "string.regexp.sema",
"match": "\\\\."
}
]
},
"block-comment": {
"name": "comment.block.sema",
"begin": "#\\|",
Expand Down
12 changes: 12 additions & 0 deletions syntaxes/Sema.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ contexts:
main:
- include: block-comment
- include: line-comment
- include: regex
- include: string
- include: quoted-expression
- include: definition
Expand Down Expand Up @@ -58,6 +59,17 @@ contexts:
# ---------------------------------------------------------------------
# STRINGS
# ---------------------------------------------------------------------
regex:
- match: '#"'
scope: punctuation.definition.string.begin.sema string.regexp.sema
push:
- meta_scope: string.regexp.sema
- match: '\\.'
scope: string.regexp.sema
- match: '"'
scope: punctuation.definition.string.end.sema string.regexp.sema
pop: true

string:
- match: '"'
scope: punctuation.definition.string.begin.sema
Expand Down
30 changes: 30 additions & 0 deletions tests/grammar_assets_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use serde_json::Value;

#[test]
fn textmate_assets_define_the_canonical_regex_scope() {
let prototype: Value = serde_json::from_str(include_str!("../prototypes/sema.tmLanguage.json"))
.expect("prototype grammar must be valid JSON");
let static_grammar: Value =
serde_json::from_str(include_str!("../static/sema.tmLanguage.json"))
.expect("static grammar must be valid JSON");

assert_eq!(prototype, static_grammar);
assert_eq!(
prototype["repository"]["regex"]["name"],
"string.regexp.sema"
);
assert_eq!(prototype["repository"]["regex"]["begin"], "#\"");
assert_eq!(prototype["repository"]["regex"]["end"], "\"");
}

#[test]
fn syntect_asset_defines_the_regex_context_before_strings() {
let syntax = include_str!("../syntaxes/Sema.sublime-syntax");
let regex = syntax.find(" - include: regex").expect("regex include");
let string = syntax
.find(" - include: string")
.expect("string include");

assert!(regex < string);
assert!(syntax.contains("meta_scope: string.regexp.sema"));
}