Added #1496 repeat escape sequence \{xx}C to avoid long same char strings/names

This commit is contained in:
Jindra Petřík
2021-11-19 12:31:02 +01:00
parent b68b7ff2f0
commit bbb3ed8c72
21 changed files with 4224 additions and 3937 deletions

View File

@@ -39,6 +39,8 @@ import com.jpexs.decompiler.flash.ecma.Undefined;
StringBuilder string = new StringBuilder();
private int repeatNum = 1;
/**
* Create an empty lexer, yyrset will be called later to reset and assign
* the reader
@@ -159,29 +161,33 @@ Constant= constant{PositiveNumberLiteral}
<STRING> {
\" {
yybegin(PARAMETERS);
repeatNum = 1;
// length also includes the trailing quote
return new ASMParsedSymbol(ASMParsedSymbol.TYPE_STRING, string.toString());
}
{StringCharacter}+ { string.append(yytext()); }
{StringCharacter} { for(int r=0;r<repeatNum;r++) string.append(yytext()); repeatNum = 1; }
/* escape sequences */
"\\b" { string.append('\b'); }
"\\t" { string.append('\t'); }
"\\n" { string.append('\n'); }
"\\f" { string.append('\f'); }
"\\r" { string.append('\r'); }
"\\\"" { string.append('\"'); }
"\\'" { string.append('\''); }
"\\\\" { string.append('\\'); }
"\\b" { for(int r=0;r<repeatNum;r++) string.append('\b'); repeatNum = 1;}
"\\t" { for(int r=0;r<repeatNum;r++) string.append('\t'); repeatNum = 1;}
"\\n" { for(int r=0;r<repeatNum;r++) string.append('\n'); repeatNum = 1;}
"\\f" { for(int r=0;r<repeatNum;r++) string.append('\f'); repeatNum = 1;}
"\\\u00A7" { for(int r=0;r<repeatNum;r++) string.append('\u00A7'); repeatNum = 1;}
"\\r" { for(int r=0;r<repeatNum;r++) string.append('\r'); repeatNum = 1;}
"\\\"" { for(int r=0;r<repeatNum;r++) string.append('\"'); repeatNum = 1;}
"\\'" { for(int r=0;r<repeatNum;r++) string.append('\''); repeatNum = 1;}
"\\\\" { for(int r=0;r<repeatNum;r++) string.append('\\'); repeatNum = 1;}
\\x{HexDigit}{2} { char val = (char) Integer.parseInt(yytext().substring(2), 16);
string.append(val); }
for(int r=0;r<repeatNum;r++) string.append(val); repeatNum = 1; }
\\u{HexDigit}{4} { char val = (char) Integer.parseInt(yytext().substring(2), 16);
string.append(val); }
for(int r=0;r<repeatNum;r++) string.append(val); repeatNum = 1; }
\\\{{PositiveNumberLiteral}\} { repeatNum = Integer.parseInt(yytext().substring(2, yytext().length()-1)); }
/* error cases */
\\. { throw new ActionParseException("Illegal escape sequence \"" + yytext() + "\"", yyline + 1); }
{LineTerminator} { throw new ActionParseException("Unterminated string at end of line", yyline + 1); }
\\. { repeatNum = 1; throw new ActionParseException("Illegal escape sequence \"" + yytext() + "\"", yyline + 1); }
{LineTerminator} { repeatNum = 1; throw new ActionParseException("Unterminated string at end of line", yyline + 1); }
}