-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from cheddar-lang/feature-funcop
Functionized Operators
- Loading branch information
Showing
8 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FEATURE: | ||
- [x] Functionized Operators | ||
- [ ] Custom REPL Colors | ||
- [ ] Strict typing in assignment | ||
- [ ] Static enforcement in functions | ||
- [ ] Class literals | ||
- [ ] Func statement | ||
- [ ] Signal propogation | ||
- [x] for of | ||
|
||
FIX: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import CheddarFunction from '../env/func'; | ||
import CheddarError from '../consts/err'; | ||
import CheddarClass from '../env/class'; | ||
import CheddarErrorDesc from '../consts/err_msg'; | ||
|
||
export default function(operator) { | ||
return new CheddarFunction([ | ||
["a", {}], | ||
["b", {}] | ||
], function(scope, input) { | ||
let LHS = input("a"); | ||
let RHS = input("b"); | ||
|
||
let resp; // output / response | ||
let opfunc = ( | ||
LHS.constructor.Operator || | ||
LHS.Operator | ||
).get(operator); | ||
|
||
if (opfunc) { | ||
resp = opfunc(LHS, RHS); | ||
} | ||
else { | ||
resp = CheddarError.NO_OP_BEHAVIOR; | ||
} | ||
|
||
if (resp === CheddarError.NO_OP_BEHAVIOR) { | ||
return CheddarErrorDesc.get(resp) | ||
.replace(/\$0/g, operator) | ||
.replace(/\$1/g, LHS ? ( | ||
LHS.constructor.Name || ( | ||
LHS.prototype instanceof CheddarClass ? | ||
"Class" : | ||
"nil" | ||
) | ||
) : "nil") | ||
.replace(/\$2/g, RHS ? ( | ||
RHS.constructor.Name || ( | ||
RHS.prototype instanceof CheddarClass ? | ||
"Class" : | ||
"nil" | ||
) | ||
) : "nil"); | ||
} else { | ||
return resp; | ||
} | ||
|
||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Functionized operators | ||
import {OP} from '../consts/ops'; | ||
import CheddarPrimitive from './primitive'; | ||
|
||
export default class CheddarFunctionizedOperatorToken extends CheddarPrimitive { | ||
exec() { | ||
return this.grammar(true, [ | ||
'(', OP, ')' | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.