Delete legacy DFA code

This commit is contained in:
Wilson Lin 2021-08-06 21:08:33 +10:00
parent e52d85bc28
commit c1c0b61317
2 changed files with 0 additions and 154 deletions

View File

@ -1,77 +0,0 @@
# Prefixes:
# `_` means to lowercase accumulate.
# `<` means to accumulate transition pattern as part of current state.
# `+` means to accumulate transition pattern as part of next state.
# `?` means to look ahead but don't accumulate transition pattern and allow next state to reconsume.
Text:
'\w': ?TextWhitespace
'\<': +OpeningTagStart
'\</': +ClosingTag
'\<!--': +Comment
'&': ?TextEntity
'': Text
TextWhitespace:
'\w': TextWhitespace
'&': ?TextEntity
'': ?Text
Comment:
'-->': <Text
'': Comment
ClosingTag:
'<tagName>': _ClosingTag
'>': <Text
OpeningTagStart:
'\w': ?OpeningTagWhitespace
'<tagName>': _OpeningTagStart
OpeningTagWhitespace:
'\w': OpeningTagWhitespace
'<attrName>': ?AttrName
'>': <Text
AttrName:
'[>=\w]': ?AttrAfterName
'<attrName>': _AttrName
AttrAfterName:
'\w': AttrAfterName
'>': ?OpeningTagWhitespace
'=': +AttrBeforeValue
AttrBeforeValue:
'\w': AttrBeforeValue
"'": +AttrSingleQuotedValue
'"': +AttrDoubleQuotedValue
'': ?AttrUnquotedValue
AttrSingleQuotedValue:
"'": <OpeningTagWhitespace
'&': ?AttrValueEntity
'\w': ?AttrSingleQuotedValueWhitespace
'': AttrSingleQuotedValue
AttrSingleQuotedValueWhitespace:
'\w': AttrSingleQuotedValueWhitespace
'&': ?AttrValueEntity
'': ?AttrSingleQuotedValue
AttrDoubleQuotedValue:
'"': <OpeningTagWhitespace
'&': ?AttrValueEntity
'\w': ?AttrDoubleQuotedValueWhitespace
'': AttrDoubleQuotedValue
AttrDoubleQuotedValueWhitespace:
'\w': AttrDoubleQuotedValueWhitespace
'&': ?AttrValueEntity
'': ?AttrDoubleQuotedValue
AttrUnquotedValue:
'\w': ?OpeningTagWhitespace
'&': ?AttrValueEntity
'': AttrUnquotedValue

View File

@ -1,77 +0,0 @@
import yaml from "yaml";
import { DATA_DIR, RUST_OUT_DIR } from "./_common";
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
import { EOL } from "os";
import { parsePattern, TrieBuilder } from "./trie";
const dfa: { [node: string]: { [transition: string]: string } } = yaml.parse(
readFileSync(join(DATA_DIR, "dfa.yaml"), "utf8")
);
// These states must always exist; see lex/mod.rs for more details.
dfa["TextEntity"] = {};
dfa["AttrValueEntity"] = {};
dfa["Unknown"] = {};
dfa["EOF"] = {};
const nodes = Object.keys(dfa).sort();
const rsTransition = (val: string) => {
const [_, flag, next] = /^([_<+?]?)(.*)$/.exec(val)!;
const consumeMode = {
_: "AccumulateLowerCase",
"": "Accumulate",
"<": "Current",
"+": "Next",
"?": "Reconsume",
}[flag];
return `Transition {
to: State::${next},
consume: ConsumeMode::${consumeMode},
}`;
};
const output = `
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum State {
${nodes.map((n, i) => `${n} = ${i}`).join(`,${EOL} `)}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ConsumeMode {
Current,
Next,
Reconsume,
Accumulate,
AccumulateLowerCase,
}
#[derive(Clone, Copy)]
pub struct Transition {
// Make pub to allow destructuring.
pub to: State,
pub consume: ConsumeMode,
}
${nodes
.map((n) => {
const trieBuilder = new TrieBuilder(n.toUpperCase(), "Transition");
for (const [pat, val] of Object.entries(dfa[n])) {
if (pat == "") {
continue;
}
trieBuilder.addPattern(parsePattern(pat), rsTransition(val));
}
if (dfa[n][""] !== undefined) {
trieBuilder.fillRemaining(rsTransition(dfa[n][""]));
}
return trieBuilder.generate();
})
.join(EOL + EOL)}
pub static TRANSITIONS: [&'static crate::pattern::TrieNode<Transition>; ${
nodes.length
}] = [${nodes.map((n) => n.toUpperCase()).join(", ")}];
`;
writeFileSync(join(RUST_OUT_DIR, "dfa.rs"), output);