Commit ce8395ac authored by POTTIER Francois's avatar POTTIER Francois

Cleanup of [SentenceParser].

parent 63aaf75e
/* This is two parsers in one. */
/* This parser is used to read the sentences provided on the standard input
channel when [--interpret] is enabled. */
channel when [--interpret] is set. The entry point is [optional_sentence]. */
/* It is used also to read a [.messages] file. This is two parsers in one. */
/* It is used also to read a [.messages] file. The entry point is [entry]. */
/* ------------------------------------------------------------------------ */
/* Tokens. */
......@@ -9,8 +11,6 @@
%token COLON EOF EOL
%token<Grammar.Terminal.t> TERMINAL
%token<Grammar.Nonterminal.t> NONTERMINAL
/* A block of text, preceded with '=' and terminated with a blank line. */
%token<string> BLOCK
/* ------------------------------------------------------------------------ */
/* Types. */
......@@ -21,54 +21,41 @@
type terminals = Terminal.t list
type sentence = Nonterminal.t option * terminals
type located_sentence = Positions.positions * sentence
type message = string
type entry = located_sentence list * message
type file = entry list
%}
%type <terminals> terminals
%type <sentence> sentence
%type <located_sentence> located_sentence
%type <entry> entry
%type <file> entries
/* %start <sentence option> optional_sentence */
%type <(Grammar.Nonterminal.t option * Grammar.Terminal.t list) option> optional_sentence
%type
<(Grammar.Nonterminal.t option * Grammar.Terminal.t list) option>
optional_sentence
%start optional_sentence
/* %start <file> file */
%type <((Positions.positions * (Grammar.Nonterminal.t option * Grammar.Terminal.t list)) list * string) list> file
%start file
/* %start<located_sentence list> entry1 */
%type <(Positions.positions * (Grammar.Nonterminal.t option * Grammar.Terminal.t list)) list> entry1
%start entry1
/* %start<located_sentence list> entry */
%type
<(Positions.positions * (Grammar.Nonterminal.t option * Grammar.Terminal.t list)) list>
entry
%start entry
%%
/* ------------------------------------------------------------------------ */
/* A file is a list of entries, terminated with an end-of-file. */
file: entries EOF { $1 }
/* A list of entries. */
entries: { [] } | entry entries { $1 :: $2 }
/* An entry is a non-empty list of located sentences, followed with a block of text. */
entry: entry1 BLOCK
{ $1, $2 }
entry1: located_sentence located_sentences
/* An entry is a non-empty list of located sentences. */
entry: located_sentence located_sentences EOF
{ $1 :: $2 }
| EOF
{ [] } /* a bit of a hack */
/* A list of located sentences. */
located_sentences: { [] } | located_sentence located_sentences { $1 :: $2 }
/* A located sentence. (Must be non-empty, because we use blank lines as delimiters.) */
located_sentence: nonempty_sentence
{ let pos = Positions.two (Parsing.symbol_start_pos()) (Parsing.symbol_end_pos()) in
/* A located sentence. */
located_sentence: sentence
{ let pos = Positions.two
(Parsing.symbol_start_pos())
(Parsing.symbol_end_pos()) in
pos, $1 }
/* An optional sentence. */
......@@ -86,14 +73,6 @@ sentence:
| terminals EOL
{ None, $1 }
/* A sentence is a pair of an optional non-terminal start symbol and a list
of terminal symbols. It is terminated by a newline. */
nonempty_sentence:
| NONTERMINAL COLON TERMINAL terminals EOL
{ Some $1, $3 :: $4 }
| TERMINAL terminals EOL
{ None, $1 :: $2 }
/* A list of terminal symbols. */
terminals:
|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment