mirror of
https://github.com/pdemian/human2regex.git
synced 2025-05-16 12:30:09 -07:00
Parser doesn't throw any errors
But doesn't work
This commit is contained in:
parent
79c9b9edd4
commit
bacb104d89
@ -15,7 +15,7 @@ export class Human2RegexParser extends CstParser {
|
||||
public nodes: { [key: string]: (idxInCallingRule?: number, ...args: unknown[]) => CstNode } = {};
|
||||
|
||||
constructor(private options: Human2RegexParserOptions = new Human2RegexParserOptions()) {
|
||||
super(T.AllTokens, { recoveryEnabled: true, maxLookahead: 4});
|
||||
super(T.AllTokens, { recoveryEnabled: true, maxLookahead: 2});
|
||||
|
||||
if (Human2RegexParser.already_init) {
|
||||
throw new Error("Only 1 instance of Human2RegexParser allowed");
|
||||
@ -25,7 +25,7 @@ export class Human2RegexParser extends CstParser {
|
||||
|
||||
const $ = this;
|
||||
|
||||
this.nodes.NumberSubStatement = $.RULE("Number Sub-Statement", () => {
|
||||
this.nodes.NumberSubStatement = $.RULE("NumberSubStatement", () => {
|
||||
$.OR([
|
||||
{ ALT: () => $.CONSUME(T.One) },
|
||||
{ ALT: () => $.CONSUME(T.Two) },
|
||||
@ -43,48 +43,49 @@ export class Human2RegexParser extends CstParser {
|
||||
});
|
||||
|
||||
// 1, 1..2, between 1 and/to 2 inclusively/exclusively
|
||||
this.nodes.CountSubStatement = $.RULE("Count Sub-Statement", () => {
|
||||
this.nodes.CountSubStatement = $.RULE("CountSubStatement", () => {
|
||||
$.OR([
|
||||
{ ALT: () => {
|
||||
$.OPTION(() => $.CONSUME(T.Exactly));
|
||||
$.SUBRULE(this.nodes.NumberSubStatement);
|
||||
$.OPTION(() => $.CONSUME(T.Times));
|
||||
}},
|
||||
{ ALT: () => {
|
||||
$.OPTION(() => $.CONSUME(T.From));
|
||||
$.SUBRULE(this.nodes.NumberSubStatement);
|
||||
$.OR([
|
||||
{ ALT: () => $.CONSUME(T.OrMore) },
|
||||
{ ALT: () => {
|
||||
$.CONSUME(T.To);
|
||||
$.SUBRULE(this.nodes.NumberSubStatement);
|
||||
}}
|
||||
]);
|
||||
$.OPTION(() => $.CONSUME(T.Times));
|
||||
}},
|
||||
|
||||
{ ALT: () => {
|
||||
$.CONSUME(T.Between);
|
||||
$.SUBRULE(this.nodes.NumberSubStatement);
|
||||
$.OR([
|
||||
{ ALT: () => $.CONSUME(T.To) },
|
||||
$.SUBRULE4(this.nodes.NumberSubStatement);
|
||||
$.OR3([
|
||||
{ ALT: () => $.CONSUME2(T.To) },
|
||||
{ ALT: () => $.CONSUME(T.And) }
|
||||
]);
|
||||
$.SUBRULE(this.nodes.NumberSubStatement);
|
||||
$.OPTION(() => $.CONSUME(T.Times));
|
||||
$.OPTION(() => {
|
||||
$.OR([
|
||||
$.SUBRULE5(this.nodes.NumberSubStatement);
|
||||
$.OPTION4(() => $.CONSUME3(T.Times));
|
||||
$.OPTION5(() => {
|
||||
$.OR4([
|
||||
{ ALT: () => $.CONSUME(T.Inclusive) },
|
||||
{ ALT: () => $.CONSUME(T.Exclusive) }
|
||||
]);
|
||||
});
|
||||
}},
|
||||
|
||||
{ ALT: () => {
|
||||
$.OPTION2(() => $.CONSUME(T.From));
|
||||
$.SUBRULE2(this.nodes.NumberSubStatement);
|
||||
$.OR2([
|
||||
{ ALT: () => $.CONSUME(T.OrMore) },
|
||||
{ ALT: () => {
|
||||
$.CONSUME(T.To);
|
||||
$.SUBRULE3(this.nodes.NumberSubStatement);
|
||||
}}
|
||||
]);
|
||||
$.OPTION3(() => $.CONSUME2(T.Times));
|
||||
}},
|
||||
|
||||
{ ALT: () => {
|
||||
$.OPTION(() => $.CONSUME(T.Exactly));
|
||||
$.SUBRULE(this.nodes.NumberSubStatement);
|
||||
$.OPTION6(() => $.CONSUME(T.Times));
|
||||
}}
|
||||
]);
|
||||
});
|
||||
|
||||
this.nodes.MatchSubStatement = $.RULE("Match Sub-Statement", () => {
|
||||
this.nodes.MatchSubStatement = $.RULE("MatchSubStatement", () => {
|
||||
$.OPTION(() => $.SUBRULE(this.nodes.CountSubStatement) );
|
||||
$.OPTION(() => $.CONSUME(T.Not));
|
||||
$.OPTION2(() => $.CONSUME(T.Not));
|
||||
$.AT_LEAST_ONE_SEP({
|
||||
SEP: T.Or,
|
||||
DEF: () => {
|
||||
@ -113,14 +114,14 @@ export class Human2RegexParser extends CstParser {
|
||||
$.SUBRULE(this.nodes.MatchSubStatement);
|
||||
$.MANY(() => {
|
||||
$.OR([
|
||||
{ ALT: () => $.CONSUME(T.And) },
|
||||
{ ALT: () => {
|
||||
$.OPTION(() => $.CONSUME(T.And));
|
||||
$.OPTION2(() => $.CONSUME2(T.And));
|
||||
$.CONSUME(T.Then);
|
||||
}}
|
||||
}},
|
||||
{ ALT: () => $.CONSUME(T.And) },
|
||||
]);
|
||||
$.OPTION(() => $.CONSUME(T.Optional));
|
||||
$.SUBRULE(this.nodes.MatchSubStatement);
|
||||
$.OPTION3(() => $.CONSUME2(T.Optional));
|
||||
$.SUBRULE2(this.nodes.MatchSubStatement);
|
||||
});
|
||||
});
|
||||
|
||||
@ -143,26 +144,26 @@ export class Human2RegexParser extends CstParser {
|
||||
});
|
||||
|
||||
this.nodes.GroupStatement = $.RULE("GroupStatement", () => {
|
||||
$.OPTION(() => $.CONSUME(T.Optional));
|
||||
$.OPTION2(() => $.CONSUME(T.Optional));
|
||||
$.CONSUME(T.Create);
|
||||
$.CONSUME(T.A);
|
||||
$.OPTION(() => $.CONSUME(T.Optional));
|
||||
$.OPTION3(() => $.CONSUME2(T.Optional));
|
||||
$.CONSUME(T.Group);
|
||||
$.OPTION(() => {
|
||||
$.CONSUME(T.Called);
|
||||
$.CONSUME(T.StringLiteral);
|
||||
});
|
||||
$.CONSUME(T.Indent);
|
||||
$.AT_LEAST_ONE(() => this.nodes.Statement);
|
||||
$.AT_LEAST_ONE(this.nodes.Statement);
|
||||
$.CONSUME(T.Outdent);
|
||||
});
|
||||
|
||||
this.nodes.RepeatStatement = $.RULE("RepeatStatement", () => {
|
||||
$.OPTION(() => $.CONSUME(T.Optional));
|
||||
$.OPTION3(() => $.CONSUME(T.Optional));
|
||||
$.CONSUME(T.Repeat);
|
||||
$.OPTION(() => $.SUBRULE(this.nodes.CountSubStatement));
|
||||
$.CONSUME(T.Indent);
|
||||
$.AT_LEAST_ONE(() => this.nodes.Statement);
|
||||
$.AT_LEAST_ONE(this.nodes.Statement);
|
||||
$.CONSUME(T.Outdent);
|
||||
});
|
||||
|
||||
|
@ -72,8 +72,8 @@ export const By = createToken({name: "By", pattern: /by/i});
|
||||
|
||||
export const EndOfLine = createToken({name: "EOL", pattern: /\n/ });
|
||||
export const WS = createToken({name: "Whitespace", pattern: /\s+/, group: Lexer.SKIPPED });
|
||||
export const SingleLineComment = createToken({name: "Single-Line Comment", pattern: /(#|\/\/).*/, group: Lexer.SKIPPED });
|
||||
export const MultilineComment = createToken({name: "Multi-Line Comment", pattern: /\/\*(.*)\*\//, line_breaks: true, group: Lexer.SKIPPED });
|
||||
export const SingleLineComment = createToken({name: "SingleLineComment", pattern: /(#|\/\/).*/, group: Lexer.SKIPPED });
|
||||
export const MultilineComment = createToken({name: "MultiLineComment", pattern: /\/\*(.*)\*\//, line_breaks: true, group: Lexer.SKIPPED });
|
||||
|
||||
export const Identifier = createToken({name: "Identifier", pattern: /[a-z]\w*/i });
|
||||
export const NumberLiteral = createToken({name: "NumberLiteral", pattern: /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/ });
|
||||
|
Loading…
x
Reference in New Issue
Block a user