Conversation
|
@TonyGravagno What do you think? |
|
I will merge and try this within the next couple days.
🙏❤️😁 |
|
I see from the value replacement that a new regex should be valid Good regex "beginRegex": "\\/\\*(?![^\\\"]*\\\"[^\\\"]*(?:\\*\\/))",
"endRegex": "\\*\\/"With variables "beginRegex": "{{:BeginCommentBlock}}(?![^\\\"]*\\\"[^\\\"]*(?:\\*\\/))",
"endRegex": "{{:EndCommentBlock}}"When variables aren't defined, new code correctly parses variable names. And when the variables are defined: "variables": {
"BeginCommentBlock": "\\/\\*",
"EndCommentBlock": "\\*\\/"
},We can't see the new pattern (#145) but we know it's resolved. Maybe I have the syntax wrong? I'm not referring to the code right now, just looking at the notes above where the ":" and "!" are specified as a prefix to the variable name. |
|
I think it would be much better for the "variables" declaration to be higher in the settings hierarchy. As currently implemented, "variables" must be defined within a rule at the same level as begin/end props. To re-use the variables we need to copy them to other rules. 😢 I'm hoping for a change for this enhancement, to raise variables into the "explicitFolding.rules" scope as a reserved-word rule (like "*"). All patterns within that one rule can then be used by any other rule, including perFiles rules: "explicitFolding.rules": {
// "lang1,lang2": []
"*": [],
"variables": {
"BeginCommentBlock": "\\/\\*",
"EndCommentBlock": "\\*\\/",
"AtoZ1": "[A-Za-z0-9]+",
"AtoZ2": "[A-Za-z_$]"
},
"#comments": [
{
"name": "Comments",
// Beginning of the line, followed by some spaces, then "/*"
"beginRegex": "{{:BeginCommentBlock}}(?![^\\\"]*\\\"[^\\\"]*(?:\\*\\/))",
// Anywhere on a line with "*/"
"endRegex": "{{:EndCommentBlock}}"
}
],
|
try:
I've pondered about that but if I didn't do that it because it wouldn't be able to do that: |
|
Also there might a lunatic who will create a language called |
|
Since the "variables" block defines patterns and literal string values, I don't think it's required to specify the ":" "!" escaped/raw code in each usage. It can be specified once in the variable block: "BeginCommentRegex": ":\\/\\*", // ":" prefix here
"BeginCommentText": "!/*",
...
"beginRegex": "{{BeginCommentRegex}}(?![^\\\"]*\\\"[^\\\"]*(?:\\*\\/))", // no ":" prefixFurther... It's obvious in the context of regex that we're using regex (within the "beginRegex"). Maybe we can assume that a variable matches the type of the current prop value "begin" or "beginRegex", and only prefix the variable if it's going to be used in a different context. To be clear, in the above, "BeginCommentRegex" is used within "beginRegex". We don't need to add a colon on the variable value because we know it's only used in a beginRegex prop. I doubt someone is going to use the same variable in different contexts: name: "rule1",
begin: "{{!BeginComment}"
...
name: "rule23",
beginRegex: "{{:BeginComment}}"It seems more reasonable to define variables for their purpose: name: "rule1",
begin: "{{BeginComment}"
...
name: "rule23",
beginRegex: "{{BeginCommentRegex}}"The prefix actually seems unnecessary - a rare option that may or may not ever be used and might only serve to confuse more than help. Maybe a contradiction, but I do think unescaped variables are helpful: "BeginCommentRegex": "\\/\\*",
"BeginCommentText": "/*",
}
I prefer to see "/*" as a human-friendly pattern when possible than to be burdened with the regex. With a ":" prefix that says "escape this" or with some convention on variable names, it would be nice if a variable can be auto-converted from raw to escaped when injected into the final regex for compilation. That is, we write "/*" and it's transparently changed to "\\/\\*".
Honestly I think the value of this is as rare as the prefix itself but maybe with some thinking on this we can establish a better pattern for distinguishing escaped/raw text that does present some value. |
OK, but htat syntax is icky. 🤮 Without being able to see what it's processing we don't really know which "/" it's tripping on. (#145). (Another issue but here for now...) |
|
Currently, it's
I was thinking that maybe an escaped string for regex could be useful in some case. Yes, |
Yes, but recommend to use And |
|
For the syntax, it has its origin from https://olado.github.io/doT/index.html What do you think? |
References:
{ "variables": { "BeginComment1": "\\/\\*", "EndComment1": "\\*\\/", }, }, { "beginRegex": "{{!BeginComment1}}", "endRegex": "{{!EndComment1}}", },{{:varname}}: the replacement is escaped{{!varname}}: the replacement is raw (only available for regex properties)