Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
xiretza
@xiretza:xiretza.xyz
[m]
no,that would kind of defeat the purpose of using parser combinators. just use the take parser - take(21)(input)
or even replace the entire function body with take(21).map(ImplicitAddress::from_base58check)
simple_user
@simple_user:matrix.org
[m]
│error[E0425]: cannot find function `take` in this scope │ --> pallets/tezos/src/types/implicit_address.rs:98:3 │ | │98 | take(21).map(ImplicitAddress::from_base58check) │ | ^^^^ not found in this scope │ | │help: consider importing one of these items │ | │1 | use core::mem::take; │ | │1 | use frame_support::storage::child::take; │ | │1 | use frame_support::storage::hashed::take; │ | │1 | use frame_support::storage::unhashed::take; │ | │ and 8 other candidates │ │warning: unused import: `nom::InputTake` │ --> pallets/tezos/src/types/implicit_address.rs:10:5 │ | │10 | use nom::InputTake; │ | ^^^^^^^^^^^^^^ │ | │ = note: `#[warn(unused_imports)]` on by default
looks like syntax issue
xiretza
@xiretza:xiretza.xyz
[m]
please format your code blocks properly - triple backticks on their own line, then the code, then another line of triple backticks
simple_user
@simple_user:matrix.org
[m]
sorry
            │error[E0425]: cannot find function `take` in this scope
                                                                                                                                        │  --> pallets/tezos/src/types/implicit_address.rs:98:3
                                                                                                                                        │   |
                                                                                                                                        │98 |   take(21).map(ImplicitAddress::from_base58check)
                                                                                                                                        │   |   ^^^^ not found in this scope
                                                                                                                                        │   |
                                                                                                                                        │help: consider importing one of these items
                                                                                                                                        │   |
                                                                                                                                        │1  | use core::mem::take;
                                                                                                                                        │   |
                                                                                                                                        │1  | use frame_support::storage::child::take;
                                                                                                                                        │   |
                                                                                                                                        │1  | use frame_support::storage::hashed::take;
                                                                                                                                        │   |
                                                                                                                                        │1  | use frame_support::storage::unhashed::take;
                                                                                                                                        │   |
                                                                                                                                        │     and 8 other candidates
                                                                                                                                        │
                                                                                                                                        │warning: unused import: `nom::InputTake`
                                                                                                                                        │  --> pallets/tezos/src/types/implicit_address.rs:10:5
                                                                                                                                        │   |
                                                                                                                                        │10 | use nom::InputTake;
                                                                                                                                        │   |     ^^^^^^^^^^^^^^
                                                                                                                                        │   |
                                                                                                                                        │   = note: `#[warn(unused_imports)]` on by default
xiretza
@xiretza:xiretza.xyz
[m]
Bradley Gannon
@bmgxyz
does tuple() have a maximum number of children? i'm writing a parser, and when i add a 22nd child parser, i get an inscrutable error about trait bounds suddenly not being satisfied—even though everything was fine before. it doesn't seem to matter what parser i add, only that it's the 22nd one in the tuple
Bradley Gannon
@bmgxyz
looks like there are some unclear limits on tuple length because of a lack of variadic generators in the language (see here). what a fun rabbit hole! in any case i'm now thinking my 22+ tuple approach needs a refactor
fwiw it's not yet clear to me how to use nom's nested function pattern to accommodate "wide" inputs—that is, inputs that have lots of pieces at the same level and don't nest deeply
simple_user
@simple_user:matrix.org
[m]
I am getting following error
^^^^^^^^^^^^^^^^^^^^^ the trait nom::error::ParseError<&str> is not implemented for &str
am I missing some imports from nom?
xiretza
@xiretza:xiretza.xyz
[m]
please don't post just a single isolated line of the error message, there's a lot more information there for a reason
simple_user
@simple_user:matrix.org
[m]
I am still having problem
warning: unused import: `crate::error::Span`
  --> pallets/tezos/src/types/implicit_address.rs:10:5
   |
