Created
March 29, 2014 02:28
-
-
Save srikumarks/9847260 to your computer and use it in GitHub Desktop.
sweetjs's resolveCtx rewritten recursively
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // (Syntax) -> String | |
| function resolveCtx(originalName, ctx, stop_spine, stop_branch) { | |
| if (ctx instanceof Mark) { | |
| return resolveCtx(originalName, ctx.context, stop_spine, stop_branch); | |
| } | |
| if (ctx instanceof Def) { | |
| if (stop_spine.indexOf(ctx.defctx) !== -1) { | |
| return resolveCtx(originalName, ctx.context, stop_spine, stop_branch); | |
| } | |
| return resolveCtx(originalName, renames(ctx.defctx, ctx.context, originalName), stop_spine, unionEl(stop_branch, ctx.defctx)); | |
| } | |
| if (ctx instanceof Rename) { | |
| if (originalName === ctx.id.token.value) { | |
| var idName = resolveCtx(ctx.id.token.value, ctx.id.context, stop_branch, stop_branch); | |
| var subName = resolveCtx(originalName, ctx.context, unionEl(stop_spine, ctx.def), stop_branch); | |
| if (idName === subName) { | |
| var idMarks = marksof(ctx.id.context, originalName + "$" + ctx.name, originalName); | |
| var subMarks = marksof(ctx.context, originalName + "$" + ctx.name, originalName); | |
| if (arraysEqual(idMarks, subMarks)) { | |
| return originalName + "$" + ctx.name; | |
| } | |
| } | |
| } | |
| return resolveCtx(originalName, ctx.context, stop_spine, stop_branch); | |
| } | |
| return originalName; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment