diff --git a/prototypes/sema.tmLanguage.json b/prototypes/sema.tmLanguage.json index 3de9967..ebc12bc 100644 --- a/prototypes/sema.tmLanguage.json +++ b/prototypes/sema.tmLanguage.json @@ -9,6 +9,9 @@ { "include": "#comment" }, + { + "include": "#regex" + }, { "include": "#string" }, @@ -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": "#\\|", diff --git a/static/sema.tmLanguage.json b/static/sema.tmLanguage.json index 3de9967..ebc12bc 100644 --- a/static/sema.tmLanguage.json +++ b/static/sema.tmLanguage.json @@ -9,6 +9,9 @@ { "include": "#comment" }, + { + "include": "#regex" + }, { "include": "#string" }, @@ -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": "#\\|", diff --git a/syntaxes/Sema.sublime-syntax b/syntaxes/Sema.sublime-syntax index 8a05da2..35a662b 100644 --- a/syntaxes/Sema.sublime-syntax +++ b/syntaxes/Sema.sublime-syntax @@ -17,6 +17,7 @@ contexts: main: - include: block-comment - include: line-comment + - include: regex - include: string - include: quoted-expression - include: definition @@ -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 diff --git a/tests/grammar_assets_test.rs b/tests/grammar_assets_test.rs new file mode 100644 index 0000000..07bc292 --- /dev/null +++ b/tests/grammar_assets_test.rs @@ -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")); +}