Author: pmichaud
Date: Thu Jan 25 12:19:16 2007
New Revision: 16792

Added:
   trunk/languages/perl6/src/parser/
   trunk/languages/perl6/src/parser/expression.pir
      - copied, changed from r16791, /trunk/languages/perl6/src/parse.pir
   trunk/languages/perl6/src/parser/grammar_optok.pg
      - copied unchanged from r16791, 
/trunk/languages/perl6/src/grammar_optok.pg
   trunk/languages/perl6/src/parser/grammar_rules.pg
      - copied unchanged from r16791, 
/trunk/languages/perl6/src/grammar_rules.pg
   trunk/languages/perl6/src/parser/quote.pir
      - copied, changed from r16791, /trunk/languages/perl6/src/quote.pir
   trunk/languages/perl6/src/parser/regex.pir
Removed:
   trunk/languages/perl6/src/grammar_optok.pg
   trunk/languages/perl6/src/grammar_rules.pg
   trunk/languages/perl6/src/grammar_sub.pg
   trunk/languages/perl6/src/parse.pir
   trunk/languages/perl6/src/quote.pir
Modified:
   trunk/MANIFEST
   trunk/languages/perl6/config/makefiles/root.in
   trunk/languages/perl6/perl6.pir

Log:
[perl6]: Refactors, part 1
* Refactor the parser components into a separate src/parser/ subdirectory.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Thu Jan 25 12:19:16 2007
@@ -1541,12 +1541,12 @@
 languages/perl6/src/classes/Code.pir                        [perl6]
 languages/perl6/src/classes/Num.pir                         [perl6]
 languages/perl6/src/classes/Str.pir                         [perl6]
-languages/perl6/src/grammar_optok.pg                        [perl6]
-languages/perl6/src/grammar_rules.pg                        [perl6]
-languages/perl6/src/grammar_sub.pg                          [perl6]
-languages/perl6/src/parse.pir                               [perl6]
+languages/perl6/src/parser/expression.pir                   [perl6]
+languages/perl6/src/parser/grammar_optok.pg                 [perl6]
+languages/perl6/src/parser/grammar_rules.pg                 [perl6]
+languages/perl6/src/parser/quote.pir                        [perl6]
+languages/perl6/src/parser/regex.pir                        [perl6]
 languages/perl6/src/pmc/perl6str.pmc                        [perl6]
-languages/perl6/src/quote.pir                               [perl6]
 languages/perl6/t/00-parrot/01-literals.t                   [perl6]
 languages/perl6/t/00-parrot/02-op-math.t                    [perl6]
 languages/perl6/t/00-parrot/03-op-logic.t                   [perl6]

Modified: trunk/languages/perl6/config/makefiles/root.in
==============================================================================
--- trunk/languages/perl6/config/makefiles/root.in      (original)
+++ trunk/languages/perl6/config/makefiles/root.in      Thu Jan 25 12:19:16 2007
@@ -20,10 +20,11 @@
 all: perl6.pbc 
 
 SOURCES = perl6.pir \
-  src/grammar_rules.pg \
-  src/grammar_optok.pg \
-  src/parse.pir \
-  src/quote.pir \
+  src/parser/grammar_rules.pg \
+  src/parser/grammar_optok.pg \
+  src/parser/expression.pir \
+  src/parser/quote.pir \
+  src/parser/regex.pir \
   src/PAST/Grammar.tg \
   src/PAST/Perl6.pir \
   src/builtins_gen.pir \
@@ -51,8 +52,8 @@
 
 # the default target
 perl6.pbc: $(PARROT) $(PGE_DIR)/pgc.pir $(SOURCES)
-       $(PARROT) $(PGE_DIR)/pgc.pir --output=src/grammar_gen.pir \
-           src/grammar_rules.pg src/grammar_optok.pg
+       $(PARROT) $(PGE_DIR)/pgc.pir --output=src/parser/grammar_gen.pir \
+           src/parser/grammar_rules.pg src/parser/grammar_optok.pg
        $(PARROT) $(TGE_DIR)/tgc.pir --output=src/PAST/Grammar_gen.pir 
src/PAST/Grammar.tg
        $(PARROT) -o perl6.pbc perl6.pir
 
@@ -95,7 +96,7 @@
 CLEANUPS = \
   perl6.pbc \
   perl6-orig.pbc \
-  src/grammar_gen.pir \
+  src/parser/grammar_gen.pir \
   src/parse2past_gen.pir \
   src/pge2past_gen.pir \
   src/past2post_gen.pir \

Modified: trunk/languages/perl6/perl6.pir
==============================================================================
--- trunk/languages/perl6/perl6.pir     (original)
+++ trunk/languages/perl6/perl6.pir     Thu Jan 25 12:19:16 2007
@@ -58,17 +58,16 @@
     .return $P0.'command_line'(args)
 .end
 
-
-.include 'src/parse.pir'
-
-.include 'src/quote.pir'
+.include 'src/parser/expression.pir'
+.include 'src/parser/quote.pir'
+.include 'src/parser/regex.pir'
 
 .include 'src/builtins_gen.pir'
 
 .include 'src/PAST/Perl6.pir'
 
 .namespace [ 'Perl6::Grammar' ]
-.include 'src/grammar_gen.pir'
+.include 'src/parser/grammar_gen.pir'
 
 .include 'src/PAST/Grammar_gen.pir'
 

Copied: trunk/languages/perl6/src/parser/expression.pir (from r16791, 
/trunk/languages/perl6/src/parse.pir)
==============================================================================
--- /trunk/languages/perl6/src/parse.pir        (original)
+++ trunk/languages/perl6/src/parser/expression.pir     Thu Jan 25 12:19:16 2007
@@ -2,12 +2,14 @@
 
 =head1 TITLE
 
-parse.pir - Parsing support subroutines
+expression.pir - Parsing of <expression> and <listop_expression> subrules
 
 =head2 DESCRIPTION
 
-This file contains support subroutines for parsing Perl 6 programs.  
-Specialized parsing subroutines will appear here as the parser grows.
+This file contains the grammar subrules for <expression> and
+<listop_expression>.  These have special parsing requirements,
+and are therefore written in PIR instead of as a standard
+Perl 6 rule statement.
 
 =over 4
 
@@ -60,219 +62,6 @@
     .return optable.'parse'(mob, 'tighter'=>'infix:<==')
 .end
 
-
-=item C<quoted_literal>
-
-Handles parsing of the various types of quoted literals.
+=back
 
 =cut
-
-.sub 'quoted_literal'
-    .param pmc mob                                 # object to parse
-    .param string delim                            # string delimiter (XXX)
-    .param pmc adv             :slurpy :named      # adverbs
-
-    ##   XXX: This is a temporary hack to set adverbs based
-    ##   on the delimiter.  We'll remove this when we have full
-    ##   qq[...] adverb capability.
-    if delim == "'" goto q_string
-    adv['double'] = 1
-  q_string:
-    adv['single'] = 1
-
-    .local int adv_single, adv_backslash, adv_scalar
-    adv_single = 1
-    adv_backslash = 0
-    adv_scalar = 0
-    $I0 = exists adv['double']
-    if $I0 == 0 goto with_double
-    adv_backslash = 1
-    adv_scalar = 1
-  with_double:
-    $I0 = exists adv['backslash']
-    if $I0 == 0 goto with_backslash
-    adv_backslash = adv['backslash']
-  with_backslash:
-    $I0 = exists adv['scalar']
-    if $I0 == 0 goto with_scalar
-    adv_scalar = adv['scalar']
-  with_scalar:
-
-    .local string target
-    .local pmc mfrom, mpos
-    .local int pos
-    (mob, pos, target, mfrom, mpos) = mob.'new'(mob)
-
-    .local int capt, lastpos, delimlen
-    capt = 0
-    lastpos = length target
-    delimlen = length delim
-
-    .local string lstop
-    lstop = ''
-    if adv_scalar == 0 goto lstop_1
-    lstop .= '$'
-  lstop_1:
-
-  outer_loop:
-    .local string literal
-    .local int litfrom
-    literal = ''
-    litfrom = pos
-    if pos >= lastpos goto fail
-    $S0 = substr target, pos, delimlen
-    if $S0 == delim goto outer_end
-    if $S0 == '$' goto scan_scalar
-    goto scan_literal
-
-  scan_scalar:
-    literal = $S0
-    mpos = pos
-    inc pos
-    if adv_scalar == 0 goto scan_literal
-    $P0 = find_global 'Perl6::Grammar', 'variable'
-    $P1 = $P0(mob)
-    unless $P1 goto scan_literal
-    $P1['type'] = 'Perl6::Grammar::variable'
-    mob[capt] = $P1
-    inc capt
-    pos = $P1.to()
-    goto outer_loop
-
-  scan_literal:
-  scan_literal_loop:
-    if pos >= lastpos goto fail
-    $S0 = substr target, pos, delimlen
-    if $S0 == delim goto scan_literal_end
-    $S0 = substr target, pos, 1
-    $I0 = index lstop, $S0
-    if $I0 >= 0 goto scan_literal_end
-    if adv_single == 0 goto scan_literal_1
-    if $S0 != "\\" goto scan_literal_1
-    if adv_backslash goto scan_literal_backslash
-    $I0 = pos + 1
-    $S1 = substr target, $I0, 1
-    if $S1 == "\\" goto scan_literal_backslash
-    if $S1 != delim goto scan_literal_1            # XXX: single-char delim
-  scan_literal_backslash:
-    inc pos
-    $S0 = substr target, pos, 1
-    if $S0 == 'x' goto scan_backslash_x
-    if $S0 == 'd' goto scan_backslash_d
-    if $S0 == 'o' goto scan_backslash_o
-    $I0 = index "abefnrt0123456789", $S0
-    if $I0 > 7 goto fail_backslash_num
-    $S0 = substr "\x07\x08\e\f\n\r\t\0", $I0, 1
-    if $I0 != 7 goto scan_literal_1
-    ## lookahead for [0..7], fail if found
-    $I0 = pos + 1
-    $S0 = substr target, $I0, 1
-    $I0 = index "01234567", $S0
-    if $I0 > -1 goto fail_backslash_num
-
-  scan_literal_1:
-    concat literal, $S0
-    inc pos
-    goto scan_literal_loop
-
-  ## parse \x, \x[NN], \x[NN,NN]; same for \d and \o
-  scan_backslash_x:
-    .local int base
-    base = 16
-    goto scan_bxdo_chars
-  scan_backslash_d:
-    base = 10
-    goto scan_bxdo_chars
-  scan_backslash_o:
-    base = 8
-    goto scan_bxdo_chars
-  scan_bxdo_chars:
-    ##   increment past the x, d, or o
-    inc pos
-    .local int decnum, isbracketed
-    decnum = 0
-    $S0 = substr target, pos, 1
-    isbracketed = iseq $S0, '['
-    ##   increment past any open bracket
-    pos += isbracketed
-  scan_bxdo_chars_loop:
-    $S0 = substr target, pos, 1
-    $I0 = index '0123456789abcdef', $S0
-    if $I0 < 0 goto scan_bxdo_chars_end
-    if $I0 >= base goto scan_bxdo_chars_end
-    decnum *= base
-    decnum += $I0
-    inc pos
-    goto scan_bxdo_chars_loop
-  scan_bxdo_chars_end:
-    ##   add the character to the literal
-    $S1 = chr decnum
-    concat literal, $S1
-    unless isbracketed goto scan_bxdo_end
-    if $S0 == ']' goto scan_bxdo_end
-    if $S0 != ',' goto fail
-    inc pos
-    decnum = 0
-    goto scan_bxdo_chars_loop
-  scan_bxdo_end:
-    pos += isbracketed
-    goto scan_literal_loop
-
-  scan_literal_end:
-    ($P0, $P1, $P2, $P3, $P4) = mob.'new'(mob)
-    $P3 = litfrom
-    $P4 = pos
-    $P0.'result_object'(literal)
-    $P0['type'] = 'str'
-    mob[capt] = $P0
-    inc capt
-    goto outer_loop
-
-  outer_end:
-    mpos = pos
-    .return (mob)
-  fail:
-    mpos = -1
-    .return (mob)
-  fail_backslash_num:
-    dec pos
-    mpos = pos
-    ## XXX: use 'syntax_error' as soon is it accepts arguments
-    .local pmc die
-    die = get_hll_global ['PGE::Util'], 'die'
-    die(mob, '\123 form deprecated, use \o123 instead')
-    goto fail
-.end
-
-
-=item C<slash_regex(PMC mob)>
-
-Handles parsing of "slash regexes" -- i.e., regexes that are 
-terminated by a slash.  For this, we just call PGE's p6 regex 
-parser, telling it to stop parsing on the closing slash.  
-
-XXX: This is just a temporary sub to get things
-working -- it will likely change.
-
-=cut
-
-.sub 'regex'
-    .param pmc mob
-    .param pmc args            :slurpy
-    .param pmc adverbs         :slurpy :named
-    .local string stop
-
-    stop = ''
-    if null adverbs goto with_stop_adverb
-    stop = adverbs['stop']
-    if stop > '' goto with_stop
-  with_stop_adverb:
-    unless args goto with_stop
-    stop = shift args
-  with_stop: 
-    .include 'interpinfo.pasm'
-    $P0 = get_root_namespace
-    $P0 = $P0['parrot';'PGE::Grammar';'regex']
-    $P1 = $P0(mob, 'stop'=>stop)
-    .return ($P1)
-.end

Copied: trunk/languages/perl6/src/parser/quote.pir (from r16791, 
/trunk/languages/perl6/src/quote.pir)
==============================================================================
--- /trunk/languages/perl6/src/quote.pir        (original)
+++ trunk/languages/perl6/src/parser/quote.pir  Thu Jan 25 12:19:16 2007
@@ -1,3 +1,25 @@
+## $Id$
+
+=head1 TITLE
+
+quote.pir - <quote_expression> subrule
+
+=head2 DESCRIPTION
+
+This file contains the grammar subrules for <quote_expression>,
+which handles Perl 6's various quoting constructs.  Trying to
+use a regular expression for parsing the various quote styles
+and interpolations is a bit of a pain, so we write a
+special-purpose parsing subroutine here.
+
+=over 4
+
+=item __onload()
+
+Initialize the tables needed for quote parsing.
+
+=cut
+
 .namespace [ 'Perl6::Grammar' ]
 
 .include "cclass.pasm"
@@ -43,6 +65,17 @@
 .end
 
 
+=item quote_expression(match [, adverbs :slurpy :named])
+
+Parse a quoted expression of some sort.  The $<KEY>
+attribute of the incoming C<match> object identifies
+the type of quoting to parse.  This is simply a lookup
+into C<%!quotetable>, which contains the default adverb
+settings for the type of quote.  Other adverbs are then
+merged into the default, and quote parsing begins.
+
+=cut
+
 .sub 'quote_expression'
     .param pmc mob
     .param pmc adverbs         :slurpy :named
@@ -331,3 +364,7 @@
     die(mob, '\123 form deprecated, use \o123 instead')
     goto fail
 .end
+
+=back
+
+=cut

Added: trunk/languages/perl6/src/parser/regex.pir
==============================================================================
--- (empty file)
+++ trunk/languages/perl6/src/parser/regex.pir  Thu Jan 25 12:19:16 2007
@@ -0,0 +1,45 @@
+## $Id$
+
+=head1 TITLE
+
+regex.pir - The <regex> subrule
+
+=head2 DESCRIPTION
+
+=over 4
+
+=item C<regex(PMC mob)>
+
+Handles parsing of "slash regexes" -- i.e., regexes that are 
+terminated by a slash.  For this, we just call PGE's p6 regex 
+parser, telling it to stop parsing on the closing slash.  
+
+FIXME: This is just a temporary sub to get things working -- 
+it will likely change.
+
+=cut
+
+.sub 'regex'
+    .param pmc mob
+    .param pmc args            :slurpy
+    .param pmc adverbs         :slurpy :named
+    .local string stop
+
+    stop = ''
+    if null adverbs goto with_stop_adverb
+    stop = adverbs['stop']
+    if stop > '' goto with_stop
+  with_stop_adverb:
+    unless args goto with_stop
+    stop = shift args
+  with_stop: 
+    .include 'interpinfo.pasm'
+    $P0 = get_root_namespace
+    $P0 = $P0['parrot';'PGE::Grammar';'regex']
+    $P1 = $P0(mob, 'stop'=>stop)
+    .return ($P1)
+.end
+
+=back
+
+=cut

Reply via email to