Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Acornima/EcmaVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum EcmaVersion
ES12 = 12,
ES13 = 13,
ES14 = 14,
ES15 = 15,

ES2015 = ES6,
ES2016 = ES7,
Expand All @@ -25,9 +26,10 @@ public enum EcmaVersion
ES2021 = ES12,
ES2022 = ES13,
ES2023 = ES14,
ES2024 = ES15,

/// <summary>
/// The latest version which is fully supported (<see cref="ES2023"/>).
/// The latest version which is fully supported (<see cref="ES2024"/>).
/// </summary>
Latest = ES2023,
Latest = ES2024,
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Acornima/Properties/RegExpConversionErrorMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<value>Inconvertible Unicode property escape</value>
</data>
<data name="RegExpUnicodeSetsModeNotSupported" xml:space="preserve">
<value>Unicode sets mode (flag v) is not supported currently</value>
<value>Conversion of Unicode sets mode (flag v) regular expressions to .NET Regex is not supported</value>
</data>
<data name="RegExpUnmappableGroupName" xml:space="preserve">
<value>Cannot map group name '{0}' to a unique group name in the adapted regex</value>
Expand Down
18 changes: 18 additions & 0 deletions src/Acornima/Properties/SyntaxErrorMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Acornima/Properties/SyntaxErrorMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@
<value>Invalid regular expression: /{0}/{1}: Invalid character class</value>
<comment>https://github.com/v8/v8/blob/14.8.3/src/regexp/regexp-error.h</comment>
</data>
<data name="RegExpInvalidCharacterInCharacterClass" xml:space="preserve">
<value>Invalid regular expression: /{0}/{1}: Invalid character in character class</value>
<comment>https://github.com/v8/v8/blob/14.8.3/src/regexp/regexp-error.h</comment>
</data>
<data name="RegExpNegatedCharacterClassMayContainStrings" xml:space="preserve">
<value>Invalid regular expression: /{0}/{1}: Negated character class may contain strings</value>
<comment>https://github.com/v8/v8/blob/14.8.3/src/regexp/regexp-error.h</comment>
</data>
<data name="RegExpInvalidClassPropertyName" xml:space="preserve">
<value>Invalid regular expression: /{0}/{1}: Invalid property name in character class</value>
<comment>https://github.com/v8/v8/blob/14.8.3/src/regexp/regexp-error.h</comment>
Expand Down
5 changes: 5 additions & 0 deletions src/Acornima/Tokenizer.RegExpParser.Legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ public bool AdjustEscapeSequence(RegExpParser parser, out RegExpConversionError?
conversionError = null;
return true;
}

public bool TryParseCharacterClass(RegExpParser parser)
{
return false;
}
}
}
}
63 changes: 10 additions & 53 deletions src/Acornima/Tokenizer.RegExpParser.Unicode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,59 +534,11 @@ private static void AddStandardCharClass(ref ArrayList<CodePointRange> set, char
set.AddRange(ranges);
}

private static bool ValidateUnicodeProperty(ReadOnlyMemory<char> expression, bool translateToRanges, RegExpParser parser, out CodePointRange[]? codePointRanges)
// Delegates to the shared ValidateUnicodeProperty on RegExpParser.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool ValidateUnicodePropertyForConversion(ReadOnlyMemory<char> expression, bool translateToRanges, RegExpParser parser, out CodePointRange[]? codePointRanges)
{
var index = expression.Span.IndexOf('=');
if (index >= 0)
{
// https://tc39.es/ecma262/#table-nonbinary-unicode-properties

var propertyName = expression.Span.Slice(0, index);
expression = expression.Slice(index + 1);
switch (propertyName)
{
case "gc" or "General_Category":
if (translateToRanges)
{
codePointRanges = UnicodeProperties.GetGeneralCategoryRange(expression, parser.GetCodePointRangeCache());
return codePointRanges is not null;
}
else
{
codePointRanges = default;
return UnicodeProperties.IsAllowedGeneralCategoryValue(expression);
}

case "sc" or "Script" or "scx" or "Script_Extensions":
// Translating unicode properties other than General Categories is not implemented currently.
codePointRanges = default;
return UnicodeProperties.IsAllowedScriptValue(expression, parser._tokenizer._options._ecmaVersion);

default:
codePointRanges = default;
return false;
}
}
else
{
if (translateToRanges)
{
codePointRanges = UnicodeProperties.GetGeneralCategoryRange(expression, parser.GetCodePointRangeCache());
if (codePointRanges is not null)
{
return true;
}
}
else if (UnicodeProperties.IsAllowedGeneralCategoryValue(expression))
{
codePointRanges = default;
return true;
}

// Translating unicode properties other than General Categories is not implemented currently.
codePointRanges = default;
return UnicodeProperties.IsAllowedBinaryValue(expression, parser._tokenizer._options._ecmaVersion);
}
return ValidateUnicodeProperty(expression, translateToRanges, parser, out codePointRanges);
}

public void RewriteDot(RegExpParser parser)
Expand Down Expand Up @@ -874,7 +826,7 @@ public bool AdjustEscapeSequence(RegExpParser parser, out RegExpConversionError?

endIndex = pattern.IndexOf('}', i + 2);
if (endIndex < 0
|| !ValidateUnicodeProperty(pattern.AsMemory(i + 2, endIndex - (i + 2)), translateToRanges: sb is not null, parser, out codePointRanges))
|| !ValidateUnicodePropertyForConversion(pattern.AsMemory(i + 2, endIndex - (i + 2)), translateToRanges: sb is not null, parser, out codePointRanges))
{
if (!parser.WithinSet)
{
Expand Down Expand Up @@ -987,6 +939,11 @@ public bool AdjustEscapeSequence(RegExpParser parser, out RegExpConversionError?
conversionError = null;
return true;
}

public bool TryParseCharacterClass(RegExpParser parser)
{
return false;
}
}
}
}
Loading