In this part of the series, we'll start working on the definition collection process for the analyser. We'll be using the https://github.com/pxp-lang/parser since it is a superset and supports all of PHP as well as extended language features for PXP.
let files = discoverer::discover(&["php"], &["."]).unwrap(); for file in files { let contents = std::fs::read(&file).unwrap(); let ast = pxp_parser::parse(&contents).unwrap(); }
impl Visitor for DefinitionCollector { fn visit(&mut self, node: &mut dyn Node) -> Result { if let Some(BracedNamespace { name: Some(SimpleIdentifier { value,... }),... }) = downcast:: (node) { let mut namespace = ByteString::from(b"\\"); namespace.extend(&value.bytes); self.current_namespace = namespace; } else if let Some(UnbracedNamespace { name: SimpleIdentifier { value,... },... }) = downcast:: (node) { let mut namespace = ByteString::from(b"\\"); namespace.extend(&value.bytes); self.current_namespace = namespace; }