10 | use crate::error::Span;
   |     ^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused import: `nom::InputTake`
  --> pallets/tezos/src/types/implicit_address.rs:12:5
   |
12 | use nom::InputTake;
   |     ^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> pallets/tezos/src/types/implicit_address.rs:101:8
    |
101 |   Ok ((rem, ImplicitAddress::from_base58check(enc)))
    |        ^^^ expected struct `LocatedSpan`, found `&str`
    |
    = note: expected struct `LocatedSpan<&str>`
            found reference `&str`
xiretza
@xiretza:xiretza.xyz
[m]
what's the signature of that function?
simple_user
@simple_user:matrix.org
[m]
pub fn parse_implicit_address(input : &str) -> IResult<ImplicitAddress> {
xiretza
@xiretza:xiretza.xyz
[m]
and what's your IResult?
simple_user
@simple_user:matrix.org
[m]
use nom_locate::LocatedSpan;

pub type Span<'a> = LocatedSpan<&'a str>;

pub type IResult<'a, O> = nom::IResult<Span<'a>, O, ParseError<'a>>;
xiretza
@xiretza:xiretza.xyz
[m]
so you're returning a IResult whose input type is Span, but your parser takes a &str as input, that's not gonna work
simple_user
@simple_user:matrix.org
[m]
oh I see
that makes sense
how to fix that?
without located_span
but it seems due to substrate
I need to implement parseerror for sp_std::str
xiretza
@xiretza:xiretza.xyz
[m]
oh some weird blockchain thing, that's just great
naive.rs never touches the E generic of IResult though, so there should be no reason for it to be &str (which is invalid either way) instead of the default Error<I>
simple_user
@simple_user:matrix.org
[m]
xiretza: I updated my PraseError implementation
but still getting
error[E0283]: type annotations needed
   --> pallets/tezos/src/types/implicit_address.rs:100:20
    |
100 |   let (rem, enc) = take(21usize)(input).unwrap();
    |                    ^^^^ cannot infer type for type parameter `Error` declared on the function `take`
    | 
   ::: /home/vivek/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.2.1/src/bytes/complete.rs:401:30
    |
401 | pub fn take<C, Input, Error: ParseError<Input>>(
    |                              ----------------- required by this bound in `nom::bytes::complete::take`
    |
    = note: cannot satisfy `_: nom::error::ParseError<&str>`
help: consider specifying the type arguments in the function call
    |
100 |   let (rem, enc) = take::<C, Input, Error>(21usize)(input).unwrap();
xiretza
@xiretza:xiretza.xyz
[m]
you really should stop .unwrap()ing parser results
simple_user
@simple_user:matrix.org
[m]
thanks! it compiles now, let me write a test to see if that worjs
aravk33
@aravk33:matrix.org
[m]
how do I take the longest input until a two-character pattern appears? like how I can use take_till to take the longest input until a single-character pattern
I want to parse *foo* from ***foo***, if I use delimited(tag("**"), take_until("**"), tag("**")) then I only get *foo
xiretza
@xiretza:xiretza.xyz
[m]
nom doesn't do backtracking
shenkan
@shenkan
seems nom::IResult<T> takes errors differently in 6.2.1 then it did in 5.0, can anyone tell me how I can update this?
assert_eq!(not_whitespace(" abcdefg"), Err(nom::Err::Error((" abcdefg", nom::error::ErrorKind::IsNot))));
This message was deleted
in 5.0 it was happy with this but now it isn't and i'm unsure how to create the error now
Federico Bergero
@fbergero
hey one question (more related to rust idiomatic), i found myself writing this
pub fn do(input) {
    let mut input = input;
    while ... {
        let (i, _) = parse(input)?;
        input = i;
    }
}
what's the right/proper way of writing this?
pub fn do(input) {
    let mut input = input;
    while ... {
        (input, _) = parse(input)?;
    }
}
with ^ that i get
destructuring assignments are unstable
xiretza
@xiretza:xiretza.xyz
[m]
I keep running into that one too, haven't found a nice general abstraction yet