jEdit Community - Resources for users of the jEdit Text Editor
Having trouble with lookahead regex in a syntax highlighting mode
Submitted by soapi on Tuesday, 27 June, 2006 - 15:26
In the particular language I am writing a mode for, the start and end of code blocks are delimited by { }. Code appears within these braces. So, it's a little like except with different symbols. Within these braces, *everything* after a double slash - // - is a comment... right to the end of a code block (not just on the same line). For example: { some code // this is a comment } Now, the syntax I first tried was: // } However, this interferes with the match for the end of the code block, and so the end } is not detected correctly. I then tried: // (?=}) ...which I think should do the trick, as the lookahead should trigger a match upon encountering the end brace, but not include it in the match, so it should still be there for the code block rule to find. The trouble is, it doesn't match anything at all! Further experimentation seems to suggest that the END block cannot actually contain regex - just the BEGIN block. If so, this is pretty useless, so I have to assume I'm doing something wrong. Can anyone help me out and show me how to accomplish what I want? Thanks!
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Oooops...
by soapi on Tue, 27/06/2006 - 15:29
Sorry, it looks like the forums can't handle some characters very well, and the chevrons were causing problems. I've replaced them with their HTML entity equivalents - apologies for the repost but I don't see an "edit" option.

----------------------------------------------------------------------

In the particular language I am writing a mode for, the start and end of code blocks are delimited by { }. Code appears within these braces. So, it's a little like <? ?> except with different symbols.

Within these braces, *everything* after a double slash - // - is a comment... right to the end of a code block (not just on the same line).

For example:

{ some code // this is
a comment }

Now, the syntax I first tried was:

<SPAN TYPE="COMMENT">
<BEGIN>//</BEGIN>
<END>}</END>
</SPAN>

However, this interferes with the match for the end of the code block, and so the end } is not detected correctly.

I then tried:

<SPAN_REGEXP HASH_CHAR="/" TYPE="COMMENT4">
<BEGIN>//</BEGIN>
<END>(?=})</END>
</SPAN_REGEXP>

...which I think should do the trick, as the lookahead should trigger a match upon encountering the end brace, but not include it in the match, so it should still be there for the code block rule to find. The trouble is, it doesn't match anything at all! Further experimentation seems to suggest that the END block cannot actually contain regex - just the BEGIN block. If so, this is pretty useless, so I have to assume I'm doing something wrong.

Can anyone help me out and show me how to accomplish what I want?

Thanks!
User login
Browse archives
« September 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   97301
Context Free Art (*.cfdg)   0.31   46061
BBEdit scheme   1.0   18600
JBuilder scheme   .001   18501
ColdFusion scheme   1.0   18030
R Edit Mode - extensive version   0.1   17480
Advanced HTML edit mode   1.0   16212
Matlab Edit Mode   1.0   16074
jEdit XP icons   1.0   15235
XP icons for jEdit   1.1   14299