Joe Kuhn
Well-known member
I've installed the Code addon in my FoxProToCSharp discussion forum to add line numbering and line highlighting for my users. Code coloring is supported in XF via PrismJS which supports C#, but not FoxPro. My goal is to take the PrismJS file for VisualBasic and make it work for FoxPro.
Believe it or not, here's the complete PrismJS JavaScript file for VB:
I took the above file, renamed it accordingly and changed the header and footer to say foxpro instead of visual-basic. After installing per the Code addon directions, you can see that coloring is happening, but it's not working correctly for FoxPro comments:
First goal: get comments working for Fox.
In VB comments start with 'REM' or the single quote character.
In Fox they start with 'NOTE' an asterisk or two ampersand characters. More details about comments are included in my link just above, but I'd like to get some coloring working correctly first.
Based on this for VB:
I'm changing it to this for Fox:
But I have some questions:
1. It appears forward slash is some type of delimiter, correct?
2. Why the question mark and colon after the pattern object?
3. What's with the 'i' at the end of some of the lines?
4. And \b. What's that for?
Any other comments you care to make about my first pass are welcome. And thanks in advance.
Believe it or not, here's the complete PrismJS JavaScript file for VB:
JavaScript:
[CODE=javascript]Prism.languages['visual-basic'] = {
'comment': {
pattern: /(?:['‘’]|REM\b).*/i,
inside: {
'keyword': /^REM/i
}
},
'directive': {
pattern: /#(?:Const|Else|ElseIf|End|ExternalChecksum|ExternalSource|If|Region)(?:[^\S\r\n]_[^\S\r\n]*(?:\r\n?|\n)|.)+/i,
alias: 'comment',
greedy: true
},
'string': {
pattern: /["“”](?:["“”]{2}|[^"“”])*["“”]C?/i,
greedy: true
},
'date': {
pattern: /#[^\S\r\n]*(?:\d+([/-])\d+\1\d+(?:[^\S\r\n]+(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))?|(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))[^\S\r\n]*#/i,
alias: 'builtin'
},
'number': /(?:(?:\b\d+(?:\.\d+)?|\.\d+)(?:E[+-]?\d+)?|&[HO][\dA-F]+)(?:U?[ILS]|[FRD])?/i,
'boolean': /\b(?:True|False|Nothing)\b/i,
'keyword': /\b(?:AddHandler|AddressOf|Alias|And(?:Also)?|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|C(?:Bool|Byte|Char|Date|Dbl|Dec|Int|Lng|Obj|SByte|Short|Sng|Str|Type|UInt|ULng|UShort)|Char|Class|Const|Continue|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else(?:If)?|End(?:If)?|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get(?:Type|XMLNamespace)?|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|Must(?:Inherit|Override)|My(?:Base|Class)|Namespace|Narrowing|New|Next|Not(?:Inheritable|Overridable)?|Object|Of|On|Operator|Option(?:al)?|Or(?:Else)?|Out|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TryCast|TypeOf|U(?:Integer|Long|Short)|Using|Variant|Wend|When|While|Widening|With(?:Events)?|WriteOnly|Xor)\b/i,
'operator': [
/[+\-*/\\^<=>&#@$%!]/,
{
pattern: /([^\S\r\n])_(?=[^\S\r\n]*[\r\n])/,
lookbehind: true
}
],
'punctuation': /[{}().,:?]/
};
Prism.languages.vb = Prism.languages['visual-basic'];
I took the above file, renamed it accordingly and changed the header and footer to say foxpro instead of visual-basic. After installing per the Code addon directions, you can see that coloring is happening, but it's not working correctly for FoxPro comments:
Fox syntax coloring
This is what the forum uses to do syntax coloring for many different languages: https://github.com/PrismJS/prism/blob/gh-pages/components/prism-visual-basic.js And here is the actual script that does the work for VisualBasic: Prism.languages['visual-basic'] = { 'comment': {...
www.foxprotocsharp.com
First goal: get comments working for Fox.
In VB comments start with 'REM' or the single quote character.
In Fox they start with 'NOTE' an asterisk or two ampersand characters. More details about comments are included in my link just above, but I'd like to get some coloring working correctly first.
Based on this for VB:
JavaScript:
'comment': {
pattern: /(?:['‘’]|REM\b).*/i,
inside: {
'keyword': /^REM/i
}
I'm changing it to this for Fox:
JavaScript:
'comment': {
pattern: /(?:['*’]|['&&’]|NOTE\b).*/,
inside: {
'keyword': /^['&&']/
}
But I have some questions:
1. It appears forward slash is some type of delimiter, correct?
2. Why the question mark and colon after the pattern object?
3. What's with the 'i' at the end of some of the lines?
4. And \b. What's that for?
Any other comments you care to make about my first pass are welcome. And thanks in advance.
Last edited: