All Projects → dalance → Sv Parser

dalance / Sv Parser

Licence: other
SystemVerilog parser library fully complient with IEEE 1800-2017

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Sv Parser

Surelog
SystemVerilog 2017 Pre-processor, Parser, Elaborator, UHDM Compiler. Provides IEEE Design/TB C/C++ VPI and Python AST API.
Stars: ✭ 116 (-31.36%)
Mutual labels:  parser, verilog
Netlist Graph
Java library for parsing and manipulating graph representations of gate-level Verilog netlists
Stars: ✭ 7 (-95.86%)
Mutual labels:  parser, verilog
Ink
A fast and flexible Markdown parser written in Swift.
Stars: ✭ 2,049 (+1112.43%)
Mutual labels:  parser
Kryon
FPGA,Verilog,Python
Stars: ✭ 169 (+0%)
Mutual labels:  verilog
Pegparser
💡 Build your own programming language! A C++17 PEG parser generator supporting parser combination, memoization, left-recursion and context-dependent grammars.
Stars: ✭ 164 (-2.96%)
Mutual labels:  parser
Sha256
Hardware implementation of the SHA-256 cryptographic hash function
Stars: ✭ 160 (-5.33%)
Mutual labels:  verilog
Command Line Api
Command line parsing, invocation, and rendering of terminal output.
Stars: ✭ 2,418 (+1330.77%)
Mutual labels:  parser
Fpg1
PDP-1 FPGA implementation in Verilog, with CRT, Teletype and Console.
Stars: ✭ 159 (-5.92%)
Mutual labels:  verilog
Fpga Chip8
CHIP-8 console on FPGA
Stars: ✭ 169 (+0%)
Mutual labels:  verilog
Fpga readings
Recipe for FPGA cooking
Stars: ✭ 164 (-2.96%)
Mutual labels:  verilog
Parser
A parsing library, focused on simplicity and great error messages
Stars: ✭ 167 (-1.18%)
Mutual labels:  parser
Vue Styleguidist
Created from react styleguidist for Vue Components with a living style guide
Stars: ✭ 2,133 (+1162.13%)
Mutual labels:  parser
Cnn Fpga
使用Verilog实现的CNN模块,可以方便的在FPGA项目中使用
Stars: ✭ 160 (-5.33%)
Mutual labels:  verilog
Php Mf2
php-mf2 is a pure, generic microformats-2 parser for PHP. It makes HTML as easy to consume as JSON.
Stars: ✭ 165 (-2.37%)
Mutual labels:  parser
Json To Ast
JSON AST parser
Stars: ✭ 161 (-4.73%)
Mutual labels:  parser
Xlsxir
Xlsx parser for the Elixir language.
Stars: ✭ 167 (-1.18%)
Mutual labels:  parser
Fast Float Rust
Super-fast float parser in Rust
Stars: ✭ 160 (-5.33%)
Mutual labels:  parser
Npeg
PEGs for Nim, another take
Stars: ✭ 163 (-3.55%)
Mutual labels:  parser
Query Translator
Query Translator is a search query translator with AST representation
Stars: ✭ 165 (-2.37%)
Mutual labels:  parser
Sdram Controller
Verilog SDRAM memory controller
Stars: ✭ 169 (+0%)
Mutual labels:  verilog

sv-parser

SystemVerilog parser library fully compliant with IEEE 1800-2017.

Actions Status Crates.io Docs.rs

Tools using sv-parser

  • morty: A SystemVerilog source file pickler
  • svinst: Determines the modules declared and instantiated in a SystemVerilog file
  • svlint: SystemVerilog linter
  • svls: SystemVerilog language server

Usage

[dependencies]
sv-parser = "0.11.1"

sv-parser provides parse_sv function which returns SyntaxTree. SyntaxTree shows Concrete Syntax Tree. It has the preprocessed string and the parsed tree.

RefNode shows a reference to any node of SyntaxTree. You can get RefNode through an iterator of SyntaxTree. Variant names of RefNode follows "Annex A Formal syntax" of IEEE 1800-2017.

Locate shows a position of token. All leaf node of SyntaxTree is Locate. You can get string from Locate by get_str.

Example

The following example parses a SystemVerilog source file and shows module names.

use std::collections::HashMap;
use std::env;
use std::path::PathBuf;
use sv_parser::{parse_sv, unwrap_node, Locate, RefNode};

fn main() {
    let args: Vec<String> = env::args().collect();

    // The path of SystemVerilog source file
    let path = PathBuf::from(&args[1]);
    // The list of defined macros
    let defines = HashMap::new();
    // The list of include paths
    let includes: Vec<PathBuf> = Vec::new();

    // Parse
    let result = parse_sv(&path, &defines, &includes, false);

    if let Ok((syntax_tree, _)) = result {
        // &SyntaxTree is iterable
        for node in &syntax_tree {
            // The type of each node is RefNode
            match node {
                RefNode::ModuleDeclarationNonansi(x) => {
                    // unwrap_node! gets the nearest ModuleIdentifier from x
                    let id = unwrap_node!(x, ModuleIdentifier).unwrap();

                    let id = get_identifier(id).unwrap();

                    // Original string can be got by SyntaxTree::get_str(self, locate: &Locate)
                    let id = syntax_tree.get_str(&id).unwrap();
                    println!("module: {}", id);
                }
                RefNode::ModuleDeclarationAnsi(x) => {
                    let id = unwrap_node!(x, ModuleIdentifier).unwrap();
                    let id = get_identifier(id).unwrap();
                    let id = syntax_tree.get_str(&id).unwrap();
                    println!("module: {}", id);
                }
                _ => (),
            }
        }
    } else {
        println!("Parse failed");
    }
}

fn get_identifier(node: RefNode) -> Option<Locate> {
    // unwrap_node! can take multiple types
    match unwrap_node!(node, SimpleIdentifier, EscapedIdentifier) {
        Some(RefNode::SimpleIdentifier(x)) => {
            return Some(x.nodes.0);
        }
        Some(RefNode::EscapedIdentifier(x)) => {
            return Some(x.nodes.0);
        }
        _ => None,
    }
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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].