Bottom-up Top-down dissonance
Having coded a bit using my new editor textended-edit, I've gotten to notice a possible problem in the editing model.
Textended pivots on the idea that source code consists of tokens, and those tokens have either one of two purposes: To communicate data or structure.
((1 * 2) + (4 * ((5 + 2) - (4 / 3)))
In the above sample the numbers and symbols communicate data and operations done for the data. Parentheses describe structure. If there are precedence rules, we can describe the same code with:
1 * 2 + 4 * (5 + 2 - 4 / 3)
Textended represents data tokens with symbols, strings or binary blobs. The structure is represented by wrapping the data tokens into lists. That effectively forms a top-down structure: The above construct is a tree structure, with numbers and operators as leaves.
In the way textended does it, reading the structure to compiler or layout it is an easy chore, but the model represents a dissonance:
- The tree structure is inherently top-down structure, read from branch down into the leaves.
- All editing operations that feel neat operate bottom-up, starting from leaves progressing into branch.
Some constructs appear to be natural to insert top-down: Lists, classes, function definitions, tables, dictionaries. Everything else seem more convenient if you can type in the data token before any structures are formed.
Even if the document were interpreted top-down, it may be the document model needs to be transformed bottom-up, to match the ways it is modified.
I thought about using the editor in this month to create a game. I scaled down the idea, doing an invaders clone in few days instead. I need to rethink on the document model before scaling up the projects.