Skip to content

Commit

Permalink
IMPROVED: all JavaScript reserved-words are reserved!
Browse files Browse the repository at this point in the history
  • Loading branch information
shanebdavis committed Jan 21, 2019
1 parent 27da463 commit f2f4c60
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 67 deletions.
17 changes: 17 additions & 0 deletions cafInCaf/CaffeineScript/JavaScriptReservedWordList.caf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
&ArtStandardLib.w
""
abstract else instanceof super
boolean enum int switch
break export interface synchronized
byte extends let this
case false long throw
catch final native throws
char finally new transient
class float null true
const for package try
continue function private typeof
debugger goto protected var
default if public void
delete implements return volatile
do import short while
double in static with
20 changes: 1 addition & 19 deletions cafInCaf/CaffeineScript/JavaScriptReservedWords.caf
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
words = &ArtStandardLib.w
""
abstract else instanceof super
boolean enum int switch
break export interface synchronized
byte extends let this
case false long throw
catch final native throws
char finally new transient
class float null true
const for package try
continue function private typeof
debugger goto protected var
default if public void
delete implements return volatile
do import short while
double in static with
each word in words into out = {}
out[word] = true
object &JavaScriptReservedWordList with true
4 changes: 4 additions & 0 deletions cafInCaf/CaffeineScript/Rules/Tokens.caf
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
| no | off
| typeof

### Reserved but not Used (from JavaScript)

| #{&ArtStandardLib.log &JavaScriptReservedWordList.join '|'}

### Reserved but not Used (future CaffeineScript)

| reduce | inject
Expand Down
7 changes: 7 additions & 0 deletions source/CaffeineScript/JavaScriptReservedWordList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";
let Caf = require("caffeine-script-runtime");
Caf.defMod(module, () => {
return require("art-standard-lib").w(
"abstract else instanceof super boolean enum int switch break export interface synchronized byte extends let this case false long throw catch final native throws char finally new transient class float null true const for package try continue function private typeof debugger goto protected var default if public void delete implements return volatile do import short while double in static with"
);
});
6 changes: 1 addition & 5 deletions source/CaffeineScript/JavaScriptReservedWords.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"use strict";
let Caf = require("caffeine-script-runtime");
Caf.defMod(module, () => {
let words, out;
words = require("art-standard-lib").w(
"abstract else instanceof super boolean enum int switch break export interface synchronized byte extends let this case false long throw catch final native throws char finally new transient class float null true const for package try continue function private typeof debugger goto protected var default if public void delete implements return volatile do import short while double in static with"
);
return Caf.each2(words, word => (out[word] = true), null, (out = {}));
return Caf.object(require("./JavaScriptReservedWordList"), () => true);
});
8 changes: 7 additions & 1 deletion source/CaffeineScript/Rules/Tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ Caf.defMod(module, () => {
_closeCurly: /\ *\}/,
_else: /(( *\n)+| +)else/,
ellipsis: "'...'",
reservedWord: /(import|true|false|null|undefined|global|require|module|eval|super|class|new|this|delete|instanceof|is|isnt|switch|when|then|else|if|until|while|unless|array|each|find|object|from|in|with|do|into|returning|with-key|to|by|til|try|catch|throw|and|or|not|extract|as|for|return|break|of|yes|on|no|off|typeof|reduce|inject|promise|await|short|skip|mixin|tap)(-[a-z]+)*\b(?![-])/,
reservedWord: RegExp(
`(import|true|false|null|undefined|global|require|module|eval|super|class|new|this|delete|instanceof|is|isnt|switch|when|then|else|if|until|while|unless|array|each|find|object|from|in|with|do|into|returning|with-key|to|by|til|try|catch|throw|and|or|not|extract|as|for|return|break|of|yes|on|no|off|typeof|${Caf.toString(
require("art-standard-lib").log(
require("../JavaScriptReservedWordList").join("|")
)
)}|reduce|inject|promise|await|short|skip|mixin|tap)(-[a-z]+)*\\b(?![-])`
),
identifier: [
/(?!\d)((?!\s)[$\w\u007f-\uffff])+/,
{
Expand Down
17 changes: 9 additions & 8 deletions source/CaffeineScript/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ module.exports = require './namespace'
module.exports
.includeInNamespace require './CaffeineScript'
.addModules
CaffeineScriptParser: require './CaffeineScriptParser'
CafParseNodeBaseClass: require './CafParseNodeBaseClass'
JavaScriptReservedWords: require './JavaScriptReservedWords'
Lib: require './Lib'
OperatorHelper: require './OperatorHelper'
Preprocessors: require './Preprocessors'
StandardImport: require './StandardImport'
StnRegistry: require './StnRegistry'
CaffeineScriptParser: require './CaffeineScriptParser'
CafParseNodeBaseClass: require './CafParseNodeBaseClass'
JavaScriptReservedWordList: require './JavaScriptReservedWordList'
JavaScriptReservedWords: require './JavaScriptReservedWords'
Lib: require './Lib'
OperatorHelper: require './OperatorHelper'
Preprocessors: require './Preprocessors'
StandardImport: require './StandardImport'
StnRegistry: require './StnRegistry'
require './Rules'
require './SemanticTree'
3 changes: 3 additions & 0 deletions test/tests/CaffeineScript/Parser/Values.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ module.exports = suite: parseTestSuite
"1 + (2 * 5)": "1 + 2 * 5;"
"(new Foo).bar": "(new Foo).bar;"

reservedWords:
"default = 1": null

51 changes: 17 additions & 34 deletions tests-to-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
&DotSubdir
# Should generate: require('./.DotSubdir')
```
---
```coffeescript
# bad regexp detect
rect a.left, a.top, a.w/2, a.h/2
```


# Improvements
```coffeescript
Expand All @@ -33,6 +39,10 @@ array a in-array b
a
b
} = myObject

{
hi: 1
}

{}
a
Expand All @@ -50,6 +60,12 @@ like string-blocks or comment-blocks themselves, needs something akin to the
current preprocess step: Any under-indented comments should be up-indented to
the base of the sub-block. I -think- that'll solve it.

```coffeescript
# extra-indented comments should be ignored
->
# extra indented first comment
foo
```



Expand Down Expand Up @@ -146,7 +162,7 @@ foo (a)->
.bar
```

Above one is super tricky! The function def correctly fails to match the indented block starting with a dot-line-start, but then the indented-dot-line-start happily accepts it. It actually could be considered legal! However, it's horrific to my eyes. It breaks principle-of-least-surprise badly.
Above one is super tricky! The function definition correctly fails to match the indented block starting with a dot-line-start, but then the indented-dot-line-start happily accepts it. It actually could be considered legal! However, it's horrific to my eyes. It breaks principle-of-least-surprise badly.

I think we need "match-block-or-no-block" to solve this.

Expand All @@ -156,11 +172,6 @@ NOTE: It isn't just dot-line-starts. This also fails fore operator-line-starts.
```coffeescript
App extends FluxComponent
```
---
'default' is an illegal variable name in JS
```coffeescript
({default, fields}) ->
```



Expand Down Expand Up @@ -228,34 +239,6 @@ Probably same problem as above:
array item in -> a when item
```

# Should Compile

```coffeescript
# backward compatible with coffeescript
{
hi: 1
}

{
a
b
} = foo
```



# TO SORT

```coffeescript
# bad regexp detect
rect a.left, a.top, a.w/2, a.h/2

# extra-indented comments should be ignored
->
# extra indented first comment
123
```

# Improved Parse Errors

```
Expand Down

0 comments on commit f2f4c60

Please sign in to comment.