diff --git a/lib/kpeg/compiled_parser.rb b/lib/kpeg/compiled_parser.rb
index <HASH>..<HASH> 100644
--- a/lib/kpeg/compiled_parser.rb
+++ b/lib/kpeg/compiled_parser.rb
@@ -3,6 +3,11 @@ require 'kpeg/position'
 module KPeg
   class CompiledParser
 
+    # Must be outside the STANDALONE block because a standalone
+    # parser always injects it's own version of this method.
+    def setup_foreign_grammar
+    end
+
     # Leave these markers in! They allow us to generate standalone
     # code automatically!
     #
@@ -18,9 +23,6 @@ module KPeg
       setup_foreign_grammar
     end
 
-    def setup_foreign_grammar
-    end
-
     # This is distinct from setup_parser so that a standalone parser
     # can redefine #initialize and still have access to the proper
     # parser setup code.
Fix where the default setup_foreign_grammar method lives