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

ECR: support removing leading indentation and trailing newline #2991

Merged
merged 1 commit into from
Jul 19, 2016

Conversation

asterite
Copy link
Member

Fixes #2980

This is an alternative implementation to #2985

@beno I hope you don't mind I decided to try to implement this, but I think the needed changes were really few, and there's no need to introduce more classes nor use regex for this. To do this one just has to look at at most one token ahead, and check if its string value needs to be adjusted. Please check the code, I might have made a mistake or maybe I didn't implement it correctly (I tried a few templates and they seemed to work exactly like ERB).

This now supports all of ERB idioms, as you can see in the specs. Additionally, one can also use <%-= ... %>, which removes leading indentation from it, and I guess because of how it's done this also works for <%-# ... %>.

@beno
Copy link

beno commented Jul 13, 2016

I find this to be a less functional (-% is now illegal to use?) much more impenetrable and messy implementation that favours an ugly procedural style over OO principles, but if this is what you prefer I guess it'll have to do.

I also wonder if this implementation correctly respects all line semantics, but I'm not going to check. Thanks for solving this.

@@ -42,13 +63,40 @@ module ECR
end
end

private def append_loc(str, filename, token)
private def do_supress_leading(token, string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe suppress_leading_whitespace?

@asterite asterite force-pushed the feature/ecr_dash branch 2 times, most recently from 344621c to 5fbbdc0 Compare July 13, 2016 21:06
@ysbaddaden
Copy link
Contributor

I agree. Skipping trailing and leading linefeeds can be considered as mere modifiers and we should avoid new types, as well as regular expressions —they're slow and may quickly increase compile time— to achieve this.

Yet, maybe the lexer could foresee a second char, so we could properly parse -℅>?

@asterite
Copy link
Member Author

@beno I fixed the -% issue.

I don't try to use OOP for everything, every programming style has its uses and pros/cons. In this case I want ECR parsing to be super fast, and creating many objects and using regex is slow.

@asterite asterite merged commit 30fdda9 into master Jul 19, 2016
@asterite asterite mentioned this pull request Jul 19, 2016
@asterite asterite added this to the 0.19.0 milestone Jul 22, 2016
@asterite asterite deleted the feature/ecr_dash branch July 23, 2016 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants