Skip to content

Commit

Permalink
Merge pull request #4 from Release-Candidate/Fix-windows-line-ends-br…
Browse files Browse the repository at this point in the history
…eaking-sexp-parsing

Fix windows line endings in sexp parsing, see #3
  • Loading branch information
Release-Candidate authored Jun 26, 2023
2 parents 7218984 + 1f60e3a commit d5268c6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Chez Scheme REPL for Visual Studio Code Changelog

## Version 0.3.0 (2023-06-26)

### Bugfixes

- Fix [#3](https://github.com/Release-Candidate/vscode-scheme-repl/issues/3). Windows line endings - `\r\n` instead of `\n` break parsing of sexps for **evalLastSexp**, only the last line of a sexp is evaluated if the sexp spans multiple lines.

## Version 0.2.0 (2023-06-26)

### Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-scheme-repl",
"displayName": "Chez Scheme REPL",
"version": "0.2.0",
"version": "0.3.0",
"preview": false,
"publisher": "release-candidate",
"description": "Support for Chez Scheme.",
Expand Down
5 changes: 3 additions & 2 deletions src/evalREPL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const notAnEnvRegex =
* function of the REPL.
* The last expression is saved in the match group `last`.
*/
const lastExprRegex = /\n(?<last>[^\n]+)\s+(\S?\S?\S?[>%@#$~^&])\s\2?\s?\n*$/su;
const lastExprRegex =
/\r?\n(?<last>[^\n]+)\s+(\S?\S?\S?[>%@#$~^&])\s\2?\s?\r?\n*$/su;

/**
* Returns a list of identifiers beginning with the string `prefix` or
Expand Down Expand Up @@ -346,7 +347,7 @@ async function evalSexp(
*/
function matchREPLResponse(group: string): RegExp {
return new RegExp(
`(?:${c.replPrompt}\\s+)+${group}\\n${c.replPrompt}\\s+$`,
`(?:${c.replPrompt}\\s+)+${group}\\r?\\n${c.replPrompt}\\s+$`,
"su"
);
}
Expand Down
22 changes: 20 additions & 2 deletions src/sexps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function startOfSexp(data: {
* right end of the string, if present and the following string until the left
* end of the current sexp.
*/
// eslint-disable-next-line max-lines-per-function
function listSeparators(data: {
s: string;
delim: Delimiter | undefined;
Expand All @@ -169,6 +170,7 @@ function listSeparators(data: {
delimStack: data.delimStack,
level: data.level,
delimString: ",",
numChars: 1,
});
} else if (data.s.endsWith(" ")) {
return addDelimAndContinue({
Expand All @@ -177,6 +179,16 @@ function listSeparators(data: {
delimStack: data.delimStack,
level: data.level,
delimString: " ",
numChars: 1,
});
} else if (data.s.endsWith("\r\n")) {
return addDelimAndContinue({
s: data.s,
delim: data.delim,
delimStack: data.delimStack,
level: data.level,
delimString: "\r\n",
numChars: 2,
});
} else if (data.s.endsWith("\n")) {
return addDelimAndContinue({
Expand All @@ -185,6 +197,7 @@ function listSeparators(data: {
delimStack: data.delimStack,
level: data.level,
delimString: "\n",
numChars: 1,
});
} else if (data.s.endsWith("\t")) {
return addDelimAndContinue({
Expand All @@ -193,6 +206,7 @@ function listSeparators(data: {
delimStack: data.delimStack,
level: data.level,
delimString: "\t",
numChars: 1,
});
}
return undefined;
Expand Down Expand Up @@ -413,10 +427,14 @@ function addDelimAndContinue(data: {
delimStack: Delimiter[];
level: number;
delimString: string;
numChars: number;
}): string {
return (
parseSexpToLeft(data.delimStack, data.s.slice(0, -1), data.level) +
data.delimString
parseSexpToLeft(
data.delimStack,
data.s.slice(0, -data.numChars),
data.level
) + data.delimString
);
}

Expand Down

0 comments on commit d5268c6

Please sign in to comment.