-1

I am attempting to implement a parser for a simple query language. The goal is to generate operations from the text and then evaluate them before passing them up the tree. If I understand correctly, I'll have to implement some of the nom traits (InputLength, InputTake, Slice).

Part way through implementing the InputTake trait, I realize that I'm expected to return subslices of the enums which represent my query operations where a split may be made part way through an identifier. For example, I may parse an identifier name_of_var and this take_split() method could produce 2 slices which doesn't make sense to me.

What should I be doing here? I don't like the idea of slicing a bool/number since they only make sense as a whole.

What do you think about returning None in the case where I consider a byte slice invalid?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
candronikos
  • 159
  • 1
  • 13
  • what is your input type? Is it not `&str`? Or do you separate the text in a list of tokens that you then want to process with nom? – Géal Dec 17 '17 at 08:29
  • I figured out what I was doing wrong. I assumed that the output type of one parser was the input of a parent parser. What really happens is that all parsers can expect the same input type and return whatever they like. The generated object (which is an AST) is returned and manipulated in the end. I literally figured that out 5 mins after posting this. – candronikos Dec 17 '17 at 09:28
  • I'm voting to close this question as off-topic because you say you figured out the problem, but didn't post the solution as an answer, rather you posted it as a comment. – Stephen Ostermiller Dec 17 '17 at 10:45

1 Answers1

0

For what it's worth...

I assumed that the output type of one parser was the input of a parent parser. What really happens is that all parsers can expect the same input type and return whatever they like. The generated object (which is an AST) is returned and manipulated in the end.

candronikos
  • 159
  • 1
  • 13