Labeling an expression appears to require another expression; why? #21

Closed
jbrains opened this Issue Dec 8, 2011 · 5 comments

Comments

Projects
None yet
3 participants
@jbrains

jbrains commented Dec 8, 2011

I'm test-driving my grammar, because I'm learning Treetop at the same time as designing my language. As an intermediate step, I try to write a grammar with a rule whose expression I want to label. When I do this, the grammar itself no longer parses correctly. It looks like what I've done somewhere else, so I can't figure out the problem. Finally, I conclude that labeling an expression requires having at least one more expression following it. I don't find that constraint helpful, so why have it? This spec describes the difference. Skip to the end, then read it backwards.


require 'treetop'

describe "Grammar with a simple rule that uses a label" do
  context "Labeled subexpression followed by another expression" do
    let(:subject) { Treetop.load_from_string(
<<GRAMMAR
grammar SimpleRuleWithLabel
  rule word
    letters:[A-Za-z]+ [A-Za-z]*
  end
end
GRAMMAR
    )}

    let (:parser) { subject.new }

    context "matching many letters, the match result" do
      let(:result) { parser.parse("aBcDeF") }

      it { result.should respond_to(:letters) }
      it { result.letters.text_value.should == "aBcDeF" }
    end
  end

  context "Labeled subexpression without another expression" do
    it "does not represent a valid grammar, even though I think it should" do
      lambda {
        Treetop.load_from_string(
<<GRAMMAR
grammar SimpleRuleWithLabel
  rule word
    letters:[A-Za-z]+
  end
end
GRAMMAR
      )}.should raise_error(RuntimeError, /Expected \#/)
    end
  end
end
@cjheath

This comment has been minimized.

Show comment Hide comment
@cjheath

cjheath Dec 10, 2011

Collaborator

I'm sorry, that does look like a bug. It's possible you're the first person to attempt to use a label in a situation like that though :). If you care to offer a patch, I'll happily include it.

Collaborator

cjheath commented Dec 10, 2011

I'm sorry, that does look like a bug. It's possible you're the first person to attempt to use a label in a situation like that though :). If you care to offer a patch, I'll happily include it.

@teleological

This comment has been minimized.

Show comment Hide comment
@teleological

teleological May 24, 2013

I submitted a pull-request (cjheath#4) to support this use case to the fork of treetop maintained by @cjheath which seems to have been used to build the latest release, v1.4.12.

I submitted a pull-request (cjheath#4) to support this use case to the fork of treetop maintained by @cjheath which seems to have been used to build the latest release, v1.4.12.

@cjheath

This comment has been minimized.

Show comment Hide comment
@cjheath

cjheath May 24, 2013

Collaborator

Thanks. I'm travelling right now, and will process this next week.
On May 24, 2013 2:36 PM, "Riley Lynch" notifications@github.com wrote:

I submitted a pull-request (cjheath#4cjheath#4)
to support this use case to the fork of treetop maintained by @cjheathhttps://github.com/cjheathwhich seems to have been used to build the latest release, v1.4.12.


Reply to this email directly or view it on GitHubhttps://github.com/nathansobo/treetop/issues/21#issuecomment-18386178
.

Collaborator

cjheath commented May 24, 2013

Thanks. I'm travelling right now, and will process this next week.
On May 24, 2013 2:36 PM, "Riley Lynch" notifications@github.com wrote:

I submitted a pull-request (cjheath#4cjheath#4)
to support this use case to the fork of treetop maintained by @cjheathhttps://github.com/cjheathwhich seems to have been used to build the latest release, v1.4.12.


Reply to this email directly or view it on GitHubhttps://github.com/nathansobo/treetop/issues/21#issuecomment-18386178
.

@teleological

This comment has been minimized.

Show comment Hide comment
@teleological

teleological May 24, 2013

Thank you!

Thank you!

@cjheath

This comment has been minimized.

Show comment Hide comment
@cjheath

cjheath Jul 13, 2013

Collaborator

Fixed via a patch submitted and merged on my fork.

Collaborator

cjheath commented Jul 13, 2013

Fixed via a patch submitted and merged on my fork.

@cjheath cjheath closed this Jul 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment