Convert Figma logo to code with AI

facebookarchive logopfff

Tools for code analysis, visualizations, or style-preserving source transformation.

2,441
204
2,441
36

Top Related Projects

Fast, indexed regexp search over large file trees

OpenGrok is a fast and usable source code search and cross reference engine, written in Java

Parsing, analyzing, and comparing source code across many languages

1,939

Kythe is a pluggable, (mostly) language-agnostic ecosystem for building tools that work with code.

2,366

A code rewrite tool for structural search and replace that supports ~every language.

Quick Overview

PFFF (PHP Frontend For Frontend) is a set of tools and APIs to perform static analysis, code visualizations, code navigations, and refactoring on source code. It supports multiple languages, including PHP, JavaScript, Java, and more. PFFF is designed to help developers understand and maintain large codebases.

Pros

  • Supports multiple programming languages
  • Provides a wide range of static analysis tools and visualizations
  • Offers both command-line tools and programmatic APIs
  • Can be used for code refactoring and navigation

Cons

  • The project is archived and no longer actively maintained
  • Documentation may be outdated or incomplete
  • Installation and setup can be complex
  • Some features may not work with newer versions of supported languages

Code Examples

(* Example 1: Parsing PHP code *)
let ast = Parse_php.parse_program "<?php echo 'Hello, World!'; ?>"
(* Example 2: Analyzing function calls *)
let calls = Analyzer_php.function_calls_of_program ast
(* Example 3: Generating a control flow graph *)
let cfg = Control_flow_php.cfg_of_program ast

Getting Started

To get started with PFFF, follow these steps:

  1. Clone the repository:

    git clone https://github.com/facebookarchive/pfff.git
    
  2. Install dependencies (on Ubuntu):

    sudo apt-get install ocaml ocaml-native-compilers camlp4-extra opam
    opam init
    opam install ocamlgraph ocamlfind
    
  3. Build PFFF:

    ./configure
    make depend
    make
    
  4. Run PFFF tools:

    ./pfff -help
    

Note: As the project is archived, you may encounter issues with newer systems or language versions. Refer to the project's documentation for more detailed instructions and troubleshooting.

Competitor Comparisons

Fast, indexed regexp search over large file trees

Pros of codesearch

  • Faster indexing and searching capabilities, especially for large codebases
  • Supports regular expression searches, allowing for more flexible and powerful queries
  • Lightweight and easy to integrate into existing workflows

Cons of codesearch

  • Limited language support compared to pfff's multi-language capabilities
  • Lacks advanced static analysis features that pfff provides
  • Less actively maintained, with fewer recent updates and community contributions

Code comparison

pfff:

let parse_program file =
  let ast = Parse_php.parse_program file in
  Ast_php.program_of_program ast

codesearch:

func (ix *Index) PostingQuery(q query.Q) (*PostingReader, error) {
    return ix.matchQuery(q)
}

While both projects aim to analyze and search code, their implementations differ significantly. pfff uses OCaml and focuses on multi-language support and static analysis, while codesearch is written in Go and prioritizes fast indexing and searching.

OpenGrok is a fast and usable source code search and cross reference engine, written in Java

Pros of OpenGrok

  • More actively maintained with regular updates and contributions
  • Supports a wider range of programming languages and file formats
  • Offers a web-based interface for easier access and collaboration

Cons of OpenGrok

  • Requires more setup and configuration compared to pfff
  • May have higher resource requirements for large codebases
  • Less focused on static analysis and code transformation

Code Comparison

OpenGrok (Java):

public class Search {
    public void doSearch() {
        // Search implementation
    }
}

pfff (OCaml):

let search () =
  (* Search implementation *)

OpenGrok is primarily written in Java, while pfff is implemented in OCaml. This difference in programming languages affects the ecosystem, tooling, and potential contributors for each project.

OpenGrok focuses on code search and cross-referencing, providing a web interface for browsing and searching source code. pfff, on the other hand, emphasizes static analysis, code visualization, and transformation tools.

While both projects aim to improve code understanding and navigation, they cater to different use cases and development workflows. OpenGrok is better suited for large-scale code browsing and search, while pfff excels in code analysis and transformation tasks.

Parsing, analyzing, and comparing source code across many languages

Pros of semantic

  • More actively maintained with recent updates
  • Supports a wider range of programming languages
  • Better documentation and examples for usage

Cons of semantic

  • Larger codebase and potentially more complex to set up
  • May have higher resource requirements for parsing and analysis

Code comparison

semantic:

parseAndAnalyze :: FilePath -> IO (Either SomeException (Term Syntax))
parseAndAnalyze path = do
  contents <- readFile path
  runExceptT $ do
    ast <- ExceptT $ parseFile path contents
    pure $ analyze ast

pfff:

let parse_and_analyze file =
  let ast = Parse_php.parse file in
  let env = Analyze_php.analyze ast in
  (ast, env)

