Highlighting variable types in Delphi(Object-Pascal)

138 views
Skip to first unread message

Thibmo

unread,
Dec 4, 2015, 4:34:55 PM12/4/15
to highlight.js
I seem to have found this to be missing in this great syntax highlighter.
I tried some edits to the original but only got a half-working success.

If you look at the syntax highlighting of both RAD studio and Lazarus you see that, for example, Integer, String, Boolean, Word, AnsiString, etc are also highlighted separately.
Is there any way to get all these types to be highlighted?
I am currently running with this(Using this in highlight.pack.js):
tD={
cN:"type",
bK:"TKMHandIndex THouseType integer shortint smallint longint int64 byte real cardinal word longword qword single double extended comp currency bool boolean bytebool wordbool longbool char widechar ansistring shortstring widestring",
e:/[ = ;]/
};

I'd love to set it to cN:"type" and that it wouldn't color the semicolons/equals-signs but the keywords themselves.
Message has been deleted
Message has been deleted

Thibmo

unread,
Dec 6, 2015, 12:25:06 PM12/6/15
to highlight.js
Seems like I got it fixed now.
This did the job:
hljs.registerLanguage("delphi",function(e){
var r="exports register file shl array record property for mod while set ally label uses raise not stored class safecall var interface or private static exit index inherited to else stdcall override shr asm far resourcestring finalization packed virtual out and protected library do xorwrite goto near function end div overload object unit begin string on inline repeat until destructor write message program with read initialization except default nil if case cdecl in downto threadvar of try pascal const external constructor type public then implementation finally published procedure",
t=[
e.CLCM,
e.C(/\{/,/\}/,{
r:0
}),
e.C(/\(\*/,/\*\)/,{
r:10
})
],
i={
cN:"string",
b:/'/,
e:/'/,
c:[
{
b:/''/
}
]
},
c={
cN:"string",
b:/(#\d+)+/
},
tD={
cN:"type",
b:'(integer|shortint|real|smallint|longint|int64|cardinal|word|longword|qword|single|double|extended|comp|currency|bytebool|bool|wordbool|longbool|char|widechar|ansistring|shortstring|widestring|boolean)',
e:/[;|\\s*=|\\s*:=|\)|\)]/,
eE:!0
},
o={
b:e.IR+"\\s*=\\s*class\\s*\\(",
rB:!0,
c:[e.TM]
},
n={
cN:"function",
bK:"function constructor destructor procedure",
e:/[:;]/,
k:"function constructor|10 destructor|10 procedure|10",
c:[
e.TM,
{
cN:"params",
b:/\(/,
e:/\):|\);/,
k:r,
c:[
i,
c,
tD
]
}
].concat(t)
};
return{
cI:!0,
k:r,
i:/"|\$[G-Zg-z]|\/\*|<\/|\|/,
c:[
i,
c,
e.NM,
o,
n,
tD
].concat(t)
}
});
Reply all
Reply to author
Forward
0 new messages