Re: regexp pattern problems



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.
.



Relevant Pages

  • Re: regexp pattern problems
    ... comes to syntax hilighting i got problems defining a pattern (which is ... stored in a variable) got match strings and ... The pattern for strings is at the moment (if you don't want to open ...
    (comp.lang.tcl)
  • Re: regexp pattern problems
    ... stored in a variable) got match strings and ... The pattern for strings is at the moment (if you don't want to open ... You might want to check out how I did the syntax hilighting in my own ...
    (comp.lang.tcl)
  • Re: OT: novice regular expression question
    ... > data record begins with either a string, or a list of strings. ... If the format is "Python strings and lists of ... "negative lookbehind assertion" - in other words, a pattern that doesn't ... Let's try matching a single string first: ...
    (comp.lang.python)
  • Re: OT: novice regular expression question
    ... >> data record begins with either a string, or a list of strings. ... If the format is "Python strings and lists of ... Then use that pattern, parenthesized to turn it ... > Let's try matching a single string first: ...
    (comp.lang.python)
  • Re: Java vs. Pascal
    ... Ich meine nur dass wenn Strings ... so beginnt der Garbage Collector zu laufen. ... Aber das wiederverwenden von Pattern und Matcher spart unter anderem ... 18s Laufzeit, davon ca. 2s GC ...
    (de.comp.lang.java)

Loading