Skip to content

Support parser generation without %union directive (Bison compatibility) - #765

Merged
ydah merged 2 commits into
ruby:masterfrom
ydah:non-need-union
Jan 23, 2026
Merged

Support parser generation without %union directive (Bison compatibility)#765
ydah merged 2 commits into
ruby:masterfrom
ydah:non-need-union

Conversation

@ydah

@ydah ydah commented Dec 21, 2025

Copy link
Copy Markdown
Member

Motivation

When writing simple parser samples or prototypes, defining %union can be cumbersome and unnecessary. Bison allows users to generate parsers without the %union directive, defaulting YYSTYPE to int. This PR brings the same convenience to lrama for better Bison compatibility.

How it works

When %union is not defined:

  1. YYSTYPE defaults to int (same as Bison)
  2. Semantic value references are generated without union member access
  3. The parser works exactly like Bison-generated parsers

## Motivation

When writing simple parser samples or prototypes, defining `%union` can be cumbersome and unnecessary. Bison allows users to generate
parsers without the `%union` directive, defaulting `YYSTYPE` to `int`. This PR brings the same convenience to lrama for better Bison
compatibility.

## How it works

When %union is not defined:
1. YYSTYPE defaults to int (same as Bison)
2. Semantic value references are generated without union member access
3. The parser works exactly like Bison-generated parsers
end

# @rbs () -> bool
def union_not_defined?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more straightforward to check if %union is used in the input grammar file (by checking @grammar.union), what do you think about it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I push the following commit. Is my understanding correct?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

@ydah
ydah merged commit b5eba1e into ruby:master Jan 23, 2026
23 checks passed
@ydah
ydah deleted the non-need-union branch January 23, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants