Skip to content
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

Dedent multiline text to preserve content indentation #197

Merged
merged 9 commits into from
Nov 6, 2018

Conversation

stasm
Copy link
Contributor

@stasm stasm commented Oct 30, 2018

Fix #162.

@stasm stasm requested a review from Pike November 6, 2018 10:03
@stasm
Copy link
Contributor Author

stasm commented Nov 6, 2018

@Pike This is based on your branch from #162 (comment). Here's a summary of differences:

  • Leading indent in block text is now preserved, too.
  • Placeables on a new line with no indent count as indent of width 0. On your branch, they were skipped. I did this to make the "ruler rule" easier to visualize in all cases.
  • I removed FTL.Indent. I don't have strong feelings about either way but I realized that it was the only non-base AST class which would never be used in an actual AST. I don't know if that's good or bad; we can figure it out later. Right now I went for a simple typeof element === "string" check instead.

Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two comment nits, r=me.

@@ -154,18 +159,36 @@ function attach_comments(acc, cur) {
}
}

const LEADING_BLANK = /^[ \n\r]*/;
const TRAILING_BLANK = /[ \n\r]*$/;
// Remove the largest common indentation from a list of PatternElements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extend this comment to make it expressive that all literal strings are indents, thanks to grammar.mjs separating those out?

function join_adjacent(...types) {
return function(acc, cur) {
let prev = acc[acc.length - 1];
for (let Type of types) {
if (prev instanceof Type && cur instanceof Type) {
join_of_type(Type, prev, cur);
// Replace prev with a new node of the same type whose value is
// the sum of prev and cur, and discard cur.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... discard cur and prev.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's needed given that the comment starts with Replace...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could go without the , and discard ... altogether, too.

Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not particularly opinionated on that last comment, r=me.

function join_adjacent(...types) {
return function(acc, cur) {
let prev = acc[acc.length - 1];
for (let Type of types) {
if (prev instanceof Type && cur instanceof Type) {
join_of_type(Type, prev, cur);
// Replace prev with a new node of the same type whose value is
// the sum of prev and cur, and discard cur.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could go without the , and discard ... altogether, too.

@stasm stasm merged commit d2229f2 into projectfluent:master Nov 6, 2018
@stasm stasm deleted the dedent branch November 6, 2018 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants