Treetop always want more, but I am out of stock!

62 views
Skip to first unread message

EternalFury

unread,
May 21, 2012, 2:28:37 PM5/21/12
to treet...@googlegroups.com
No matter what I try, I always get something like:

Consumed 0 characters.
Line: 19
Column: 1
, ason: Expected one of ,, any character, 
, " at line 19, column 1 (byte 394) after Chapter: "The beginning of the end"

  Action: unlock_grate
    Terms:
      "unlock grate, open grate"
    Processor:
      {{{
        if !player_in?('depression')
          ['There is no grate here.', {}]
        elsif !player_has?('keys')
          ['You have no keys!', {}]
        else
          ['The grate is now unlocked.', {:grate_unlocked => true}]
        end
      }}}
  end

end







Sample input:

Chapter: "The beginning of the end"

  Action: unlock_grate
    Terms:
      "unlock grate, open grate"
    Processor:
      {{{
        if !player_in?('depression')
          ['There is no grate here.', {}]
        elsif !player_has?('keys')
          ['You have no keys!', {}]
        else
          ['The grate is now unlocked.', {:grate_unlocked => true}]
        end
      }}}
  end

end


grammar TheFates

  #
  # Interactive Fiction
  #

  rule interactive_fiction
    chapter (white_space chapter)*
  end

  #
  # Chapter
  #

  rule chapter
    chapter_header white_space actions 'end' !not_space_or_tab
  end

  rule chapter_header
    'Chapter:' space_or_tab quoted_string end_of_line
  end

  #
  # Actions
  #

  rule actions
    action white_space+ actions white_space+ 'end' !not_space_or_tab
  end

  rule action
    action_header white_space+ terms white_space+ processor
  end

  rule action_header
    'Action:' space_or_tab+ identifier end_of_line
  end

  rule terms
    'Terms:' white_space+ term_list
  end

  rule processor
    'Processor:' white_space+ '{{{' code '}}}'
  end

  rule code
    !'}}}'
    (. / white_space)+
  end

  # Low-level constructs

  rule alphanumeric_character
    alphabetical_character / [0-9]
  end

  rule alphabetical_character
    [A-Za-z_]
  end

  rule comment_to_end_of_line
    '#' characters_to_end_of_line
  end

  rule characters_to_end_of_line
    (!end_of_line .)*
  end

  rule description
    'Description:' white_space+ quoted_string
  end

  rule identifier
    [a-zA-Z] [a-zA-Z0-9_]*
  end

  rule quoted_string
    single_quoted_string / double_quoted_string
  end

  rule double_quoted_string
    '"' (!'"' ("\\\\" / '\"' / .))* '"'
  end

  rule single_quoted_string
    "'" (!"'" ("\\\\" / "\\'" / .))* "'"
  end

  rule term_list
    '"' term  (white_space* ',' white_space* term)*  '"'
  end

  rule term
    (!',' .)+
  end

  # White space

  rule white_space
    (space_or_tab / end_of_line)+
  end

  rule not_space_or_tab
    !space_or_tab .
  end

  rule space_or_tab
    [ \t]
  end

  rule end_of_line
    ("\r" "\n"?) / "\n"
  end

end

Justin Collins

unread,
May 21, 2012, 10:15:23 PM5/21/12
to Treetop Development
#SNIP
>   rule not_space_or_tab
>     !space_or_tab .
>   end
>
>   rule space_or_tab
>     [ \t]
>   end
>
>   rule end_of_line
>     ("\r" "\n"?) / "\n"
>   end
>
> end


The double negation of "!not_space_or_tab" makes me suspicious. It
looks
like it is expecting a space or a tab?

I would start there. Either add a space to the end of your file or
remove the negation, and see what happens.

Good luck.

-Justin
Reply all
Reply to author
Forward
0 new messages