Skip to content

Commit

Permalink
Merge pull request #112 from anweiss/tuple-cleanup
Browse files Browse the repository at this point in the history
Doc updates and tuple enhancements
  • Loading branch information
anweiss authored Mar 23, 2022
2 parents aeb063a + 086b95e commit 59548f1
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
minimum-version-check:
strategy:
matrix:
rust_toolchain: [1.51.0]
rust_toolchain: [1.56.0]
os: [ubuntu-latest, macOS-latest, windows-latest]
name: minimum version check using Rust ${{ matrix.rust_toolchain }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A Rust implementation of the Concise data definition language (CDDL). CDDL is an

This crate includes a handwritten parser and lexer for CDDL, and its development has been heavily inspired by the techniques outlined in Thorsten Ball's book ["Writing An Interpretor In Go"](https://interpreterbook.com/). The AST has been built to closely match the rules defined by the ABNF grammar in [Appendix B.](https://tools.ietf.org/html/rfc8610#appendix-B) of the spec. All CDDL must use UTF-8 for its encoding per the spec.

This crate supports validation of both CBOR and JSON data structures. An extremely basic REPL is included as well. This crate's minimum supported Rust version (MSRV) is 1.51.0.
This crate supports validation of both CBOR and JSON data structures. An extremely basic REPL is included as well. This crate's minimum supported Rust version (MSRV) is 1.56.0.

Also bundled into this repository is a basic language server implementation and extension for Visual Studio Code for editing CDDL. The implementation is backed by the compiled WebAssembly target included in this crate.

Expand Down Expand Up @@ -100,7 +100,7 @@ docker run -i --rm -v $PWD:/data -w /data ghcr.io/anweiss/cddl-cli:0.9.0-beta.1

## Website

You can also find a simple RFC 8610 conformance tool at [https://cddl.anweiss.tech](https://cddl.anweiss.tech). This same codebase has been compiled for use in the browser via WebAssembly. The web tool does not yet support the additional control operators defined by [RFC 9165](https://datatracker.ietf.org/doc/html/rfc9165).
You can also find a simple RFC 8610 conformance tool at [https://cddl.anweiss.tech](https://cddl.anweiss.tech). This same codebase has been compiled for use in the browser via WebAssembly.

## Visual Studio Code extension

Expand Down Expand Up @@ -400,3 +400,4 @@ Both JSON and CBOR validation are dependent on their respective heap allocated `
Below are some known projects that leverage this crate:

- [https://github.com/Emurgo/cddl-codegen](https://github.com/Emurgo/cddl-codegen)
- [https://github.com/p2panda/p2panda](https://github.com/p2panda/p2panda)
6 changes: 3 additions & 3 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,10 +1514,10 @@ impl<'a> From<RangeValue<'a>> for Type2<'a> {
let span = (0, 0, 0);

match rv {
RangeValue::IDENT(ident) => Type2::Typename {
RangeValue::IDENT(ident, socket) => Type2::Typename {
ident: Identifier {
ident: ident.0,
socket: ident.1,
ident,
socket,
#[cfg(feature = "ast-span")]
span,
},
Expand Down
68 changes: 34 additions & 34 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,19 @@ impl<'a> Lexer<'a> {

Ok((
self.position,
Token::TAG((Some(t as u8), Some(self.read_number(idx)?.1))),
Token::TAG(Some(t as u8), Some(self.read_number(idx)?.1)),
))
}
_ => {
self.position.range = (token_offset, self.position.index + 1);

Ok((self.position, Token::TAG((Some(t as u8), None))))
Ok((self.position, Token::TAG(Some(t as u8), None)))
}
}
}
_ => {
self.position.range = (token_offset, self.position.index + 1);
Ok((self.position, Token::TAG((None, None))))
Ok((self.position, Token::TAG(None, None)))
}
},
(_, '\'') => {
Expand Down Expand Up @@ -1082,33 +1082,33 @@ mod tests {
"; this is another comment",
),
(NEWLINE, ""),
(IDENT(("mynumber".into(), None)), "mynumber"),
(IDENT("mynumber".into(), None), "mynumber"),
(ASSIGN, "="),
(VALUE(Value::FLOAT(10.5)), "10.5"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("mytag".into(), None)), "mytag"),
(IDENT("mytag".into(), None), "mytag"),
(ASSIGN, "="),
(TAG((Some(6), Some(1234))), "#6.1234"),
(TAG(Some(6), Some(1234)), "#6.1234"),
(LPAREN, "("),
(TSTR, "tstr"),
(RPAREN, ")"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("myfirstrule".into(), None)), "myfirstrule"),
(IDENT("myfirstrule".into(), None), "myfirstrule"),
(ASSIGN, "="),
(VALUE(Value::TEXT("myotherrule".into())), "\"myotherrule\""),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("mybytestring".into(), None)), "mybytestring"),
(IDENT("mybytestring".into(), None), "mybytestring"),
(ASSIGN, "="),
(
VALUE(Value::BYTE(ByteValue::UTF8(b"hello there".as_ref().into()))),
"'hello there'",
),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("mybase16rule".into(), None)), "mybase16rule"),
(IDENT("mybase16rule".into(), None), "mybase16rule"),
(ASSIGN, "="),
(
VALUE(Value::BYTE(ByteValue::B16(
Expand All @@ -1118,7 +1118,7 @@ mod tests {
),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("mybase64rule".into(), None)), "mybase64rule"),
(IDENT("mybase64rule".into(), None), "mybase64rule"),
(ASSIGN, "="),
(
VALUE(Value::BYTE(ByteValue::B64(
Expand All @@ -1128,66 +1128,66 @@ mod tests {
),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("mysecondrule".into(), None)), "mysecondrule"),
(IDENT("mysecondrule".into(), None), "mysecondrule"),
(ASSIGN, "="),
(IDENT(("mynumber".into(), None)), "mynumber"),
(IDENT("mynumber".into(), None), "mynumber"),
(RANGEOP(true), ".."),
(VALUE(Value::FLOAT(100.5)), "100.5"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("myintrule".into(), None)), "myintrule"),
(IDENT("myintrule".into(), None), "myintrule"),
(ASSIGN, "="),
(VALUE(Value::INT(-10)), "-10"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("mysignedfloat".into(), None)), "mysignedfloat"),
(IDENT("mysignedfloat".into(), None), "mysignedfloat"),
(ASSIGN, "="),
(VALUE(Value::FLOAT(-10.5)), "-10.5"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("myintrange".into(), None)), "myintrange"),
(IDENT("myintrange".into(), None), "myintrange"),
(ASSIGN, "="),
(VALUE(Value::INT(-10)), "-10"),
(RANGEOP(true), ".."),
(VALUE(Value::UINT(10)), "10"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("mycontrol".into(), None)), "mycontrol"),
(IDENT("mycontrol".into(), None), "mycontrol"),
(ASSIGN, "="),
(IDENT(("mynumber".into(), None)), "mynumber"),
(IDENT("mynumber".into(), None), "mynumber"),
(GT, ".gt"),
(VALUE(Value::UINT(0)), "0"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("@terminal-color".into(), None)), "@terminal-color"),
(IDENT("@terminal-color".into(), None), "@terminal-color"),
(ASSIGN, "="),
(IDENT(("basecolors".into(), None)), "basecolors"),
(IDENT("basecolors".into(), None), "basecolors"),
(TCHOICE, "/"),
(IDENT(("othercolors".into(), None)), "othercolors"),
(IDENT("othercolors".into(), None), "othercolors"),
(COMMENT(" an inline comment".into()), "; an inline comment"),
(NEWLINE, ""),
(IDENT(("messages".into(), None)), "messages"),
(IDENT("messages".into(), None), "messages"),
(ASSIGN, "="),
(IDENT(("message".into(), None)), "message"),
(IDENT("message".into(), None), "message"),
(LANGLEBRACKET, "<"),
(VALUE(Value::TEXT("reboot".into())), "\"reboot\""),
(COMMA, ","),
(VALUE(Value::TEXT("now".into())), "\"now\""),
(RANGLEBRACKET, ">"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("address".into(), None)), "address"),
(IDENT("address".into(), None), "address"),
(ASSIGN, "="),
(LBRACE, "{"),
(IDENT(("delivery".into(), None)), "delivery"),
(IDENT("delivery".into(), None), "delivery"),
(RBRACE, "}"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("delivery".into(), None)), "delivery"),
(IDENT("delivery".into(), None), "delivery"),
(ASSIGN, "="),
(LPAREN, "("),
(NEWLINE, ""),
(IDENT(("street".into(), None)), "street"),
(IDENT("street".into(), None), "street"),
(COLON, ":"),
(TSTR, "tstr"),
(COMMA, ","),
Expand All @@ -1197,40 +1197,40 @@ mod tests {
(ARROWMAP, "=>"),
(UINT, "uint"),
(COMMA, ","),
(IDENT(("city".into(), None)), "city"),
(IDENT("city".into(), None), "city"),
(GCHOICE, "//"),
(NEWLINE, ""),
(IDENT(("po-box".into(), None)), "po-box"),
(IDENT("po-box".into(), None), "po-box"),
(COLON, ":"),
(UINT, "uint"),
(COMMA, ","),
(IDENT(("city".into(), None)), "city"),
(IDENT("city".into(), None), "city"),
(GCHOICE, "//"),
(NEWLINE, ""),
(IDENT(("per-pickup".into(), None)), "per-pickup"),
(IDENT("per-pickup".into(), None), "per-pickup"),
(COLON, ":"),
(TRUE, "true"),
(NEWLINE, ""),
(RPAREN, ")"),
(NEWLINE, ""),
(NEWLINE, ""),
(IDENT(("city".into(), None)), "city"),
(IDENT("city".into(), None), "city"),
(ASSIGN, "="),
(LPAREN, "("),
(NEWLINE, ""),
(IDENT(("name".into(), None)), "name"),
(IDENT("name".into(), None), "name"),
(COLON, ":"),
(TSTR, "tstr"),
(NEWLINE, ""),
(IDENT(("zip-code".into(), None)), "zip-code"),
(IDENT("zip-code".into(), None), "zip-code"),
(COLON, ":"),
(UINT, "uint"),
(NEWLINE, ""),
(VALUE(Value::UINT(1)), "1"),
(ASTERISK, "*"),
(VALUE(Value::UINT(3)), "3"),
(
IDENT(("tcp-option".into(), Some(SocketPlug::GROUP))),
IDENT("tcp-option".into(), Some(SocketPlug::GROUP)),
"$$tcp-option",
),
(COMMA, ","),
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//!
//! This crate supports validation of both CBOR and JSON data structures. An
//! extremely basic REPL is included as well. This crate's minimum supported
//! Rust version (MSRV) is 1.51.0.
//! Rust version (MSRV) is 1.56.0.
//!
//! Also bundled into this repository is a basic language server implementation
//! and extension for Visual Studio Code for editing CDDL. The implementation is
Expand Down Expand Up @@ -136,7 +136,7 @@
//! or using Docker:
//!
//! ```sh
//! docker run -i --rm -v $PWD:/cddl -w /cddl ghcr.io/anweiss/cddl-cli:latest validate --cddl reputon.cddl --stdin < reputon.json
//! docker run -i --rm -v $PWD:/data -w /data ghcr.io/anweiss/cddl-cli:0.9.0-beta.1 validate --cddl reputon.cddl --stdin < reputon.json
//! ```
//!
//! ## Website
Expand Down Expand Up @@ -217,9 +217,9 @@
//!
//! **`--feature additional-controls`**
//!
//! Enable validation support for the additional control operators proposed in
//! [https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cddl-control-05](https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cddl-control-05).
//! Enabled by default.
//! Enable validation support for the additional control operators defined in
//! [RFC 9165](https://datatracker.ietf.org/doc/html/rfc9165). Enabled by
//! default.
//!
//! ### Parsing CDDL
//!
Expand Down Expand Up @@ -406,7 +406,7 @@
//!
//! let json = r#""v""#;
//!
//! #[cfg(feature = "additional-controls")]
//! #[cfg(not(feature = "additional-controls"))]
//! assert!(validate_json_from_str(cddl, json, Some(&["json"])).is_ok())
//! ```
//!
Expand Down Expand Up @@ -492,7 +492,6 @@
//!
//! let cbor = b"\x02";
//!
//! #[cfg(feature = "additional-controls")]
//! assert!(validate_cbor_from_slice(cddl, cbor, Some(&["cbor"])).is_ok())
//! ```
//!
Expand Down Expand Up @@ -520,6 +519,7 @@
//! Below are some known projects that leverage this crate:
//!
//! - [https://github.com/Emurgo/cddl-codegen](https://github.com/Emurgo/cddl-codegen)
//! - [https://github.com/p2panda/p2panda](https://github.com/p2panda/p2panda)
//!
#![allow(dead_code)]
Expand Down
Loading

0 comments on commit 59548f1

Please sign in to comment.