Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict or relaxed parser mode #27

Open
Luro02 opened this issue Sep 19, 2019 · 5 comments
Open

Strict or relaxed parser mode #27

Luro02 opened this issue Sep 19, 2019 · 5 comments
Labels
E-easy Effort: easy. A task that would be a great starting point for a new contributor. P-low Priority: low. This task has a low priority. T-enhancement Type: enhancement. New feature or request
Milestone

Comments

@Luro02
Copy link
Collaborator

Luro02 commented Sep 19, 2019

By default the parser should try to parse everything possible without erroring. Sometimes it might be useful to check for any malformed input/errors and this could be done by a "strict" flag?

// MasterPlaylist::parse(input: &str, strict: bool);
MasterPlaylist::parse(&input, true);
@Luro02 Luro02 added T-enhancement Type: enhancement. New feature or request E-easy Effort: easy. A task that would be a great starting point for a new contributor. P-low Priority: low. This task has a low priority. labels Sep 19, 2019
@Erk-
Copy link

Erk- commented Sep 19, 2019

I would think that it would be better to have a parse_optioned method that takes an option struct.
Then there could be a parse method that is strict and a parse_relaxed that calls with differnt parameters of the option struct.

@Luro02
Copy link
Collaborator Author

Luro02 commented Sep 20, 2019

Would you mind giving an example or a function signature? (like in my post)

I understood it like this;

fn parse_optioned(input: &str, config: Option<Config>) -> crate::Result<_>;
fn parse(input: &str, config: Config) -> crate::Result<_>; // variable strictness?
fn parse_relaxed(input: &str) -> crate::Result<_>;
// this would call parse_optioned with `None`

I like the idea of having a Config, which can be used to configure the level of strictness. For example, you can ignore any unknown tags and error on a tag conflict?

@Erk-
Copy link

Erk- commented Sep 20, 2019

I think of it like this

fn parse_optioned(input: &str, config: Config) -> Result<_>;
fn parse(input: &str) -> crate::Result<_> {
    parse_optioned(input, Config{/* Strict config */}
}
fn parse_relaxed(input: &str) -> crate::Result<_> {
    parse_optioned(input, Config{/* Relaxed config */}
}

@Luro02
Copy link
Collaborator Author

Luro02 commented Sep 23, 2019

Wouldn't this defeat the purpose, of having a Config? If there is a Config, it should be configurable by the user, for example like this;

fn parse(input: &str); // relaxed
fn parse_with(|config| {
   // edit config here
   config
});

@Erk-
Copy link

Erk- commented Sep 24, 2019 via email

@Luro02 Luro02 added this to the 0.4 milestone Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Effort: easy. A task that would be a great starting point for a new contributor. P-low Priority: low. This task has a low priority. T-enhancement Type: enhancement. New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants