Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sqf.js to match latest changes in Arma 3 v2.11 #3686

Merged
merged 1 commit into from Mar 19, 2023

Conversation

Leopard20
Copy link
Contributor

@Leopard20 Leopard20 commented Jan 7, 2023

Changes

  • Added new commands
  • Removed invalid commands
  • Removed # as an illegal character (legal as of Arma 3 v1.82)

This is a follow up to #3193. It was quite outdated so I opened a new one. It also applies the requested changes to make it not fail the detection asserts.

P.S: I think GitHub's diff is broken because it shows the entire file has changed. It looks correct in VSCode though.

src/languages/sqf.js Outdated Show resolved Hide resolved
src/languages/sqf.js Outdated Show resolved Hide resolved
className: 'meta',
begin: /#\s*[a-z]+\b/,
end: /$/,
keywords: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this could collapse to just keywords a nested hash isn't necessary if one isn't specified keyword is the default scope used.

// https://community.bistudio.com/wiki/PreProcessor_Commands
const PREPROCESSOR = {
className: 'meta',
begin: /#\s*[a-z]+\b/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to start at the beginning of a line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to start at the beginning of a line?

Whitespaces are allowed too. Will update this too.

],
illegal: [
//$ is only valid when used with Hex numbers (e.g. $FF) or at the beginning of localized strings (e.g. "$STR_HELLO")
/\$[^Sa-fA-F0-9]/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the S here?

Copy link
Contributor Author

@Leopard20 Leopard20 Jan 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the S here?

I wasn't sure if it would flag a string like "$STR_bla" as illegal. (which are localized strings)
It was just my lazy attempt to prevent it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I yet follow how one knows it's a localized string - they alway have a $STR prefix? If it's actually quoted though then it's already handled by STRINGS rule and doesn't need to be guarded against here since its inside the string scope already, unless I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I yet follow how one knows it's a localized string - they alway have a $STR prefix? If it's actually quoted though then it's already handled by STRINGS rule and doesn't need to be guarded against here since its inside the string scope already, unless I'm missing something?

Yeah if the string rule prevents it I should remove it. I didn't actually test this to be sure.

src/languages/sqf.js Outdated Show resolved Hide resolved
'waitUntil', 'while', 'with'
];

const LITERAL = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a LOT of literals. Consider variable.constant and variable.language perhaps... pi (if it's math) seems like a reference to a literal (a constant), not a literal itself.

I won't force any changes here since I dunno the language, but just making you aware we have more scopes to differentiate these sorts of things.

Copy link
Contributor Author

@Leopard20 Leopard20 Jan 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a LOT of literals. Consider variable.constant and variable.language perhaps... pi (if it's math) seems like a reference to a literal (a constant), not a literal itself.

I won't force any changes here since I dunno the language, but just making you aware we have more scopes to differentiate these sorts of things.

Technically they're all commands (so they should be part of built-in array). They're what we call "nular (sic) commands" (commands with no left or right params, i.e. they behave like functions with no params or sometimes global variables)
Again this is from previous contributions so I didn't want to change them.

Could you point me to the list of scopes you guys have?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html

Technically they're all commands (so they should be part of built-in array).

Let's not do that. :-). For first party grammars we take a "wider perspective" view of such things. Literal concepts that are non-reducible like true, false, null, nil, undefined... these are considered literals. We prefer consistency in this across our grammars - rather than adhering to any particular grammars technicalities.

Since pi is simply a label for 3.1459 etc it would be better thought of as a variable.constant... and the fact that what provides that is a function pi() doesn't really change that "wider perspective" categorization.

@Dahlgren
Copy link

Dahlgren commented Jan 7, 2023

P.S: I think GitHub's diff is broken because it shows the entire file has changed. It looks correct in VSCode though.

Your new file has different line endings on most/all lines, resave with same as the previous version

src/languages/sqf.js Outdated Show resolved Hide resolved
@@ -2506,7 +2629,7 @@ export default function(hljs) {
hljs.C_BLOCK_COMMENT_MODE
]
};

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

'worldToScreen',
];
'worldToScreen'
];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
];
];

@@ -2424,7 +2543,7 @@ export default function(hljs) {
'vestMagazines',
'viewDistance',
'visibleCompass',
'visibleGPS',
'visibleGps',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'visibleGps',
'visibleGPS',

https://community.bistudio.com/wiki/visibleGPS

'getUserMFDText',
'getUserMFDValue',
'getVariable',
'getVehicleCargo',
'getVehicleTIPars',
'getVehicleTiPars',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'getVehicleTiPars',
'getVehicleTIPars',

https://community.bistudio.com/wiki/getVehicleTIPars

'setTimeMultiplier',
'setTiParameter',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'setTiParameter',
'setTIParameter',

https://community.bistudio.com/wiki/setTIParameter

'setVehicleLock',
'setVehiclePosition',
'setVehicleRadar',
'setVehicleReceiveRemoteTargets',
'setVehicleReportOwnPosition',
'setVehicleReportRemoteTargets',
'setVehicleTIPars',
'setVehicleTiPars',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'setVehicleTiPars',
'setVehicleTIPars',

https://community.bistudio.com/wiki/setVehicleTIPars

@@ -2147,7 +2269,7 @@ export default function(hljs) {
'showCommandingMenu',
'showCompass',
'showCuratorCompass',
'showGPS',
'showGps',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'showGps',
'showGPS',

https://community.bistudio.com/wiki/showGPS

src/languages/sqf.js Show resolved Hide resolved
Comment on lines 136 to 137
'sideLogic',
'sideUnknown',
'sideEnemy',
'sideFriendly',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in alphabetic order

@Leopard20
Copy link
Contributor Author

Leopard20 commented Jan 7, 2023

I'm not gonna update this PR beyond this point, because it took way more time that I wanted to invest in it.

The point was to update the SQF commands list and fix the highlighter breaking when you put # (easily reproducible on Discord looks like it's been fixed).

Further changes to other stuff can be made in future contributions.

Regarding the spelling changes, like I said they come from the game itself, not the wiki. I prefer to keep it as the game says, which is more correct.

@joshgoebel
Copy link
Member

Indeed, case_insensitive: true, so the exact casing doesn't matter - using what the language provides for easier maintenance on our end makes the most sense.

@joshgoebel
Copy link
Member

Whatever you did with line endings made this almost impossible to rebase cleanly. I finally just gave up and went with git diff x..y | patch to squash the whole history - then made another pass at converting any remaining tabs to spaces. I tried to make sure you were still noted as the committer of record.

@joshgoebel joshgoebel merged commit 909ba4e into highlightjs:main Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants