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 6169849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:55:38+00:00 2026-05-23T22:55:38+00:00

(Sorry, not sure if ad-hoc is the right word here … open for a

  • 0

(Sorry, not sure if ad-hoc is the right word here … open for a better suggestion)

I’m trying to parse the Galaxy ToolConfig XML CLI tool wrapper format in a Java app, for replicating (in part) the behaviour of the Galaxy software itself.

The format includes some “free-text” if/else clauses, inside the command tag (that’s the only place they occur, AFAIK):

...
<command interpreter="python">
  sam_to_bam.py
    --input1=$source.input1
    --dbkey=${input1.metadata.dbkey} 
    #if $source.index_source == "history":
      --ref_file=$source.ref_file
    #else
      --ref_file="None"
    #end if
    --output1=$output1
    --index_dir=${GALAXY_DATA_INDEX_DIR}
</command>
...

What would be a recommended strategy for parsing this if/else structure into something that can be used to remodel the if/else logic in Java?

Is BNF/ANTLR overkill, better just to parse into some object structure, or? Any design patterns that would fit here? (Haven’t worked with BNF/ANTLR before, but am willing to look into it if it will be worth it).

  • 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-23T22:55:39+00:00Added an answer on May 23, 2026 at 10:55 pm

    If you want to capture all the structure of the your input, a parser is the only way to go. One can code a parser manually top-down recursive, but there is little point in doing that, which is why parser generator tools exist; use them.

    Regarding the #if #then #else: if that’s the only structure you want to capture, then you need only a pretty primitive grammar that also allows tokens containing arbitrary text to pick up the goo between the #if#then#else constructs as a blob of text.

    If you want to capture all code structure, and the conditionals are only allowed in certain places, then their existence can be simply integrated into whatever BNF you are using.

    If, as I suspect, these can occur anywhere (“ad hoc”? the #if follows C preprocessor style, and those conditionals can occur virtually anywhere in the input stream), then parsing the text and retaining the conditionals is presently at the bleeding edge of what state of the art parsing can do. This is the standard C-preprocessing disease, and there have been no good solutions to this. Standard parser generators pretty can’t help in this case. (Hand coded parsers don’t fare better here either; the same kind of solution has to be used in either case).

    One of the recent schemes (just reported as PhD research results in the last few months) to handle this is to fork the parse whenever a #if token is found to handle #if, and #else, and join when #endif is found; then you need a way to fuse to the generated subtrees typically as ambiguous subtrees marked with which arm of the conditional.

    If you want to get on with your life, I suggest you simply insist that these conditionals occur in well-defined places in your grammar, and put up with the occasional complaint from people that write unstructured preprocessor directives. (“You wrote crazy code? Sorry, my tool doesn’t handle it”).

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

Sidebar

Related Questions

Sorry, I'm not sure how to really word my question. Here it goes. If
Sorry, I'm not sure of the right language here, but when methods are called
Sorry about terrible title, not sure of a better one. Here's a gross simplification
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
Sorry, I'm not really sure of the right way to ask this one so
Not sure if the title makes sense sorry... basically I'm generating Word documents that
Sorry if my title is not clear, I'm not sure how to word this.
Sorry about the title, not sure how to describe without example. I trying to
Sorry for the unclear title, but I'm not sure how else to word it.
Sorry if the title is vague, I'm not sure what terminology to use. Here

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.