SQF Highlighter – Extension

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Fixes)
m (Some wiki formatting)
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
{| class="wikitable" style="float: right; margin: 0 0 0.5em 1.5em"
{| class="wikitable float-right"
! colspan="2" style="padding: 1.5em" | SQF Highlighter
! colspan="2" style="padding: 1.5em" | SQF Highlighter
|-
|-
! style="vertical-align: top" | Description
! Description
| Highlights and links SQF commands and functions
| Highlights and links SQF commands and functions
|-
|-
! style="vertical-align: top" | Author
! Author
| {{User|Lou Montana}}
| {{User|Lou Montana}}
|-
|-
! style="vertical-align: top" | Version
! Project Start
| 0.5b<br>(version is not incremented for now<br>due to continuous updates as of 2022-03-14)
| 2022-03-08: Project start
|-
|-
! style="vertical-align: top" | Release Date
! Release Date
| 2022-03-12: First upload
|
* 2022-03-12: "v1" (0.50b), first upload
* 2022-07-11: "v2" (0.85b), new parser
* 2023-11-02: 0.9b, allow some wiki formatting in comments
|-
|-
! style="vertical-align: top" | Project Start
! Version
| 2022-03-08: Project start
| 0.9b
|}
|}
This extension highlights and automatically links SQF commands and functions.
This extension highlights and automatically links [[SQF Syntax|SQF]] commands and functions. It also covers [[SQS Syntax|SQS]] (free of charge).
 
 
{{TOC}}
 
 
{{Clear}}
== Features ==
 
