Re: [scintilla-interest] highlighting a word in coustom lexer
최원준 <wonjunchoi001 <at> gmail.com>
2011-09-01 02:32:05 GMT
I have found some document but I don't know how to do that
-----------------------------------------------------------------------------------------
The lexer code
The task of a lexer can be summarized briefly: for each range r of
characters that are to be colored the same, the lexer should call
styler.ColourTo(i, state)
where i is the position of the last character of the range r. The lexer
should set the state variable to the coloring state of the character at
position i and continue until the entire text has been colored.
Note 1: the styler (Accessor) object remembers the i parameter in the
previous calls to styler.ColourTo, so the single i parameter suffices to
indicate a range of characters.
Note 2: As a side effect of calling styler.ColourTo(i,state), the
coloring states of all characters in the range are remembered so that
Scintilla may set the initStyle parameter correctly on future calls to
the
lexer.
Lexer organization
There are at least two ways to organize the code of each lexer. Present
lexers use what might be called a "character-based" approach: the outer
loop iterates over characters, like this:
lengthDoc = startPos + length ;
for (unsigned int i = startPos; i < lengthDoc; i++) {
chNext = styler.SafeGetCharAt(i + 1);
<< handle special cases >>
switch(state) {
// Handlers examine only ch and chNext.
// Handlers call styler.ColorTo(i,state) if the state changes.
case state_1: << handle ch in state 1 >>
case state_2: << handle ch in state 2 >>
...
case state_n: << handle ch in state n >>
}
chPrev = ch;
}
styler.ColourTo(lengthDoc - 1, state);
An alternative would be to use a "state-based" approach. The outer loop
would iterate over states, like this:
lengthDoc = startPos+lenth ;
for ( unsigned int i = startPos ;; ) {
char ch = styler.SafeGetCharAt(i);
int new_state = 0 ;
switch ( state ) {
// scanners set new_state if they set the next state.
case state_1: << scan to the end of state 1 >> break ;
case state_2: << scan to the end of state 2 >> break ;
case default_state:
<< scan to the next non-default state and set new_state >>
}
styler.ColourTo(i, state);
if ( i >= lengthDoc ) break ;
if ( ! new_state ) {
ch = styler.SafeGetCharAt(i);
<< set state based on ch in the default state >>
}
}
styler.ColourTo(lengthDoc - 1, state);
This approach might seem to be more natural. State scanners are simpler
than character scanners because less needs to be done. For example,
there is no need to test for the start of a C string inside the scanner
for a C comment. Also this way makes it natural to define routines that
could be used by more than one scanner; for example, a scanToEndOfLine
routine.
-----------------------------------------------------------------------------------------
2011년 9월 1일 오전 10:21, 최원준
<wonjunchoi001 <at> gmail.com>님의 말:
def StyleText(self, event):
"""Handle the EVT_STC_STYLENEEDED event"""
stc = event.GetEventObject()
# Last correctly styled character
last_styled_pos = stc.GetEndStyled()
# Get styling range for this call
line = stc.LineFromPosition(last_styled_pos)
start_pos = stc.PositionFromLine(line)
end_pos = event.GetPosition()
words = ""
stc.StartStyling(start_pos, 0x1f)
while start_pos < end_pos:
line_length = end_pos - start_pos
word_length = start_pos + line_length
while start_pos == word_length:
words += stc.GetCharAt(start_pos)
start_pos +=1
if words in self.words:
# Set Vowel Keyword style
style = VowelLexer.STC_STYLE_VOWEL_KW
else:
# Set Default style
style = VowelLexer.STC_STYLE_VOWEL_DEFAULT
stc.SetStyling(1, style)
start_pos += 1
am I right? or how to fix this code?
2011년 9월 1일 오전 10:04, 최원준
<wonjunchoi001 <at> gmail.com>님의 말:
def StyleText(self, event):
"""Handle the EVT_STC_STYLENEEDED event"""
stc = event.GetEventObject()
# Last correctly styled character
last_styled_pos = stc.GetEndStyled()
# Get styling range for this call
line = stc.LineFromPosition(last_styled_pos)
start_pos = stc.PositionFromLine(line)
end_pos = event.GetPosition()
while start_pos < end_pos:
line_length = end_pos - start_pos
word_length = start_pos + line_length
stc.StartStyling(start_pos, 0x1f)
for pos in range(word_length):
if stc.GetCharAt(pos + 1) in self.words:
# Set Vowel Keyword style
style = VowelLexer.STC_STYLE_VOWEL_KW
else:
# Set Default style
style = VowelLexer.STC_STYLE_VOWEL_DEFAULT
# char = stc.GetCharAt(start_pos)
# Set the styling byte information for 1 char from
# current styling position (start_pos) with the
# given style.
stc.SetStyling(1, style)
start_pos += 1
Is this right?
Please review this code!
2011년 9월 1일 오전 8:38, 최원준
<wonjunchoi001 <at> gmail.com>님의 말:
is this right?
stc = event.GetEventObject()
# Last correctly styled character
last_styled_pos = stc.GetEndStyled()
# Get styling range for this call
line = stc.LineFromPosition(last_styled_pos)
start_pos = stc.PositionFromLine(line)
end_pos = event.GetPosition()
line_length = end_pos - start_pos
if line_length > 0:
stc.StartStyling(start_pos, 0x1f)
stc.SetStyling(line_length, VowelLexer.STC_STYLE_VOWEL_DEFAULT)
2011/8/31 최원준
<wonjunchoi001 <at> gmail.com> while start_pos < end_pos:
stc.StartStyling(start_pos, 0x1f)
char = stc.GetCharAt(start_pos)
if char in self.words:
style = VowelLexer.STC_STYLE_VOWEL_KW
else:
style = VowelLexer.STC_STYLE_VOWEL_DEFAULT
from above [if char in self.words:] code checks the character.
word
|
start_pos|good |end_pos
I think this will check the word.
but I have no idea how can I make it.
Wonjun, Choi:
>> ==> how can I examing each word?
How would you write a program that examines text input from a file
and outputs a list of words?
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-interest <at> googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.