I am about to start (again) recoding my FELT project in SWI and having learned more Prolog idioms over the last year or so, I now know SWI much better to the point where I feel I can actually pull it off this time!
I am currently using a string, converted to a stream, to test against as I can then issue REPL queries etc, but one of my early goals(!) is to be able to report the line and column of where my parser is not happy with something as it consumes s-expression based input.
I am also considering tokenising the input instead to make the parser cleaner not having to take whitespace into account all the time.
In both cases, having accurate error reporting is a must. I also read a really good posting yesterday about using print_message/2 for generating output that is hookable etc. so I am keen to do some exploratory hacking about before wading into the main code.
One warning: the lazy_list_location stuff is nice for errors/warnings, but not for regularly asking for the position as it requires skipping the list to the next attributed variable, get the location of the start of this block and redo the position computation from the start of this block. That is fine for an error, but not for -for example- record the start of each token.
OK. I think I read on the forum recently that it might be better to do “state passing” within the DCG using the push back feature but I thought that that might actually add more visual noise to each DCG rule.
Given that I want to bail on the first detected error I will use lazy_list_location to being with. I do not expect source files to be large at all either.
In my previous tokeniser I manually counted out the line/column by detecting the 0D and 0A character codes. I need to go and revisit my old code too I think as I do remember completing the tokeniser but I considered it ugly in some way!! But it did work just fine.
I think the term “push-back list” totally explains it and I agree, why not show respect!!
The term “semicontext” is starting down the Haskell path of using flowery language just for the sake of it some times.
As a non-academic self-taught person, who has spent six weeks solid last year learning category theory every evening for three hours straight, I really don’t know what a “semicontext” is other than half a context?
But…whataver. If you had the benefit of a degree level education, don’t assume everybody else did!