Adding a new built in Language?

Feb 18, 2008 at 7:04 PM
Hi,
Just downloaded the 2.0 release and would like to add a new built in language. I see there is MSSQL, I would like to add all the keywords etc for PostgreSQL (PGSQL)

Also how does the files in LexerStyleNames and LexerKeywordListNames relate to the mssql.xml file?

Would I just have to create a new pgsql.xml file using the mssql.xml file as a guide?

I would of course submit the new PGSQL language back to the project.

Thanks,

Tony
Coordinator
Feb 19, 2008 at 4:15 AM
Edited Feb 19, 2008 at 4:17 AM
The MSSQL language has a lexer written specifically for it's syntax. Since PGSQL doesn't, it has to use the generic SQL lexer. This means a couple of things: First in the config file find the Lexer element and add an attribute LexerName="sql". The reason that MSSQL doesn't have to do this is because if a language name matches a lexer name it is automatically picked up.

Secondly your keyword list now corresponds to the LexerKeywordListNames\sql.txt (as follows) instead of mssql.txt
Keywords
Database Objects
PLDoc
SQL*Plus
User Keywords 1
User Keywords 2
User Keywords 3
User Keywords 4

Each <Keyword List="N"> matches one of these list. So <Keyword List="4"> matches User Keywords 1. These keyword lists are used by the lexer to set styles. If it comes across a keyword in one of the lists it will style that word in the corresponding style.

It also means that the style names come from LexerStyleNames\sql.txt (listed below)
DOCUMENT_DEFAULT = 0
COMMENT = 1
COMMENTLINE = 2
COMMENTDOC = 3
NUMBER = 4
WORD = 5
STRING = 6
CHARACTER = 7
SQLPLUS = 8
SQLPLUS_PROMPT = 9
OPERATOR = 10
IDENTIFIER = 11
SQLPLUS_COMMENT = 13
COMMENTLINEDOC = 15
WORD2 = 16
COMMENTDOCKEYWORD = 17
COMMENTDOCKEYWORDERROR = 18
USER1 = 19
USER2 = 20
USER3 = 21
USER4 = 22
QUOTEDIDENTIFIER = 23

That means that you can't use some of the styles from MSSQL like
<Style Name="GLOBAL_VARIABLE" ForeColor="#ff00ff" />

But you can use
<Style Name="QUOTEDIDENTIFIER" ForeColor="#ff00ff" />

I hope this makes sense to you. I know it's not the easiest thing to get (I spent days going over all the Scintilla lexer stuff before I fully grasped it)
Feb 19, 2008 at 3:53 PM
Hi Chris, thanks for the info, it helped a lot.
I have a new pgsql.xml file that uses the sql lexer. It's mostly working but I am having problems
with the text in singe and double quotes. I want them to be blue, but I can't seem to get it working:
Here is the text from the xml file:

Here is a link to the whole file: (http://www.milwaukeesoft.com/pgsql.xml)

From what I can tell QUOTEDIDENTIFIER would highlight text like this "this is quoted text" and that seems to work, I figured STRING would be 'this is single qouted' but it does not seem to work and the single qouted is always coming out red.

<Styles>
<Style Name="DOCUMENT_DEFAULT"/>
<!--Keyword list 0 PostgreSQL Keywords -->
<Style Name="WORD" ForeColor="black" bold="true" />
<!--Keyword list 1 PostgreSQL Types -->
<Style Name="WORD2" ForeColor="teal" bold="true" />
<Style Name="QUOTEDIDENTIFIER" ForeColor="blue" />
<Style Name="STRING" ForeColor="blue" />
<!--Keyword list 3 PostgreSQL Exceptions -->
<Style Name="SQLPLUS" ForeColor="red" bold="true" italic="true" />
<Style Name="OPERATOR" ForeColor="#ff00ff" />
<Style Name="NUMBER" ForeColor="#ff00ff" bold="true" />
<Style Name="COMMENTLINE" ForeColor="green" bold="true" italic="true" />
<Style Name="COMMENTDOC" ForeColor="green" bold="true" italic="true" />
<Style Name="COMMENT" ForeColor="green" bold="true" italic="true" />


<!--Keyword list 4 Postgresql System tables -->
<Style Name="USER1" ForeColor="#FFA36B" bold="true"/>

<!--Keyword list 5 PostgreSQL Functions-->
<Style Name="USER2" ForeColor="purple" bold ="true" />

<!--Keyword list 6 -->
<Style Name="USER3" ForeColor="yellow" />

<!--Keyword list 7 -->
<Style Name="USER4" ForeColor="yellow" />
</Styles>

Feb 19, 2008 at 4:11 PM
Hi Chris,
Also forgot to mention I coudn't figure out what style when with Keywords List="2"
I figured out the other ones, but that one didn't seem to work.
Coordinator
Feb 19, 2008 at 6:12 PM
Edited Feb 19, 2008 at 6:12 PM
It's using the CHARACTER style (I know, I didn't write the lexer :)

Here's a snippet that will help debug stying issues. It gives you the style number and name (if applicable) at Scintilla's current caret position.

int styleNumber = Document.Styles.GetStyleAt(Document.Caret.Position);
string styleName = string.Empty;
foreach (KeyValuePair<string, int> map in Document.Lexing.StyleNameMap)
{
if (map.Value == styleNumber)
{
styleName = map.Key;
break;
}
}
MessageBox.Show(string.Format("Style Name:{0}\r\nStlyNumber{1}", styleName, styleNumber));
Feb 19, 2008 at 6:26 PM
Thanks Chris,
That will help a bunch :-)
Coordinator
Feb 19, 2008 at 6:35 PM
Oh and about Keywords List="2", I'm sorry but I can't really help too much. My best guess is that it's some sort of PLSQL documentation markup syntax specific to Oracle.
Feb 19, 2008 at 7:39 PM


ChrisRickard wrote:
Oh and about Keywords List="2", I'm sorry but I can't really help too much. My best guess is that it's some sort of PLSQL documentation markup syntax specific to Oracle.


Yep, I can't get that one to work, but there is enough with the user defined ones to get everything for PostgreSQl working. I got the quoting sorted out with that test code you posted. Thanks again for that.

Later,

Tony