module FoodIngredientParser::Strict::Grammar

grammar Root
  include Common
  include List
  include ListColoned
  include ListNewlined

  rule root
    '"'?
    root_prefix? ws*
    contains:( list_newlined / list_coloned / list )
    notes:(
      root_mark_sentences_in_list? ws*
      ( ( [.;] ws* newline* / [.;]?  ws* newline+ ) ws* root_sentences? ws* )?
    )
    '"'?
    <RootNode>
  end

  rule root_prefix
    (
      'ingredients'i / 'contains'i /
      ('ingred'i [IÏiï] [EËeë] 'n'i ( 't'i 'en'i? 'declaratie'i? )? ) / 'bevat'i / 'dit zit er in'i / 'samenstelling'i /
      'zutaten'i
    )
    ( ws* [:;.] ( ws* newline )? / ws* newline / ws ) ws*  # optional colon or other separator
    "'"? ws*                                               # stray quote occurs sometimes
  end

  rule root_sentences
    ( root_sentence ws* )+ root_sentence_open? / root_sentence_open
  end

  rule root_sentence
    root_sentence_open ( '.' / ';' / newline+ )
  end

  rule root_sentence_open
    ( word / ws / [,:()%] / '[' / ']' / mark )+ <NoteNode>
  end

  rule root_mark_sentences_in_list
    ( ( ws* [,.;] / ws )+ root_mark_sentence_in_list )+
  end

  rule root_mark_sentence_in_list
    mark ws* root_sentence_open <NoteNode>
  end

end

end