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

Make Liquid::C::Tokenizer#shift private so it is only used for testing #140

Merged
merged 1 commit into from
Jan 7, 2021

Conversation

dylanahsmith
Copy link
Contributor

Depends on Shopify/liquid#1386

Problem

The liquid template (de)serialization support that is being added by #138 won't actually support Liquid::C::Tokenizer#shift being used during parsing. The method would seem to work for the initial parsing, but then it would fail on deserialization where there is no longer a tokenizer.

Solution

Leverage Shopify/liquid#1386 to update the tokenizer monkey patch to instead be on Liquid::ParseContext.new_tokenizer so that we avoid using the Liquid::C::Tokenizer when the liquid-c VM is disabled.

Make Liquid::C::Tokenizer#shift private, like shift_trimmed, and only use it for testing.

lib/liquid/c.rb Outdated
source = source.to_s
if source.bytesize <= Liquid::C::Tokenizer::MAX_SOURCE_BYTE_SIZE
source = source.encode(Encoding::UTF_8)
return Liquid::C::Tokenizer.new(source, line_number || 0, for_liquid_tag)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be || 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The C code uses 0 to mean that line numbers aren't tracked, similar to if line_number is nil in the ruby tokenizer.

Since it won't be supported for liquid template (de)serialization.
@dylanahsmith dylanahsmith force-pushed the tokenizer-private-shift branch from bf2e637 to fb27449 Compare January 7, 2021 19:52
@dylanahsmith dylanahsmith merged commit 83e41df into master Jan 7, 2021
@dylanahsmith dylanahsmith deleted the tokenizer-private-shift branch January 7, 2021 22:05
dylanahsmith added a commit that referenced this pull request Feb 12, 2021
#140)

Since it won't be supported for liquid template (de)serialization.

(cherry picked from commit 83e41df)
dylanahsmith added a commit that referenced this pull request Mar 17, 2021
#140)

Since it won't be supported for liquid template (de)serialization.

(cherry picked from commit 83e41df)
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.

3 participants