Skip to content

Commit 1239bf8

Browse files
committed
work on lexer
1 parent bb89fff commit 1239bf8

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/lexer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ lexer.prototype.next = function () {
474474

475475
// extends the lexer with states
476476
[
477+
require("./lexer/attribute.js"),
477478
require("./lexer/comments.js"),
478479
require("./lexer/initial.js"),
479480
require("./lexer/numbers.js"),

src/lexer/attribute.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (C) 2018 Glayzzle (BSD3 License)
3+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
4+
* @url http://glayzzle.com
5+
*/
6+
"use strict";
7+
8+
module.exports = {
9+
matchST_ATTRIBUTE: function () {
10+
const ch = this.input();
11+
// console.log("Char:", ch);
12+
if (this.is_LABEL_START()) {
13+
this.consume_LABEL();
14+
return this.tok.T_STRING;
15+
}
16+
17+
if (ch === "]") {
18+
this.popState();
19+
return "]";
20+
} else if (ch === "(") {
21+
return this.consume_TOKEN();
22+
// return "(";
23+
} else if (ch === ":") {
24+
return this.consume_TOKEN();
25+
} else if (ch === ")") {
26+
return this.consume_TOKEN();
27+
} else if (ch === ",") {
28+
return ch;
29+
} else if (ch === '"') {
30+
return this.ST_DOUBLE_QUOTES();
31+
} else if (ch === "'") {
32+
return this.T_CONSTANT_ENCAPSED_STRING();
33+
} else if (this.is_NUM()) {
34+
return this.consume_NUM();
35+
} else if (this.is_TABSPACE()) {
36+
return this.consume_TABSPACE();
37+
}
38+
39+
throw new Error("what now?");
40+
},
41+
};

src/lexer/scripting.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ module.exports = {
1616
case "\r\n":
1717
return this.T_WHITESPACE();
1818
case "#":
19+
if (this._input[this.offset] === "[") {
20+
this.input();
21+
this.begin("ST_ATTRIBUTE");
22+
return this.tok.T_ATTRIBUTE;
23+
}
1924
return this.T_COMMENT();
2025
case "/":
2126
if (this._input[this.offset] === "/") {

src/tokens.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ module.exports = {
148148
235: "T_FN",
149149
236: "T_NULLSAFE_OBJECT_OPERATOR",
150150
237: "T_MATCH",
151+
238: "T_ATTRIBUTE",
151152
},
152153
names: {
153154
T_HALT_COMPILER: 101,
@@ -287,5 +288,6 @@ module.exports = {
287288
T_FN: 235,
288289
T_NULLSAFE_OBJECT_OPERATOR: 236,
289290
T_MATCH: 237,
291+
T_ATTRIBUTE: 238,
290292
},
291293
};

0 commit comments

Comments
 (0)