Skip to content

Commit

Permalink
shove
Browse files Browse the repository at this point in the history
  • Loading branch information
simplygreatwork committed Apr 17, 2020
1 parent 907193b commit 005f636
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions compiler/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class Transform {
transform(macros_) {

this.macros = {}
this.system.keywords = {}
macros_.forEach(function(macro, precedence) {
macro = macro(this.system, this.document, precedence)
let key = macro.type + ':' + (macro.value ? macro.value : '')
if (macro.value) this.system.keywords[macro.value] = macro.value
this.macros[key] = this.macros[key] || []
this.macros[key].push(macro)
}.bind(this))
this.system.keywords = Array.from(Object.keys(this.system.keywords))
let tree = this.document.tree
this.walk(tree[0], 0, [], {})
}
Expand Down
12 changes: 12 additions & 0 deletions macros/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = function(system, document) {
if (! query.is_type(parent, 'expression')) return
if (! shared.is_inside_function(state)) return
if (! query.is_type_value(parent.value[0], 'symbol', 'set')) return
if (system.keywords.indexOf(parent.value[1].value) > -1) {
warn(parent.value[1].value)
}
if (query.is_length_exceeding(parent, 2)) {
if (query.is_type_value(parent.value[2], 'symbol', 'to')) {
let index_ = query.remove(parent, parent.value[2])
Expand All @@ -27,3 +30,12 @@ module.exports = function(system, document) {
}
}
}

function warn(value) {

if (false) {
console.error('')
console.error(`>>>>> Warning: The variable "${value}" could conflict with an existing keyword. <<<<<`)
console.error('')
}
}
2 changes: 1 addition & 1 deletion macros/set_local.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(system, document) {
if (! query.is_type_value(parent.value[0], 'symbol', 'set_local')) return
parent.value[1].value = shared.dollarize(parent.value[1].value)
shared.declare(parent.value[1].value, state)
if (false) return
if (false) return // below for: "set list to List clone" instead of "set list to (List clone)""
if (query.is_type(parent.value[2], 'expression')) return
let expression = parse(` ()`)[0]
expression.value = parent.value.splice(2, parent.value.length - 2)
Expand Down
2 changes: 1 addition & 1 deletion macros/typeof.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(system, document) {
let parent = query.last(parents)
if (! query.is_type(parent, 'expression')) return
if (! query.is_type_value(node, 'symbol', 'typeof')) return
if (! (index === 0)) return
if (index !== 0) return
let type = parent.value[1].value
if (system.state.index_type[type] === undefined) {
system.state.index_type[type] = system.state.id_type
Expand Down

0 comments on commit 005f636

Please sign in to comment.