Skip to content

Commit

Permalink
Implement assigment operators
Browse files Browse the repository at this point in the history
  • Loading branch information
batiste committed Jan 20, 2020
1 parent 612ccdf commit 5b6c043
Show file tree
Hide file tree
Showing 12 changed files with 520 additions and 63 deletions.
2 changes: 1 addition & 1 deletion example/ComponentState/ComponentStatePage.blop
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Animation = (attributes, children, node) => {
runAnimation = true
i = attributes.initial || 0
animate = () => {
i := i + 0.02
i += 0.02
position.x = (w.innerWidth / 2) + 120 * Math.cos(i) - 60
position.y = (w.innerHeight / 2) + 120 * Math.sin(i) - 60
setPos(position)
Expand Down
4 changes: 2 additions & 2 deletions example/DogPage/DogBreedGame.blop
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def DogGame(attributes, children) {
def check() {
guess = input.elm.value.toLowerCase().replace(' ', '-')
input.elm.value = ''
page.attempt = page.attempt + 1
page.attempt += 1
if (guess == dog.breed) {
delete page.lastMistake
page.success = page.success + 1
page.success += 1
} else {
page.lastMistake = { breed: dog.breed, guess }
}
Expand Down
4 changes: 2 additions & 2 deletions example/PetStore/index.blop
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def pagination(petStore) {
nbPage = Math.ceil(pets.length / pageSize)
nextPage = (e) => {
e.preventDefault()
petStore.pageIndex = pageIndex + 1
petStore.pageIndex += 1
}
previousPage = (e) => {
e.preventDefault()
petStore.pageIndex = pageIndex - 1
petStore.pageIndex -= 1
}
<p class="pagination">
if pageIndex > 0 {
Expand Down
10 changes: 9 additions & 1 deletion src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function _backend(node, _stream, _input, _filename = false, rootSource, resolve
const redefinedBy = stream[node.stream_index];
const sourceContext = utils.streamContext(input, token, token, stream);
const redefineContext = utils.streamContext(input, redefinedBy, redefinedBy, stream);
const error = new Error(`Redefinition of ${name} from upper scope. Use explicit := or rename ${name}
const error = new Error(`Redefinition of ${name} within this scope. Use explicit := or rename ${name}
${sourceContext}
Redefined by
Expand Down Expand Up @@ -342,6 +342,14 @@ function _backend(node, _stream, _input, _filename = false, rootSource, resolve
output.push(';');
return output;
},
'assign_op': (node) => {
const output = [];
shouldBeDefined(node.named.name.value, node.named.name);
for (let i = 0; i < node.children.length; i++) {
output.push(...generateCode(node.children[i]));
}
return output;
},
'exp_statement': (node) => {
const output = [];
for (let i = 0; i < node.children.length; i++) {
Expand Down
6 changes: 6 additions & 0 deletions src/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const grammar = {
'GLOBAL_STATEMENT': [
['condition'],
['assign'],
['assign_op'],
['virtual_node'],
['class_def'],
['try_catch'],
Expand All @@ -39,6 +40,7 @@ const grammar = {
'SCOPED_STATEMENT': [
['condition'],
['assign'],
['assign_op'],
['virtual_node'],
['class_def'],
['try_catch'],
Expand All @@ -61,6 +63,10 @@ const grammar = {
['object_destructuring:destructuring', 'w', '=', 'w', 'exp:exp'],
['name:path', 'object_access:access', 'w', '=', 'w', 'exp:exp'],
],
'assign_op': [
['name:name', 'annotation?:annotation', 'w', 'assign_operator', 'w', 'exp:exp'],
['name:name', 'object_access:access', 'w', 'assign_operator', 'w', 'exp:exp'],
],
'for_loop': [
['for', 'name:value', 'w', 'in', 'exp:exp', 'annotation?:objectannotation', 'w', '{', 'SCOPED_STATEMENTS*:stats', '}'],
['for', 'name:key', 'annotation?:keyannotation', ',', 'w', 'name:value', 'w', 'in', 'exp:exp', 'annotation?:objectannotation', 'w', '{', 'SCOPED_STATEMENTS*:stats', '}'],
Expand Down
Loading

0 comments on commit 5b6c043

Please sign in to comment.