Re: Wherein prof.ebral and I discuss node referencing systems
Ah no, I forgot about the other half of it.
Once you have done the translation [string ==> node] you still need to extract the value of the node as a string [node ==> string]. I tend to think of that as the easier and more straight-forward part of it but we are diverging there too.
Specifically once I have the node I have arranged things so that getting the data out is this simple:
Code:
value = handler.get_value()
Now exactly what get_value() does may be complex internal to the node handler but my referencing system doesn't care. I just changed my nodes so they all have such a function and it defaults to "None" in the base class. All the nodes that can't be references such as image nodes, minilibs, linknodes etc return None. Those that can return something useful (text, macro, gridrow, list, resource) do so. But your code doesn't have a get_value() so you pick out what kind of node you have and then follow different code for each. ie the code that should be inside the handler object is in your referencing code. The referencing code should be able to say to the node handler "give me your value".
If you don't do that then we have to drag all the nodes and all their code into the referencing system as a dependency. See what I mean there?
Now there's one catch here. Just as I have a little extra piece of data (parserContext) flying around my referencing functions, you have a little extra piece of data you use to extract the value of your node handler. You might be doing it with the custom nodes (ie the StarWars and d20 bunch) but you are definately doing it with the grid. You are basically passing in some data such as the cell's grid co-ordinate when you are calculating the value of the node. so your function would be more like this:
Code:
value = handler.get_value(queryContext)
Hopefully that queryContext can just be a string like "(1,3)" or "([1d3], [1d2])" but you may need something more complicated if you want to support those custom nodes (I do NOT want to support them!) I don't think you do though; I think you only need it for the grid.
This is good programming practise anyway of course; object orientated. But there's an immediate benefit of decoupling the nodes from the referencing system.