All Projects → fasterthanlime → Pegviz

fasterthanlime / Pegviz

Licence: mit
PEG trace visualizer

Programming Languages

rust
11053 projects
grammar
57 projects

Projects that are alternatives of or similar to Pegviz

Npeg
PEGs for Nim, another take
Stars: ✭ 163 (+805.56%)
Mutual labels:  peg, parser
Pegparser
💡 Build your own programming language! A C++17 PEG parser generator supporting parser combination, memoization, left-recursion and context-dependent grammars.
Stars: ✭ 164 (+811.11%)
Mutual labels:  peg, parser
Pigeon
Command pigeon generates parsers in Go from a PEG grammar.
Stars: ✭ 603 (+3250%)
Mutual labels:  peg, parser
Hardhat
Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. Get Solidity stack traces & console.log.
Stars: ✭ 727 (+3938.89%)
Mutual labels:  debugging
Expr Eval
Mathematical expression evaluator in JavaScript
Stars: ✭ 752 (+4077.78%)
Mutual labels:  parser
Markdown Wasm
Markdown parser and HTML generator implemented in WebAssembly, based on md4c
Stars: ✭ 833 (+4527.78%)
Mutual labels:  parser
Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (+4866.67%)
Mutual labels:  parser
Action Tmate
Debug your GitHub Actions via SSH by using tmate to get access to the runner system itself.
Stars: ✭ 713 (+3861.11%)
Mutual labels:  debugging
Viztracer
VizTracer is a low-overhead logging/debugging/profiling tool that can trace and visualize your python code execution.
Stars: ✭ 874 (+4755.56%)
Mutual labels:  debugging
Imdbpy
IMDbPY is a Python package useful to retrieve and manage the data of the IMDb movie database about movies, people, characters and companies
Stars: ✭ 792 (+4300%)
Mutual labels:  parser
Php Parser
PHP parser written in Go
Stars: ✭ 787 (+4272.22%)
Mutual labels:  parser
Esprima
ECMAScript parsing infrastructure for multipurpose analysis
Stars: ✭ 6,391 (+35405.56%)
Mutual labels:  parser
Netlist Graph
Java library for parsing and manipulating graph representations of gate-level Verilog netlists
Stars: ✭ 7 (-61.11%)
Mutual labels:  parser
Bugsnag Laravel
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
Stars: ✭ 746 (+4044.44%)
Mutual labels:  debugging
Eylogviewer
A simple viewer to see your app's logs on your iDevice in realtime.
Stars: ✭ 16 (-11.11%)
Mutual labels:  debugging
Tolerant Php Parser
An early-stage PHP parser designed for IDE usage scenarios.
Stars: ✭ 717 (+3883.33%)
Mutual labels:  parser
Rust Peg
Parsing Expression Grammar (PEG) parser generator for Rust
Stars: ✭ 836 (+4544.44%)
Mutual labels:  peg
Node Csv Parse
CSV parsing implementing the Node.js `stream.Transform` API
Stars: ✭ 768 (+4166.67%)
Mutual labels:  parser
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+4116.67%)
Mutual labels:  parser
Proposal Binary Ast
Binary AST proposal for ECMAScript
Stars: ✭ 831 (+4516.67%)
Mutual labels:  parser

pegviz

Visualizer for https://crates.io/crates/peg parsers.

Screenshot

pegviz reads peg's tracing markers and generates a collapsible HTML tree.

Left side:

  • Green: matched rule
  • Red: failed rule

Right side:

  • Gray: previous input, for context
  • Blue background: input matched by this rule
  • White text: rest of input after matching

Format

pegviz expects input in the following format:

[PEG_INPUT_START]
int a = 12 + 45;
[PEG_TRACE_START]
[PEG_TRACE] Attempting to match rule `translation_unit0` at 1:1
[PEG_TRACE] Attempting to match rule `list0` at 1:1
[PEG_TRACE] Attempting to match rule `node` at 1:1
[PEG_TRACE] Attempting to match rule `external_declaration` at 1:1
[PEG_TRACE] Attempting to match rule `declaration` at 1:1
[PEG_TRACE] Attempting to match rule `node` at 1:1
[PEG_TRACE] Attempting to match rule `declaration0` at 1:1
[PEG_TRACE] Attempting to match rule `gnu` at 1:1
[PEG_TRACE] Attempting to match rule `gnu_guard` at 1:1
[PEG_TRACE] Failed to match rule `gnu_guard` at 1:1
[PEG_TRACE] Failed to match rule `gnu` at 1:1
[PEG_TRACE] Attempting to match rule `_` at 1:1
[PEG_TRACE] Matched rule `_` at 1:1 to 1:1

The _START and _STOP marker are pegviz-specific, you'll need to add them to your program. See the Integration section for more information.

Multiple traces may be processed, they'll all show up in the output file. Output that occurs between traces is ignored.

Compatibility

pegviz has been used with:

  • peg 0.5.7
  • peg 0.6.2

There are no tests. It's quickly thrown together.

Integration

In your crate, re-export the trace feature:

# in Cargo.toml

[features]
trace = ["peg/trace"]

Then, in your parser, add a tracing rule that captures all the input and outputs the markers pegviz is looking for:

peg::parser! { pub grammar example() for str {

rule traced<T>(e: rule<T>) -> T =
    &(input:$([_]*) {
        #[cfg(feature = "trace")]
        println!("[PEG_INPUT_START]\n{}\n[PEG_TRACE_START]", input);
    })
    e:e()? {?
        #[cfg(feature = "trace")]
        println!("[PEG_TRACE_STOP]");
        e.ok_or("")
    }

pub rule toplevel() -> Toplevel = traced(<toplevel0()>)

}}

The above is the recommended way if you're maintaining the grammar and want to be able to turn on pegviz support anytime.

If you're debugging someone else's parser, you may want to print the start/stop markers and the source yourself, around the parser invocation, like so:

    let source = std::fs::read_to_string(&source).unwrap();
    println!("[PEG_INPUT_START]\n{}\n[PEG_TRACE_START]", source);
    let res = lang_c::driver::parse_preprocessed(&config, source);
    println!("[PEG_TRACE_STOP]");

Make sure you've installed pegviz into your $PATH:

cd pegviz/
cargo install --force --path .

While installing it, you may notice pegviz depends on peg. That's right! It's using a PEG to analyze PEG traces.

Then, simply run your program with the trace Cargo feature enabled, and pipe its standard output to pegviz.

cd example/
cargo run --features trace | pegviz --output ./pegviz.html

Note that the --output argument is mandatory.

The last step is to open the resulting HTML file in a browser and click around!

License

pegviz is released under the MIT License. See the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].