Added an example of how to use Antlr with Java

Review Request #1088 — Created Sept. 30, 2014 and submitted

zundel
pants
zundel/java-antlr-example
620
1a49ec9...
pants-reviews
jcoveney, jsirois, stuhood

Added an example of how to use Antlr with Java.

Added integration test and unit test.

  • 0
  • 0
  • 1
  • 0
  • 1
Description From Last Updated
LA
  1. examples/src/antlr/com/pants/examples/exp/ could use a README.md that points folks at where it's used. Maybe something like "Antlr grammar that evals expressions. To see how Java code might use it, see examples/tests/java/com/pants/examples/antlr/ and examples/tests/java/com/pants/examples/useantlr/"

  2. not sure whether these are supposed to fail or succeed

    1. Why is that? The comparisions are supposed to be equal. Is it because of the .001 on the end? If that is it, the 3rd 'delta' argument is used when comparing floats to account for floating point precision error.

    2. or is it just because I am bad at math: 8*6 != 56. Don't tell my Dad - he used to quiz me on my times tables in 5th grade until I was in tears.

    3. or is it just because I am bad at math

      A combination of that and I'm a java ignoramus; for all I know 'testFoo() throws Exception' is junit magic for expect-an-exception. So don't tell my dad either, I guess.

  3. 
      
ZU
IT
ZU
JS
  1. 
      
  2. IIUC this is considered not-best-practice. Jonathan Coveney added support for the best practice, see here:
    + https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/codegen/targets/java_antlr_library.py#L30
    + https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/codegen/tasks/antlr_gen.py#L82

    1. Using 'package' for java_antlr_library isn't working for me. When I remove these package options from the Exp.g file and add package='com.pants.examples.exp' to the target, my code ends up under:

      ./.pants.d/gen/antlr/antlr3/gen-java/examples/src/antlr/com/pants/examples/exp/ExpParser.java

      Looking at the generated java code, there is no 'package' line present in the .java file. I'll see if I can fix it.

    2. Its an antlr3 vs. antlr4 issue. I'll provide working examples of both.

  3. 
      
ZU
  1. 
      
  2. Using 'package' for java_antlr_library isn't working for me. When I remove these package options from the Exp.g file and add package='com.pants.examples.exp' to the target, my code ends up under:

    ./.pants.d/gen/antlr/antlr3/gen-java/examples/src/antlr/com/pants/examples/exp/ExpParser.java

    Looking at the generated java code, there is no 'package' line present in the .java file. I'll see if I can fix it.

    1. reposted this comment to be inline with John's...

  3. 
      
ZU
ZU
JC
  1. Ship It!

  2. 
      
JS
  1. Ship It!

  2. 
      
ZU
ZU
Review request changed

Status: Closed (submitted)

Change Summary:

Thanks for the reviews.  commit 8328255
Loading...