summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUriel Lizama <uriel@baboonmedia.com>2023-08-26 16:53:55 -0600
committerUriel Lizama <uriel@baboonmedia.com>2023-08-26 16:53:55 -0600
commit49b6bcde6210ead927b2a332a442d075c77b13d7 (patch)
tree60fbc0b1fd6cde75e42eeaa2f04aed3e8de651c6
parent49285ac451713012d5ead68876a38c14f23a5759 (diff)
downloadPerlNavigator-49b6bcde6210ead927b2a332a442d075c77b13d7.zip
Improved support for Dancer and Dancer2
-rw-r--r--server/src/perl/lib_bs22/pltags.pm25
-rw-r--r--syntaxes/dancer.json4
2 files changed, 24 insertions, 5 deletions
diff --git a/server/src/perl/lib_bs22/pltags.pm b/server/src/perl/lib_bs22/pltags.pm
index 5b7871a..1bd8794 100644
--- a/server/src/perl/lib_bs22/pltags.pm
+++ b/server/src/perl/lib_bs22/pltags.pm
@@ -109,6 +109,7 @@ sub CleanForBalanced {
# $input =~ s@\s//(\n|\s)@ ||$1@g;
$input =~ s/[^\x00-\x7F]/ /g;
$input =~ s/->@\*/ /g;
+ $input =~ s/qr\{[^\}]+\}/ /g;
# A different approach to keep around; Remove everything except the bare minimum. Will do bracket matching and anything that impacts the interpretation of those brackets (e.g. regex, quotes, comments).
#$input =~ s/[^\{\}#\\\/"'`]/ /g;
@@ -324,14 +325,32 @@ sub build_pltags {
}
elsif (($sActiveOO->{"Dancer"} or $sActiveOO->{"Dancer2"} or $sActiveOO->{"Mojolicious::Lite"}) and
- $stmt=~/^(?:get|any|post|put|delete)\s+(?:[\s\w,\[\]'"]+=>\h*)?(['"])(\/[\w\/:\-]*)\1\s*=>\s*sub/) { # Routing paths
- my $route = $2;
+ $stmt=~/^(?:any|before\_route)\s+\[([^\]]+)\]\s+(?:=>\h*)?(['"])([^\2]+)\2\s*=>\s*sub/) { # Multiple request routing paths
+ my $requests = $1;
+ if ($requests) {
+ $requests =~ s/['"\s\n]+//g;
+ }
+ my $route = "$requests $3";
+ my $end_line = SubEndLine(\@codeClean, $i, $offset);
+ MakeTag($route, "g", '', $file, "$line_number;$end_line", $package_name, \@tags);
+ }
+
+ elsif (($sActiveOO->{"Dancer"} or $sActiveOO->{"Dancer2"} or $sActiveOO->{"Mojolicious::Lite"}) and
+ $stmt=~/^(get|any|post|put|patch|delete|del|options|ajax|before_route)\s+(?:[\s\w,\[\]'"]+=>\h*)?(['"])([^\2]+)\2\s*=>\s*sub/) { # Routing paths
+ my $route = "$1 $3";
+ my $end_line = SubEndLine(\@codeClean, $i, $offset);
+ MakeTag($route, "g", '', $file, "$line_number;$end_line", $package_name, \@tags);
+ }
+
+ elsif (($sActiveOO->{"Dancer"} or $sActiveOO->{"Dancer2"} or $sActiveOO->{"Mojolicious::Lite"}) and
+ $stmt=~/^(get|any|post|put|patch|delete|del|options|ajax|before_route)\s+(qr\{[^\}]+\})\s+\s*=>\s*sub/) { # Regexp routing paths
+ my $route = "$1 $2";
my $end_line = SubEndLine(\@codeClean, $i, $offset);
MakeTag($route, "g", '', $file, "$line_number;$end_line", $package_name, \@tags);
}
elsif (($sActiveOO->{"Dancer"} or $sActiveOO->{"Dancer2"} or $sActiveOO->{"Mojolicious::Lite"}) and
- $stmt=~/^(?:hook)\s+(['"]|)(\w+)\1\s*=>\s*sub/) { # Hooks
+ $stmt=~/^(?:hook)\s+(['"]|)(\w+)\1\s*(?:=>)?\s*sub/) { # Hooks
my $hook = $2;
my $end_line = SubEndLine(\@codeClean, $i, $offset);
MakeTag($hook, "j", '', $file, "$line_number;$end_line", $package_name, \@tags);
diff --git a/syntaxes/dancer.json b/syntaxes/dancer.json
index fb08ca2..3c9ed74 100644
--- a/syntaxes/dancer.json
+++ b/syntaxes/dancer.json
@@ -15,7 +15,7 @@
"dancer": {
"patterns": [
{
- "match": "^\\s*\\b(hook)\\s+(\\w+)\\s+(?==>\\s*sub\\b)",
+ "match": "^\\s*\\b(hook)\\s+(\\w+)\\s+(?=sub\\b)",
"captures": {
"1": {
"name": "keyword.other.attribute.dancer.perl"
@@ -26,7 +26,7 @@
}
},
{
- "match": "^\\s*\\b(get|any|post|put|delete|hook)(?=.*=>\\s*sub\\b)",
+ "match": "^\\s*\\b(get|any|post|put|patch|delete|del|options|ajax|before_route)(?=.*=>\\s*sub\\b)",
"captures": {
"1": {
"name": "keyword.other.attribute.dancer.perl"