mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(ptx): share version scanner comment states (#17315)
This commit is contained in:
+16
-30
@@ -700,14 +700,11 @@ export const createPtxVersionScanner = (): {
|
||||
| "block-star"
|
||||
| "version-word"
|
||||
| "after-version"
|
||||
| "after-slash"
|
||||
| "after-line-comment"
|
||||
| "after-block-comment"
|
||||
| "after-block-star"
|
||||
| "version-major"
|
||||
| "version-minor";
|
||||
const VERSION_DIRECTIVE = ".version";
|
||||
let state: State = "leading";
|
||||
let afterComment: "leading" | "after-version" = "leading";
|
||||
let wordIndex = 0;
|
||||
let majorValue = 0;
|
||||
let hasMajorDigit = false;
|
||||
@@ -751,7 +748,8 @@ export const createPtxVersionScanner = (): {
|
||||
return "incomplete";
|
||||
}
|
||||
if (byte === 0x2f) {
|
||||
state = state === "leading" ? "slash" : "after-slash";
|
||||
afterComment = state;
|
||||
state = "slash";
|
||||
return "incomplete";
|
||||
}
|
||||
if (state === "leading") {
|
||||
@@ -766,35 +764,23 @@ export const createPtxVersionScanner = (): {
|
||||
hasMajorDigit = true;
|
||||
return "incomplete";
|
||||
}
|
||||
if (state === "slash" || state === "after-slash") {
|
||||
if (byte === 0x2f) {
|
||||
state = state === "slash" ? "line-comment" : "after-line-comment";
|
||||
return "incomplete";
|
||||
}
|
||||
if (byte === 0x2a) {
|
||||
state = state === "slash" ? "block-comment" : "after-block-comment";
|
||||
return "incomplete";
|
||||
}
|
||||
return "no";
|
||||
}
|
||||
if (state === "line-comment" || state === "after-line-comment") {
|
||||
if (byte === 0x0a)
|
||||
state = state === "line-comment" ? "leading" : "after-version";
|
||||
if (state === "slash") {
|
||||
if (byte === 0x2f) state = "line-comment";
|
||||
else if (byte === 0x2a) state = "block-comment";
|
||||
else return "no";
|
||||
return "incomplete";
|
||||
}
|
||||
if (state === "block-comment" || state === "after-block-comment") {
|
||||
if (byte === 0x2a)
|
||||
state = state === "block-comment" ? "block-star" : "after-block-star";
|
||||
if (state === "line-comment") {
|
||||
if (byte === 0x0a) state = afterComment;
|
||||
return "incomplete";
|
||||
}
|
||||
if (state === "block-star" || state === "after-block-star") {
|
||||
if (byte === 0x2f) {
|
||||
state = state === "block-star" ? "leading" : "after-version";
|
||||
return "incomplete";
|
||||
}
|
||||
if (byte !== 0x2a)
|
||||
state =
|
||||
state === "block-star" ? "block-comment" : "after-block-comment";
|
||||
if (state === "block-comment") {
|
||||
if (byte === 0x2a) state = "block-star";
|
||||
return "incomplete";
|
||||
}
|
||||
if (state === "block-star") {
|
||||
if (byte === 0x2f) state = afterComment;
|
||||
else if (byte !== 0x2a) state = "block-comment";
|
||||
return "incomplete";
|
||||
}
|
||||
if (state === "version-word") {
|
||||
|
||||
Reference in New Issue
Block a user