Skip to content

Commit

Permalink
Identifiers that start with numbers should be quoted (#2852)
Browse files Browse the repository at this point in the history
* Identifiers that start with numbers should be quoted

* Ensure parser and composer treat values the same way (if parsed as identifier, compose it as such)
  • Loading branch information
rafaelbey committed May 16, 2024
1 parent 711dbe5 commit 3714c4c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static String renderClassMappingId(ClassMapping cm)

public static String renderMappingId(String id)
{
return (id != null ? ("[" + PureGrammarComposerUtility.convertIdentifier(id) + "]") : "");
return (id != null ? ("[" + id + "]") : "");
}

public static String renderAggregateSetImplementationContainer(AggregateSetImplementationContainer agg, DEPRECATED_PureGrammarComposerCore transformer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class PureGrammarComposerUtility
{
private static final String PACKAGE_SEPARATOR = "::";
private static final Pattern UNQUOTED_IDENTIFIER_PATTERN = Pattern.compile("[A-Za-z0-9_][A-Za-z0-9_$~]*"); // TODO
private static final Pattern UNQUOTED_IDENTIFIER_PATTERN = Pattern.compile("[A-Za-z_][A-Za-z0-9_$~]*"); // TODO

public static final String TAB = " ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ public void testQuotedEnumerations()
"}\n");
}

@Test
public void testNumbersInEnumerationName()
{
test("Enum my::Enum\n" +
"{\n" +
" '30_360',\n" +
" '30_ACT'\n" +
"}\n");
}

@Test
public void testAssociations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public void testLambdaWithLambdaWithEnumWithPackage()
public void testLambdaWithEnum()
{
testLambda("|MyEnum.ok");
testLambda("|MyEnum.'30_360'");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ public void testEnumerationMapping()
" MT22: [200],\n" +
" MT23: [300, 400]\n" +
" }\n" +
" meta::pure::mapping::modelToModel::test::enumerationMapping::enumToEnum::model::DayCount: EnumerationMapping\n" +
" {\n" +
" '30_ACT': [My::DayCount.'30_ACT'],\n" +
" '30_360': [My::DayCount.'30_360']\n" +
" }\n" +
")\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static String renderDataspacePackageableElementExecutable(DataSpacePacka
private static String renderDataspaceTemplateExecutable(DataSpaceTemplateExecutable executable, PureGrammarComposerContext context)
{
return getTabString(2) + "{\n" +
(getTabString(3) + "id: " + convertIdentifier(executable.id) + ";\n") +
(getTabString(3) + "id: " + executable.id + ";\n") +
(getTabString(3) + "title: " + convertString(executable.title, true) + ";\n") +
(executable.description != null ? (getTabString(3) + "description: " + convertString(executable.description, true) + ";\n") : "") +
getTabString(3) + "query: " + executable.query.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance(context).withIndentation(getTabSize(2)).build()) + ";\n" +
Expand Down

0 comments on commit 3714c4c

Please sign in to comment.