RecDescent examples/urls ? 
Author Message
 RecDescent examples/urls ?

I'm building a piece of software that will take sermon notes from our
pastor, parse out the scripture references and replace them with links
to online Bibles.

Having had some experience with Lexx & Yacc so many years ago in grad
school, RecDescent sounds like it might be the right tool for the job.

What I'm looking for, outside of the documentation at CPAN.Org and
Perl.com, are examples of grammar. Especially those that might help
with with stuff like:

I John 1:12-14
II John 1:7&8
III John 1:2-4, 2:1&2
III John 1:2-4, 2:1&2; 2nd Peter 2:1



Sat, 17 Apr 2004 04:03:01 GMT  
 RecDescent examples/urls ?

Quote:

>I'm building a piece of software that will take sermon notes from our
>pastor, parse out the scripture references and replace them with links
>to online Bibles.

>Having had some experience with Lexx & Yacc so many years ago in grad
>school, RecDescent sounds like it might be the right tool for the job.

I think not, unless your pastor has a very formal way of saying things.
I think a simple regular expression, likely in a s/// form, would be
more suitable.

Quote:
>What I'm looking for, outside of the documentation at CPAN.Org and
>Perl.com, are examples of grammar. Especially those that might help
>with with stuff like:

I assume you have seen Damian Conwy's own tutorial, originally p?blished
in TPJ, then? If not, it can be found at

<http://search.cpan.org/doc/DCONWAY/Parse-RecDescent-1.80/tutorial/tut...>

As for Lex/Yacc: I like the into at Microman:

        <http://www.uman.com/lexyacc.shtml>

Quote:
>I John 1:12-14
>II John 1:7&8
>III John 1:2-4, 2:1&2
>III John 1:2-4, 2:1&2; 2nd Peter 2:1

Is the "I"/"II"/"III" part of the reference? One can just ask. Oh well:

while(<DATA>) {
    my $who;
    print "Before = $_";
    s/(?:(I+ John|2nd Peter)|\G,)\s+(\d+:\d+(?:[-&]\d+)?)/
        $who = $1 if defined $1; "[$who $2]"/gce;
    print "After = $_";

Quote:
}

__DATA__
I John 1:12-14
II John 1:7&8
III John 1:2-4, 2:1&2
III John 1:2-4, 2:1&2; 2nd Peter 2:1

This prints:

Before = I John 1:12-14
After = [I John 1:12-14]
Before = II John 1:7&8
After = [II John 1:7&8]
Before = III John 1:2-4, 2:1&2
After = [III John 1:2-4][III John 2:1&2]
Before = III John 1:2-4, 2:1&2; 2nd Peter 2:1
After = [III John 1:2-4][III John 2:1&2]; [2nd Peter 2:1]

As you can see, my "reference" is a simple scheme of the name plus the
chapter and verses, that all between square brackets. The name may have
been retained from the previous match.

--
        Bart.



Sat, 17 Apr 2004 10:03:08 GMT  
 RecDescent examples/urls ?

Boomer2k> I'm building a piece of software that will take sermon notes from our
Boomer2k> pastor, parse out the scripture references and replace them with links
Boomer2k> to online Bibles.

Boomer2k> Having had some experience with Lexx & Yacc so many years ago in grad
Boomer2k> school, RecDescent sounds like it might be the right tool for the job.

Boomer2k> What I'm looking for, outside of the documentation at CPAN.Org and
Boomer2k> Perl.com, are examples of grammar. Especially those that might help
Boomer2k> with with stuff like:

Boomer2k> I John 1:12-14
Boomer2k> II John 1:7&8
Boomer2k> III John 1:2-4, 2:1&2
Boomer2k> III John 1:2-4, 2:1&2; 2nd Peter 2:1

You can ask this question on the P::RD mailing list and
get a more concentrated collection of experts.  See <http://lists.perl.org>.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Sun, 18 Apr 2004 04:11:33 GMT  
 RecDescent examples/urls ?

Quote:
> Is the "I"/"II"/"III" part of the reference? One can just ask. Oh well:

Sometimes. Meaning, your code example works great up until the guys
writing the text pull stunts like:

1 John 1:12-14, John 3:16
Second Peter 3
1st Corinthians 13:1-4
Romans 10:9-10

Quote:

> while(<DATA>) {
>     my $who;
>     print "Before = $_";
>     s/(?:(I+ John|2nd Peter)|\G,)\s+(\d+:\d+(?:[-&]\d+)?)/
>         $who = $1 if defined $1; "[$who $2]"/gce;
>     print "After = $_";
> }

> __DATA__
> I John 1:12-14
> II John 1:7&8
> III John 1:2-4, 2:1&2
> III John 1:2-4, 2:1&2; 2nd Peter 2:1



Sun, 16 May 2004 23:52:18 GMT  
 RecDescent examples/urls ?
Bart.

Thanks !

With a bit more work ... here's a rough cut at something that mostly
works.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - -

my $volumes = "I+|1st|2nd|3rd|First|Second|Third|1|2|3";
my $books = "Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther|Job|Psalm|Proverbs|Ecclesiastes|Song
of Solomon|Isaiah|Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|Zechariah|Malachi|Matthew|Mark|Luke|John|Acts|Romans|Corinthians|Galatians|Ephesians|Philippians|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|Jude|Revelation";
$books .= "Psalms|Proverb|Revelations";

while(<DATA>) {
    my $passage;
    print "Before = $_";
    s/(?:($volumes)\s*)*(?:($books)|\G,)\s+(\d+:\d+(?:[-&]\d+)?)/
        $passage = ($1 ? "$1 ":"").($2 ? $2:"").($3 ? " $3":"") if defined
$2;
        "<scripRef passage=\"$passage\">$passage<\/scripRef>"/gce;
        # see http://ccel.org/ThML/scripref.htm about scripRef tag ..
    print "After = $_";

Quote:
}

__DATA__
Something we see here all the time in I John 1:12-14 where it says ...
I John 1:12-14
2nd John 1:2-4
Romans 3:23
Romans 10:9-10, 1 Corinthians 13:1-8
II John 1:7&8
III John 1:2-4, 2:1&2
III John 1:2-4, 2:1&2; 2nd Peter 2:1


Mon, 17 May 2004 00:48:20 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Errors running Randal and Damian's Parse::RecDescent examples

2. need help with demo_logic example of Parse::RecDescent

3. need help with demo_logic example of Parse::RecDescent

4. Substituting source urls with redirected urls

5. filter of absolute urls to relative urls?

6. Tell apart file URLs from dir URLs?

7. Newbie Help: example 1 works example 2 doesn't:

8. Having Trouble with Parse::RecDescent on Solaris

9. Converting SQL89 YACC rule to Parse::RecDescent

10. ANNOUNCE: Parse::RecDescent 1.42

11. ANNOUNCE: Parse::RecDescent 1.41

12. ANNOUNCE: Parse::RecDescent 1.35

 

 
Powered by phpBB® Forum Software