Repository: joernio/joern (scala)

Issue:
[Bug][rubySrc2cpg] - ternary operator with regex
Describe the bug
getting parser error -  ` no viable alternative at input ' =~ /filename="(.*)"/ ?`

To Reproduce

```
filename = content_filename =~ /filename="(.*)"/ ? $1 : id
```

Pull request description:
Closes #3186

Patch:
diff --git a/joern-cli/frontends/rubysrc2cpg/src/main/antlr4/io/joern/rubysrc2cpg/parser/RubyLexer.g4 b/joern-cli/frontends/rubysrc2cpg/src/main/antlr4/io/joern/rubysrc2cpg/parser/RubyLexer.g4
index 73601fd85dfb..723641847a7b 100644
--- a/joern-cli/frontends/rubysrc2cpg/src/main/antlr4/io/joern/rubysrc2cpg/parser/RubyLexer.g4
+++ b/joern-cli/frontends/rubysrc2cpg/src/main/antlr4/io/joern/rubysrc2cpg/parser/RubyLexer.g4
@@ -462,6 +462,7 @@ LOCAL_VARIABLE_IDENTIFIER
 
 GLOBAL_VARIABLE_IDENTIFIER
     :   '$' IDENTIFIER_START_CHARACTER IDENTIFIER_CHARACTER*
+    |   '$' [0-9]+
     ;
 
 INSTANCE_VARIABLE_IDENTIFIER


Test patch:
diff --git a/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/parser/RubyLexerTests.scala b/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/parser/RubyLexerTests.scala
index 892f58fe6a98..c2e2096d5c67 100644
--- a/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/parser/RubyLexerTests.scala
+++ b/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/parser/RubyLexerTests.scala
@@ -302,6 +302,20 @@ class RubyLexerTests extends AnyFlatSpec with Matchers {
     )
   }
 
+  "Non-empty regex literal on the RHS of an regex matching operation" should "be recognized as such" in {
+    val code = """content_filename =~ /filename="(.*)"/"""
+    tokenize(code) shouldBe Seq(
+      LOCAL_VARIABLE_IDENTIFIER,
+      WS,
+      EQTILDE,
+      WS,
+      REGULAR_EXPRESSION_START,
+      REGULAR_EXPRESSION_BODY,
+      REGULAR_EXPRESSION_END,
+      EOF
+    )
+  }
+
   "Regex literals without metacharacters" should "be recognized as such" in {
     val eg = Seq("/regexp/", "/a regexp/")
     all(eg.map(tokenize)) shouldBe Seq(REGULAR_EXPRESSION_START, REGULAR_EXPRESSION_BODY, REGULAR_EXPRESSION_END, EOF)
@@ -603,4 +617,9 @@ class RubyLexerTests extends AnyFlatSpec with Matchers {
       EOF
     )
   }
+
+  "Regex match global variables" should "be recognized as such" in {
+    val eg = Seq("$0", "$10", "$2", "$3")
+    all(eg.map(tokenize)) shouldBe Seq(GLOBAL_VARIABLE_IDENTIFIER, EOF)
+  }
 }