Skip to content
Browse files

Fix trailing whitespace in standalone parsers

Previously kpeg would insert trailing whitespace into standalone
parsers.  This was due to a regular expression that did not trim leading
space when replacing `include Position` with the standalone
functionality.

Now the entire line is replaced instead of just the include which fixes
the whitespace problem.
  • Loading branch information...
1 parent 9c43e6f commit 818e25bac9c0a0f97ac3379debfcbbd3966e3fcc @drbrain drbrain committed Sep 18, 2013
Showing with 1 addition and 3 deletions.
  1. +1 −1 lib/kpeg/code_generator.rb
  2. +0 −1 lib/kpeg/format_parser.rb
  3. +0 −1 lib/kpeg/string_escape.rb
View
2 lib/kpeg/code_generator.rb
@@ -450,7 +450,7 @@ def output_header(code)
cpi = standalone_region("compiled_parser.rb", "INITIALIZE")
pp = standalone_region("position.rb")
- cp.gsub!(/include Position/, pp)
+ cp.gsub!(/^\s*include Position/, pp)
code << " # :stopdoc:\n"
code << cpi << "\n" unless @grammar.variables['custom_initialize']
code << cp << "\n"
View
1 lib/kpeg/format_parser.rb
@@ -18,7 +18,6 @@ def setup_parser(str, debug=false)
attr_reader :failing_rule_offset
attr_accessor :result, :pos
-
def current_column(target=pos)
if c = string.rindex("\n", target-1)
return target - c - 1
View
1 lib/kpeg/string_escape.rb
@@ -26,7 +26,6 @@ def setup_parser(str, debug=false)
attr_reader :failing_rule_offset
attr_accessor :result, :pos
-
def current_column(target=pos)
if c = string.rindex("\n", target-1)
return target - c - 1

0 comments on commit 818e25b

Please sign in to comment.
Something went wrong with that request. Please try again.