Re: understanding elements

Lorenzo Bettini <[email protected]> Thu, 22 Dec 2011 15:42:00 +0100
Newsgroups gmane.comp.gnu.source-highlight.general
Message-ID <[email protected]>
On 18/12/2011 16:55, Federico Bruni wrote:
> Hi,
>
> I've finished the draft of the lilypond.lang file and I have some
> questions before asking for comments on my file in the lilypond-devel
> mailing list.
>
> 1) ELEMENTS
> First of all, there's any place in the doc where each element is
> explained? I mean: some elements are straightforward (comment, string,
> function), while others (preproc, cbracket) are a bit obscure...at least
> for a non-developer.
> Also, I guess that names of these elements generally work fine with all
> the programming languages. But other kind of languages may have
> different peculiarities.

exactly: some of them work fine with most languages (cbracket stands for 
curcly brackets, i.e., { } )

'preproc' can be used for preprocessing things which can assume 
different meanings in different languages, and they can be associated 
with some language elements as one sees fit... for instance, preproc can 
be # directives in C/C++ and import statements in Java

basically you can associate any meaning, these elements will be used 
only for formatting styles

>
> For examples, in the lilypond syntax - besides strings, comments,
> operators and numbers - I have basically:
>
> - music functions
> - contexts
> - layout objects
> - context properties
> - layout properties
>
> Which elements should I use for each of them?
> Function for music functions, that's easy.
> What about all the rest?
>

you can create new elements, and put a formatting strategy in the style file

or you can create these new elements (but no space is allowed, so use, 
e.g., layout_objects), and, if you don't want to change the style files 
you may want to use

http://www.gnu.org/software/src-highlite/source-highlight.html#Default-Styles

which allows to map your element to an existing one,

e.g., if you map

layout_objects = function

if a formatting style for layout_objects is not found in a style file, 
then the same style of function will be used (that's just an example)

> So far I used different elements, even if not related to the meaning of
> the group, just to see them styled differently.
> But I guess that's not the right way.
>
> Should I create new elements maybe?
>

see above

>
>
> 2) SIMILAR ELEMENTS
> Let's say I want to style differently two groups of numbers.
> Which elements should I use?
> For example, in the lilypond syntax numbers are used in two contexts:
>
> # Fingering and string number
> specialchar = '-[1-5]\b', '\\[0-9]\b'
>
> # Note duration
> number = '(1|2|4|8|16|32|64|128)(\.+|\b)'
>
> specialchar is ok?
>

that's your choice, as I said above, it's just up to you :)

>
>
> 3) VARIABLES
> In latex.lang I found:
>
> vardef command = '\\[[:alpha:]]+'
> keyword = $command
>
> Why not writing just one line?
> keyword = '\\[[:alpha:]]+'
>
> What's the benefit of creating a variable?

in case you want to reuse the same regular expressions in different parts

hope to hear from you soon
cheers
	Lorenzo