-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat: add PHP language #52
Changes from 39 commits
bb95dad
b1493d1
4a5c70f
7aacc80
a8f3731
1f1a15d
fcc3fc7
b6ac729
ae56041
0229548
a379303
3d442ec
48f5a27
eace2a4
d5c1201
197575d
0a8d0fc
f009c77
bc91a14
4a5c69f
a3c0e4f
9acad21
2225d9a
8b4dba9
6c98c81
55ff702
8c77c49
9f4f125
fc90e44
cbf8081
16f4d8a
c432a14
8a54196
066da65
b0870fb
17d80bc
c631247
c469d93
6fedda7
27ea566
df1a576
fd4e1d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,13 @@ use super::{ | |
r#where::Where, rewrite::Rewrite, some::Some, string_constant::StringConstant, | ||
variable::Variable, within::Within, Node, State, | ||
}; | ||
use marzano_util::node_with_source::NodeWithSource; | ||
use crate::context::Context; | ||
use crate::pattern::register_variable; | ||
use crate::pattern::string_constant::AstLeafNode; | ||
use anyhow::{anyhow, bail, Result}; | ||
use core::fmt::Debug; | ||
use grit_util::{traverse, Order}; | ||
use grit_util::{traverse, Order, AstNode}; | ||
use marzano_language::language::{Field, GritMetaValue}; | ||
use marzano_language::{language::Language, language::SnippetNode}; | ||
use marzano_util::analysis_logs::AnalysisLogs; | ||
|
@@ -482,7 +483,7 @@ impl Pattern { | |
} | ||
if node_types[sort as usize].is_empty() { | ||
let content = node.utf8_text(text)?; | ||
if node.named_child_count() == 0 | ||
if (node.named_child_count() == 0 || node.named_child_count() == 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just reverted this change, it was related to my attempt to match partial nodes. |
||
&& lang.replaced_metavariable_regex().is_match(&content) | ||
{ | ||
let regex = implicit_metavariable_regex( | ||
|
@@ -539,14 +540,18 @@ impl Pattern { | |
) | ||
}) | ||
.collect::<Result<Vec<Pattern>>>()?; | ||
// assumes that non multiple field has exactly one element | ||
|
||
// TODO check if Pattern is Dots, and error at compile time, | ||
// dots only makes sense in a list. | ||
if !field.multiple() { | ||
let lang = lang.get_ts_language(); | ||
let field_name = lang.field_name_for_id(field_id).unwrap(); | ||
let message = format!("field {} was empty!", field_name); | ||
return Ok((field_id, false, nodes_list.pop().expect(&message))); | ||
if !field.multiple() { | ||
if nodes_list.len() == 1 { | ||
return Ok((field_id, false, nodes_list.pop().unwrap())); | ||
} | ||
let field_node = node.child_by_field_id(field_id).unwrap(); | ||
let field_node_with_source = NodeWithSource::new(field_node.clone(), str::from_utf8(text).unwrap()); | ||
return Ok((field_id, false, Pattern::AstLeafNode(AstLeafNode::new( | ||
field_node.kind_id(), field_node_with_source.text(), lang, | ||
)?))); | ||
Comment on lines
+546
to
+554
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason for these changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also removed this comment I think the assumption that a node where multiple=false will have exactly 1 node is false, multiple=true means that you can have more than one element so this means multiple=false can have 0 (an unnamed node) or 1 node. I added the code to handle the case where nodes_list is empty. such as binary_expression-> operator in php. (Where there are unnamed strings, such at |
||
} | ||
if nodes_list.len() == 1 | ||
&& matches!( | ||
|
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.
Tip
Codebase Verification
The provided context from the shell scripts does not directly address the original verification task, which was to ensure that the new pattern
^_
is documented and tested across the application. However, the search for references toPattern::Underscore
in the Rust files returned multiple matches across various files in thecrates/core/src/pattern
directory. This indicates that thePattern::Underscore
enum variant, which is related to the^_
pattern, is indeed used throughout the application's logic.The second search attempt, which aimed to find comments or documentation mentioning the
^_
pattern, resulted in a regex parse error due to an incorrect pattern. After correcting the search pattern, the script did not produce any output, suggesting that there might not be explicit comments or documentation within the Rust files that mention the^_
pattern directly.Given the context and the results from the executed shell scripts, it appears that while the
Pattern::Underscore
enum variant is integrated into the application's logic, there might not be explicit comments or documentation within the Rust files that directly mention the^_
pattern. This could indicate a gap in documentation or comments regarding this specific pattern.Considering the information gathered, the verification process concludes with the observation that while the
Pattern::Underscore
is utilized in the application, explicit documentation or comments mentioning the^_
pattern directly within the Rust files might be lacking or not captured by the search scripts executed.Analysis chain
The addition of
^_
to returnPattern::Underscore
introduces a new pattern matching case. Ensure that this new pattern is consistently handled across all relevant parts of the application, including documentation and tests. It's also important to verify that this change aligns with the intended use cases for pattern matching within the project.Given the lack of output from the initial search, it's necessary to refine our approach to verify the integration and testing of the new
^_
pattern. We'll search for references to thePattern::Underscore
enum variant and any comments or documentation that specifically mention the^_
pattern. This should provide a clearer picture of how the new pattern is handled across the application.The search for references to
Pattern::Underscore
confirmed its usage across various parts of the application, indicating that the new^_
pattern is integrated into the application's logic. However, there was an error in the regex pattern used to search for comments or documentation mentioning the^_
pattern. Let's correct this and perform the search again to ensure comprehensive verification.Scripts Executed
The following scripts were executed for the analysis:
Script:
Length of output: 21
Script:
Length of output: 1580
Script:
Length of output: 201083