New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FLUID syntax highlighting bug with quotes #135
Comments
Hmm, not sure that's the solution. I tried the recommended mod, and I can still get it to fail with a simple two line code block in the code editor:
..where
It seems like the problem is that in the beginning of the And this seems due to code outside of I'll see if I can dig a little more, and when a fix is determined, see if that can be pulled over to the editor demo too. Let me know if I'm missing something. |
I'm thinking this might be the fix; updates the stale style buffer state from previous line
To use this mod, undo your change and use this in its place; can you confirm if it solves or not for your test case? |
I think there's more stale style issues; while experimenting with /* .. */ comment blocks, I still see more stale info coming in, so continuing to investigate. |
Are you using the source from v1.3.5? That's what my patch is against. You are partly right about *style pointing to "D". BUT that is as it should be! A starting quote gets styled as D, same as the continuing text and the closing quote. Where things go wrong is assuming that a quote already styled as D is the terminating quote, hence end of the style. When the quote occurs one or more chars from the start of the line the highlighting code had enough info to make the correct decisions. So the only place it failed is when the quote was literally the first char on the line, hence the "&& col". Using my patch on my copy of the 1.3.5 source makes the quote highlighting work and I never had trouble with the /* ... */ remarks, crossing lines. Now in the demo code I mentioned the mutli-line remark and quote handling are broken. This is what my FLUID code editor does: That was typed in in the order seen in the image and I went back and did some edits and open and closed the window. The formatting remained true. Its working for me and this is the patch I'm using. |
Oh! One other note: style_update() only passes text/style to style_parse() from the previous line if it determines its needed, like multi-line remarks. Otherwise it only passes the current line. In some cases it will also pass the remainder of the text & style buffers. |
Ah, I think I see what you're saying. I guess you're right then. OK, let me do a few more tests.. have to admit I'm not fully understanding what's going on in there, you've probably got a better handle on it, sounds like. I thought style_parse() was being called to recalculate the style starting with 'text' it's passed, and since it starts parsing with the ("), it seemed like 'A' would be the 'before' style, and the first (") would snap it into 'D' mode. The implemented logic is weird to me, because then it never gets a chance to parse the opening (") for either the start or end quote conditions when parsing text[0], but I guess it's supposed to work that way, since it's apparently pre-determined its in quote mode, and will effectively skip over both quote conditions for that leading quote. I'm gonna stare at the code a little more to see why it would work that way.. the design escapes me at present. |
I confess I haven't spent much more than an hour looking at it and that sitting next to my wife while she's watching TV. Not my most productive situation. But the code seems fairly well documented. The basic flow as I see it is:
So, in the case of quotes we can always expect that style[0] and text[0] are first character of the line (col=0) and corresponding style. C++ syntax dictates that a quote in that column is always going to be the beginning of a quoted string. At least in my version of g++. So I prevent it from being interpreted as an ending quote. If the quote occurs in col >=1 then I did do some |
I am still getting weird behavior with multiline block comments (nothing to do with your mod). |
Interesting! I hadn't tried that variation of a /*...*/ edit. Looks like that section at the end of style_update, that starts with |
And, yes, I verified that I have that issue too. |
I tried an experiment to rewrite the parser; made a fork. Some new features:
Curious if you have luck. I started with branch-1.3 when I created the branch, so it should be just like 1.3 only with my mods. |
Looks like you need to escape your backslash in the comment about trailing ones. I'm sure you weren't concerned with trailing apostrophe esses. :-) I gave it a quick test spin and I couldn't break it. Well, except for one teensy minor thing: Leaving a quote off the end of a quoted string the highlight spills over to the next line. My g++ will bark about that missing quote, so it seems that the syntax highlight should end with the line, unless other commonly used C++ compilers accept multi-line strings. I've been contemplating various syntactic elements and I think without a trailing '\' the only C++ format that crosses lines is the /* ... */ remark format. I suppose one could always debate whether the directive highlight should extend beyond the directive. You turned on quote highlighting in there but what about other C++ syntactic elements? For example:
OK not very wonderful, but you often see some significant C/C++ code tucked in macros. C++ templates reduce some of that. So... do you highlight the whole as language syntax or paint it in the directive color? I think my preference would be to limit the directive highlight to the directive itself, and paint the remainder with standard syntax highlights. But others probably have different takes on that. |
A follow on comment: I suppose my thoughts on directive highlights in FLUID is probably irrelevant since its not likely that anyone would do anything that complex within FLUID. I know beyond initial form/window layout I have to bail out simply because it can't facilitate what I need to do. |
RE: your follow up, oh, I've done multiline #define's in fluid, I have some pretty crazy large apps written in fluid that abuse the macro parser, no doubt about it. The reason I'm jumping on this is I spent a bit of time on fluid adding the external editor option, so I've been in the editor stuff before. The internals of fluid is a whole other thing.. well designed I have to say. |
No, FLUID didn't highlight character constants using single-quotes. I was going to say something but figured I caused enough trouble just trying to help out. ;-) I'm all for highlighting those. As far as missing quotes: as long as that is the behavior you want you're golden. I'll have to play with g++ to see why it grumps. Oh! Its probably because I left the trailing backslashes out. :-D Its been a while since I've tried. I'm glad you could jump on it and felt compelled to do so. I started in that same direction (a rewrite) but simply had to back-burner it and do other things that needed doing. I'm new to FLTK but I like what I've seen and have committed to using it for my GUI dev. I would also agree its well designed but oddly not very OOP oriented. Perhaps for legacy reasons. |
Ah rats. OK since we've gone this far I gotta bring this up too: If the directive syntax highlight ends at the end of the directive you'll probably want to highlight the < ... > combination too, and that gets a bit trickier since that really only applies to #include. Trying to handle it anywhere else in the editor's content breaks things. |
Pushed a few commits to the Cleaned up the Has the features described above.. hope I didn't break anything. |
Great job so far AFAICT (didn't test yet), thank you very much. What I'd be much more interested in though would be improved syntax highlighting in test/editor and in FLTK 1.4 rather than in 1.3 which your current work seems to be based on (or did I miss anything?). test/editor would also be much simpler to test (at least for me). Do you think that your new code would be portable to 1.4 (fluid) and the test/editor demo? That would be awesome... |
@Albrecht-S yes, it'll easily go into 1.4; I'm not sure I can commit this to 1.3.x anyway because it adds two files, Not sure about the test/editor demo; the way I broke it out into separate files might be too "complicated" for a demo. Perhaps the editor demo could be simplified; I didn't look at it, but maybe it could be changed from syntax highlighting C/C++ code to something simpler, as it might be a bit confusing for a beginner looking for inspiration for syntax highlighting with what is almost a full on C code parser. My currently pre-caffeinated mind can't offer an alternative, but there's probably something simpler it could do, like maybe highlight html tags, or maybe a syslog parser that highlights lines with "error:" and "warning:", and we could include a small sample log. I dunno, just thinkin out loud. |
Yep. And you'd only have to add the |
@albrecht: Question: To apply to 1.4.x, since my fork already has an |
For now I've done the former; created an So if you want a 1.4 thing to try out/code review, that's the place to look. |
I'll be test driving the highlighter inside fluid on the 1.3 branch. Sorry I want to work with stable code for my projects. So far its working as expected. Thanks @erco77 for the effort. |
Rewrite CodeEditor syntax highlighting for issue #135
Rewrite fluid CodeEditor syntax highlighting for issue #135
@erco77, @jafcobend: |
I should probably additionally merge this into the 1.3.x branch to solve the OP's original problem. Not sure if I should apply this fix to the text editor demo though; perhaps the editor demo should be /simplified/ so as to just highlight /* and // comments or something, to keep the demonstration of highlighting simple.. it is perhaps a bit of a reach to use a full on C highlighter. |
@Albrecht-S: @erco77's fix worked for me. I've considered it fixed for a while now. :-) |
Or maybe not. This is not a serious bug and we don't intend to fix all bugs in 1.3. Just in case a fix would maybe introduce other bugs we should IMHO not backport this to 1.3.
The docs in chapter "Designing a Simple Text Editor" show in paragraph "Syntax Highlighting" much code including the entire
or something like that. In the simplest case we'd just document that the documentation is incomplete and that the real code in the source distro should be consulted (to avoid too much code duplication in the docs). |
I'm closing this issue now after the code changes have been fixed (this issue) and I opened a new "documentation" issue (#189). |
The syntax highlighter in FLUID gets confused when a quote (") is the first character of a line. It essentially believes its the end quote, when it must always be a starting quote.
This is in v1.3.5. It would also be nice to push the improved highlighter code in FLUID into the "designing a simple text editor" example. Its good to demo what works, not what doesn't. :-)
The text was updated successfully, but these errors were encountered: