diff --git a/gen/data/dfa.yaml b/gen/data/dfa.yaml deleted file mode 100644 index e93462d..0000000 --- a/gen/data/dfa.yaml +++ /dev/null @@ -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 - '>': ': _OpeningTagStart - -OpeningTagWhitespace: - '\w': OpeningTagWhitespace - '': ?AttrName - '>': =\w]': ?AttrAfterName - '': _AttrName - -AttrAfterName: - '\w': AttrAfterName - '>': ?OpeningTagWhitespace - '=': +AttrBeforeValue - -AttrBeforeValue: - '\w': AttrBeforeValue - "'": +AttrSingleQuotedValue - '"': +AttrDoubleQuotedValue - '': ?AttrUnquotedValue - -AttrSingleQuotedValue: - "'": { - 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; ${ - nodes.length -}] = [${nodes.map((n) => n.toUpperCase()).join(", ")}]; -`; - -writeFileSync(join(RUST_OUT_DIR, "dfa.rs"), output);