SynEdit, custom highlighter and doubts lazarus / 31-LCL ---------------------------------------------------------------------- Henppy · 2014-01-06 19:30 Ok, so I'm thinking on implementing my own custom highlighter from SynEdit. I've been reading about this and I'm still not sure it would be a good idea based on my current understanding of how SynEdit works and what can be done with it. So, before I delve into writing the code, I'd like to ask the most knowledgeable members of this forum, if the solutions to my problems are indeed a custom highlighter. There are two points I'd like so address: [1] The language has a symbol "." for sentence terminator. Currently the highlighter I'm using, a TSynAny, is having problems with something like this "10.33.". It will paint the last "." after a number as if it is part of that number when in reality it's not. [2] I'd like to be able to syntax check the code. So some form of token list will be needed. The syntax check is on my part, but what I would like to do is avoid tokenizing the code all over again if SynEdit already did and I can have access to that list. Also I should be able to mark the parts of the code that fail said check. So... Thoughts? Should I proceed or I'm talking non-sense here? Thanks all. ---------------------------------------------------------------------- Martin_fr · 2014-01-06 19:55 TSynAnySyn is just a basic demonstration. Very simple and no features. [1] Identifying the grammar of your codes language, is exactly what a HL is for. You can copy the example from the example/SynEdit folder and start with that. I assume you have read: http://wiki.lazarus.freepascal.org/SynEdit_Highlighter It has a tutorial on writing a HL. [2] You mean spelling English words with a dictionary? Or showing anything that is not a token, or tokens that are in the wrong place? It can all be done by the HL (There in a html/css/js Hl, that does all of this (no spelling, but css errors) https://github.com/rnapoles/SynWeb-Port However, if it is spelling, which is independent of the keywords and grammar, then there is an alternative. TSynEditMarkup. There is no doc on it though. It is used in the IDE for showing the selection, the current word (mark other occurrences of the same word), the syncro-edit frames, .... it can add markup over any highlighted text. But technically some of it it can be done in the HL too. If the syntax check needs to break the HL token further down, or needs to combine them, then use a Markup. e.g. *  tFooBar     only mark the "t" because it should be uppercase. But the HL would normally return the entire word. *  new := old increment;    something missing! the HL would return each word/space as 1 token. If the error should have a red frame, you can not do it in the HL. Because a frame by the HL would frame each word on its own. A markup can use info from the HL. See SynEditMarkupWordGroup (which shows begin/end pairs) ---------------------------------------------------------------------- Henppy · 2014-01-06 20:13 Thanks Martin, much appreciated. Yes I read that one link, among a lot others. Right now I'm not sure that I fully understand the implications of what I'm reading. That's why I'm asking, just to confirm that this is the way to go to accomplish what I want to do. My time's a little tight so I don't want to invest hours in a dead end! The syntax highlight is just like your second example. Code like "this_var = 4 +." is wrong because "4+." should be "4+something." So I will be highlighting the "." or maybe the "4+." ---------------------------------------------------------------------- Edson · 2014-01-06 20:44 For the number [1], (getting an appropiate HL), it could be solved writting your own HL, like Martin said, or probably there is already some that fit your needs (it will save you a lot of time). If you give more information about the syntax, we could suggest something better. For the number [2] (check the syntax of code), I suggest you do it, out of the HL. It could be done on the HL, but if the rules are complex, the HL could turn into complexity too. The syntax checking could use the "tokenizer" of the Highlighter, but it should fit with the lexical rules of the language, for being successful. Doing that way, the syntax checking will be as simple as verifying some basic syntax rules. For highlight the syntax error,  I suggest to use the Markup options of SynEdit. ---------------------------------------------------------------------- Henppy · 2014-01-06 21:09 Yeah, I was originally thinking on doing my own tokenizer, but then I thought maybe I don't need to do it because the job is already done by whatever HL I'm using (custom or otherwise). So I would get the tokens from it and start from there. Saving process time by not having to go through the code again. The language by the way, is KerboScript and looks something like this: Code: [Select]print "1". wait 1. lock throttle to 1. lock steering to up + R(0,0,180). stage. print "Launch!". wait until altitude >10000. lock steering to up + R(0,0,180) + R(0,-60,0). print "Beginning gravity turn.". wait until stage:liquidfuel < 540. stage. print "Stage 1 separated.". wait until apoapsis > 100200. ... So as you can see, it's pretty simple to process. I just need a token list and "a couple" of procedures to parse-evaluate the code alas top-down fashion. ---------------------------------------------------------------------- Edson · 2014-01-07 02:09 The syntax looks simple, with exception of having the "." like a sentence terminator, and like part of a number too. It's some unsual for me. I don't know if there is some HL for that. You could adapt some HL for considering that case. So you could do something like: "consider a number like all the numeric digits but the decimal point can appear only one time" This is one simple HL that I used for SQL syntax. Maybe you could adapt it for your needs. It's based on the document: http://blog.pucp.edu.pe/media/4946/20131031-la_biblia_del_synedit_- _rev4.pdf ---------------------------------------------------------------------- Henppy · 2014-01-11 23:21 Disregard. Another thread stated at: http://forum.lazarus.freepascal.org/index.php/topic,23217.0.html