Support for parsecontext config
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .sunbeam import parse
|
||||
from .libsunbeam import action
|
||||
|
||||
__version__ = '0.0.1'
|
||||
__license__ = 'GNU General Public License version 3'
|
||||
|
||||
@@ -15,6 +15,14 @@ py::class_< EclipseState >( "EclipseState", py::no_init )
|
||||
.add_property( "title", &EclipseState::getTitle )
|
||||
;
|
||||
|
||||
void (ParseContext::*ctx_update)(const std::string&, InputError::Action) = &ParseContext::update;
|
||||
py::class_< ParseContext >( "ParseContext" )
|
||||
.def( "update", ctx_update )
|
||||
;
|
||||
|
||||
py::enum_< InputError::Action >( "action" )
|
||||
.value( "throw", InputError::Action::THROW_EXCEPTION )
|
||||
.value( "warn", InputError::Action::WARN )
|
||||
.value( "ignore", InputError::Action::IGNORE )
|
||||
;
|
||||
}
|
||||
|
||||
@@ -3,5 +3,27 @@ import libsunbeam as lib
|
||||
class EclipseState(lib.EclipseState):
|
||||
pass
|
||||
|
||||
def parse(path):
|
||||
return lib.parse(path, lib.ParseContext())
|
||||
def _parse_context(actions):
|
||||
ctx = lib.ParseContext()
|
||||
|
||||
if actions is None:
|
||||
return ctx
|
||||
|
||||
# this might be a single tuple, in which case we unpack it and repack it
|
||||
# into a list. If it's not a tuple we assume it's an iterable and just
|
||||
# carry on
|
||||
try:
|
||||
key, action = actions
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
actions = [(key, action)]
|
||||
|
||||
for key, action in actions:
|
||||
ctx.update(key, action)
|
||||
|
||||
return ctx
|
||||
|
||||
|
||||
def parse(path, actions = None):
|
||||
return lib.parse(path, _parse_context(actions))
|
||||
|
||||
Reference in New Issue
Block a user