Skip to main content
deleted 9 characters in body
Source Link
Doc Brown
  • 214k
  • 34
  • 394
  • 603

... that will be used to parse: string -> object

Em, no. The output of a parser is not an "arbitrary object". It is parse tree (and a boolean indicating if the input string matched the given grammar or not).

I haven't seen any data structures for defining how stringifying would work (similar to a PEG), but I think this would be possible.

That is because there is no datastructure needed to stringify a parse tree (except the tree itself). Just do a depth-first in-order tree traversal and concatenate the string representation of the terminal nodes - that should result in the same string as you started with (assumed your parser did not swallow characters like whitespaces from the tree).

... that will be used to parse: string -> object

Em, no. The output of a parser is not an "arbitrary object". It is parse tree (and a boolean indicating if the input string matched the given grammar or not).

I haven't seen any data structures for defining how stringifying would work (similar to a PEG), but I think this would be possible.

That is because there is no datastructure needed to stringify a parse tree (except the tree itself). Just do a depth-first in-order tree traversal and concatenate the string representation of the terminal nodes - that should result in the same string as you started with (assumed your parser did not swallow characters like whitespaces from the tree).

... that will be used to parse: string -> object

Em, no. The output of a parser is not an "arbitrary object". It is parse tree (and a boolean indicating if the input string matched the given grammar or not).

I haven't seen any data structures for defining how stringifying would work (similar to a PEG), but I think this would be possible.

That is because there is no datastructure needed to stringify a parse tree (except the tree itself). Just do a depth-first in-order tree traversal and concatenate the string representation of the nodes - that should result in the same string as you started with (assumed your parser did not swallow characters like whitespaces from the tree).

added 25 characters in body
Source Link
Doc Brown
  • 214k
  • 34
  • 394
  • 603

... that will be used to parse: string -> object

Em, no. The output of a parser is not an "arbitrary object". It is parse tree (and a boolean indicating if the input string matched the given grammar or not).

I haven't seen any data structures for defining how stringifying would work (similar to a PEG), but I think this would be possible.

That is because there is no datastructure needed to stringify a parse tree (except the tree itself). Just do a depth-first in-order tree traversal and concatenate the string representation of the terminal nodes - that should result in the same string as you started with (assumed your parser did not swallow characters like whitespaces from the tree).

... that will be used to parse: string -> object

Em, no. The output of a parser is not an "arbitrary object". It is parse tree (and a boolean indicating if the input string matched the given grammar or not).

I haven't seen any data structures for defining how stringifying would work (similar to a PEG), but I think this would be possible.

That is because there is no datastructure needed to stringify a parse tree. Just do a depth-first in-order tree traversal and concatenate the string representation of the terminal nodes - that should result in the same string as you started with (assumed your parser did not swallow characters like whitespaces from the tree).

... that will be used to parse: string -> object

Em, no. The output of a parser is not an "arbitrary object". It is parse tree (and a boolean indicating if the input string matched the given grammar or not).

I haven't seen any data structures for defining how stringifying would work (similar to a PEG), but I think this would be possible.

That is because there is no datastructure needed to stringify a parse tree (except the tree itself). Just do a depth-first in-order tree traversal and concatenate the string representation of the terminal nodes - that should result in the same string as you started with (assumed your parser did not swallow characters like whitespaces from the tree).

Source Link
Doc Brown
  • 214k
  • 34
  • 394
  • 603

... that will be used to parse: string -> object

Em, no. The output of a parser is not an "arbitrary object". It is parse tree (and a boolean indicating if the input string matched the given grammar or not).

I haven't seen any data structures for defining how stringifying would work (similar to a PEG), but I think this would be possible.

That is because there is no datastructure needed to stringify a parse tree. Just do a depth-first in-order tree traversal and concatenate the string representation of the terminal nodes - that should result in the same string as you started with (assumed your parser did not swallow characters like whitespaces from the tree).