tobiatesan / abc4j

Automatically exported from code.google.com/p/abc4j
0 stars 1 forks source link

Space after colon causes failure to parse tune #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the following ABC input (from
http://www.thesession.org/tunes/display/8145)

X: 1
T: Key To The Cellar, The
M: 3/2
L: 1/8
R: three-two
K: Edor
G2E2 E2D2 E4 | G2E2 E2G2 FGA2 |
G2E2 E2D2 E4 | F2D2 D2 B2 A2GF :|
E2e2 e2d2 e4 | E2e2 e2f2 g2e2 |
E2e2 e2dc d3B | A2F2 D2B2 A2GF :|

2.
Use the following code (adapted from tutorial): 
    private static void test1() throws IOException {
        StringReader reader = new StringReader(TEST);
        TuneBook book = new TuneBook(reader);
        int tunesNb = book.size();
        System.out.println("Nb of tunes in input : " + tunesNb);
        // now retrieve the tune with reference number "10"
        Tune aTune = book.getTune(1);
        // display its title
        System.out.print("Title n°1 is " + aTune.getTitles()[0]);
        // and the name of its composer.
        System.out.println(" and has been composed by " + aTune.getComposer());

    }

What is the expected output? What do you see instead?

Expect to see the title displayed.  Instead, a NullPointerException is
thrown.  Removing the spaces after the colons in the header resolves this
problem, but requires manual intervention on each input (or a
pre-processing routing to automatically remove spaces)

What version of the product are you using? On what operating system?
Using abc4j_v0.5.jar on Windows XP SP2.  Running JRE 1.5_06

Please provide any additional information below.

Original issue reported on code.google.com by Joel.McN...@gmail.com on 29 Sep 2008 at 12:35

GoogleCodeExporter commented 9 years ago
abc4j implements a strict version of the abc format (v1.6). This definition of 
the
format can be found here : 
http://www.norbeck.nu/abc/abcbnf.htm
In this definition , the space is not allowed between the X: and the number of 
the
tune (same for T: or any field ain general) :
field-number ::= "X:" 1*DIGIT end-of-line

I know that many tunes from the web have this blank between fields and values 
but
they don't match the v1.6 definition (maybe the v2.0 accepts it but I restrict 
the
implementation to v1.6)

You don't attach the stack trace but I think that exception occurs on your side 
at line
System.out.print("Title n°1 is " + aTune.getTitles()[0]);
because aTune is null (cannot be found when invoking int tunesNb = book.size(); 
)

So yes abc4j does not recognize it (and this is a choice because it only 
validates
strict abc grammar v1.6) but it's not a defect (unless the crash occurs in the 
abc4j
part but I don't think so)

Original comment by lionel.g...@gmail.com on 21 Oct 2008 at 5:28

GoogleCodeExporter commented 9 years ago
Ah, well.  I now see in the grammar that they made a space a token, so it is 
picked
up during parsing instead of ignored.  Since that is an unfortunate side-effect 
of
how the language is written, I'll have to go the regex replacement route.  
Thanks for
looking into this.

Original comment by Joel.McN...@gmail.com on 21 Oct 2008 at 5:44

GoogleCodeExporter commented 9 years ago

Original comment by iubito@gmail.com on 16 Aug 2012 at 1:22