Repository navigation
Conversation
|
Some edge cases are not working with this solution. I think you should reconsider the negative sign parsing. It should be apply on the expression. let amount: i64 = 7;
let buffer = tvf!(SimpleStringTvf {
1 => -amount as Signed,
});
assert_eq!(Ok(-7), buffer.get_signed(1));Also for String conversion: let buffer = tvf!(SimpleStringTvf {
1 => -7 as String,
});
assert_eq!(
Ok("-7"),
buffer.get_string(1).map(|value| value.to_string()).as_deref(),
);And maybe an error could be trigger if we try to negate an unsigned value: let buffer = tvf!(SimpleStringTvf {
1 => -7 as Unsigned,
2 => -7u64,
});
assert_ne!(Ok(7), buffer.get_unsigned(1));
assert_ne!(Ok(7), buffer.get_unsigned(2)); |
There was a problem hiding this comment.
You fix common things, but we still have an issue regarding expression.
For example: -(left - right) as Signed, with left = 10 and right = 3, stores 7 instead of -7. Can you also consider it please ?
Also what can we do about these ?
-7 as Unsigned // stores 7
-7u64 // stores 7
-7 as Byte // stores 7BTW you didn't sign your last commit.
And can you increase prose_macros version to 0.5.1 please.
| // Check if the first element is a sign (+ or -) | ||
| let is_negative = if let Some(TokenTree::Punct(punct)) = tokens.peek() { | ||
| let negative = punct.as_char() == '-'; | ||
| tokens.next(); // move to next token |
There was a problem hiding this comment.
User can also put !false and it'll be consider as false. It should consume the token only if it's -.
8271a3f to
9384d63
Compare
They should throw an error. I'll look into it. |
|
I think I've fixed some of the issues. But I am not satisfied with the implementation. |
e2fa14f to
3f165d3
Compare
|
The refactoring is done. |
|
Test borrow and dereference operators with strings. Implement let buffer = tvf!(SimpleStringTvf {
1 => format!("{:0<12}", var),
}); |
d6385a2 to
91b4b7f
Compare
4c6bb90 to
a90a852
Compare
d5ddbd9 to
11ee73b
Compare
| TvfType::Signed => (modifier, quote![ as i64 ]), | ||
| TvfType::Unsigned => (modifier, quote![ as u64 ]), | ||
| TvfType::Float => (modifier, quote![ as f64 ]), | ||
| _ => (modifier.filter_out_numeric(), TokenStream::new()), |
There was a problem hiding this comment.
-"abc" give "abc", but -"abc" as String give an error. You should return an error when modifier.is_numeric() and the type is not Byte/Signed/Unsigned/Float.
There was a problem hiding this comment.
-format!(..) should not work. Can you reject the case ?
There was a problem hiding this comment.
It should be fixed now
|
|
||
| /// Given a literal deduce a String | ||
| /// We pass an extra modifier argument for primitives before being converted into string literals | ||
| pub(crate) fn parse_string(literal: &syn::Lit, modifier: Modifier) -> Result<String, syn::Error> { |
There was a problem hiding this comment.
There is lot ongoing in this.
But there is many case to handle.
It's maybe dumb, but could this be enough: (#modifier #lit).to_string() ?
There was a problem hiding this comment.
Nope it doesn't work, I encounter edge-cases
assertion `left == right` failed
left: Ok("string from bytes")
right: Ok("b\"string from bytes\"")
…extra parenthesis Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
…arsing then generating tokens Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
11ee73b to
457ca4d
Compare
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Signed-off-by: Olivier Schyns <olivier.schyns@worldline.com>
Allow defining the sign of a numerical value without wrapping into into extra parenthesis.
from
to