I want to remove a default content assist from my grammar, that provides an opening and a closing brace almost everywhere.
The grammar roughly looks like:
Model:
'Elements' ':' '{' elements += Element* '}'
Element:
'Attributes' ':' '{' attributes += STRING* '}'
So let's say I'm writing in this grammar:
Attributes: {
"a"
"b"
}
Now if I hit CTRL-Space after "b" it shows me a closing brace as a suggestion, but it shouldn't because a closing brace is already present.
I want to disable opening and closing brace suggestions, when they are already present in the document.
Implement a specialized completeKeyword method in your Proposal Provider (you have to find out if there is a closing } using information from content assist context from the node model
Related
I'm doing a POC with playwright with {expect} from '#playwright/test'.
I'm a bit confused how to create the regexp, I expect to validate this string which is correct as per the regex validator.
expect('abc123').toMatch('abc(\d+)')
first the '\' is marked as Unnecessary escape character
tried '\\' marks error
removed '\' marks error
How about toMatchText:
import { expect } from '#playwright/test';
await expect('abc123').toMatchText(/abc\d+/);
I don't see toMatch in the docs, so I used toMatchText(). I also think that capturing group in the regex () is not necessary in this example, so \d+ should be enough.
import { expect } from '#playwright/test';
let pattern = new RegExp('abc(\d+)');
const text = await page.locator('.label').textContent();
expect(text).toEqual(expect.stringMatching(pattern));
On this example you can receive a Regular Expression parameter as string and converted to a RegExp object, hence backlashes are not explicitly necessary.
Then compare with a text with expect.stringMatching as shown in the last row
Can someone help me solve the problem I'm having with a regular expression? I have a file containing the following code:
I'm using a visit to find matches and replace them so that I can remove the empty lines. The result is, however, not what I'm expecting. The code is as follows:
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^[ \t\f\v]*?$(?:\r?\n)*/sm => ""
}
This regular expression also removes non empty lines resulting in an output equal to:
Can someone explain what I'm doing wrong with the regular expression as well as the one shown below? I can't seem to figure out why it's not working.
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^\s+^/m => ""
}
Kind regards,
Bob
I think the big issue here is that in the context of visit, the ^ anchor does not mean what you think it does. See this example:
rascal>visit ("aaa") { case /^a/ : println("yes!"); }
yes!
yes!
yes!
visit matches the regex at every postfix of the string, so the ^ is relative for every postfix.
first it starts at "aaa", then at "aa" and then at "a".
In your example visit, what will happen is that empty postfixes of lines will also match your regex, and substitute those by empty strings. I think an additional effect is that the carriage return is not eaten up eagerly.
To fix this, simply not use a visit but a for loop or while, with a := match as the condition.
I am trying to write a program that will understand a language where embedded comments are allowed. Such as:
/* Here's a comment
/* This comment is further embedded */ second comment is closed
Must close first comment */
This should be recognized as a comment (and as such not stop at the first */ it sees unless it has only seen 1 comment opening prior).
This would be an easy issue to fix in C, I could simply have a counter that incremented when it saw comment opens and decrements when it sees a comment close. If the counter is at 0, we're in "code section".
However, without having state in Haskell, it's a little more challenging.
I've read up on monadUserState which supposedly allows to keep track of a state for this exact type of parsing. However, I can't find very much reading material on it aside from the tutorial page on alex.
When I try to compile it gives the error
templates\wrappers.hs:213:16: Not in scope: `alexEOF`
It should be noted that I directly changed from the "basic" wrapper to the "monadUserState" without changing my code (I don't know what to add in order to use it). It says that this must be initialized in the user code:
data AlexState = AlexState {
alex_pos :: !AlexPosn, -- position at current input location
alex_inp :: String, -- the current input
alex_chr :: !Char, -- the character before the input
alex_bytes :: [Byte], -- rest of the bytes for the current char
alex_scd :: !Int, -- the current startcode
alex_ust :: AlexUserState -- AlexUserState will be defined in the user program
}
I'm a bit of a lexxing noob and I'm not at all sure what I should be adding here to make it at least compile... then I can worry about the logic of the thing.
Update: Working example available here: http://lpaste.net/119212
The file "tiger.x" (link) in the alex github repo contains an example of how to track embedded comments using the monadUserState wrapper.
Well, unfortunately that example doesn't compile but the ideas there should work.
Basically, these lines perform embedded comment processing:
<0> "/*" { enterNewComment `andBegin` state_comment }
<state_comment> "/*" { embedComment }
<state_comment> "*/" { unembedComment }
<state_comment> . ;
<state_comment> \n { skip }
As for alexEOF, the idea is to add an EOF token to your token data type:
data Tokens = ... | EOF
and define alexEOF as:
alexEOF = return EOF
See the file tests/tokens_monadUserState_bytestring.x in the alex repo for an example of this.
For example, say I wanted to determine whether this form was storing newlines as carriage returns or newlines or whatever characters. I'm often in situations where I'm writing code and am not sure what type of new-line character a file/form/whatever I'm parsing is using.
How could I determine this? Is there a way to determine this without actually doing a check inside of code? (It seems like I should be able to right-click and "show all characters" or something like that).
Note: I realize I could write code saying
(if == '\r') cout << "Carriage";
etc
but I have a feeling there's a simpler solution.
Maybe is list what you are looking for (from vim help):
:[range]l[ist] [count] [flags]
Same as :print, but display unprintable characters
with '^' and put $ after the line. This can be
changed with the 'listchars' option.
See ex-flags for [flags].
You can switch modes with:
:set list
and
:set nolist
Additionally you can use "listchars" as shown in this example:
You could for example check your document for occourences of "Carriage Return" or "New Line"/"Line Feed".
e.g. (php):
if( strstr( $yourstring , "\r" ) != false ){ // You have Carriage return
// Do something
}
elseif( strstr( $yourstring , "\n" ) != false ){ // You have New Line/Line feed
// Do something
}
else{
// You cannot determine which on is used, because the string is single-lined
}
I hope this is the thing you're looking for
Note: In windows "\r\n" is used to specify ne lines
I have an expression statement to display content for a text box for a reportviewer but went blank when trying to add a carriage return or a new line between the two expression. My expression as follows:
=Format(Fields!LastDateVisited.Value, "d")+ " "+Fields!LastVisitType.Value
Instead of the space i want to make it a new line. I tried "\n" but didn't work, any suggestions would be great. Thanks!
You can also use following :
= Fields!FirstField1.Value + System.Environment.NewLine + Fields!MyField2
I think that a end of line character should work: '\n'
in your placeholder properties (Expr page) change the markup type to html