-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
296fcc4
commit 70cfa36
Showing
75 changed files
with
15,399 additions
and
897 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,8 @@ | ||
func test() { | ||
$a = "123" | ||
for($i of $a) { | ||
print($i) | ||
} | ||
} | ||
|
||
test() |
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
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,70 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseForStatement = void 0; | ||
const lexer1_1 = require("../lexer1"); | ||
const parser_1 = require("../parser"); | ||
const Assignment_1 = require("./Assignment"); | ||
const Function_1 = require("./Function"); | ||
function parseForStatement(lexer) { | ||
lexer.NextTokenIs(lexer1_1.TOKEN_FOR); | ||
lexer.LookAheadAndSkip(lexer1_1.TOKEN_IGNORED); | ||
lexer.NextTokenIs(lexer1_1.TOKEN_LEFT_PAREN); // ( | ||
const ForOfStatement = parseBinaryExpression(lexer); | ||
lexer.NextTokenIs(lexer1_1.TOKEN_RIGHT_PAREN); // ) | ||
lexer.LookAheadAndSkip(lexer1_1.TOKEN_IGNORED); | ||
lexer.NextTokenIs(lexer1_1.BLOCK_START); // { | ||
lexer.LookAheadAndSkip(lexer1_1.TOKEN_IGNORED); // 去除空格回车等 | ||
const BlockStatementBody = []; | ||
const consequent = { | ||
type: "BlockStatement", | ||
body: [] | ||
}; | ||
consequent.body = Function_1.paseBlock(lexer, BlockStatementBody); | ||
lexer.NextTokenIs(lexer1_1.BLOCK_END); | ||
lexer.LookAheadAndSkip(lexer1_1.TOKEN_IGNORED); // 去除空格回车等 | ||
ForOfStatement.body = consequent; | ||
return ForOfStatement; | ||
} | ||
exports.parseForStatement = parseForStatement; | ||
function parseBinaryExpression(lexer) { | ||
const ForOfStatement = { | ||
type: "ForOfStatement", | ||
await: false, | ||
left: { | ||
type: "VariableDeclaration", | ||
declarations: [ | ||
{ | ||
type: "VariableDeclarator", | ||
id: { | ||
type: "Identifier", | ||
name: "" | ||
}, | ||
init: null | ||
} | ||
], | ||
kind: "let" | ||
}, | ||
// operator: "", | ||
right: { | ||
type: "Identifier", | ||
// name: "b" | ||
} | ||
}; | ||
const Variable = parser_1.parseVariable(lexer); // 标识符,这里面会把邻近的空格回车删掉 | ||
const identifier = new Assignment_1.Identifier(Variable.Name); | ||
lexer.NextTokenIs(lexer1_1.TOKEN_OF); | ||
// BinaryExpression.operator = (lexer.NextTokenIs(Operator)).nowToken; // +-*/ | ||
lexer.LookAheadAndSkip(lexer1_1.TOKEN_IGNORED); // 空格 | ||
let ahead = lexer.LookAhead(); | ||
ForOfStatement.left.declarations[0].id = new Assignment_1.Identifier(identifier.name); | ||
if (ahead.tokenType === lexer1_1.NUMBER) { | ||
const literial = new Assignment_1.Literal(parser_1.parseNumber(lexer)); | ||
ForOfStatement.right = literial; | ||
} | ||
else if (ahead.tokenType === lexer1_1.TOKEN_VAR_PREFIX) { | ||
const Variable = parser_1.parseVariable(lexer); // 标识符 | ||
const identifier = new Assignment_1.Identifier(Variable.Name); | ||
ForOfStatement.right = identifier; | ||
} | ||
return ForOfStatement; | ||
} |
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,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Prototype = void 0; | ||
class Prototype { | ||
constructor(constructor) { | ||
this.constructor = constructor; | ||
} | ||
} | ||
exports.Prototype = Prototype; |
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,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.This = void 0; | ||
class This { | ||
constructor(context) { | ||
this.context = context; | ||
} | ||
} | ||
exports.This = This; |
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 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ANONYMOUS = exports.NEW = exports.ARGUMENTS = exports.UNDEFINED = exports.REQUIRE = exports.EXPORTS = exports.MODULE = exports.THIS = void 0; | ||
exports.THIS = "this"; | ||
exports.MODULE = "module"; | ||
exports.EXPORTS = "exports"; | ||
exports.REQUIRE = "require"; | ||
exports.UNDEFINED = "undefined"; | ||
exports.ARGUMENTS = "arguments"; | ||
exports.NEW = "new"; | ||
exports.ANONYMOUS = "anonymous"; |
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,149 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Context = exports.DEFAULT_CONTEXT = void 0; | ||
const constant_1 = require("./constant"); | ||
// ECMA standar refs: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects | ||
exports.DEFAULT_CONTEXT = { | ||
Function, | ||
Array, | ||
Boolean, | ||
clearInterval, | ||
clearTimeout, | ||
console, | ||
Date, | ||
decodeURI, | ||
decodeURIComponent, | ||
encodeURI, | ||
encodeURIComponent, | ||
Error, | ||
escape, | ||
eval, | ||
EvalError, | ||
Infinity, | ||
isFinite, | ||
isNaN, | ||
JSON, | ||
Math, | ||
NaN, | ||
Number, | ||
["null"]: null, | ||
[constant_1.UNDEFINED]: void 0, | ||
Object, | ||
parseFloat, | ||
parseInt, | ||
RangeError, | ||
ReferenceError, | ||
RegExp, | ||
setInterval, | ||
setTimeout, | ||
String, | ||
SyntaxError, | ||
TypeError, | ||
unescape, | ||
URIError | ||
}; | ||
// need to polyfill by user | ||
/* istanbul ignore if */ | ||
if (typeof Promise !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Promise = Promise; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Proxy !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Proxy = Proxy; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Reflect !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Reflect = Reflect; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Symbol !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Symbol = Symbol; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Set !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Set = Set; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof WeakSet !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.WeakSet = WeakSet; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Map !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Map = Map; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof WeakMap !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.WeakMap = WeakMap; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof ArrayBuffer !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.ArrayBuffer = ArrayBuffer; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof SharedArrayBuffer !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.ArrayBuffer = SharedArrayBuffer; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof DataView !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.ArrayBuffer = DataView; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Atomics !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Atomics = Atomics; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Float32Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Float32Array = Float32Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Float64Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Float64Array = Float64Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Int16Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Int16Array = Int16Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Int32Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Int32Array = Int32Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Int8Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Int32Array = Int8Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Intl !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Intl = Intl; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Uint16Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Uint16Array = Uint16Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Uint32Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Uint32Array = Uint32Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Uint8Array !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Uint8Array = Uint8Array; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof Uint8ClampedArray !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.Uint8ClampedArray = Uint8ClampedArray; | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof WebAssembly !== constant_1.UNDEFINED) { | ||
exports.DEFAULT_CONTEXT.WebAssembly = WebAssembly; | ||
} | ||
class Context { | ||
constructor(externalContext = {}) { | ||
const ctx = { ...exports.DEFAULT_CONTEXT, ...externalContext }; | ||
for (const attr in ctx) { | ||
/* istanbul ignore next */ | ||
if (ctx.hasOwnProperty(attr)) { | ||
this[attr] = ctx[attr]; | ||
} | ||
} | ||
} | ||
} | ||
exports.Context = Context; |
Oops, something went wrong.