-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]Typescript target #3870
[WIP]Typescript target #3870
Conversation
mmm... not sure why my commits aren't signed |
Every commit should have a sign, for example:
Also, is it possible to squash most part of commits? Commits like
are not useful for reviewers and git history since they are not informative. |
As written, I know what DCO expects, but I had automated this on my end, and it seems to no longer work.. |
runtime-testsuite/test/org/antlr/v4/test/runtime/typescript/TscRunner.java
Outdated
Show resolved
Hide resolved
runtime-testsuite/test/org/antlr/v4/test/runtime/typescript/TscRunner.java
Outdated
Show resolved
Hide resolved
runtime-testsuite/test/org/antlr/v4/test/runtime/typescript/TscRunner.java
Outdated
Show resolved
Hide resolved
runtime-testsuite/test/org/antlr/v4/test/runtime/typescript/TscRunner.java
Outdated
Show resolved
Hide resolved
Looks like so because not every commit has a sign. |
8bb1697
to
a342aa4
Compare
When using variables to compare (like in if clause) the variable shouldn't be quoted. More details can be found at the link below: https://cmake.org/cmake/help/latest/command/if.html#variable-expansion Signed-off-by: HS <[email protected]> Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: nicksxs <[email protected]> Signed-off-by: Eric Vergnaud <[email protected]>
Signed-off-by: Terence Parr <[email protected]> Signed-off-by: Eric Vergnaud <[email protected]>
@parrt thanks for merging #3878 (which was missing some tweaks, my bad), however I noticed you merged it into master rather than dev ? So I had to merge back from master which brings into this PR a few unrelated files, I guess they'll fade away once you merge master onto dev. |
runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.ts.stg
Outdated
Show resolved
Hide resolved
runtime-testsuite/test/org/antlr/v4/test/runtime/typescript/TscRunner.java
Outdated
Show resolved
Hide resolved
It’s an incorrect implementation therefore it’s a design bug. I’m not really interested in arguing about code style. Your suggestions are welcome but they should remain suggestions.
Envoyé de mon iPhone
… Le 13 sept. 2022 à 23:13, Ivan Kochurkin ***@***.***> a écrit :
@KvanTTT commented on this pull request.
In tool/src/org/antlr/v4/codegen/target/TypeScriptTarget.java:
> + public String getTargetStringLiteralFromANTLRStringLiteral(
+ CodeGenerator generator,
+ String literal, boolean addQuotes)
+ {
+ StringBuilder sb = new StringBuilder();
+ String is = literal;
+
+ if ( addQuotes ) sb.append('"');
+
+ for (int i = 1; i < is.length() - 1; ) {
+ int codePoint = is.codePointAt(i);
+ int toAdvance = Character.charCount(codePoint);
+ if (codePoint == '\\') {
+ // Anything escaped is what it is! We assume that
+ // people know how to escape characters correctly. However
+ // we catch anything that does not need an escape in Java (which
+ // is what the default implementation is dealing with and remove
+ // the escape. The C target does this for instance.
+ //
+ int escapedCodePoint = is.codePointAt(i + toAdvance);
+ toAdvance++;
+ switch (escapedCodePoint) {
+ // Pass through any escapes that Java also needs
+ //
+ case 'n':
+ case 'r':
+ case 't':
+ case 'b':
+ case 'f':
+ case '\\':
+ // Pass the escape through
+ sb.append('\\');
+ sb.appendCodePoint(escapedCodePoint);
+ break;
+
+ case 'u': // Either unnnn or u{nnnnnn}
+ if (is.charAt(i + toAdvance) == '{') {
+ while (is.charAt(i + toAdvance) != '}') {
+ toAdvance++;
+ }
+
+ toAdvance++;
+ } else {
+ toAdvance += 4;
+ }
+
+ if (i + toAdvance <= is.length()) {
+ // we might have an invalid \\uAB or something
+ String fullEscape = is.substring(i, i + toAdvance);
+ appendUnicodeEscapedCodePoint(
+ CharSupport.getCharValueFromCharInGrammarLiteral(fullEscape),
+ sb);
+ }
+
+ break;
+
+ default:
+ if (shouldUseUnicodeEscapeForCodePointInDoubleQuotedString(escapedCodePoint)) {
+ appendUnicodeEscapedCodePoint(escapedCodePoint, sb);
+ } else {
+ sb.appendCodePoint(escapedCodePoint);
+ }
+
+ break;
+ }
+
+ // Go past the \ character
+ i++;
+ } else {
+ if (codePoint == 0x22) {
+ // ANTLR doesn't escape " in literal strings, but every other language needs to do so.
+ sb.append("\\\"");
+ } else if (shouldUseUnicodeEscapeForCodePointInDoubleQuotedString(codePoint)) {
+ appendUnicodeEscapedCodePoint(codePoint, sb);
+ } else {
+ sb.appendCodePoint(codePoint);
+ }
+ }
+
+ i += toAdvance;
+ }
+
+ if ( addQuotes ) sb.append('"');
+
+ return sb.toString();
+ }
IMHO it's a bug to have just one translation method for all targets because inevitably users will complain, and we need to safely fix the translation on a per target basis.
Firstly, it's not bug, but maybe incorrect implementation. Secondly, IMHO it's not optimal to create duplicated functionality because of slightly different things. They can be encapsulated to separated methods according to OOP. The less code we have, the less potential errors we have. Moreover, this method not only escapes chars but also joins them. Joining logic should be the same. For that matter, charCount, codePointAt and other char methods are Java-specific, they should not be used for TypeScript or other target literals, but actually it doesn't matter.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
|
Well, sounds reasonable to me but I need to evaluate the merits of either approach discussed in #3867 What's involved in creating a suitable beta? A zip? A branch? |
It involves publishing a beta in maven central and npm
|
Signed-off-by: ERIC-WINDOWS\ericv <[email protected]>
I was going to propose an issue to make the javascript target work better in typescript (exporting context classes so we can import them as typescript types). However having an official typescript target is of course a lot better :-). Just to know which way I should proceed I wanted to check if this PR will have a chance of getting merged in the foreseeable future or if it is more of an experiment? |
All ts tests pass locally.
Submitting a PR to ensure nothing else is broken, and try ts CI.
Also fixes #3868
tsc generates tons of warnings which I need to deal with