Re: regexp pattern problems
- From: Bryan Oakley <oakley@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Feb 2009 06:55:57 -0800 (PST)
On Feb 26, 7:50 am, richard.poett...@xxxxxxxxx wrote:
Hi,
to learn tcl/tk I an tryping to write a little texteditor. When it
comes to syntax hilighting i got problems defining a pattern (which is
stored in a variable) got match strings (enclosed by ''' or '"') and
includes (enclosed by '{}'). Could you help me with this? I think, I
got the escapes wrong. How it is done until now you can see here:http://gist.github.com/70854.
The pattern for strings is at the moment (if you don't want to open
the link):
set highlight(string,patterns) [list (\[\\\'\]).*\\1]
and for includes:
set highlight(include,patterns) [list \\{.*\\}]
Your expressions are fine (though I don't see the advantage of putting
them in a list). To help debug the problem I suggest you add more
debug code so you can see what the real problem is.
In the block of code with the comment "determine the right tag for the
word" add a debug statement to print out what $word" is. I suspect
you'll see you're not applying the pattern to what you think you are.
For example, when I type a quoted string and press space, what I see
is that you're comparing the patterns to only a single quote character
which, of course, doesn't match.
By the way, are you aware that the text widget has a way to search for
text with regular expressions without having to pull a string out of
the widget and run the regexp command?
You might be interested in page http://wiki.tcl.tk/3246. It shows how
to implement a command for matching text in a text widget. You can,
for instance, do something like this:
forText .t -regexp "{.*?}" 1.0 end {
.t tag configure foo -foreground green -background blue
.t tag add foo matchStart matchEnd
}
You may not be interested since you're just learning, but if you want
to focus more on the text editor part and less on the syntax
highlighting part you might find it useful.
.
- References:
- regexp pattern problems
- From: richard . poettler
- regexp pattern problems
- Prev by Date: Re: Q: How to determine if a process has been terminated
- Next by Date: Re: TkTable selectioncommand
- Previous by thread: regexp pattern problems
- Next by thread: Re: regexp pattern problems
- Index(es):
Relevant Pages
|
Loading