[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phpinspect a93f645216 2/2: Implement parsing of string
From: |
ELPA Syncer |
Subject: |
[elpa] externals/phpinspect a93f645216 2/2: Implement parsing of string concatenation tokens |
Date: |
Wed, 21 Aug 2024 18:58:38 -0400 (EDT) |
branch: externals/phpinspect
commit a93f6452168b92dd7edcf04915817d090be90160
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>
Implement parsing of string concatenation tokens
---
phpinspect-parser.el | 34 +++++++++++++---------
phpinspect-resolvecontext.el | 1 +
phpinspect-token-predicates.el | 3 ++
test/fixtures/IncompleteClass.eld | 2 +-
test/fixtures/IncompleteClassBlockedNamespace.eld | 2 +-
.../fixtures/IncompleteClassMultipleNamespaces.eld | 2 +-
test/fixtures/IndexClass1-indexed.eld | 2 +-
test/fixtures/IndexClass2-indexed.eld | 2 +-
test/fixtures/NamespacedClass.eld | 2 +-
test/test-resolve.el | 6 ++--
10 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/phpinspect-parser.el b/phpinspect-parser.el
index dedd792524..acd0700ee8 100644
--- a/phpinspect-parser.el
+++ b/phpinspect-parser.el
@@ -283,7 +283,7 @@ root token, in string form without \":\" prefix.")
assignment-operator whitespace scope-keyword
static-keyword const-keyword use-keyword
class-keyword function-keyword word terminator
- here-doc string comment block)
+ here-doc string string-concatenator comment block)
:type list
:read-only t
:documentation "A list of symbols referring to the
@@ -448,7 +448,7 @@ parsing incrementally."
:handlers '(array tag equals list comma
attribute-reference variable assignment-operator
whitespace function-keyword word terminator here-doc
- string comment block-without-scopes))
+ string string-concatenator comment block-without-scopes))
(phpinspect-defhandler list (start-token max-point)
"Handler for php syntactic lists (Note: this does not include
@@ -587,6 +587,11 @@ nature like argument lists"
((regexp . "[+-]?="))
(phpinspect-munch-token-without-attribs operator :assignment))
+(phpinspect-defhandler string-concatenator (token &rest _ignored)
+ "Handler for string concatenator tokens. (the . operator)."
+ ((regexp . "\\."))
+ (phpinspect-munch-token-without-attribs token :string-concatenator))
+
(phpinspect-defhandler terminator (terminator &rest _ignored)
"Handler for statement terminators."
((regexp . ";"))
@@ -645,7 +650,7 @@ nature like argument lists"
(phpinspect-defparser const
:tree-keyword "const"
- :handlers '(word comment assignment-operator string array terminator)
+ :handlers '(word comment assignment-operator string string-concatenator
array terminator)
:delimiter-predicate #'phpinspect-end-of-token-p)
(phpinspect-defhandler const-keyword (start-token max-point)
@@ -666,7 +671,7 @@ nature like argument lists"
(phpinspect-defparser block-without-scopes
:tree-keyword "block"
- :handlers '(array tag equals list comma attribute-reference variable
+ :handlers '(array tag equals string-concatenator list comma
attribute-reference variable
assignment-operator whitespace function-keyword word
terminator here-doc string comment block-without-scopes))
@@ -687,10 +692,10 @@ static keywords with the same meaning as in a class
block."
(phpinspect-defparser class-block
:tree-keyword "block"
- :handlers '(array tag equals list comma attribute-reference class-variable
- assignment-operator whitespace scope-keyword static-keyword
- const-keyword use-keyword function-keyword word terminator
- here-doc string comment block))
+ :handlers '(array tag equals list comma string-concatenator
attribute-reference
+ class-variable assignment-operator whitespace scope-keyword
+ static-keyword const-keyword use-keyword function-keyword
+ word terminator here-doc string comment block))
(phpinspect-defhandler class-block (start-token max-point)
"Handler for code blocks that cannot contain classes"
@@ -799,19 +804,22 @@ Returns the consumed text string without face properties."
(phpinspect-defparser scope-public
:tree-keyword "public"
:handlers '(function-keyword static-keyword const-keyword class-variable
here-doc
- string terminator tag comment
assignment-operator array word)
+ string string-concatenator terminator tag
comment
+ assignment-operator array word)
:delimiter-predicate #'phpinspect--scope-terminator-p)
(phpinspect-defparser scope-private
:tree-keyword "private"
:handlers '(function-keyword static-keyword const-keyword class-variable
here-doc
- string terminator tag comment
assignment-operator array word)
+ string string-concatenator terminator tag
comment
+ assignment-operator array word)
:delimiter-predicate #'phpinspect--scope-terminator-p)
(phpinspect-defparser scope-protected
:tree-keyword "protected"
:handlers '(function-keyword static-keyword const-keyword class-variable
here-doc
- string terminator tag comment
assignment-operator array word)
+ string string-concatenator terminator tag
comment
+ assignment-operator array word)
:delimiter-predicate #'phpinspect--scope-terminator-p)
(phpinspect-defhandler scope-keyword (start-token max-point)
@@ -900,8 +908,8 @@ the properties of the class"
:handlers '(namespace array equals list comma attribute-reference variable
assignment-operator whitespace scope-keyword
static-keyword const-keyword use-keyword class-keyword
- function-keyword word terminator here-doc string
comment
- tag block))
+ function-keyword word terminator here-doc string
string-concatenator
+ comment tag block))
(defun phpinspect-parse-current-buffer ()
(phpinspect-parse-buffer-until-point
diff --git a/phpinspect-resolvecontext.el b/phpinspect-resolvecontext.el
index f3c57134ce..051f6c5359 100644
--- a/phpinspect-resolvecontext.el
+++ b/phpinspect-resolvecontext.el
@@ -46,6 +46,7 @@
(inline-quote
(or (phpinspect-return-p ,token)
(phpinspect-end-of-statement-p ,token)
+ (phpinspect-string-concatenator-p ,token)
(phpinspect-function-p ,token)))))
(cl-defstruct (phpinspect--resolvecontext
diff --git a/phpinspect-token-predicates.el b/phpinspect-token-predicates.el
index 1e47cea30b..b25a72b593 100644
--- a/phpinspect-token-predicates.el
+++ b/phpinspect-token-predicates.el
@@ -35,6 +35,9 @@ Type can be any of the token types returned by
(defsubst phpinspect-object-attrib-p (token)
(phpinspect-token-type-p token :object-attrib))
+(defun phpinspect-string-concatenator-p (token)
+ (phpinspect-token-type-p token :string-concatenator))
+
(defsubst phpinspect-static-attrib-p (token)
(phpinspect-token-type-p token :static-attrib))
diff --git a/test/fixtures/IncompleteClass.eld
b/test/fixtures/IncompleteClass.eld
index e4e7d734cc..078fe5f8db 100644
--- a/test/fixtures/IncompleteClass.eld
+++ b/test/fixtures/IncompleteClass.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") (: [...]
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") (: [...]
diff --git a/test/fixtures/IncompleteClassBlockedNamespace.eld
b/test/fixtures/IncompleteClassBlockedNamespace.eld
index a599875aa2..431194f965 100644
--- a/test/fixtures/IncompleteClassBlockedNamespace.eld
+++ b/test/fixtures/IncompleteClassBlockedNamespace.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block
(:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";"))
(:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") ( [...]
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block
(:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";"))
(:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") ( [...]
diff --git a/test/fixtures/IncompleteClassMultipleNamespaces.eld
b/test/fixtures/IncompleteClassMultipleNamespaces.eld
index a674fa85bf..8ef103e4eb 100644
--- a/test/fixtures/IncompleteClassMultipleNamespaces.eld
+++ b/test/fixtures/IncompleteClassMultipleNamespaces.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "Circus\\Artist") (:block (:use (:word
"Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word
"App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") (:terminator [...]
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "Circus\\Artist") (:block (:use (:word
"Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word
"App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") (:terminator [...]
diff --git a/test/fixtures/IndexClass1-indexed.eld
b/test/fixtures/IndexClass1-indexed.eld
index 217b10ffb5..848dcca241 100644
--- a/test/fixtures/IndexClass1-indexed.eld
+++ b/test/fixtures/IndexClass1-indexed.eld
@@ -1 +1 @@
-`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t)
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken"
:collection nil :contains nil :fully-qualified t)) (declaration \,
'(:declaration (:word "class") (:word "AuthToken"))) (imports \, (list (cons
(phpinspect-intern-name "ORM") (phpinspect--make-type :nam [...]
+`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t)
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken"
:collection nil :contains nil :fully-qualified t)) (declaration \,
'(:declaration (:word "class") (:word "AuthToken"))) (location \, '(0 0))
(imports \, (list (cons (phpinspect-intern-name "ORM") (phpin [...]
diff --git a/test/fixtures/IndexClass2-indexed.eld
b/test/fixtures/IndexClass2-indexed.eld
index 86af9def45..a34d222ff0 100644
--- a/test/fixtures/IndexClass2-indexed.eld
+++ b/test/fixtures/IndexClass2-indexed.eld
@@ -1 +1 @@
-`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t)
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken"
:collection nil :contains nil :fully-qualified t)) (declaration \,
'(:declaration (:word "class") (:word "AuthToken"))) (imports \, (list (cons
(phpinspect-intern-name "ORM") (phpinspect--make-type :nam [...]
+`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t)
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken"
:collection nil :contains nil :fully-qualified t)) (declaration \,
'(:declaration (:word "class") (:word "AuthToken"))) (location \, '(0 0))
(imports \, (list (cons (phpinspect-intern-name "ORM") (phpin [...]
diff --git a/test/fixtures/NamespacedClass.eld
b/test/fixtures/NamespacedClass.eld
index fc41a5e4e1..2c9e9c18a8 100644
--- a/test/fixtures/NamespacedClass.eld
+++ b/test/fixtures/NamespacedClass.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") (: [...]
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "="))
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";"))
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use
(:word "App\\Repository\\UserRepository") (: [...]
diff --git a/test/test-resolve.el b/test/test-resolve.el
index 29962da5d8..97b9835cbf 100644
--- a/test/test-resolve.el
+++ b/test/test-resolve.el
@@ -126,7 +126,8 @@
(paths (list "$banana->bar"
"if ($baz = $banana) { $bar = $banana; } $bar->bar"
"$baz = new \\DateTime(); /** @var \\DateTime $pear */}
$banana->bar"
- "if ($baz = $banana->bar) { $baz"))
+ "if ($baz = $banana->bar) { $baz"
+ "if ($baz = $banana->bar . 'a string') { $baz"))
(project (phpinspect--make-dummy-project)))
(phpinspect-project-add-index
@@ -172,7 +173,8 @@
(let ((base-code "$bar = foo()")
(paths (list (cons ";$bar" "Foo")
(cons ";$bar->baz" "string")
- (cons "->baz" "string")))
+ (cons "->baz" "string")
+ (cons "; curl('aaa' . $bar->baz" "string")))
(project (phpinspect--make-dummy-project)))
(phpinspect-project-add-index