Skip to content

Commit

Permalink
Document comment feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
ISibboI committed Aug 19, 2023
1 parent 1d05964 commit 57bdc8c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ assert_eq!(eval("1 + 2 + 3"), Ok(Value::from(6)));
// while `eval_[type]` returns the respective type directly.
// Both can be used interchangeably.
assert_eq!(eval_int("1 + 2 + 3"), Ok(6));
assert_eq!(eval("1 - 2 * 3"), Ok(Value::from(-5)));
assert_eq!(eval("1 /* inline comments are supported */ - 2 * 3 // as are end-of-line comments"), Ok(Value::from(-5)));
assert_eq!(eval("1.0 + 2 * 3"), Ok(Value::from(7.0)));
assert_eq!(eval("true && 4 > 2"), Ok(Value::from(true)));
```
Expand Down Expand Up @@ -534,6 +534,28 @@ This crate implements `serde::de::Deserialize` for its type `Node` that represen
The implementation expects a [serde `string`](https://serde.rs/data-model.html) as input.
Example parsing with [ron format](docs.rs/ron):

### Comments

Evalexpr supports C-style inline comments and end-of-line comments.
Inline comments are started with a `/*` and terminated with a `*/`.
End-of-line comments are started with a `//` and terminated with a newline character.
For example:

```rust
use evalexpr::*;

assert_eq!(
eval(
"
// input
a = 1; // assignment
// output
2 * a /* first double a */ + 2 // then add 2"
),
Ok(Value::Int(4))
);
```

```rust
extern crate ron;
use evalexpr::*;
Expand Down
24 changes: 23 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! // while `eval_[type]` returns the respective type directly.
//! // Both can be used interchangeably.
//! assert_eq!(eval_int("1 + 2 + 3"), Ok(6));
//! assert_eq!(eval("1 - 2 * 3"), Ok(Value::from(-5)));
//! assert_eq!(eval("1 /* inline comments are supported */ - 2 * 3 // as are end-of-line comments"), Ok(Value::from(-5)));
//! assert_eq!(eval("1.0 + 2 * 3"), Ok(Value::from(7.0)));
//! assert_eq!(eval("true && 4 > 2"), Ok(Value::from(true)));
//! ```
Expand Down Expand Up @@ -515,6 +515,28 @@
//! The implementation expects a [serde `string`](https://serde.rs/data-model.html) as input.
//! Example parsing with [ron format](docs.rs/ron):
//!
//! ### Comments
//!
//! Evalexpr supports C-style inline comments and end-of-line comments.
//! Inline comments are started with a `/*` and terminated with a `*/`.
//! End-of-line comments are started with a `//` and terminated with a newline character.
//! For example:
//!
//! ```rust
//! use evalexpr::*;
//!
//! assert_eq!(
//! eval(
//! "
//! // input
//! a = 1; // assignment
//! // output
//! 2 * a /* first double a */ + 2 // then add 2"
//! ),
//! Ok(Value::Int(4))
//! );
//! ```
//!
//! ```rust
//! # #[cfg(feature = "serde_support")] {
//! extern crate ron;
Expand Down

0 comments on commit 57bdc8c

Please sign in to comment.