Permalink
Browse files

IMPROVED: all JavaScript reserved-words are reserved!

  • Loading branch information...
shanebdavis committed Jan 21, 2019
1 parent 27da463 commit f2f4c608cd77bb712f355face6d5841af1ebf6a0
@@ -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
@@ -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
@@ -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
@@ -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"
);
});
@@ -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);
});
@@ -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])+/,
{
@@ -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'
@@ -51,3 +51,6 @@ module.exports = suite: parseTestSuite
"1 + (2 * 5)": "1 + 2 * 5;"
"(new Foo).bar": "(new Foo).bar;"

reservedWords:
"default = 1": null

@@ -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
@@ -33,6 +39,10 @@ array a in-array b
a
b
} = myObject
{
hi: 1
}
{}
a
@@ -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
```



@@ -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.

@@ -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}) ->
```



@@ -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

```

0 comments on commit f2f4c60

Please sign in to comment.