As part of a project I need to write a parser that can read a file and parse into facts I can use in my program.
The file structure looks as follows:
p
I parse the string into a list and then manipulate the list. Using DCG you can convert
T = (saf>{saf, as13s}>a32s>asf).
to
S = [saf-0, saf-1, as13s-1, a32s-2, asf-3] .
Note to do:
1. parseLine(<>,Position) --> parseLine(L,Position), parseLine(R,NewPosition)
2. parseLine(Item,Pos) --> [Item-Pos].
Here you have 2 patterns to handle those are the (L>R) and the {L,R}. That won't be much complicated and really easy to read.