The right way to parse non-self-described text files?

What is the right way to parse non-self-described text files?

Let's say I have a text file like that:

75
(10.0, 63.0),(11.0, 62.0)
30
(80.0, 96.0),(80.0, 95.0),(80.0, 94.0),(80.0, 93.0),(80.0, 92.0),(80.0, 91.0),(80.0, 90.0),(80.0, 89.0),(80.0, 88.0)
100
(58.0, 76.0),(58.0, 75.0),(58.0, 74.0)

Should I use serde for this? If so which traits should be implemented? Any good example? I there a better way?

I don't think serde has a built-in format for that file format. :slight_smile:

I would just write some code to parse it manually. The file format seems relatively simple. I do not think you would gain anything from trying to use a crate to build the parser.

6 Likes

What about nom?
How to get optimal performance and use all cores?

I mean, I'm sure you could do this with nom. If you are already familiar with nom, that might be a good option, but I could probably write a custom parser a lot faster than I could learn to use nom.

As for multi-threading, don't bother. This is not really the kind of task that multi-threading tends to be useful for.

9 Likes

Is not one of the most performant JS parser multi-threaded?

Perhaps, I'm not familiar with that parser. But writing a multi-threaded parser that is faster than a single-threaded one for something like this is probably really really hard. Certainly there isn't a parser crate out there to help you with that.

2 Likes

Aha. I see. Thanks for answer :slight_smile:

It parses multiple files in parallel, it doesn't parse one character stream in parallel.

5 Likes

Oh, really? Eh..

Ah, that makes sense. Parsing multiple files in parallel is not especially difficult.

2 Likes

Maybe you can advise magazines to publish scientific articles about parsing for getting a degree?

What do you mean?

Is that possible in the domain of parsers and compilers?
What did I phrase badly?

I don't know anything about scientific articles related to parsing.

Hm. Is that possible to get degree in this domain?

There are probably quite many people whose thesis is about parsers.

1 Like

Interesting, how do they publish their articles. Is not publishing articles mandatory to get a degree?

That depends on the type of degree. It certainly wouldn't be for a bachelor's degree, but it would be for a PhD.

As for how you publish articles about parsers, well, like any other kind of article. You write up the article, and submit it to a conference or journal that accepts articles on the topic of parsers.

2 Likes

Aha. Where would you look for a list of such conferences and journals?

I would ask someone in academia who works with parsers which conference/journal is appropriate for the article I have in mind. Alternatively, I would try to find recent articles about parsers and look where they are published.

I suspect that many computer science conferences/journals have parsers as one of the topics they publish about.

2 Likes