Trying to create Language for ChordPro Format but I am miserably failing
-
Notepad++ v8.6.2 (64-bit)
Build time : Jan 14 2024 - 02:16:00
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : “C:\Users\Name\AppData\Roaming\Notepad++\userDefineLang.xml”
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Pro (64-bit)
OS Version : 22H2
OS Build : 19045.3930
Current ANSI codepage : 1252
Plugins :
mimeTools (3)
NppConverter (4.5)
NppExport (0.4)ChordPro Format
Hi
I am a hobby musician an using Np++ as a text editor to add / place the chords to its appropriate places. While playing around in NP++ I selecting a language I suddenly found some of the lyrics colored. it made me curious if I cold use it to colorize the keywords. So I tried and failed.As I am not a Programmer I do not understand the description at
ivan radic github io udl-documentation except for the KeywordsKeywords can either have an argument or none like
{title:Ashes of Love}{c:Chorus}
title: and c: are the Keywords, Ashes of Love and Chorus are arguments
Start_Of_Chorus here has no argument, but could have
If a keyword has an argument, there is a separator : between keyword and argument which could be also a number eg. {SOC:2) if the number could be colorized in a different color as text arguments, that would be a bonus.
[C] represents a Chord to be played
What I would like to have is:
Start each keyword with {( in red) followed by the keyword incl. separator :(in blue) argument (in orange) and finally in red a closing }
Be aware, arguments can be a list of words separated by space, so from the beginning of the argument(s) right after : to the closing } should be in orangeException: if the keyword is c: its argument should be green (because in different languages it’s a comment c: stands for comment.
Everything within [C] is considered a chord and is always completely in red [C] incl. the bracket.
It seemed to me that should be easily feasible, but I got nowhere. If you feel you could this easily, I d’ be very grateful.
Here’s a sample File, extension is .pro
{title:Ashes of Love}
{c:Jack Anglin, Jim Anglin, Johnnie Wright}{start_of_chorus:2}
[G]Ashes of love [C]cold [G]as [D]ice
You made the debt and I’ll pay the [G]price
[G]Our love is gone [C]there’s [G]no [D]doubt
Ashes of love, the flames burned [G]out
{end_of_chorus}A [G]love light that gleamed [C]in [G]your [D]eyes
Has gone out to my sur[G]prise
[G]We said goodbye and [C]my [G]heart [D]bled
I can’t revive your love is [G]dead{c:Chorus}
-
So it turns out that the Notepad++ UDL system is not really capable of doing everything you want, specifically coloring the
argumentsof a{keyword:arguments}differently from thekeyword.That said, I was able to hack together a lexer that meets some of your requirements. The coloring is shown below, and below that, the XML file generated.
You can get more advanced syntax coloring with the EnhanceAnyLexer plugin, so if that interests you, let me know.

<NotepadPlus> <UserLang name="ChordPro" ext="pro" udlVersion="2.1"> <Settings> <Global caseIgnored="no" allowFoldOfComments="no" foldCompact="no" forcePureLC="2" decimalSeparator="0" /> <Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" /> </Settings> <KeywordLists> <Keywords name="Comments">00 01 02 03{c: 04}</Keywords> <Keywords name="Numbers, prefix1"></Keywords> <Keywords name="Numbers, prefix2"></Keywords> <Keywords name="Numbers, extras1"></Keywords> <Keywords name="Numbers, extras2"></Keywords> <Keywords name="Numbers, suffix1"></Keywords> <Keywords name="Numbers, suffix2"></Keywords> <Keywords name="Numbers, range"></Keywords> <Keywords name="Operators1"></Keywords> <Keywords name="Operators2"></Keywords> <Keywords name="Folders in code1, open"></Keywords> <Keywords name="Folders in code1, middle"></Keywords> <Keywords name="Folders in code1, close"></Keywords> <Keywords name="Folders in code2, open"></Keywords> <Keywords name="Folders in code2, middle"></Keywords> <Keywords name="Folders in code2, close"></Keywords> <Keywords name="Folders in comment, open"></Keywords> <Keywords name="Folders in comment, middle"></Keywords> <Keywords name="Folders in comment, close"></Keywords> <Keywords name="Keywords1"></Keywords> <Keywords name="Keywords2"></Keywords> <Keywords name="Keywords3"></Keywords> <Keywords name="Keywords4"></Keywords> <Keywords name="Keywords5"></Keywords> <Keywords name="Keywords6"></Keywords> <Keywords name="Keywords7"></Keywords> <Keywords name="Keywords8"></Keywords> <Keywords name="Delimiters">00[ 01 02] 03{ 04 05} 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords> </KeywordLists> <Styles> <WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="COMMENTS" fgColor="2CAF10" bgColor="FFFFFF" fontStyle="3" nesting="0" /> <WordsStyle name="LINE COMMENTS" fgColor="EE9B11" bgColor="FFFFFF" fontStyle="1" nesting="0" /> <WordsStyle name="NUMBERS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS3" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS1" fgColor="FF0000" bgColor="FFFFFF" fontStyle="1" nesting="0" /> <WordsStyle name="DELIMITERS2" fgColor="0000FF" bgColor="FFFFFF" fontStyle="1" nesting="0" /> <WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontStyle="1" nesting="0" /> <WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> </Styles> </UserLang> </NotepadPlus>Let me explain my choices too.
Coloring the comments (
{c:...})
I went toComment & Number->Comment style, set theOpento{c:and theCloseto}- You could also use
Delimitersfor this.
If you needed the comments to be only on one line (that is,
{c: foo} baris not a comment but{c: foo}is, you could do the following:Comment & Number->Comment line style- use
{c:as theOpenand}as theCloseand leaveContinue characterblank
Coloring the chords (
[CHORD])I went to
Operators & Delimiters->Delimiter 1 style, set[toOpenand]toClose, and set the color to red.Coloring the keywords and arguments (all the same color, sorry :c )
I went to
Operators & Delimiters->Delimiter 2 style, set{toOpenand}toClose, and set the color to blue. - You could also use
-
If you’re still interested, I was able to meet all your requirements by enhancing the UDL above using EnhanceAnyLexer
The result:

The entry in the EnhanceAnyLexer config file:
[chordpro] ; color each word, 0x66ad1 is the color used, see the description above for more information on the color coding. ; start curlybrace of keyword and arguments 0x0000ff = \{(?=(?!c:)\w+(?::[^}]*)?\}) ; arguments to a keyword 0x88888ef = \{\w+(?<!\{c)\K:[^\}]*(?=}) ; end curlybrace of keyword and arguments 0x0000ff = \{\w+(?<!\{c)\K(?::[^\}]*)?\K\} ; numbers in arguments 0xcc00dd = :[^\}]*?\K\d+(?=[^\}]*\}) ; check in the respective styler xml if the following IDs are valid excluded_styles = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20,21,22,23The keys are BGR colors, so
0x0000ffis pure red,0x8888efis orange, and0xcc00ddis purple.See here for an explanation of the regular expressions in the config file. But the key things to understand are:
x(?=y)is saying “matchxonly if it is followed byy, but don’t match the y”\{and\}match literal{and}because those are special characters in regular expressions[^\}]*matches any number (including zero) of characters other than}.(?<!x)yis saying “matchyonly it is not directly preceded byx”\Kforgets everything that has been matched so far. It is useful here because it allows me to match the keyword (without coloring it the same as the arguments) when determining where the arguments are.
-
@Mark-Olson said in Trying to create Language for ChordPro Format but I am miserably failing:
EnhanceAnyLexer
While reading about UDL I cam across EnhanceAnyLexer so I knew I have to install that plugin :-) Then I copied the Chordpro lexer code into C:\Users\UserName\AppData\Roaming\Notepad++\plugins\config\EnhanceAnyLexer\EnhanceAnyLexerConfig.ini
Guess what? You’v made my day.
Everything is working the way I wantet it to be.
Thank you very much Mark