Home » Eclipse Projects » Eclipse Platform » ICharacterScanner.unread() should return an error if I unread to many times
ICharacterScanner.unread() should return an error if I unread to many times [message #287022] |
Thu, 23 June 2005 04:17  |
Eclipse User |
|
|
|
Hi,
I've noticed something strange which I believe might be a misstake in
the Eclipse plugin developer API.
To make a long story short, I wonder why the ICharacterScanner.unread()
method does not return some error/exception. Clearly if I .unread()
enough times the scanner will hit the end of the current partition or
the end of the editor contents. What then? Is this silently ignored?
---
Below is a more detailed description of my problem, and how I ran into it.
I'm in the process of developing a customized IPredicateRule for
partition scanning in an Eclipse syntax highlighting plugin. My language
uses constructs like this one:
#include <filename.ext>
Notice that there is no " or ' symbols which limit the string, but
rather the angle bracket (< and >) symbols are the limits of the string.
Because this language also has angle brackets as comparision operators,
I cannot just put everything that is placed between angle brackets into
a separate string partition. On the other hand, I cannot scan for
#include because I only want the <filename.ext> part to be highlighted
as a string.
So what I did was, I scanned for the starting angle bracket <, and then
I used the scanner.unread() method to backtrack a few chars, discard any
whitespace between the "#include" word and the "<filename.ext>" parts.
Then I check if the previously read chars where infact "#include" and
then I continue scanning forward until I hit the > symbol. This makes
only the <filename.ext> part become highlighted as a string.
The problem is, what if someone opens a file that says only
" <filename.ext>"
Then my scanner would find the < symbol and start backtracking. As long
as it only finds whitespace it will continue backtracking forever
because the scanner.unread() will never return any errors. The loop
looks something like this:
do {
scanner.unread();
ch = scanner.read(),
scanner.unread();
} while (Character.isWhitespace(ch));
regards,
martin
|
|
|
Re: ICharacterScanner.unread() should return an error if I unread to many times [message #287030 is a reply to message #287022] |
Thu, 23 June 2005 05:36   |
Eclipse User |
|
|
|
Martin,
ICharacterScanners should simply return EOF to 'read' when unread
further than the document start.
-tom
Martin Olsson wrote:
> Hi,
>
> I've noticed something strange which I believe might be a misstake in
> the Eclipse plugin developer API.
>
> To make a long story short, I wonder why the ICharacterScanner.unread()
> method does not return some error/exception. Clearly if I .unread()
> enough times the scanner will hit the end of the current partition or
> the end of the editor contents. What then? Is this silently ignored?
>
> ---
>
> Below is a more detailed description of my problem, and how I ran into it.
>
> I'm in the process of developing a customized IPredicateRule for
> partition scanning in an Eclipse syntax highlighting plugin. My language
> uses constructs like this one:
>
> #include <filename.ext>
>
> Notice that there is no " or ' symbols which limit the string, but
> rather the angle bracket (< and >) symbols are the limits of the string.
> Because this language also has angle brackets as comparision operators,
> I cannot just put everything that is placed between angle brackets into
> a separate string partition. On the other hand, I cannot scan for
> #include because I only want the <filename.ext> part to be highlighted
> as a string.
>
> So what I did was, I scanned for the starting angle bracket <, and then
> I used the scanner.unread() method to backtrack a few chars, discard any
> whitespace between the "#include" word and the "<filename.ext>" parts.
> Then I check if the previously read chars where infact "#include" and
> then I continue scanning forward until I hit the > symbol. This makes
> only the <filename.ext> part become highlighted as a string.
>
> The problem is, what if someone opens a file that says only
>
> " <filename.ext>"
>
> Then my scanner would find the < symbol and start backtracking. As long
> as it only finds whitespace it will continue backtracking forever
> because the scanner.unread() will never return any errors. The loop
> looks something like this:
>
> do {
> scanner.unread();
> ch = scanner.read(),
> scanner.unread();
> } while (Character.isWhitespace(ch));
>
>
> regards,
> martin
|
|
|
Re: ICharacterScanner.unread() should return an error if I unread to many times [message #287042 is a reply to message #287030] |
Thu, 23 June 2005 09:35   |
Eclipse User |
|
|
|
A agree with you, that EOF would be excellent here.
The thing is that ICharacterScanner.unread() returns void and casts no
exceptions. I'm using Eclipse 3.0.2 stable but I checked out cvs head
and its the same situation there. I've browsed the bugzilla and
apparently a lot of other people have run into this particular problem. See:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=79057
But no solution (for all variant of the problem) has been proposed
afaik, and nobody has submitted any patch.
regards,
martin
Tom Eicher wrote:
> ICharacterScanners should simply return EOF to 'read' when unread
> further than the document start.
>
> -tom
>
> Martin Olsson wrote:
>>
>> I've noticed something strange which I believe might be a misstake in
>> the Eclipse plugin developer API.
>>
>> To make a long story short, I wonder why the
>> ICharacterScanner.unread() method does not return some
>> error/exception. Clearly if I .unread() enough times the scanner will
>> hit the end of the current partition or the end of the editor
>> contents. What then? Is this silently ignored?
>>
>> ---
>>
>> Below is a more detailed description of my problem, and how I ran into
>> it.
>>
>> I'm in the process of developing a customized IPredicateRule for
>> partition scanning in an Eclipse syntax highlighting plugin. My
>> language uses constructs like this one:
>>
>> #include <filename.ext>
>>
>> Notice that there is no " or ' symbols which limit the string, but
>> rather the angle bracket (< and >) symbols are the limits of the
>> string. Because this language also has angle brackets as comparision
>> operators, I cannot just put everything that is placed between angle
>> brackets into a separate string partition. On the other hand, I cannot
>> scan for #include because I only want the <filename.ext> part to be
>> highlighted as a string.
>>
>> So what I did was, I scanned for the starting angle bracket <, and
>> then I used the scanner.unread() method to backtrack a few chars,
>> discard any whitespace between the "#include" word and the
>> "<filename.ext>" parts. Then I check if the previously read chars
>> where infact "#include" and then I continue scanning forward until I
>> hit the > symbol. This makes only the <filename.ext> part become
>> highlighted as a string.
>>
>> The problem is, what if someone opens a file that says only
>>
>> " <filename.ext>"
>>
>> Then my scanner would find the < symbol and start backtracking. As
>> long as it only finds whitespace it will continue backtracking forever
>> because the scanner.unread() will never return any errors. The loop
>> looks something like this:
>>
>> do {
>> scanner.unread();
>> ch = scanner.read(),
>> scanner.unread();
>> } while (Character.isWhitespace(ch));
>>
>>
>> regards,
>> martin
|
|
|
Re: ICharacterScanner.unread() should return an error if I unread to many times [message #287069 is a reply to message #287022] |
Thu, 23 June 2005 13:30  |
Eclipse User |
|
|
|
Originally posted by: bob.objfac.com
Why make your life hard? Begin the partition with #include and only scan
forward. The fact that you only want to color the filename is not a good
reason for doing what you're doing. You're not obligated to color all
characters in a partition. In fact, coloring is a completely different
scanner.
Bob Foster
Martin Olsson wrote:
> Hi,
>
> I've noticed something strange which I believe might be a misstake in
> the Eclipse plugin developer API.
>
> To make a long story short, I wonder why the ICharacterScanner.unread()
> method does not return some error/exception. Clearly if I .unread()
> enough times the scanner will hit the end of the current partition or
> the end of the editor contents. What then? Is this silently ignored?
>
> ---
>
> Below is a more detailed description of my problem, and how I ran into it.
>
> I'm in the process of developing a customized IPredicateRule for
> partition scanning in an Eclipse syntax highlighting plugin. My language
> uses constructs like this one:
>
> #include <filename.ext>
>
> Notice that there is no " or ' symbols which limit the string, but
> rather the angle bracket (< and >) symbols are the limits of the string.
> Because this language also has angle brackets as comparision operators,
> I cannot just put everything that is placed between angle brackets into
> a separate string partition. On the other hand, I cannot scan for
> #include because I only want the <filename.ext> part to be highlighted
> as a string.
>
> So what I did was, I scanned for the starting angle bracket <, and then
> I used the scanner.unread() method to backtrack a few chars, discard any
> whitespace between the "#include" word and the "<filename.ext>" parts.
> Then I check if the previously read chars where infact "#include" and
> then I continue scanning forward until I hit the > symbol. This makes
> only the <filename.ext> part become highlighted as a string.
>
> The problem is, what if someone opens a file that says only
>
> " <filename.ext>"
>
> Then my scanner would find the < symbol and start backtracking. As long
> as it only finds whitespace it will continue backtracking forever
> because the scanner.unread() will never return any errors. The loop
> looks something like this:
>
> do {
> scanner.unread();
> ch = scanner.read(),
> scanner.unread();
> } while (Character.isWhitespace(ch));
>
>
> regards,
> martin
|
|
|
Goto Forum:
Current Time: Tue May 06 21:12:28 EDT 2025
Powered by FUDForum. Page generated in 0.04174 seconds
|