Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:42:14+00:00 2026-05-23T21:42:14+00:00

I have a parser rule in ANTLR that takes a parameter. tincture [Tinctures tinctures]

  • 0

I have a parser rule in ANTLR that takes a parameter.

tincture [Tinctures tinctures] returns [Tincture tincture]   
    :   { String tinctureName = ""; }
    (   COLOUR { tinctureName = $COLOUR.text; }
    |   METAL  { tinctureName = $METAL.text; }
    |   FUR    { tinctureName = $FUR.text; }
    )
    {
        try {
            $tincture = tinctures.getTincture(tinctureName);
        } catch (UnknownTinctureException e) {
            throw new MyRecognitionException("Unknown tincture found.", e);
        }
    }
    ;

How can I write a test for this in GUnit?

I have successfully written tests for my Lexer rules as they do not have any parameters.
If I write the following I get “java.lang.NoSuchMethodException: mypackage.BlazonParser.tincture()”

tincture
    :   "gules"             OK
        "sable"             OK
        "blah"              FAIL

I can find very little documentation around GUnit apart from this page, but it hasn’t covered this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:42:14+00:00Added an answer on May 23, 2026 at 9:42 pm

    Looking at the official docs, it seems you can’t provide a parameter to the rules you test, causing for the exception:

    java.lang.NoSuchMethodException: mypackage.BlazonParser.tincture()
    

    since tincture expects a Tinctures as parameter.

    You could keep keep using gUnit, and use JUnit for those rules containing parameters. But mixing gUnit and JUnit is a bit messy, IMO, so personally, I simply use JUnit for all my ANTLR tests.

    You could also have a look at aunit, a 3rd party ANTLR unit test suite. I haven’t looked at it in detail, and it seems to be lacking in documentation, but still, it could be what you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write an ANTLR parser rule that matches a list of
To outline: I have a parser that grabs Cell references using the following regex
I have a buggy xml that contains empty attributes and I have a parser
I have an AST derived from the ANTLR Parser Generator for Java. What I
I have a tree parser that's doing semantic analysis on the AST generated by
I have a data structure that represents C# code like this: class Namespace: string
It seems that sometimes the Antlr lexer makes a bad choice on which rule
i have problem with @members rule in ANTLR. I want overwrite default error handling,
I'm working with antlr 3.2. I have a simple grammar that consists of atoms
I have a grammar that I do not know what type of parser I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.