-
Notifications
You must be signed in to change notification settings - Fork 0
Parse expressions like $this->{$member} into lang.ast.nodes.Expression #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thekid
commented
Apr 8, 2023
| $line+= substr_count($string, "\n"); | ||
| } else if ('$' === $token) { | ||
| yield new Token($language->symbol('(variable)'), 'variable', '$'.$next(self::DELIMITERS), $line); | ||
| yield new Token($language->symbol('(variable)'), 'variable', '$', $line); |
Member
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For any parser implementation, it's now necessary to forward once more to get the variable name!
5 tasks
Member
Author
|
The diff --git a/composer.json b/composer.json
index b024e0d..c064b7d 100755
--- a/composer.json
+++ b/composer.json
@@ -7,7 +7,7 @@
"keywords": ["module", "xp"],
"require" : {
"xp-framework/core": "^11.0 | ^10.13",
- "xp-framework/ast": "^9.0 | ^8.0 | ^7.6",
+ "xp-framework/ast": "^10.0 | ^9.0 | ^8.0 | ^7.6",
"php" : ">=7.0.0"
},
"suggest" : {
diff --git a/src/main/php/lang/meta/FromSyntaxTree.class.php b/src/main/php/lang/meta/FromSyntaxTree.class.php
index 8adcb65..55b0cba 100755
--- a/src/main/php/lang/meta/FromSyntaxTree.class.php
+++ b/src/main/php/lang/meta/FromSyntaxTree.class.php
@@ -56,9 +56,10 @@ class FromSyntaxTree {
do {
switch ($parse->token->value) {
case '(': $b++; break;
- case ')': $b--; if ($b < 0) break 2;
+ case ')': $b--; if ($b < 0) break 2; else break;
case '[': $c++; break;
- case ']': $c--; if ($c < 0) break 2;
+ case ']': $c--; if ($c < 0) break 2; else break;
+ case '$': $parse->forward(); $parse->token->value= '$'.$parse->token->value; break;
}
$code.= ' '.$parse->token->value;
$parse->forward();
@@ -86,6 +87,9 @@ class FromSyntaxTree {
$b++;
} else if ('}' === $parse->token->value) {
if (0 === --$b) break;
+ } else if ('$' === $parse->token->value) {
+ $parse->forward();
+ $parse->token->value= '$'.$parse->token->value;
}
$code.= ' '.$parse->token->value;
$parse->forward();
diff --git a/src/main/php/lang/meta/SyntaxTree.class.php b/src/main/php/lang/meta/SyntaxTree.class.php
index 43cd132..695c5e1 100755
--- a/src/main/php/lang/meta/SyntaxTree.class.php
+++ b/src/main/php/lang/meta/SyntaxTree.class.php
@@ -96,7 +96,7 @@ class SyntaxTree extends Visitor {
// Use PHP reflection API to access members' runtime values. We cannot use
// getStaticPropertyValue() as it cannot get non-public members in PHP 7.0
if ($self->member instanceof Variable) {
- $p= (new \ReflectionClass($c))->getProperty($self->member->name);
+ $p= (new \ReflectionClass($c))->getProperty($self->member->pointer ?? $self->member->name);
$p->setAccessible(true);
return $p->getValue();
} else if ($self->member instanceof Literal) {The statement |
Member
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR:
$this->{$member}distinguishable from$this->$memberExpressionclass, which encapsulates{<expr>}syntax (see below for where this is applicable)Variableclass to be able to contain other variables or expressions$varVariable("var")$$varVariable(Variable("var"))${$var}Variable(Expression(Variable("var")))$this->varInstance(Variable("this"), Literal("var"))$this->$varInstance(Variable("this"), Variable("var")$this->{$var}Instance(Variable("this"), Expression(Variable("var"))self::$varScope("self", Variable("var")self::$$varScope("self", Variable(Variable("var"))self::${$var}Scope("self", Variable(Expression(Variable("var")))self::varScope("self", Literal("var"))self::{$var}Scope("self", Expression(Variable("var"))