codelion / gramtest

GramTest: A tool for Grammar based Test case generation
Apache License 2.0
85 stars 17 forks source link

Null checks? #3

Closed nettrino closed 8 years ago

nettrino commented 8 years ago

Hello,

First of all, thanks for gramtest!I tried to run the postal.bnf (committed) and were getting NullPointerExceptions so I made these very limited changes to get through them. Since I am (very) new to ANTLR I am not sure if this is desired functionality or not. If you think this is indeed a bug feel free to merge. Also the fixes are very rough, and probably don't address the whole issue.

Also, on a separate note, I was thinking in porting gramtest to accept ANTLR grammars instead of BNF. Do you think that would be easy?

Thanks again,

Theofilos

codelion commented 8 years ago

Hi @nettrino

The NullPointerExceptions were due to the fact that the grammar was missing a production for <space> I think we should do more validation on the grammar and improve the error messages to avoid confusion. (There is an existing issue for that #2, PRs are welcome btw ;))

But for your test case, if you use the grammar below there won't be any exceptions:

  <postalcode>           ::= <forwardsortationarea> <space> <localdeliveryunit>
  <forwardsortationarea> ::= <provarea> <loctype> <letter>
  <localdeliveryunit>    ::= <digit> <letter> <digit>
  <provarea>             ::= A | B | C | E | G | H | J | K | L | M | N |
                             P | R | S | T | V | X | Y
  <loctype>              ::= <rural> | <urban>
  <rural>                ::= 0
  <urban>                ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  <letter>               ::= A | B | C | E | G | H | J | K | L | M | N |
                             P | R | S | T | V | W | X | Y | Z
  <digit>                ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  <space>             ::= " "

If you notice the way Gramtest is implemented it uses an ANTLR grammar for BNF to implement the parser. I am not sure how much effort will it be to accept arbitrary ANTLR grammars themselves, we may have to hook into the generic ANTLR visitor instead of bnfBaseVisitor as done currently.

nettrino commented 8 years ago

That makes sense. Thanks for the prompt reply!