@@ -52,9 +52,33 @@ public function parseFeatureJobs(Feature $feature)
52
52
53
53
public function parseFunctionBody ($ contents , $ function )
54
54
{
55
- $ pattern = "/function\s $ function\([a-zA-Z0-9_ \$\s]+\)? " . // match "function handle(...)"
56
- '[\n\s]?[\t\s]* ' . // regardless of the indentation preceding the {
57
- '{([^{}]*)}/ ' ; // find everything within braces.
55
+ // $pattern = "/function\s$function\([a-zA-Z0-9_\$\s,]+\)?". // match "function handle(...)"
56
+ // '[\n\s]?[\t\s]*'. // regardless of the indentation preceding the {
57
+ // '{([^{}]*)}/'; // find everything within braces.
58
+
59
+ $ pattern = '~^\s*[\w\s]+\(.*\)\s*\K({((?>"[^"]*+"| \'[^ \']*+ \'|//.*$|/\*[\s\S]*?\*/|#.*$|<<<\s*[" \']?(\w+)[" \']?[^;]+\3;$|[^{}< \'"/#]++|[^{}]++|(?1))*)})~m ' ;
60
+
61
+ // '~^ \s* [\w\s]+ \( .* \) \s* \K'. # how it matches a function definition
62
+ // '('. # (1 start)
63
+ // '{'. # opening brace
64
+ // '('. # (2 start)
65
+ /* '(?>'.*/ # atomic grouping (for its non-capturing purpose only)
66
+ // '" [^"]*+ "'. # double quoted strings
67
+ // '| \' [^\']*+ \''. # single quoted strings
68
+ // '| // .* $'. # a comment block starting with //
69
+ // '| /\* [\s\S]*? \*/'. # a multi line comment block /*...*/
70
+ // '| \# .* $'. # a single line comment block starting with #...
71
+ // '| <<< \s* ["\']?'. # heredocs and nowdocs
72
+ // '( \w+ )'. # (3) ^
73
+ // '["\']? [^;]+ \3 ; $'. # ^
74
+ // '| [^{}<\'"/#]++'. # force engine to backtack if it encounters special characters [<'"/#] (possessive)
75
+ // '| [^{}]++'. # default matching bahaviour (possessive)
76
+ // '| (?1)'. # recurse 1st capturing group
77
+ // ')*'. # zero to many times of atomic group
78
+ // ')'. # (2 end)
79
+ // '}'. # closing brace
80
+ // ')~'; # (1 end)
81
+
58
82
59
83
preg_match ($ pattern , $ contents , $ match );
60
84
@@ -184,7 +208,7 @@ private function parseKeywordJobSyntax($match, $contents)
184
208
} else {
185
209
// nope it's just Space::class, we will figure
186
210
// out the namespace from a "use" statement.
187
- $ name = str_replace ('::class ' , '' , $ match );
211
+ $ name = str_replace ([ '::class ' , ' ); ' ] , '' , $ match );
188
212
preg_match ("/use\s(.* $ name)/ " , $ contents , $ namespace );
189
213
// it is necessary to have a \ at the beginning.
190
214
$ namespace = '\\' .preg_replace ('/^ \\\/ ' , '' , $ namespace [1 ]);
@@ -207,7 +231,7 @@ private function parseInitJobSyntax($match, $contents)
207
231
$ match = str_replace ('new ' , '' , $ match );
208
232
209
233
// match the job's class name
210
- preg_match ('/(.*Job).*\);/ ' , $ match , $ name );
234
+ preg_match ('/(.*Job).*[ \);]? / ' , $ match , $ name );
211
235
$ name = $ name [1 ];
212
236
213
237
// Determine Namespace
0 commit comments