Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marirs/nparse
Parser library for specific use-cases
https://github.com/marirs/nparse
nom nom-parser parser rust rust-crate rust-lang rust-library
Last synced: 3 months ago
JSON representation
Parser library for specific use-cases
- Host: GitHub
- URL: https://github.com/marirs/nparse
- Owner: marirs
- License: mit
- Created: 2021-01-21T03:51:57.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-21T05:05:10.000Z (about 1 year ago)
- Last Synced: 2024-09-30T12:04:24.762Z (3 months ago)
- Topics: nom, nom-parser, parser, rust, rust-crate, rust-lang, rust-library
- Language: Rust
- Homepage:
- Size: 50.8 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
nparse 0.0.10
----------
[![Build Status](https://travis-ci.com/marirs/nparse.svg?branch=master)](https://travis-ci.com/marirs/nparse)Parser for various [Rust](https://www.rust-lang.org/) Strings.
Parsers for:
- Well Indent Strings (eg: `dmidecode` output)
- KV pair Strings (eg: `lscpu` output)
- Multiline KV pair strings (eg: `systeminfo` output of windows)
- Dotted tree Strings (eg: `sysctl` output)### Requirements
- Rust 1.50+
## Usage
```toml
nparse = "0.0.10"
```### Example use
- Converting an `Indent` string into json
```rust
use std::{fs::File, io::Read};
use nparse::*;fn main () {
let path = "data/dmidecode.txt";
let mut out = String::new();
{
let mut f = File::open(path).unwrap();
f.read_to_string(&mut out).unwrap();
}
let result = out.indent_to_json();
println!("{:?}", result);
}
```- Converting a `K:V` string into json
```rust
use std::{fs::File, io::Read};
use nparse::*;fn main () {
let path = "data/lscpu.txt";
let mut out = String::new();
{
let mut f = File::open(path).unwrap();
f.read_to_string(&mut out).unwrap();
}
let result = out.kv_str_to_json();
println!("{:?}", result);
}
```- Converting a `K=V` string into json
```rust
use std::{fs::File, io::Read};
use nparse::*;fn main () {
let path = "data/os-release.txt";
let mut out = String::new();
{
let mut f = File::open(path).unwrap();
f.read_to_string(&mut out).unwrap();
}
let result = out.kev_str_to_json();
println!("{:?}", result);
}
```- Converting a `dotted` string into json (eg: `parent.sub.sub: val`)
```rust
use std::{fs::File, io::Read};
use nparse::*;fn main () {
let path = "data/sysctl.txt";
let mut out = String::new();
{
let mut f = File::open(path).unwrap();
f.read_to_string(&mut out).unwrap();
}
let result = out.dotted_tree_to_json();
println!("{:?}", result);
}
```---
## Tests, Build
- Test
```bash
cargo t
```- Build Release
```bash
cargo b --release
```## Examples
- Parse dmidecode output to json
```bash
cargo run --example dmidecode
```- Parse sysctl output to json
```bash
cargo run --example sysctl
```- Parse lscpu to json
```bash
cargo run --example lscpu
```- Parse windows systeminfo to json
```bash
cargo run --example systeminfo
```---