Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

feat: PRCE-compliant RegEx updates for GitHub Linguist #57

Merged
merged 11 commits into from
Mar 15, 2023
118 changes: 59 additions & 59 deletions grammars/apex.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1914,15 +1914,15 @@
<dict>
<key>begin</key>
<string>(?x)
(?&lt;type-name&gt;
(?&lt;type_name&gt;
Copy link

@jeffb-sfdc jeffb-sfdc Feb 23, 2023

Choose a reason for hiding this comment

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

Dumb question: should everything between a <string></string> be changed from foo-bar to foo_bar? (or is it only that which starts with (?x)?)

If yes, what about line 1909, line 1899, etc...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@muenzpraeger can you help answer this, given the update needs for Github Linguist?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are no dumb questions. ;-) Especially not with this change. It took me a while to find this small statement in the PCRE docs for named capture groups.

When PCRE2_UTF is not set, they may contain only ASCII alphanumeric characters and underscores, but must start with a non-digit.

So yes, the change only applies to (?<the_name>).

Also the source of the changes is src/apex.tmLanguage.yml, which is the source definition for this TextMate grammar. Looking at that will make it clearer.

The grammar outputs in the grammars folder are auto-generated via gulp.

(?:
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
Copy link

@jeffb-sfdc jeffb-sfdc Feb 23, 2023

Choose a reason for hiding this comment

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

Another dumb questions: Should alias-qualification on line 1920 be alias_qualification?
(also on line 1993, and others)

Or is that a comment, and it doesn't matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@muenzpraeger same question here

\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -1985,25 +1985,25 @@
<key>begin</key>
<string>(?x)
(?!.*\b(?:class|interface|enum)\b)\s*
(?&lt;return-type&gt;
(?&lt;type-name&gt;
(?&lt;return_type&gt;
(?&lt;type_name&gt;
(?:
(?:ref\s+)? # ref return
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
)
)\s+
)
(?&lt;interface-name&gt;\g&lt;type-name&gt;\s*\.\s*)?
(?&lt;property-name&gt;\g&lt;identifier&gt;)\s*
(?&lt;interface_name&gt;\g&lt;type_name&gt;\s*\.\s*)?
(?&lt;property_name&gt;\g&lt;identifier&gt;)\s*
(?=\{|=&gt;|$)</string>
<key>beginCaptures</key>
<dict>
Expand Down Expand Up @@ -2067,25 +2067,25 @@
<dict>
<key>begin</key>
<string>(?x)
(?&lt;return-type&gt;
(?&lt;type-name&gt;
(?&lt;return_type&gt;
(?&lt;type_name&gt;
(?:
(?:ref\s+)? # ref return
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
)
)\s+
)
(?&lt;interface-name&gt;\g&lt;type-name&gt;\s*\.\s*)?
(?&lt;indexer-name&gt;this)\s*
(?&lt;interface_name&gt;\g&lt;type_name&gt;\s*\.\s*)?
(?&lt;indexer_name&gt;this)\s*
(?=\[)</string>
<key>beginCaptures</key>
<dict>
Expand Down Expand Up @@ -2205,24 +2205,24 @@
<dict>
<key>begin</key>
<string>(?x)
(?&lt;return-type&gt;
(?&lt;type-name&gt;
(?&lt;return_type&gt;
(?&lt;type_name&gt;
(?:
(?:ref\s+)? # ref return
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
)
)\s+
)
(?&lt;interface-name&gt;\g&lt;type-name&gt;\s*\.\s*)?
(?&lt;interface_name&gt;\g&lt;type_name&gt;\s*\.\s*)?
(\g&lt;identifier&gt;)\s*
(&lt;([^&lt;&gt;]+)&gt;)?\s*
(?=\()</string>
Expand Down Expand Up @@ -3235,15 +3235,15 @@
<dict>
<key>match</key>
<string>(?x)
(?&lt;type-name&gt;
(?&lt;type_name&gt;
(?:
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -3305,16 +3305,16 @@
<string>(?x)
(?:
(?:(\bref)\s+)?(\bvar\b)| # ref local
(?&lt;type-name&gt;
(?&lt;type_name&gt;
(?:
(?:ref\s+)? # ref local
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -3383,16 +3383,16 @@
<dict>
<key>begin</key>
<string>(?x)
(?&lt;const-keyword&gt;\b(?:const)\b)\s*
(?&lt;type-name&gt;
(?&lt;const_keyword&gt;\b(?:const)\b)\s*
(?&lt;type_name&gt;
(?:
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -3796,15 +3796,15 @@
<key>match</key>
<string>(?x)
(\()\s*
(?&lt;type-name&gt;
(?&lt;type_name&gt;
(?:
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -3858,7 +3858,7 @@
<string>(?x)
(?:(\??\.)\s*)? # safe navigator or accessor
(@?[_[:alpha:]][_[:alnum:]]*)\s* # method name
(?&lt;type-args&gt;\s*&lt;([^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?\s* # type arguments
(?&lt;type_args&gt;\s*&lt;([^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?\s* # type arguments
(?=\() # open paren of argument list</string>
<key>beginCaptures</key>
<dict>
Expand Down Expand Up @@ -3985,7 +3985,7 @@
<string>(?x)
(\??\.)?\s*
(@?[_[:alpha:]][_[:alnum:]]*)
(?&lt;type-params&gt;\s*&lt;([^&lt;&gt;]|\g&lt;type-params&gt;)+&gt;\s*)
(?&lt;type_params&gt;\s*&lt;([^&lt;&gt;]|\g&lt;type_params&gt;)+&gt;\s*)
(?=
(\s*\?)?
\s*\.\s*@?[_[:alpha:]][_[:alnum:]]*
Expand Down Expand Up @@ -4066,15 +4066,15 @@
<string>(?x)
(delete|insert|undelete|update|upsert)?
\s*(new)\s+
(?&lt;type-name&gt;
(?&lt;type_name&gt;
(?:
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -4124,15 +4124,15 @@
<string>(?x)
(delete|insert|undelete|update|upsert)?
\s*(new)\s+
(?&lt;type-name&gt;
(?&lt;type_name&gt;
(?:
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -4172,15 +4172,15 @@
<key>begin</key>
<string>(?x)
\b(new)\b\s*
(?&lt;type-name&gt;
(?&lt;type_name&gt;
(?:
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down Expand Up @@ -4266,16 +4266,16 @@
<key>match</key>
<string>(?x)
(?:(?:\b(this)\b)\s+)?
(?&lt;type-name&gt;
(?&lt;type_name&gt;
(?:
(?:ref\s+)? # ref return
(?:
(?:(?&lt;identifier&gt;@?[_[:alpha:]][_[:alnum:]]*)\s*\:\:\s*)? # alias-qualification
(?&lt;name-and-type-args&gt; # identifier + type arguments (if any)
(?&lt;name_and_type_args&gt; # identifier + type arguments (if any)
\g&lt;identifier&gt;\s*
(?&lt;type-args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type-args&gt;)+&gt;\s*)?
(?&lt;type_args&gt;\s*&lt;(?:[^&lt;&gt;]|\g&lt;type_args&gt;)+&gt;\s*)?
)
(?:\s*\.\s*\g&lt;name-and-type-args&gt;)*
(?:\s*\.\s*\g&lt;name_and_type_args&gt;)*
)
(?:\s*\?\s*)? # nullable suffix?
(?:\s*\[(?:\s*,\s*)*\]\s*)* # array suffix?
Expand Down
Loading