Created
June 3, 2021 22:15
-
-
Save evanphx/f58eebe632530d6423ec9743fcf0782e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/kpeg/compiled_parser.rb b/lib/kpeg/compiled_parser.rb | |
index ff82467..eb16e32 100644 | |
--- a/lib/kpeg/compiled_parser.rb | |
+++ b/lib/kpeg/compiled_parser.rb | |
@@ -51,6 +51,12 @@ module KPeg | |
@string = string | |
@string_size = string ? string.size : 0 | |
@pos = pos | |
+ | |
+ if string | |
+ @chars = string.chars | |
+ else | |
+ @chars = [] | |
+ end | |
end | |
def show_pos | |
@@ -163,8 +169,7 @@ module KPeg | |
if @pos >= @string_size | |
return nil | |
end | |
- | |
- s = @string[@pos].ord | |
+ s = @chars[@pos].ord | |
@pos += 1 | |
s | |
end | |
diff --git a/lib/kpeg/format_parser.rb b/lib/kpeg/format_parser.rb | |
index 4f84e94..7b6035a 100644 | |
--- a/lib/kpeg/format_parser.rb | |
+++ b/lib/kpeg/format_parser.rb | |
@@ -56,6 +56,12 @@ class KPeg::FormatParser | |
@string = string | |
@string_size = string ? string.size : 0 | |
@pos = pos | |
+ | |
+ if string | |
+ @chars = string.chars | |
+ else | |
+ @chars = [] | |
+ end | |
end | |
def show_pos | |
@@ -168,8 +174,7 @@ class KPeg::FormatParser | |
if @pos >= @string_size | |
return nil | |
end | |
- | |
- s = @string[@pos].ord | |
+ s = @chars[@pos].ord | |
@pos += 1 | |
s | |
end | |
diff --git a/lib/kpeg/string_escape.rb b/lib/kpeg/string_escape.rb | |
index 99f8373..bcd49ca 100644 | |
--- a/lib/kpeg/string_escape.rb | |
+++ b/lib/kpeg/string_escape.rb | |
@@ -64,6 +64,12 @@ class KPeg::StringEscape | |
@string = string | |
@string_size = string ? string.size : 0 | |
@pos = pos | |
+ | |
+ if string | |
+ @chars = string.chars | |
+ else | |
+ @chars = [] | |
+ end | |
end | |
def show_pos | |
@@ -176,8 +182,7 @@ class KPeg::StringEscape | |
if @pos >= @string_size | |
return nil | |
end | |
- | |
- s = @string[@pos].ord | |
+ s = @chars[@pos].ord | |
@pos += 1 | |
s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment