Skip to content

Commit

Permalink
Support top level items and add LOC to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Dec 20, 2024
1 parent 9b4ffae commit 65901fd
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 97 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lines-of-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Update LOC metrics (lines of code)

on:
push:
branches: ["main"]

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download scc
run: |
mkdir scc
cd scc
gh release download v3.1.0 -R boyter/scc -p '*Linux_x86_64.tar.gz' -O scc.tar.gz
tar -xf scc.tar.gz
chmod +x scc
pwd >> $GITHUB_PATH
env:
GH_TOKEN: ${{ github.token }}

- name: Run update script
run: |
name="simple-json-parser"
lines_of_code=$(scc -c --no-cocomo -f json -i rs lib.rs | jq '.[] | .Code');
echo "\`$name\` has $lines_of_code lines of code" >> $GITHUB_STEP_SUMMARY;
curl \
--header "Content-Type: application/json" \
--header "X-POST-ACCESS-KEY: ${{ secrets.PROJECTS_POST_ACCESS_KEY }}" \
--data "{\"project\":\"$name\",\"language\":\"rust\",\"loc\":$lines_of_code}" \
-w "\nUpdated-project: \n" \
https://kaleidawave-projectinformation.web.val.run/update-project;
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ path = "lib.rs"

[lints.clippy]
pedantic = "deny"

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# JSON parser/lexer

![lines of code](https://kaleidawave-projectinformation.web.val.run/project/simple-json-parser/badge)
[![crates.io badge](https://img.shields.io/crates/v/simple-json-parser?style=flat-square)](https://crates.io/crates/simple-json-parser)
[![docs.rs badge](https://img.shields.io/docsrs/simple-json-parser?style=flat-square)](https://docs.rs/simple-json-parser/latest)

Features
- Under < 200 LOC Rust lexer (+ no dependencies)
- Visiting / callback based API (no allocation)
- Under < 200 LOC Rust lexer
- No dependencies
- Visiting / callback based API (avoids allocations)
- Handles single and multiline comments in JSON

See examples and tests for usage.
See [examples](/examples/) and [tests](/tests/) for usage.

17 changes: 17 additions & 0 deletions examples/comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use simple_json_parser::parse;

fn main() {
let content = r#"// Something
{
"a": 2,
// Another
"b": 5,
# another comment
}"#;

let result = parse(content, |keys, value| {
eprintln!("{keys:?} -> {value:?}");
});

assert!(result.is_ok());
}
1 change: 1 addition & 0 deletions examples/to_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
pub type Object = HashMap<String, Value>;

#[derive(Debug)]
#[allow(dead_code)]
pub enum Value {
Object(Object),
String(String),
Expand Down
1 change: 1 addition & 0 deletions examples/to_object_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
pub type Object = HashMap<String, Value>;

#[derive(Debug)]
#[allow(dead_code)]
pub enum Value {
Object(Object),
String(String),
Expand Down
21 changes: 21 additions & 0 deletions examples/top_level.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use simple_json_parser::parse;

fn main() {
let to_parse = &[
"199",
"\"Hiya\"",
"[1, 2, \"something\"]",
"true",
"false",
"null",
];

for item in to_parse {
eprintln!("parsing {item} as JSON");
let result = parse(item, |keys, value| {
eprintln!("{keys:?} -> {value:?}");
});

assert!(result.is_ok());
}
}
Loading

0 comments on commit 65901fd

Please sign in to comment.