I am having issues with the MonarchTokensProvider. In my application i am writing some custom auto-complete and need to be able to identify opening/closing parentheses.
As such, i expect the tokenizer to tokenize '()' to '(', ')'. However using default settings from monaco, parentheses that are next to each other are grouped together.
monaco-editor version: 0.30.1
Browser: Firefox, Chrome, Safari
OS: MacOS
Playground code that reproduces the issue:
See:
https://microsoft.github.io/monaco-editor/monarch.html
Press F1 and select 'Developer: Inspect Tokens'.
Move the cursor to the parentheses at 'main()'. See that '()' is listed as a single token.
Does anyone know the regex i need to use for the parentheses?
Overall i've only seen this being used
// delimiters and operators
[/[{}()\[\]]/, '#brackets'],
You can specify what you want to be interpreted as any monarch tokenizer class you want:
// [/[{}()\[\]]/, "#brackets"],
[/\(/, "openingparenthesis"],
[/\)/, "closingparenthesis"],
[/{/, "openingcurlybrace"],
[/}/, "closingcurlybrace"],
[/\]/, "openingbracket"],
[/\[/, "closingbracket"],
Related
By default, bracket matching doesn't understand strings and so will match brackets inside of quotes.
Steps to reproduce:
Start the language-configuration-sample extension
Type the following line in the file,
[ "]" ]
Move the cursor to the start of the line and hit Ctrl-\
The open bracket will match with the bracket inside the quotes.
The same behavior happens with anything defined as "brackets" in the config.
I've noticed language extensions like java, python, etc do not have this behavior. How do they get around it? I've looked through their code and haven't seen anything that looks related.
I'm writing a language extension for lisp and have noticed a weird behavior. If I have something like this,
( "(" a b )
VSCode will match the closing parenthesis with the one in quotes. If I have the cursor between the a and the b and do an expand selection, it selects from the quoted open parens to the closing parens.
What controls this behavior? How do I get it to ignore the one in quotes?
I've tried messing with different settings in language-configuration.json, but nothing has worked so far. The only other thing I can think of would be the wordPattern regex, which I copied from somewhere. It's currently set to,
"wordPattern": "[^:()# \t\n\r][^:() \t\n\r]*"
I am working with another human being on project from that the professor expects to have uniform code-style. We have written large separate junks of code on our own, in which one has written single line comments without a white-space between the single-line-comment-token and the other one has inserted a white-space. We are working with IntelliJ and have failed to find an option to enable the Reformat Code function, to insert a white-space.
TLDR:
Can you tell us how to convert comments from that to this in IntelliJ?
// This is a load bearing comment - don't dare to remove it
//This is a load bearing comment - don't dare to remove it!
You can do a global search and replace (ctrl-shift-r on windows with default keyboard layout, or Replace in Path under the Edit/Find menu).
Check the regular expression option and enter //(\S.*) as the text to find and // $1 as the replacement. Check the whole project option, and clear any file masks. You can single step through the replacements, or simply hit the All Files option.
I tried to create a regular expression for the below date format, where as I am unable to justify that, please help me out.
04-Apr-2013 [10:58:13 GMT+05:30]
This is what I came up with:
\\d{2}-\\w{3}-d{4} [\\d{2}:d{2}:d{2} \\w{3}+\\d{2}:d{2}]
Correct me where i have gone wrong.
Thanks
You have to escape the square brackets as they have a special meaning in regular expressions and also some of your digit indicators doesn't have backslash prefix. I've tested the following regex and it worked for me:
regexp:\d{2}-\w{3}-\d{4} \[\d{2}:\d{2}:\d{2} \w{3}\+\d{2}:\d{2}\]
I have many files with small differences. The included file contains this, which tries to differentiate on one part of a longer path:
<!--#if expr="${DOCUMENT_URI}=/internet/"-->Internet<!--#else-->Intranet<!--#endif-->
In the error log I get
AH01337: Could not parse expr "${DOCUMENT_URI}=/internet/" in /opt/apache/htdocs/ssi/time.shtml: Parse error near '$'
I find many variations on this theme, like no braces, parentheses around the inside of the quotes, space before the comment end or =~, but nothing helps. There doesn't seem to be a debug setting for mod_include, which would tell me what's wrong...
Another variant I found is
<!--#if expr='"${DOCUMENT_URI}"=~/internet/'-->
this gives no error. But it always chooses the else branch, likewise with REQUEST_URI, as though the variables were unset. But I can echo them fine. I also tried /.+internet.+/ in case it was anchoring this.
Since these are CGI variables I also tried loading cgid_module – no good either.
As of version 2.3.13, mod_include has switched to the new ap_expr syntax for conditional expressions in #if flow control elements.
Add the SSILegacyExprParser on directive to switch to the old syntax which is compatible with Apache HTTPD version 2.2.x and earlier.
http://httpd.apache.org/docs/current/mod/mod_include.html#ssilegacyexprparser
As many other people noted you can use the v("foo") style, but the examples given in the Apache 2.4 documentation (http://httpd.apache.org/docs/2.4/expr.html#examples) give this form:
<!--#if expr="%{DOCUMENT_URI} =~ /internet/"-->Internet<!--#else-->Intranet<!--#endif-->
Note the % instead of $ on the variable, and the =~ for regex match.
I've just tested this and it works fine.
(Or use SSILegacyExprParser on as also mentioned, to allow for backward-compatibility with the 2.2.x format. But I expect this compatibility will be removed at some point in the distant future..)
I got it working with:
<!--#if expr='v("foo") = "bar"' -->
foo is bar
<!--#endif -->
See Flow Control Elements
Newer Apache versions use ap_expr. I just wanted to add the relevant link: Apache docs. Note that the v function is not yet documented.
The variable resolves to a text string, so it needs to be enclosed in double quotes, and you need to escape those double quotes.... (warning this may be deprecated syntax - I used it on my old Apache 1 and just never changed it when upgrading):
<!--# if expr="\"$DOCUMENT_URI\"=/internet/" -->