Skip to content

Commit

Permalink
add \v escaping char
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Mar 28, 2024
1 parent 1bb6f5a commit 9452129
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/generator/writers/writeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
//

if (f.kind === 'string') {
const s = f.value.replace(/\\\\|\\"|\\n|\\r|\\t|\\b|\\f|\\u{([0-9A-Fa-f]+)}|\\u([0-9A-Fa-f]{4})|\\x([0-9A-Fa-f]{2})/g, (match, unicodeCodePoint, unicodeEscape, hexEscape) => {
const s = f.value.replace(/\\\\|\\"|\\n|\\r|\\t|\\v|\\b|\\f|\\u{([0-9A-Fa-f]+)}|\\u([0-9A-Fa-f]{4})|\\x([0-9A-Fa-f]{2})/g, (match, unicodeCodePoint, unicodeEscape, hexEscape) => {
switch (match) {
case '\\\\':
return '\\';
Expand All @@ -144,6 +144,8 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
return '\r';
case '\\t':
return '\t';
case '\\v':
return '\v';
case '\\b':
return '\b';
case '\\f':
Expand Down
1 change: 1 addition & 0 deletions src/grammar/grammar.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ Tact {
| "\\n" -- newline
| "\\r" -- carriageReturn
| "\\t" -- tab
| "\\v" -- verticalTab
| "\\b" -- backspace
| "\\f" -- formFeed
| "\\u{" hexDigit hexDigit? hexDigit? hexDigit? hexDigit? hexDigit? "}" -- unicodeCodePoint
Expand Down
1 change: 1 addition & 0 deletions src/grammar/grammar.ohm-bundle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export interface TactActionDict<T> extends ActionDict<T> {
escapeSequence_newline?: (this: NonterminalNode, arg0: TerminalNode) => T;
escapeSequence_carriageReturn?: (this: NonterminalNode, arg0: TerminalNode) => T;
escapeSequence_tab?: (this: NonterminalNode, arg0: TerminalNode) => T;
escapeSequence_verticalTab?: (this: NonterminalNode, arg0: TerminalNode) => T;
escapeSequence_backspace?: (this: NonterminalNode, arg0: TerminalNode) => T;
escapeSequence_formFeed?: (this: NonterminalNode, arg0: TerminalNode) => T;
escapeSequence_unicodeCodePoint?: (this: NonterminalNode, arg0: TerminalNode, arg1: NonterminalNode, arg2: IterationNode, arg3: IterationNode, arg4: IterationNode, arg5: IterationNode, arg6: IterationNode, arg7: TerminalNode) => T;
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/grammar.ohm-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/test/feature-strings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('feature-strings', () => {
"test \n test \t test \r test \b test \f test \" test ' test \\ \\\\ \"_\" \"\" test"
);
expect(await contract.getStringWithEscapedChars3()).toEqual(
"test \\n test \\t test \\r test \\\\b\b test \\f test \\\" test \\' test \\\\ \\\\\\\\ \\\"_\\\" \\\"\\\" test"
"test \\n test \\t test \\r test \\\\b\b test \\f test \\\" test \\' test \v \v \\\\ \\\\\\\\ \\\"_\\\" \\\"\\\" test"
);
expect(await contract.getStringWithEscapedChars4()).toEqual(
"\u{2028}\u{2029} \u0044 \x41\x42\x43"
Expand Down
2 changes: 1 addition & 1 deletion src/test/features/strings.tact
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract StringsTester {
}

get fun stringWithEscapedChars3(): String {
return "test \\n test \\t test \\r test \\\\b\b test \\f test \\\" test \\' test \\\\ \\\\\\\\ \\\"_\\\" \\\"\\\" test";
return "test \\n test \\t test \\r test \\\\b\b test \\f test \\\" test \\' test \v \v \\\\ \\\\\\\\ \\\"_\\\" \\\"\\\" test";
}

get fun stringWithEscapedChars4(): String {
Expand Down

0 comments on commit 9452129

Please sign in to comment.