Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

WIP: Parse Stone through Acorn #22

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
63b6695
Moved `each` tests from control structures to layouts
shnhrrsn Nov 25, 2017
8f54ca9
Began rebuilding to parse Stone directly through acorn and generated …
shnhrrsn Nov 25, 2017
6c17028
Parser.parseDirective() will now handle directives with parens but no…
shnhrrsn Nov 25, 2017
361d3de
Fixed issues in Parser.parseDirective() where it’d skip whitespace/ch…
shnhrrsn Nov 26, 2017
c3ec8a8
Replaced contextualize with a new Scoper class and built in support d…
shnhrrsn Nov 26, 2017
d01497c
Fixed bug in `parseDumpDirective`
shnhrrsn Nov 26, 2017
3d1188d
Rebuilt loops and conditionals on acorn
shnhrrsn Nov 26, 2017
7f11286
Updated Generator to add pushScope/popScope to state
shnhrrsn Nov 26, 2017
7fc9cc7
Rebuilt macros on acorn
shnhrrsn Nov 26, 2017
c9088d4
Abstracted logic out of StoneMacro into StoneOutputBlock
shnhrrsn Nov 26, 2017
2ec00ee
Added StoneTemplate type
shnhrrsn Nov 26, 2017
b04663f
Added assignments to StoneOutputBlock
shnhrrsn Nov 26, 2017
3221137
Template path is now shared with StoneTemplate
shnhrrsn Nov 26, 2017
a4e99da
Rebuilt include/each on acorn
shnhrrsn Nov 26, 2017
a95ec47
Rebuilt layouts on acorn
shnhrrsn Nov 27, 2017
ebe5e58
Added `MakeNode` and `MockParser`
shnhrrsn Dec 2, 2017
ec74c85
Rebuilt components on acorn
shnhrrsn Dec 2, 2017
839ffef
Added Scope class to wrap `Set` to maintain parent scope to children
shnhrrsn Dec 3, 2017
894f1ae
Updated Stone.walkVariables to better suppor spread/rest
shnhrrsn Dec 4, 2017
9ad3ea1
Rebuilt assignments on acorn
shnhrrsn Dec 4, 2017
852d34e
Merged (most) directive parsers into their respective types
shnhrrsn Dec 4, 2017
e4e62d1
Refactored custom types to be class based and extend from StoneType
shnhrrsn Dec 4, 2017
0f6444b
Abstracted assertArgs
shnhrrsn Dec 4, 2017
97bbb94
Added StoneDirectiveBlockType to abstract away some block logic
shnhrrsn Dec 4, 2017
c187e80
Added StoneBreak type, removing from Loops parser
shnhrrsn Dec 5, 2017
336b309
Added StoneContinue type, removing from Loops parser
shnhrrsn Dec 5, 2017
c6d1886
Added StoneWhile type, removing from Loops parser
shnhrrsn Dec 5, 2017
6710794
Merged StoneLoop into new StoneFor type (and added StoneForeach alias…
shnhrrsn Dec 5, 2017
03c2e8e
Added StoneUnless type, removing from Conditionals parser
shnhrrsn Dec 5, 2017
8a40478
Added StoneElse type, removing from Conditionals parser
shnhrrsn Dec 5, 2017
7036efd
Added StoneElseif type, removing from Conditionals parser
shnhrrsn Dec 5, 2017
20f747c
Added StoneIf type, removing Conditionals parser
shnhrrsn Dec 5, 2017
777ff5d
Better abstracted stack logic in StoneDirectiveBlockType
shnhrrsn Dec 5, 2017
6b33c26
Added StoneSpaceless type, removing from Output parser
shnhrrsn Dec 5, 2017
43d13f5
Merged output parsing into the StoneOutput type
shnhrrsn Dec 5, 2017
23b4c83
Updated whitespace to match pre-acorn outputs
shnhrrsn Dec 6, 2017
f367458
Moved readOutputToken to StoneOutput token
shnhrrsn Dec 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions src/AST.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/CacheManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FS } from 'grind-support'
import './AST'
// import './AST'

const path = require('path')

Expand Down
53 changes: 12 additions & 41 deletions src/Compiler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import './Errors/StoneCompilerError'
import './StoneTemplate'
import './Stone'
import './Support/StoneSections'

const fs = require('fs')
const vm = require('vm')

export class Compiler {

Expand Down Expand Up @@ -34,10 +35,10 @@ export class Compiler {
this.engine.view.emit('compile:start', file)
}

const template = new StoneTemplate(this, contents, file)
let template = null

try {
template.compile()
template = Stone.stringify(Stone.parse(contents, file))
} catch(err) {
if(!err._hasTemplate) {
err._hasTemplate = true
Expand All @@ -56,46 +57,16 @@ export class Compiler {
}

if(!shouldEval) {
return template.toString()
return template
}

return template.toFunction()
}

compileDirective(context, name, args) {
if(name === 'directive') {
// Avoid infinite loop
return null
}

if(typeof this.directives[name] === 'function') {
return this.directives[name](context, args)
}

const method = `compile${name[0].toUpperCase()}${name.substring(1)}`

if(typeof this[method] !== 'function') {
throw new StoneCompilerError(context, `@${name} is not a valid Stone directive.`)
try {
const script = new vm.Script(`(${template})`, { filename: file })
return script.runInNewContext({ StoneSections })
} catch(err) {
console.log('template', template)
throw err
}

return this[method](context, args)
}

compileEnd() {
return '}'
}

}

// Load in the rest of the compilers
for(const [ name, func ] of Object.entries({
...require('./Compiler/Assignments'),
...require('./Compiler/Components'),
...require('./Compiler/Conditionals'),
...require('./Compiler/Layouts'),
...require('./Compiler/Loops'),
...require('./Compiler/Macros'),
...require('./Compiler/Outputs'),
})) {
Compiler.prototype[name] = func
}
138 changes: 0 additions & 138 deletions src/Compiler/Assignments.js

This file was deleted.

42 changes: 0 additions & 42 deletions src/Compiler/Components.js

This file was deleted.

26 changes: 0 additions & 26 deletions src/Compiler/Conditionals.js

This file was deleted.

Loading