[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Pluma's syntax highlighting



On Mon, 13 Jan 2020, at 11:52, Richard Owlett wrote:

> I was looking for a description of what Pluma was trying to accomplish 
> by their highlighting rules.

Do you understand the purpose of syntax highlighting (in general)?  

(It's to /aid/ a programmer, reducing the chance of them making silly 
mistakes when typing in code.)

If so, do you understand that - in some text editors at least, maybe all of 
them - syntax highlighting is an /aid/, but doesn't usually exactly match 
the precise nuances of the programming language that's displayed.

That's because the precise nuances would need the text editor to have a
fully syntax-aware parser for every language it's capable of highlighting.

So what usually happens is that the editor will recognise (having been told
how to) the general shape of a certain language's characteristics.  For 
example, it'll know how commenting works, rules for variable names, 
how if/then/else/endif etc should look, how strings are delimited ... and so 
on.

Many text editor syntax highlighters only look at each line of the file in 
isolation, except for checking for block comments, string delimiters and 
the overall if/case/select control structures.  So they might be able to keep
track of nested indentation across many lines of the file, or spot what 
appears to be the start and end of long blocks of comments.   Usually 
they can be fooled if you format/layout code in peculiar ways - ways 
that a language compiler will understand, but the editor can't.

One of the reasons for this is that the highlighting needs to adjust how 
it colours a line very very fast, as a user types new characters or removes
some.  There's no time to run a complete 'compile'/parse of the whole 
file (between user keypresses) to adjust the whole file's colouring.


It occurs to me that in your specific situation there may be syntax 
differences between different shell languages, and the editor may 
possibly be using the rules for one such language when in fact the
script is written in a different one.

That apart, it would help enormously if you posted a screenshot of what 
you're seeing, and some explanation of why you think the colouring is 
wrong.

-- 
Jeremy Nicoll - my opinions are my own.


Reply to: