« Goals for release 0.37 | Main | Release 0.37 (Dove) »

March 22, 2005

parsing and scoping for 0.37

So I've accomplished two of the three goals I set for 0.37 . Here is how CX parsing and scoping works:

The parsing part isn't fancy enough to print your text and point to the area of interest. Instead, I allowed for that to be done later, by making a small parsing system that reports the line and column. To print back the line and point to the column, CX will have to read over the file again, counting to the line, and printing the right one. Then, the parsing error system would have to act differently for repl errors... It will be more worth-it to do the fancy errors when Im on the C implementation of CX. Here is an example parsing error:

(cx:) [}
Parsing Exception: Non-matching list closing
line: 2
column: 3
Runtime Error: - Couldn't cross the bridge -
subject: class contex.Parser
verb: parse
arguments given: [ "[}" ]
true types: [ java.lang.String ]
type list given: [ "java.lang.String" ]
-- environmental stacks reset --
(cx:)

What happened here? You see the parsing exception say the 'line' and column of the problem, but then we see a Runtime Error about crossing a bridge? The bridge is the java-impl.cx file in my project. It is the file made up of invoke and invoke-static that builds CX up from the reflection API in java. java-impl.cx defines 'parse' to just call on the existing java parser. The repl calls the Parser class's 'parse(String)' method, and if the parser throws something, then the 'bridge could not be crossed'. It just means that CX couldn't invoke a method reflectively.

The scoping in CX is a big change. The end result is this:

make["x" 3]
eval @{set["x" 4] print-line x}
print-line x
(prints 4, then 4)

make["x" 3]
eval @{make["x" 2] print-line x}
print-line x
(prints 2, then 3)

You can use set to set a variable that doesn't exist. It will just make the variable right now, in the most specific scope. This is not a good idea though, because if the code is edited later, where the 'outer' context suddenly now has this variable, the inner context's set will refer to the existing variable, which may not be desired. For term's sake, CX's 'make' is just like a 'declaration'.

Now, all I need to do is add those simple java abilities such as constructing an instance with CX, and array access. Then I'll be writing that CX summary I talked about last entry. I might be done with ConteX 0.37 'Dove' very soon!

Posted by Rex at March 22, 2005 08:45 AM

Comments

Post a comment




Remember Me?