Skip to content

Commit

Permalink
Some work on #52
Browse files Browse the repository at this point in the history
  • Loading branch information
back2dos committed Jul 8, 2021
1 parent 81c0f85 commit 1923be4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/tink/hxx/Generator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class Generator {
}

public function createContext():GeneratorContext {
var tags = Tag.getAllInScope(defaults);
var tags = new Map();
return {
isVoid: function (name) return Tag.resolve(tags, name).match(Success({ isVoid: true })),
generateRoot: function (root:Children) return withTags(tags, function () return children(root)),
Expand Down
81 changes: 7 additions & 74 deletions src/tink/hxx/Tag.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,83 +31,16 @@ using StringTools;
static public function resolve(localTags:Map<String, Position->Tag>, name:StringAt):Outcome<Tag, Error>
return switch localTags[name.value] {
case null:
var found = Context.getLocalVars()[name.value];

if (found == null) {
var path = name.value.split('.');
if (path.length > 1 || startsCapital(path[path.length - 1]))
found = Context.typeof(name.value.resolve(name.pos));
}

if (found == null)
name.pos.makeFailure('unknown tag <${name.value}>');
else
Success((localTags[name.value] = declaration.bind(name.value, _, found, []))(name.pos));
case get: Success(get(name.pos));
}

static public function getAllInScope(defaults:Lazy<Array<Named<Position->Tag>>>) {
var localTags = new Map();
function add(name:String, type, params)
if (name.charAt(0) != '_')//seems reasonable
localTags[name] = {
var ret = null;
function (pos) {//seems I've reimplemented `tink.core.Lazy` here for some reason
if (ret == null)
ret = declaration(name, pos, type, params);
return ret;
}
switch name.value.resolve(name.pos).typeof() {
case Success(t):
Success(declaration(name.value, name.pos, t, []));
case Failure(_):
name.pos.makeFailure('unknown tag <${name.value}>');
}
var vars = Context.getLocalVars();
for (name in vars.keys())
add(name, vars[name], []);

switch Context.getLocalType() {
case null:
case v = TInst(_.get().statics.get() => statics, _):

var fields = [for (f in v.getFields(false).sure()) f.name => f],
method = Context.getLocalMethod();

if (fields.exists(method) || method == 'new')
for (f in fields)
if (f.kind.match(FMethod(MethNormal | MethInline | MethDynamic)))
add(f.name, f.type, f.params);
for (f in statics)
add(f.name, f.type, f.params);

default:
case get:
Success(get(name.pos));
}

function add(name, f)
if (!localTags.exists(name))
localTags[name] = f;

for (i in Context.getLocalImports())
switch i {
case { mode: IAll, path: path } if (startsCapital(path[path.length - 1].name)):

path = path.copy();

var e = {
var first = path.shift();
macro @:pos(first.pos) $i{first.name};
}

for (p in path)
e = EField(e, p.name).at(p.pos);

for (t in extractAllFrom(e).get())
add(t.name, t.value);
default:
}

for (d in defaults.get())
if (!localTags.exists(d.name))
localTags[d.name] = d.value;
return localTags;
}

static function makeArgs(pos:Position, name:String, t:Type, params:Array<TypeParameter>, ?children:Type):TagArgs {
function anon(anon:AnonType, t, lift:Bool, children:Type):TagArgs {
var fields = new Map(),
Expand Down
9 changes: 0 additions & 9 deletions tests/NonSense.hx

This file was deleted.

4 changes: 0 additions & 4 deletions tests/RunTests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ class RunTests {
public function inlineMarkup() {
var a = [for (i in 0...10) '$i'];

#if tink_parse_unicode
NonSense.showOff();
#end

Plain.hxx(
<div key="5">
{a.map(x -> <div>{x}</div>)}
Expand Down

0 comments on commit 1923be4

Please sign in to comment.