Skip to content

Commit

Permalink
FIX: blocks for nested extracts work
Browse files Browse the repository at this point in the history
  • Loading branch information
shanebdavis committed Nov 18, 2018
1 parent c59aff4 commit 9530720
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
9 changes: 6 additions & 3 deletions cafInCaf/CaffeineScript/Rules/Extract.caf
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import &StandardImport, &CaffeineEight

extractExpression:
"" extractSource:value _ /extract/ conditionalExtract:conditionalExtract? _ extractionTarget
"" extractSource:value _ /extract/ conditionalExtract:conditionalExtract? _? extractBodyBlock
"" extractSource:value _ /extract/ conditionalExtract:conditionalExtract? extractActions
stnFactory: :ExtractStn
stnProps: -> conditional: !!@conditionalExtract

extractActions:
"" _ extractionTarget
"" _? extractBodyBlock

extractBodyBlock: Extensions.IndentBlocks.getPropsToSubparseBlock rule: :extractBody

extractBody: "end* extractBodyLine+"
Expand All @@ -26,7 +29,7 @@ extractAction:
:extractToIdentifier

chainExtract:
"" extractSource:extractToIdentifier _ /extract/ conditionalExtract:conditionalExtract? _ extractionTarget
"" extractSource:extractToIdentifier _ /extract/ conditionalExtract:conditionalExtract? extractActions
stnFactory: :ExtractStn
stnProps: -> conditional: !!@conditionalExtract

Expand Down
6 changes: 3 additions & 3 deletions source/CaffeineScript/Rules/Extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Caf.defMod(module, () => {
Extensions => {
return {
extractExpression: [
"extractSource:value _ /extract/ conditionalExtract:conditionalExtract? _ extractionTarget",
"extractSource:value _ /extract/ conditionalExtract:conditionalExtract? _? extractBodyBlock",
"extractSource:value _ /extract/ conditionalExtract:conditionalExtract? extractActions",
{
stnFactory: "ExtractStn",
stnProps: function() {
return { conditional: !!this.conditionalExtract };
}
}
],
extractActions: ["_ extractionTarget", "_? extractBodyBlock"],
extractBodyBlock: Extensions.IndentBlocks.getPropsToSubparseBlock({
rule: "extractBody"
}),
Expand All @@ -29,7 +29,7 @@ Caf.defMod(module, () => {
],
extractAction: ["chainExtract", "extractToIdentifier"],
chainExtract: [
"extractSource:extractToIdentifier _ /extract/ conditionalExtract:conditionalExtract? _ extractionTarget",
"extractSource:extractToIdentifier _ /extract/ conditionalExtract:conditionalExtract? extractActions",
{
stnFactory: "ExtractStn",
stnProps: function() {
Expand Down
6 changes: 6 additions & 0 deletions test/tests/CaffeineScript/Parser/Extract.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ module.exports = suite: parseTestSuite
d
""": "let b, c, d; b = a.b; c = a.c; d = a.d;"

"""
a extract
b extract
c
""": "let b, c; b = a.b; c = b.c;"

pathing:
"a extract b.c": "let c; c = a.b.c;"
###
Expand Down
18 changes: 0 additions & 18 deletions tests-to-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ while a > 0
This should have "let a" outside the while, but should have "let b" inside, like
all the comprehensions.

---------
```
result extract colorInfo extract colorMap
```

SHOULD extract colorInfo. Notes:

1. ```> result extract colorInfo, colorInfo extract colorMap```
is just weird
2. ```> (a extract b) ->```
That sets 'a' even though it is an intermediate value.

However, I'm OK with the following not setting 'b':

```
> a extract b.c
```

--------

### Extract Todo
Expand Down

0 comments on commit 9530720

Please sign in to comment.