* [[SQF Syntax]] support
* [[SQS Syntax]] support
* "Copy code to clipboard" button on hover
* Partial wiki formatting in comments: {{hl|<nowiki>''italic''</nowiki>}}, {{hl|<nowiki>'''bold'''</nowiki>}}, {{hl|<nowiki><s>striked</s></nowiki>}}, {{hl|<nowiki><u>underlined</u></nowiki>}}, {{hl|<nowiki>[[links|even styled ones]]</nowiki>}}, {{hl|<nowiki>{{templates}}</nowiki>}}
* {{hl|#define}}d constant value on mouse hover
* SQF tag button in the wiki edit toolbar (next to '''B''' and '''''I''''')
* Options:
** {{hl|inline}} for inline code
** {{hl|notrim}} to remove the auto trim (lines themselves will always be rtrimmed)
* Categorises wrong code pages in [[:Category:Pages with SQF errors]] and [[:Category:Pages with SQS errors]]




Line 23: Line 44:


* Unzip the directory to {{hl|wiki/extensions/SQFHighlighter}}
* Unzip the directory to {{hl|wiki/extensions/SQFHighlighter}}
* Add {{ic|wfLoadExtension({{Color|#F33|'SQFHighlighter'}});}} to {{hl|LocalSettings.php}}
* Add <syntaxhighlight lang="php" inline>wfLoadExtension( 'SQFHighlighter' );</syntaxhighlight> to {{hl|LocalSettings.php}}
* There are no settings - the extension creates full path links unless the host is one of the following (then relative links are created):
* there is a {{hl|case-sensitive}} setting in {{hl|extension.json}} (default true). Set to false to highlight improperly-cased commands and functions (e.g [[setDammage|setDaMMage]] instead of [[setDammage]], etc)
* The extension creates full path links unless the host is one of the following (then relative links are created):
** {{hl|community.bistudio.com}}
** {{hl|community.bistudio.com}}
** {{hl|community.bohemia.net}}
** {{hl|community.bohemia.net}}
Line 31: Line 53:
== Usage ==
== Usage ==


Using <nowiki><sqf></nowiki> tags will auto-generate syntax highlighting '''and''' links to the pages.
Using <syntaxhighlight lang="html" inline><sqf></syntaxhighlight> tags will auto-generate syntax highlighting '''and''' links to the pages.


{| style="min-width: 50em"
{| class="wikitable valign-top" style="min-width: 50em"
|+ Examples
|+ Examples
! colspan="2" | [[SQF Syntax]]
|-
! Code
! Code
! Result
! Result
|- style="vertical-align: top"
|-
| <pre><sqf/></pre>
| <syntaxhighlight lang="html"><sqf/></syntaxhighlight>
| <sqf/>
| <sqf/>
|- style="vertical-align: top"
|-
| <pre><sqf></sqf></pre>
| <syntaxhighlight lang="html"><sqf></sqf></syntaxhighlight>
| <sqf></sqf>
| <sqf></sqf>
|- style="vertical-align: top"
|-
| <pre><sqf> </sqf></pre>
| <syntaxhighlight lang="html"><sqf> </sqf></syntaxhighlight>
| <sqf> </sqf>
| <sqf> </sqf>
|- style="vertical-align: top"
|-
| <pre><sqf>hint "It Works!";</sqf></pre>
| <syntaxhighlight lang="html"><sqf>hint "It Works!";</sqf></syntaxhighlight>
| <sqf>hint "It Works!";</sqf>
| <sqf>hint "It Works!";</sqf>
|- style="vertical-align: top"
|-
| <pre><sqf>
| <syntaxhighlight lang="html">This is <sqf inline>hint "It Works!";</sqf> absolutely inline.</syntaxhighlight>
| This is <sqf inline>hint "It Works!";</sqf> absolutely inline.
|-
| <syntaxhighlight lang="html"><sqf notrim>
 
hint "It Works!";
 
 
</sqf></syntaxhighlight>
| <sqf notrim>
 
hint "It Works!";
 
 
</sqf>
|-
| <syntaxhighlight lang="html">
<sqf>
// your code here
// your code here
hint "good!";
hint "good!";
</sqf></pre>
</sqf>
</syntaxhighlight>
| <sqf>
| <sqf>
// your code here
// your code here
hint "good!";
hint "good!";
</sqf>
</sqf>
|- style="vertical-align: top"
|-
| <pre><sqf>
| <syntaxhighlight lang="html">
<sqf>
#define fadeInDuration 3
#define fadeInDuration 3


Line 70: Line 113:


/*
/*
wait for resurrection
wait for resurrection - see {{Link|Arma 3: Respawn}}
*/
*/
waitUntil { alive player && { preloadCamera getPosATL player } };
waitUntil { alive player && { preloadCamera getPosATL player } };
Line 80: Line 123:
sleep 10;
sleep 10;
[] call BIS_fnc_endMission;
[] call BIS_fnc_endMission;
</sqf></pre>
</sqf>
</syntaxhighlight>
| <sqf>
| <sqf>
#define fadeInDuration 3
#define fadeInDuration 3
Line 92: Line 136:


/*
/*
wait for resurrection
wait for resurrection - see {{Link|Arma 3: Respawn}}
*/
*/
waitUntil { alive player && { preloadCamera getPosATL player } };
waitUntil { alive player && { preloadCamera getPosATL player } };
Line 103: Line 147:
[] call BIS_fnc_endMission;
[] call BIS_fnc_endMission;
</sqf>
</sqf>
|-
! colspan="2" | [[SQS Syntax]]
|-
! Code
! Result
|-
| <syntaxhighlight lang="html"><sqs/></syntaxhighlight>
| <sqs/>
|-
| <syntaxhighlight lang="html"><sqs></sqs></syntaxhighlight>
| <sqs></sqs>
|-
| <syntaxhighlight lang="html"><sqs> </sqs></syntaxhighlight>
| <sqs> </sqs>
|-
| <syntaxhighlight lang="html"><sqs>hint "It Works!"</sqs></syntaxhighlight>
| <sqs>hint "It Works!";</sqs>
|-
| <syntaxhighlight lang="html">This is <sqs inline>hint "It Works!"</sqs> absolutely inline.</syntaxhighlight>
| This is <sqs inline>hint "It Works!"</sqs> absolutely inline.
|-
| <syntaxhighlight lang="html"><sqs notrim>
hint "It Works!";
</sqs></syntaxhighlight>
| <sqs notrim>
hint "It Works!";
</sqs>
|-
| <syntaxhighlight lang="html"><sqs>
#loop
@ alive player
; you ok - see [[getDammage]] too
hint "OK"
~1
@ not alive player
~1
hint "you ded"
; you not ok
goto "loop"
</sqs></syntaxhighlight>
| <sqs>
#loop
@ alive player
; you ok - see [[getDammage]] too
hint "OK"
~1
@ not alive player
~1
hint "you ded"
; you not ok
goto "loop"
</sqs>
|}
|}


Line 108: Line 210:
== CSS Classes ==
== CSS Classes ==


All elements are {{hl|'''<nowiki><span></nowiki>'''}} but the parent block that is a {{hl|'''<nowiki><div></nowiki>'''}}.
All elements are <syntaxhighlight lang="html" inline><span></syntaxhighlight> except for some exceptions:
* unless using <syntaxhighlight lang="html" inline><sqf inline></syntaxhighlight>, the parent block is a <syntaxhighlight lang="html" inline><div></syntaxhighlight> holding another one for scrolling purpose; otherwise, is is a <syntaxhighlight lang="html" inline><span></syntaxhighlight> as well.
 
{| class="wikitable"
{| class="wikitable"
! Element
! Element
Line 115: Line 219:
|-
|-
| parent block
| parent block
| sqfhighlighter-'''block'''
| sqfhighlighter-'''block'''<br>contains sqfhighlighter-'''scroller''' for blocks
| <sqf>&nbsp;</sqf>
| <sqf>;</sqf>
|-
|-
| error message
| error message
| sqfhighlighter-'''error'''
| sqfhighlighter-'''error'''
| <sqf></sqf>
| <sqf></sqf><br><sqs></sqs>
|-
| wild character / bad variable / unclosed string
| bv, bvl
| <sqf>
@
private _var = 3RndMag;
 
hint "hello
</sqf>
|-
|-
| comment
| comment
| sqfhighlighter-'''comment'''
| cc
| <sqf>// comment
| <sqf>
// comment


/*
/*
Line 130: Line 244:
a multiline
a multiline
comment
comment
*/</sqf>
*/
</sqf>
|-
| comment bold
| b
| <sqf>
// '''bold''' comment
</sqf>
|-
|-
| string
| string
| sqfhighlighter-'''string'''
| s
| <sqf>"string"</sqf>
| <sqf>"string"</sqf>
|-
| stringtable string
| ss
| <sqf>
"STR_entry"
"str_entry"
"sTr_entry"
"STRD_entry"
"STRM_entry"
"$STR_entry"
</sqf>
|-
|-
| number
| number
| sqfhighlighter-'''number'''
| n
| <sqf>42
| <sqf>
42
-6.9
-6.9
10e10</sqf>
10e10
</sqf>
|-
|-
| operator
| operator
| sqfhighlighter-'''operator'''
| o
| <sqf>a + b</sqf>
| <sqf>a + b</sqf>
|-
|-
| keyword ({{hl|if}}, {{hl|then}}, {{hl|waitUntil}}, etc)
| keyword ({{hl|if}}, {{hl|then}}, {{hl|waitUntil}}, etc)
| sqfhighlighter-'''keyword'''
| k
| <sqf>if</sqf>
| <sqf>if</sqf>
|-
|-
| command
| command
| sqfhighlighter-'''command'''
| c
| <sqf>setDir</sqf>
| <sqf>setDir</sqf>
|-
|-
| function
| function
| sqfhighlighter-'''function'''
| f
| <sqf>BIS_fnc_spawnGroup</sqf>
| <sqf>BIS_fnc_spawnGroup</sqf>
|-
|-
| external function
| function (external)
| sqfhighlighter-'''function-ext'''
| fe
| <sqf>// not just considering BIS_ or BIN_
| <sqf>// not just considering BIS_ or BIN_
BIS_fnc_unknownFunction
BIS_fnc_unknownFunction
Line 165: Line 299:
|-
|-
| local variable
| local variable
| sqfhighlighter-'''localvar'''
| lv
| <sqf>_localVar</sqf>
| <sqf>_localVar</sqf>
|-
|-
| global variable
| global variable
| sqfhighlighter-'''globalvar'''
| gv
| <sqf>// anything will go but UNDERSCORED_ALL_CAPS
| <sqf>
GlobalVar = 1;</sqf>
// anything will go but UNDERSCORED_ALL_CAPS
GlobalVar = 1;
</sqf>
|-
|-
| macro
| macro
| sqfhighlighter-'''macro'''
| m
| <sqf>#define
| <sqf>
#define myVar 1
#if
#if
#endif</sqf>
#endif
</sqf>
|-
|-
| constant ({{hl|#define}}d value)
| constant ({{hl|#define}}d value)
| sqfhighlighter-'''const'''
| c
| <sqf>// anything #defined or anything UNDERSCORED_ALL_CAPS
| <sqf>
#define testVar
// anything #defined only
#define testVar 1


testVar;
testVar;
otherVar;
otherVar;
MY_CONSTANT;</sqf>
MY_CONSTANT;
</sqf>
|-
|-
| array start ({{hl|[}})
| array start ({{hl|[}})
| sqfhighlighter-'''arraystart'''
| as
| <sqf>[...</sqf>
| <sqf>[ /* ... */</sqf>
|-
|-
| array end ({{hl|]}})
| array end ({{hl|]}})
| sqfhighlighter-'''arrayend'''
| ae
| <sqf>...]</sqf>
| <sqf>/* ... */ ]</sqf>
|-
|-
| code start ({{hl|{<nowiki/>}})
| code start ({{hl|{<nowiki/>}})
| sqfhighlighter-'''codestart'''
| cs
| <sqf>{...</sqf>
| <sqf>{ /* ... */</sqf>
|-
|-
| code end ({{hl|}<nowiki/>}})
| code end ({{hl|}<nowiki/>}})
| sqfhighlighter-'''codeend'''
| ce
| <sqf>...}</sqf>
| <sqf>/* ... */ }</sqf>
|-
|-
| parenthese start ({{hl|{<nowiki/>}})
| parenthese start ({{hl|{<nowiki/>}})
| sqfhighlighter-'''parenthesestart'''
| ps
| <sqf>(...</sqf>
| <sqf>( /* ... */</sqf>
|-
|-
| parenthese end ({{hl|}<nowiki/>}})
| parenthese end ({{hl|}<nowiki/>}})
| sqfhighlighter-'''parentheseend'''
| pe
| <sqf>...)</sqf>
| <sqf>/* ... */ )</sqf>
|}
|}


Line 217: Line 357:


{| class="wikitable sortable"
{| class="wikitable sortable"
! class="unsortable" | Version
! class="unsortable" | Issue
! class="unsortable" | Issue
! Report Date
! Report Date
! Fix Date
! Fix Date
|-
|-
! rowspan="5" | v1
| comment blocks still highlight words as global variables for now
| comment blocks still highlight words as global variables for now
| 2022-03-15
| 2022-03-15
Line 231: Line 373:
| single-quote strings have issues with other formatting between quotes
| single-quote strings have issues with other formatting between quotes
| 2022-03-15
| 2022-03-15
| {{n/a}}
| w/ '''v2'''
|-
|-
| negative numbers should see the minus sign coloured as well<br>''in the end, they should not''
| negative numbers should see the minus sign coloured as well<br>''in the end, they should not''
| 2022-03-15
| 2022-03-15
| 2022-03-17
| 2022-03-17
|-
| numbers in variables are highlighted as numbers (e.g {{hl|unit'''1'''}})
| 2022-03-22
| w/ '''v2'''
|-
! rowspan="1" | v2
| preprocessor instructions are not considered if not at the very beginning of the line (and the parsing of the whole line may be wrong)
| 2022-07-11
| 2022-07-12
|}
|}


{{Feature|informative|report other issues on [https://discord.gg/arma Discord]!}}
{{Feature|informative|Report issues on {{Link|https://discord.gg/arma|Discord}}, in the {{hl|#community_wiki}} channel!}}
 
 
[[Category: MediaWiki Extension]]

Latest revision as of 14:47, 23 April 2024

SQF Highlighter
Description Highlights and links SQF commands and functions
Author Lou Montana
Project Start 2022-03-08: Project start
Release Date
  • 2022-03-12: "v1" (0.50b), first upload
  • 2022-07-11: "v2" (0.85b), new parser
  • 2023-11-02: 0.9b, allow some wiki formatting in comments
Version 0.9b

This extension highlights and automatically links SQF commands and functions. It also covers SQS (free of charge).



Features

  • SQF Syntax support
  • SQS Syntax support
  • "Copy code to clipboard" button on hover
  • Partial wiki formatting in comments: ''italic'', '''bold''', <s>striked</s>, <u>underlined</u>, [[links|even styled ones]], {{templates}}
  • #defined constant value on mouse hover
  • SQF tag button in the wiki edit toolbar (next to B and I)
  • Options:
    • inline for inline code
    • notrim to remove the auto trim (lines themselves will always be rtrimmed)
  • Categorises wrong code pages in Category:Pages with SQF errors and Category:Pages with SQS errors


Installation

  • Unzip the directory to wiki/extensions/SQFHighlighter
  • Add wfLoadExtension( 'SQFHighlighter' ); to LocalSettings.php
  • there is a case-sensitive setting in extension.json (default true). Set to false to highlight improperly-cased commands and functions (e.g setDaMMage instead of setDammage, etc)
  • The extension creates full path links unless the host is one of the following (then relative links are created):
    • community.bistudio.com
    • community.bohemia.net


Usage

Using <sqf> tags will auto-generate syntax highlighting and links to the pages.

Examples
SQF Syntax
Code Result
<sqf/>
-no SQF code provided-
<sqf></sqf>
-no SQF code provided-
<sqf> </sqf>
-no SQF code provided-
<sqf>hint "It Works!";</sqf>
hint "It Works!";
This is <sqf inline>hint "It Works!";</sqf> absolutely inline.
This is hint "It Works!"; absolutely inline.
<sqf notrim>

	hint "It Works!";


</sqf>
hint "It Works!";
<sqf>
// your code here
hint "good!";
</sqf>
// your code here hint "good!";
<sqf>
#define fadeInDuration 3

waitUntil { not alive player };
hint DEATH_MESSAGE;
cutText ["", "Black", playerRespawnTime];

private _deathTime = time;
Deaths = Deaths + 1;

/*
	wait for resurrection - see {{Link|Arma 3: Respawn}}
*/
waitUntil { alive player && { preloadCamera getPosATL player } };

sleep 3;
cutText ["Welcome!", "Black in", fadeInDuration];

// after 10s, end the mission
sleep 10;
[] call BIS_fnc_endMission;
</sqf>
#define fadeInDuration 3 waitUntil { not alive player }; hint DEATH_MESSAGE; cutText ["", "Black", playerRespawnTime]; private _deathTime = time; Deaths = Deaths + 1; /* wait for resurrection - see Arma 3: Respawn */ waitUntil { alive player && { preloadCamera getPosATL player } }; sleep 3; cutText ["Welcome!", "Black in", fadeInDuration]; // after 10s, end the mission sleep 10; [] call BIS_fnc_endMission;
SQS Syntax
Code Result
<sqs/>
-no SQS code provided-
<sqs></sqs>
-no SQS code provided-
<sqs> </sqs>
-no SQS code provided-
<sqs>hint "It Works!"</sqs>
hint "It Works!";
This is <sqs inline>hint "It Works!"</sqs> absolutely inline.
This is hint "It Works!" absolutely inline.
<sqs notrim>

	hint "It Works!";


</sqs>
hint "It Works!";
<sqs>
#loop
@ alive player
; you ok - see [[getDammage]] too
hint "OK"
~1
@ not alive player
~1
hint "you ded"
; you not ok
goto "loop"
</sqs>
#loop @ alive player ; you ok - see getDammage too hint "OK" ~1 @ not alive player ~1 hint "you ded" ; you not ok goto "loop"


CSS Classes

All elements are <span> except for some exceptions:

  • unless using <sqf inline>, the parent block is a <div> holding another one for scrolling purpose; otherwise, is is a <span> as well.
Element CSS class Overview
parent block sqfhighlighter-block
contains sqfhighlighter-scroller for blocks
;
error message sqfhighlighter-error
-no SQF code provided-

-no SQS code provided-
wild character / bad variable / unclosed string bv, bvl
@ private _var = 3RndMag; hint "hello
comment cc
// comment /* this is a multiline comment */
comment bold b
// bold comment
string s
"string"
stringtable string ss
"STR_entry" "str_entry" "sTr_entry" "STRD_entry" "STRM_entry" "$STR_entry"
number n
42 -6.9 10e10
operator o
a + b
keyword (if, then, waitUntil, etc) k
command c
function f
function (external) fe
// not just considering BIS_ or BIN_ BIS_fnc_unknownFunction TAG_fnc_spawnGroup
local variable lv
_localVar
global variable gv
// anything will go but UNDERSCORED_ALL_CAPS GlobalVar = 1;
macro m
#define myVar 1 #if #endif
constant (#defined value) c
// anything #defined only #define testVar 1 testVar; otherVar; MY_CONSTANT;
array start ([) as
[ /* ... */
array end (]) ae
/* ... */ ]
code start ({) cs
{ /* ... */
code end (}) ce
/* ... */ }
parenthese start ({) ps
( /* ... */
parenthese end (}) pe
/* ... */ )


Known Issues

Version Issue Report Date Fix Date
v1 comment blocks still highlight words as global variables for now 2022-03-15 2022-03-17
#if are considered as keywords 2022-03-15 2022-03-17
single-quote strings have issues with other formatting between quotes 2022-03-15 w/ v2
negative numbers should see the minus sign coloured as well
in the end, they should not
2022-03-15 2022-03-17
numbers in variables are highlighted as numbers (e.g unit1) 2022-03-22 w/ v2
v2 preprocessor instructions are not considered if not at the very beginning of the line (and the parsing of the whole line may be wrong) 2022-07-11 2022-07-12
Report issues on Discord, in the #community_wiki channel!