   #! A terminal is an identifier enclosed in quotations
   #! and it represents the literal value of the identifier.
   'identifier' [ <ebnf-terminal> ] action ;
+
+: 'foreign-name' ( -- parser )
+  #! Parse a valid foreign parser name
+  [
+    {
+      [ dup blank?    ]
+      [ dup CHAR: > = ]
+    } 0|| not nip    
+  ] satisfy repeat1 [ >string ] action ;
+
+: 'foreign' ( -- parser )
+  #! A foreign call is a call to a rule in another ebnf grammar
+  [
+    "<foreign" syntax ,
+    'foreign-name' sp ,
+    'foreign-name' sp optional ,
+    ">" syntax ,
+  ] seq* [ first2 <ebnf-foreign> ] action ;
 
 : 'any-character' ( -- parser )
   #! A parser to match the symbol for any character match.

! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel compiler.units parser words arrays strings math.parser sequences 
       quotations vectors namespaces math assocs continuations peg
       peg.parsers unicode.categories multiline combinators combinators.lib 
       splitting accessors effects sequences.deep peg.search inference 
       io.streams.string io prettyprint ;
IN: peg.ebnf

TUPLE: ebnf-non-terminal symbol ;
TUPLE: ebnf-terminal symbol ;
TUPLE: ebnf-any-character ;
TUPLE: ebnf-range pattern ;
TUPLE: ebnf-ensure group ;


C: <ebnf-non-terminal> ebnf-non-terminal
C: <ebnf-terminal> ebnf-terminal
C: <ebnf-foreign> ebnf-foreign
C: <ebnf-any-character> ebnf-any-character
C: <ebnf-range> ebnf-range
C: <ebnf-ensure> ebnf-ensure
