obriencj / python-sibilant

A dialect of Lisp compiling to Python bytecode
GNU Lesser General Public License v3.0
7 stars 1 forks source link

support runtime addition of reader macros #27

Closed obriencj closed 7 years ago

obriencj commented 7 years ago

similar to the stepped way that compilation happens at the module level, where each top-level statement can modify the environment to add new compile-able forms and macros for the next expression

support reader macros such that additional behavior can be grafted on.

move existing reader behavior into reader macros as possible!

obriencj commented 7 years ago

things that can be implemented as reader macros

this should allow for discarding the entire sibilant.ast module, so long as I can ensure position information is stored in a lookaside during parsing.

the end result would be a stream plus a locations dict passed into a reader function which had a collection of reader macros. the reader function would use the macros is had available to parse and return a single expression.

compilation and execution could then happen, at which time more reader macros might be defined. subsequent reader calls would then operate with the new macros in place.

obriencj commented 7 years ago

(set-macro-character "{" handler_fn) where handler_fn accepts parameters as (lambda (stream trigger_char) ...) and returns a pair representing the form that it should evaluate as. The macro can read from stream to advance it as needed.

obriencj commented 7 years ago

This relies on a function named "read" which connects to the reader and pulls in a single expression/unit/whatever

obriencj commented 7 years ago

https://gist.github.com/obriencj/ed947df0d8b843ff0e7f6018ae5d79de