Key differences

  • semantic is written in Haskell, while pfff is primarily in OCaml
  • semantic uses a more functional approach with monads and error handling
  • pfff's code appears more concise but may lack some advanced features

Use cases

  • semantic: Ideal for large-scale code analysis across multiple languages
  • pfff: Better suited for PHP-specific analysis and lightweight tooling

Community and support

  • semantic has more recent activity and a larger community on GitHub
  • pfff, being archived, may have limited ongoing support but still valuable for specific use cases
1,939

Kythe is a pluggable, (mostly) language-agnostic ecosystem for building tools that work with code.

Pros of Kythe

  • More active development and community support
  • Broader language support, including C++, Java, Go, and more
  • Designed for scalability and integration with various build systems

Cons of Kythe

  • Steeper learning curve and more complex setup
  • Requires more system resources for large-scale analysis
  • Less focused on specific static analysis tasks compared to pfff

Code Comparison

Kythe (indexing example):

v = (
    kythe.VName(signature="sig", corpus="corpus", path="path", language="lang")
    .with_corpus(new_corpus)
    .with_path(new_path)
)

pfff (pattern matching example):

match x with
| A (B, C) -> ...
| D _ -> ...
| E -> ...

Summary

Kythe offers a more comprehensive and scalable solution for code indexing and analysis across multiple languages, making it suitable for large-scale projects. However, it comes with increased complexity and resource requirements. pfff, while less actively maintained, provides a more focused approach to static analysis and pattern matching, particularly for OCaml and PHP, with a simpler setup process. The choice between the two depends on project scale, language requirements, and specific analysis needs.

2,366

A code rewrite tool for structural search and replace that supports ~every language.

Pros of comby

  • Simpler and more intuitive syntax for pattern matching and rewriting
  • Language-agnostic approach, supporting a wide range of programming languages
  • Faster execution for large-scale code modifications

Cons of comby

  • Less comprehensive static analysis capabilities compared to pfff
  • Fewer built-in tools for specific languages or frameworks
  • Limited support for complex code transformations that require deep semantic understanding

Code Comparison

comby:

comby 'printf(":[1]");' 'console.log(:[1]);' .js

pfff:

spatch -sp_file printf_to_console_log.cocci .

Summary

comby offers a more accessible and versatile approach to code rewriting, making it easier for developers to perform quick modifications across various languages. However, pfff provides more advanced static analysis features and language-specific tools, which can be beneficial for complex code transformations and in-depth analysis of specific codebases. The choice between the two depends on the specific requirements of the project and the level of analysis needed.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

                          pfff

Build Status

pfff is a set of tools and APIs to perform static analysis, code visualizations, code navigations, or style-preserving source-to-source transformations such as refactorings on source code. There is good support for C, Java, Javascript and PHP. There is also preliminary support for other languages such as C++, Rust, C#, Html, CSS, Erlang, Lisp, Haskell, Python, OPA and SQL. There is also very good support for OCaml code so that the framework can be used on the code of pfff itself.

For each languages there are mainly 2 libraries, for instance parsing_php.cma and analysis_php.cma, that you can embed in your own application if you need to process PHP code. See the demos/ directory for example of use of the pfff API. See also docs/manual/Parsing_xxx.pdf and docs/manual/Analyzis_xxx.pdf for more documentation on how to use or extend pfff.

pfff is also made of few tools:

  • pfff, which allows to test the different parsers on a single file
  • scheck, a bug finder
  • stags, an Emacs tag generator
  • sgrep, a syntactical grep
  • spatch, a syntactical patch
  • codemap, which is a gtk and cairo based source code visualizer/navigator/searcher leveraging the information computed previously by pfff_db and codegraph.
  • codegraph, a source code indexer and package/module/class dependency visualizer
  • codequery, an interactive tool a la SQL to query information about the structure of a codebase using Prolog as the query engine
  • pfff_db, which does some global analysis on a set of source files and store the data in a marshalled form in a file somewhere (e.g. /tmp/db.json)

For more information, look at the pfff wiki here: http://github.com/facebook/pfff/wiki/Main as well as the docs/manual/ directory.

Usage for pfff:

$ ./pfff -parse_php demos/foo.php

or

$ ./pfff -dump_php demos/foo.php

You can also look at ./pfff --help

Usage for pfff_db:

$ ./pfff_db -lang ml -o /tmp/pfff.json ~/pfff

to analyze all the .ml and .mli files under ~/pfff and store metadata information (the database) in /tmp/pfff.json

Usage for codemap:

$ ./codemap ~/pfff

This should launch a gtk-based GUI that allows you to visualize source code and perform some code search.

Usage for codegraph:

$ ./codegraph -lang cmt -build ~/pfff

to generate a graph_code.marshall file in ~/pfff containing all dependency information about the pfff codebase using the typed bytecode .cmt files generated during the compilation of pfff.

$ ./codegraph ~/pfff

This should launch a gtk-based GUI that allows you to visualize source code dependencies.

More information

Look at the pfff wiki here: http://github.com/facebook/pfff/wiki/Main