Skip to content

Commit

Permalink
constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
horitaku1124 committed Jun 13, 2018
1 parent 40c4622 commit 21f1dd4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
22 changes: 20 additions & 2 deletions convert.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
let inPhpCode = false;
let phpCodeArray = [];
let line = 1, chars = 0;
let className = null;
const appendCode = (token) => {
phpCodeArray.push(new CodeVal(token, line, chars));
};
Expand Down Expand Up @@ -165,11 +166,20 @@
appendCode(token + tokens[i + 1]);
i += 1;
} else if(token.match(/^function$/i)) {
appendCode(token);
if(nextWord.match(/^ +$/) && next2Word.match(/^[a-zA-Z\_0-9]+$/)) {
if (className != null && next2Word === className) {
console.log(" constructor to __construct (" + line + ", " + chars + ")");
appendCode("public");
appendCode(nextWord);
appendCode("function");
appendCode(" __construct");
i += 2;
} else if(nextWord.match(/^ +$/) && next2Word.match(/^[a-zA-Z_0-9]+$/)) {
appendCode(token);
appendCode(nextWord);
appendCode(next2Word);
i += 2;
} else {
appendCode(token);
}
} else if (/^array$/i.test(token)) {
if (nextWord === "(" && next2Word === ")") {
Expand All @@ -179,6 +189,12 @@
} else {
appendCode(token);
}
} else if (/^class/i.test(token) && /^[a-zA-Z_0-9]+$/.test(next2Word)) {
className = next2Word;
appendCode(token);
appendCode(nextWord);
appendCode(next2Word);
i += 2
} else {
if(nextWord == "(" && token.match(/^[a-zA-Z\_0-9]+$/)) {
if(token.match(/^split$/i)) {
Expand Down Expand Up @@ -279,6 +295,8 @@
var $text3 = "<html><body bgcolor=\"white;\"></html>";
var $text4 = '<html><body bgcolor=\'white;\'></html>';
var $ary1 = array();
function TestClass1() {
}

function val() {
return $this->val;
Expand Down
20 changes: 18 additions & 2 deletions js/phpParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ phpParser.run = function(tokens){
let inPhpCode = false;
let phpCodeArray = [];
let line = 1, chars = 0;
let className = null;
const appendCode = (token) => {
phpCodeArray.push(new CodeVal(token, line, chars));
};
Expand Down Expand Up @@ -62,11 +63,20 @@ phpParser.run = function(tokens){
appendCode(token + tokens[i + 1]);
i += 1;
} else if(token.match(/^function$/i)) {
appendCode(token);
if(nextWord.match(/^ +$/) && next2Word.match(/^[a-zA-Z\_0-9]+$/)) {
if (className != null && next2Word === className) {
console.log(" constructor to __construct (" + line + ", " + chars + ")");
appendCode("public");
appendCode(nextWord);
appendCode("function");
appendCode(" __construct");
i += 2;
} else if(nextWord.match(/^ +$/) && next2Word.match(/^[a-zA-Z_0-9]+$/)) {
appendCode(token);
appendCode(nextWord);
appendCode(next2Word);
i += 2;
} else {
appendCode(token);
}
} else if (/^array$/i.test(token)) {
if (nextWord === "(" && next2Word === ")") {
Expand All @@ -76,6 +86,12 @@ phpParser.run = function(tokens){
} else {
appendCode(token);
}
} else if (/^class/i.test(token) && /^[a-zA-Z_0-9]+$/.test(next2Word)) {
className = next2Word;
appendCode(token);
appendCode(nextWord);
appendCode(next2Word);
i += 2
} else {
if(nextWord == "(" && token.match(/^[a-zA-Z\_0-9]+$/)) {
if(token.match(/^split$/i)) {
Expand Down
3 changes: 3 additions & 0 deletions php-codes/test1.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class TestClass1 {
var $text4 = '<html><body bgcolor=\'white;\'></html>';
var $ary1 = array();

function TestClass1() {
}

function val() {
return $this->val;
}
Expand Down

0 comments on commit 21f1dd4

Please sign in to comment.