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