-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor blocks, programs and inverses
- Loading branch information
Showing
8 changed files
with
103 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import parser from "./parser"; | ||
import AST from "./ast"; | ||
import { stripFlags, prepareBlock } from "./helpers"; | ||
|
||
export { parser }; | ||
|
||
export function parse(input) { | ||
// Just return if an already-compile AST was passed in. | ||
if(input.constructor === AST.ProgramNode) { return input; } | ||
if (input.constructor === AST.ProgramNode) { return input; } | ||
|
||
for (var key in AST) { | ||
parser.yy[key] = AST[key]; | ||
} | ||
|
||
parser.yy.stripFlags = stripFlags; | ||
parser.yy.prepareBlock = prepareBlock; | ||
|
||
parser.yy = AST; | ||
return parser.parse(input); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Exception from "../exception"; | ||
import AST from "./ast"; | ||
|
||
export function stripFlags(open, close) { | ||
return { | ||
left: open.charAt(2) === '~', | ||
right: close.charAt(close.length-3) === '~' | ||
}; | ||
} | ||
|
||
export function prepareBlock(mustache, program, inverseAndProgram, close, inverted, locInfo) { | ||
if (mustache.sexpr.id.original !== close.path.original) { | ||
throw new Exception(mustache.sexpr.id.original + " doesn't match " + close.path.original, mustache); | ||
} | ||
|
||
var inverse, strip; | ||
|
||
strip = { | ||
left: mustache.strip.left, | ||
right: close.strip.right | ||
}; | ||
|
||
if (inverseAndProgram) { | ||
inverse = inverseAndProgram.program; | ||
var inverseStrip = inverseAndProgram.strip; | ||
|
||
program.strip.left = mustache.strip.right; | ||
program.strip.right = inverseStrip.left; | ||
inverse.strip.left = inverseStrip.right; | ||
inverse.strip.right = close.strip.left; | ||
} else { | ||
program.strip.left = mustache.strip.right; | ||
program.strip.right = close.strip.left; | ||
} | ||
|
||
if (inverted) { | ||
return new AST.BlockNode(mustache, inverse, program, strip, locInfo); | ||
} else { | ||
return new AST.BlockNode(mustache, program, inverse, strip, locInfo); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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