Missing something simple?

37 views
Skip to first unread message

Scott Hall

unread,
Jan 9, 2013, 2:29:03 AM1/9/13
to treet...@googlegroups.com
Been working on this all day. Figure I must be missing something simple.

Basically I have three labels set in rules but inside the called ruby code I hookup it only has two of them set, ignoring the other. Here is the relevant rules:
  rule document
    contents:(dialog < RPGCode::DialogNode> / npc_dialog < RPGCode::DialogNode> / paragraph < RPGCode::ParagraphNode>)* break_ws* <RPGCode::DocumentNode>
  end

  rule npc_toon
    toon:([\w\s])+ ':' [ \t]*
  end
  
  rule npc_dialog
    (break_ws 2..)
    npc_toon 
    quote?
    dialog:(  
      !(break_ws 2.. / break_quote)
      paragraph_contents
    )+ 
    quote?
  end

But in RPGCode::DialogNode

dialog is set
contents is set
toon is NULL

I've tried changing things around many different ways. The idea is to capture a format like this:

Character: "Some Dialog Goes Here"

Where the quotes are optional. Getting character in one variable and the dialog inside the optional quotes as another. The last part works right now. 

contents label is used only for ParagraphNode but in DialogNode it is set as well (just doesn't do me any good).

I could resort to ruby code inside DialogNode but then that defeats the point of a tree parser. I'm sure I'm just missing something silly as this was the first time I worked with Treetop.

Any help is appreciated.

Clifford Heath

unread,
Jan 10, 2013, 7:23:08 PM1/10/13
to treet...@googlegroups.com
Scott,

Since no-one else has answered you, I'll try.

> Basically I have three labels set in rules but inside the called ruby code I hookup it only has two of them set, ignoring the other. Here is the relevant rules:
> rule document
> contents:(dialog < RPGCode::DialogNode> / npc_dialog < RPGCode::DialogNode> / paragraph < RPGCode::ParagraphNode>)* break_ws* <RPGCode::DocumentNode>
> end

I would break these up differently - especially by moving each class out to a new rule.
It's quite hard to see what you intend when you do too much in one rule.

Did you intend both the "dialog" and the "npc_dialog" nodes to use RPG::DialogNode?
Even though npc_dialog includes one or more "dialog" nodes inside it?
You didn't share your "dialog" rule, so I can't tell.

> rule npc_toon
> toon:([\w\s])+ ':' [ \t]*
> end

npc_toon is a sequence, consistent of the toon sequence, a :, and zero-or-more space-or-tab.
As such the node returned has the "toon" accessor method defined.

> rule npc_dialog
> (break_ws 2..)
> npc_toon
> quote?
> dialog:(
> !(break_ws 2.. / break_quote)
> paragraph_contents
> )+
> quote?
> end
>
> But in RPGCode::DialogNode
>
> dialog is set
> contents is set
> toon is NULL

However, in DialogNode, npc_toon will be set. You want to access "npc_toon.toon"

Clifford Heath.

> I've tried changing things around many different ways. The idea is to capture a format like this:
>
> Character: "Some Dialog Goes Here"
>
> Where the quotes are optional. Getting character in one variable and the dialog inside the optional quotes as another. The last part works right now.
>
> contents label is used only for ParagraphNode but in DialogNode it is set as well (just doesn't do me any good).
>
> I could resort to ruby code inside DialogNode but then that defeats the point of a tree parser. I'm sure I'm just missing something silly as this was the first time I worked with Treetop.
>
> Any help is appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups "Treetop Development" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/treetop-dev/-/W6-kv1wQFPYJ.
> To post to this group, send email to treet...@googlegroups.com.
> To unsubscribe from this group, send email to treetop-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/treetop-dev?hl=en.

Reply all
Reply to author
Forward
0 new messages