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

Add Rez #6524

Merged
merged 13 commits into from
Sep 7, 2023
Merged

Add Rez #6524

merged 13 commits into from
Sep 7, 2023

Conversation

cooljeanius
Copy link
Contributor

@cooljeanius cooljeanius commented Aug 21, 2023

Description

See issue #6107

Checklist:

add one for Rez (could use some more, though)
@uliwitness
Copy link

uliwitness commented Aug 21, 2023

If you're looking for a color: R has blue and grey, so I'd say pick one of the remaining colors from the ResEdit icon, which seem to be green (00CE00), red (E60100), or a light salmon ("flesh") color (FFDAB3).

For detecting, the most common resource types are probably 'vers', 'SIZE', 'ICON', 'cicn', 'ICN#', 'icns', 'BNDL', 'DITL', 'DLOG', 'ALRT', 'MENU', 'CURS' and 'PICT'. Might also be worth looking for resource '****' (with **** being a pattern, 4 characters) and data '****', and maybe #include <Types.r> and #include <Carbon/Carbon.r>.

@cooljeanius
Copy link
Contributor Author

If you're looking for a color: R has blue and grey, so I'd say pick one of the remaining colors from the ResEdit icon, which seem to be green (00CE00), red (E60100), or a light salmon ("flesh") color (FFDAB3).

OK, I counted how many pixels of each there were in the icon:

  • green (both 00CE00 and a slightly different shade): 7
  • E60100: 24
  • FFDAB3: 44

This suggests to me that we should go with the last of the 3.

For detecting, the most common resource types are probably 'vers', 'SIZE', 'ICON', 'cicn', 'ICN#', 'icns', 'BNDL', 'DITL', 'DLOG', 'ALRT', 'MENU', 'CURS' and 'PICT'. Might also be worth looking for resource '****' (with **** being a pattern, 4 characters) and data '****', and maybe #include <Types.r> and #include <Carbon/Carbon.r>.

OK, could I get some help with a regex to catch all of those? I'm not very good with regexes...

@cooljeanius cooljeanius marked this pull request as ready for review August 21, 2023 20:29
@cooljeanius cooljeanius requested a review from a team as a code owner August 21, 2023 20:29
@uliwitness
Copy link

Actually, this might be a better heuristic:

