I\'m using a simple language of only ()
, |
, spaces, and alpha characters.
Given a regular expression like the following:
(hello
When I did my own custom little language, I wrote a parser first. The parser created a structure in memory that represented the text. For this little language, I would create a structure that's something like this:
Node:
list of string values
isRequired
list of child Nodes
When you parse your text, you would get a list of nodes:
Node1:
hello, goodbye
true
[] (no child nodes)
Node2:
world,
false
[
Node3:
s,
false
[]
]
Once you parse into this structure, you can imagine code that'll generate what you want given that you understand what must be include, and what may be included. The pseudo code would look like this
recursiveGenerate( node_list, parital )
if ( node_list is null or is empty )
add partial to an output list
for the first node
if ( ! node.isRequired )
recursiveGenrate( remaining nodes, partial )
for each value
recursiveGenerate( child Nodes + remaining nodes, partial + value )
That should populate your list in the way you want.