Skip to content

Commit

Permalink
#250 Recognize regular expressions at start or after '>' in JavaScrip…
Browse files Browse the repository at this point in the history
…t when lexer is cpp,

hypertext, or xml.
  • Loading branch information
zufuliu authored and nyamatongwe committed Jun 1, 2024
1 parent 01facba commit 85d1d67
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions doc/LexillaHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ <h3>
Released 23 April 2024.
</li>
<li>
JavaScript: Recognize regular expressions at start or after '&gt;' in JavaScript when lexer is cpp,
hypertext, or xml.
<a href="https://github.com/ScintillaOrg/lexilla/issues/250">Issue #250</a>,
<a href="https://sourceforge.net/p/scintilla/bugs/918/">Bug #918</a>.
</li>
<li>
Lua: Fix non-ASCII identifiers joined with '.' or ':'.
<a href="https://github.com/ScintillaOrg/lexilla/issues/242">Issue #242</a>.
</li>
Expand Down
2 changes: 1 addition & 1 deletion lexers/LexCPP.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i
const StyleContext::Transform transform = caseSensitive ?
StyleContext::Transform::none : StyleContext::Transform::lower;

const CharacterSet setOKBeforeRE("([{=,:;!%^&*|?~+-");
const CharacterSet setOKBeforeRE("([{=,:;!%^&*|?~+-> ");
const CharacterSet setCouldBePostOp("+-");

const CharacterSet setDoxygen(CharacterSet::setAlpha, "$@\\&<>#{}[]");
Expand Down
2 changes: 1 addition & 1 deletion lexers/LexHTML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", true);
const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", true);
// TODO: also handle + and - (except if they're part of ++ or --) and return keywords
const CharacterSet setOKBeforeJSRE(CharacterSet::setNone, "([{=,:;!%^&*|?~");
const CharacterSet setOKBeforeJSRE(CharacterSet::setNone, "([{=,:;!%^&*|?~> ");
// Only allow [A-Za-z0-9.#-_:] in entities
const CharacterSet setEntity(CharacterSet::setAlphaNum, ".#-_:");

Expand Down
3 changes: 3 additions & 0 deletions test/examples/cpp/x.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ int main() {
// JavaScript regular expression (14) tests
let a = /a/;
let b = /[a-z]+/gi;
/a|b/i.test("baby");
// arrow function
() => /a|b/i.test("baby");

// Escape sequence (27) tests
printf("\'\"\?\\\a\b\f\n\r\t\v \P");
Expand Down
3 changes: 3 additions & 0 deletions test/examples/cpp/x.cxx.folded
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
0 401 401 | // JavaScript regular expression (14) tests
0 401 401 | let a = /a/;
0 401 401 | let b = /[a-z]+/gi;
0 401 401 | /a|b/i.test("baby");
0 401 401 | // arrow function
0 401 401 | () => /a|b/i.test("baby");
1 401 401 |
0 401 401 | // Escape sequence (27) tests
0 401 401 | printf("\'\"\?\\\a\b\f\n\r\t\v \P");
Expand Down
3 changes: 3 additions & 0 deletions test/examples/cpp/x.cxx.styled
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
{2}// JavaScript regular expression (14) tests
{0} {5}let{0} {11}a{0} {10}={0} {14}/a/{10};{0}
{5}let{0} {11}b{0} {10}={0} {14}/[a-z]+/gi{10};{0}
{14}/a|b/i{10}.{11}test{10}({6}"baby"{10});{0}
{2}// arrow function
{0} {10}(){0} {10}=>{0} {14}/a|b/i{10}.{11}test{10}({6}"baby"{10});{0}

{2}// Escape sequence (27) tests
{0} {11}printf{10}({6}"{27}\'\"\?\\\a\b\f\n\r\t\v{6} {27}\P{6}"{10});{0}
Expand Down
5 changes: 5 additions & 0 deletions test/examples/hypertext/Issue250RegEx.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
/a|b/i.test("baby");
// arrow function
() => /a|b/i.test("baby");
</script>
6 changes: 6 additions & 0 deletions test/examples/hypertext/Issue250RegEx.html.folded
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
2 400 0 + <script>
0 401 0 | /a|b/i.test("baby");
0 401 0 | // arrow function
0 401 0 | () => /a|b/i.test("baby");
0 401 0 | </script>
0 400 0
5 changes: 5 additions & 0 deletions test/examples/hypertext/Issue250RegEx.html.styled
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{1}<script>{40}
{52}/a|b/i{46}.test{50}({48}"baby"{50});{41}
{43}// arrow function{41}
{50}(){41} {50}=>{41} {52}/a|b/i{46}.test{50}({48}"baby"{50});{41}
{1}</script>{0}

0 comments on commit 85d1d67

Please sign in to comment.