(resource|data|type)\s+'[A-Za-z0-9]{4}'\s+((\(.*\)\s){0,1})+{

That will basically catch the first line of a resource declaration, as long as they don't have extra line breaks.

@uliwitness
Copy link

For detecting some common types, one would do

'(ICON|BNDL|vers|SIZE|cicn|ICN#|icns|DITL|DLOG|ALRT|MENU|MBAR|CURS|PICT|cfrg|thng)'

@uliwitness
Copy link

To detect the includes one would do

#include\s+["<](Types\.r|Carbon/Carbon\.r)[">]

I guess detecting any of these three regexes could be seen to indicate that it's a Rez file. So maybe something like:

(#include\s+["<](Types\.r|Carbon/Carbon\.r)[">])|('(ICON|BNDL|vers|SIZE|cicn|ICN#|icns|DITL|DLOG|ALRT|MENU|MBAR|CURS|PICT|cfrg|thng)')|((resource|data|type)\s+'[A-Za-z0-9]{4}'\s+((\(.*\)\s){0,1})+{)

should probably catch something in most files. Though some of these might give false positives if the files don't have the '.r' suffix. That said, I haven't seen an R source file yet, so we might wanna check that none of these are valid/common in that other language.

@cooljeanius
Copy link
Contributor Author

To detect the includes one would do

#include\s+["<](Types\.r|Carbon/Carbon\.r)[">]

I guess detecting any of these three regexes could be seen to indicate that it's a Rez file. So maybe something like:

(#include\s+["<](Types\.r|Carbon/Carbon\.r)[">])|('(ICON|BNDL|vers|SIZE|cicn|ICN#|icns|DITL|DLOG|ALRT|MENU|MBAR|CURS|PICT|cfrg|thng)')|((resource|data|type)\s+'[A-Za-z0-9]{4}'\s+((\(.*\)\s){0,1})+{)

should probably catch something in most files. Though some of these might give false positives if the files don't have the '.r' suffix. That said, I haven't seen an R source file yet, so we might wanna check that none of these are valid/common in that other language.

There are some examples of R sources in linguist's samples directory, if you want to take a look

@uliwitness
Copy link

uliwitness commented Aug 23, 2023

OK, the import.r sample file in there has single-quoted strings like 'name'. While I haven't seen 'ICON' or the like yet, we should probably remove that part from the regex and just look for actual syntax, conservatively:

(#include\s+["<](Types\.r|Carbon/Carbon\.r)[">])|((resource|data|type)\s+'[A-Za-z0-9]{4}'\s+((\(.*\)\s+){0,1}){)

@uliwitness
Copy link

uliwitness commented Aug 23, 2023

Oh, I also think I overlooked how one specifies a resource name in Rez.

Update: It's fine, the name is inside the parentheses where the ID is, so we correctly parse that case too: resource 'SIZE' (-1, "Our SIZE -1") {

@cooljeanius
Copy link
Contributor Author

OK, the import.r sample file in there has single-quoted strings like 'name'. While I haven't seen 'ICON' or the like yet, we should probably remove that part from the regex and just look for actual syntax, conservatively:

(#include\s+["<](Types\.r|Carbon/Carbon\.r)[">])|((resource|data|type)\s+'[A-Za-z0-9]{4}'\s+((\(.*\)\s){0,1})+{)

ok, so does that need to be quoted, or can it just be pasted as-is? Generally the other regexes in heuristics.yml are surrounded by single-quotes, and I see single-quotes in that string, so I wonder if they'll need to be escaped?

@uliwitness
Copy link

uliwitness commented Aug 26, 2023

Oh yeah since that uses YAML and that single-quotes these regexes, you'll prolly have to escape the backslashes and the single quotes, good catch. So the entire, quoted regex should be something like:

'(#include\\s+["<](Types\\.r|Carbon/Carbon\\.r)[">])|((resource|data|type)\\s+\'[A-Za-z0-9]{4}\'\\s+((\\(.*\\)\\s+){0,1}){)'

Improved Rez detection from @uliwitness
@cooljeanius
Copy link
Contributor Author

Oh yeah since that uses YAML and that single-quotes these regexes, you'll prolly have to escape the backslashes and the single quotes, good catch. So the entire, quoted regex should be something like:

'(#include\\s+["<](Types\\.r|Carbon/Carbon\\.r)[">])|((resource|data|type)\\s+\'[A-Za-z0-9]{4}\'\\s+((\\(.*\\)\\s+){0,1}){)'

OK thanks, I made this the regex in 2837cbc. Unfortunately bundler is giving me some issues that are preventing me from testing locally, so hopefully a maintainer will let the CI workflows run...

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

See comments inline.

Please remove or replace the two large samples that are currently collapsed in the PR view; they're too big with the icons file mostly filled stuff that isn't relevant to the language.

We also need the cached license file the script/add-grammar should have downloaded when your added the grammar.

lib/linguist/heuristics.yml Outdated Show resolved Hide resolved
lib/linguist/languages.yml Outdated Show resolved Hide resolved
remove `.rez` extension due to no examples of it being present; resolves review comment
backslashes don't need to be escaped, apparently, so stop doubling up on them
@cooljeanius
Copy link
Contributor Author

See comments inline.

OK, addressed.

Please remove or replace the two large samples that are currently collapsed in the PR view; they're too big with the icons file mostly filled stuff that isn't relevant to the language.

Removed in 769cf15.

We also need the cached license file the script/add-grammar should have downloaded when your added the grammar.

Hm, I guess I should just re-run the script then, if I'm not seeing it?

I tried rerunning `scripts/grammar`, but it did some other weird stuff, so I had to stash its other changes. It left this behind, though, which is hopefully what was requested in the PR
@cooljeanius
Copy link
Contributor Author

We also need the cached license file the script/add-grammar should have downloaded when your added the grammar.

Hm, I guess I should just re-run the script then, if I'm not seeing it?

OK, re-ran; is the file added in dadde18 what you were requesting?

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

OK, re-ran; is the file added in dadde18 what you were requesting?

Yup. That's the one.

lib/linguist/heuristics.yml Outdated Show resolved Hide resolved
lib/linguist/heuristics.yml Outdated Show resolved Hide resolved
Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

I've rectified the last of the issues and all looks good now. Usage appears high enough for inclusion too 👍

@lildude lildude added this pull request to the merge queue Sep 7, 2023
Merged via the queue into github-linguist:master with commit 55cfb49 Sep 7, 2023
5 checks passed
@cooljeanius cooljeanius deleted the rez_take_3 branch September 8, 2023 13:48
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants