1
0
mirror of https://github.com/pdemian/human2regex.git synced 2025-05-16 04:20:35 -07:00

Fixed bug and reduced image size

This commit is contained in:
Patrick Demian 2020-11-02 18:46:28 -05:00
parent bb0f662d1e
commit ffbd0d72b1
5 changed files with 20 additions and 7 deletions

6
docs/bundle.min.js vendored

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -448,7 +448,20 @@ export class MatchStatementCST extends StatementCST {
public toRegex(language: RegexDialect): string {
return this.matches.map((x) => {
return x.statement.toRegex(language) + (x.optional ? "?" : "");
let match_stmt = x.statement.toRegex(language);
// need to group if optional and ungrouped
if (x.optional) {
if (!isSingleRegexCharacter(match_stmt)) {
// don't re-group a group
if (match_stmt[0] !== "(" && match_stmt[match_stmt.length-1] !== ")") {
match_stmt = "(?:" + match_stmt + ")";
}
}
match_stmt += "?";
}
return match_stmt;
}).join("");
}
}

View File

@ -210,7 +210,7 @@ export class Human2RegexLexer {
const tok = last(tokens);
// Do we have an EOL marker at the end?
if (tok.tokenType !== EndOfLine) {
if (tokens.length > 0 && tok.tokenType !== EndOfLine) {
tokens.push(createTokenInstance(EndOfLine, "\n", tok.endOffset ?? NaN, tok.endOffset ?? NaN, tok.startLine ?? NaN, NaN, tok.startColumn ?? NaN, NaN));
}

View File

@ -174,7 +174,7 @@ export class CommonError {
*/
public static fromLexError(error: ILexingError): CommonError {
// not really fond of --> and <--
const new_msg = error.message.replace(/(-->|<--)/g, "");
const new_msg = error.message.replace(/(--?>|<--?)/g, "");
return new CommonError("Lexer Error", error.line, error.column, error.length, new_msg);
}
@ -187,7 +187,7 @@ export class CommonError {
*/
public static fromParseError(error: IRecognitionException): CommonError {
// not really fond of --> and <--
const new_msg = error.name + " - " + error.message.replace(/(-->|<--)/g, "");
const new_msg = error.name + " - " + error.message.replace(/(--?>|<--?)/g, "");
return new CommonError("Parser Error", error.token.startLine ?? NaN, error.token.startColumn ?? NaN, error.token.endOffset ?? NaN - error.token.startOffset, new_msg);
}