Skip to content

Commit 1321d52

Browse files
committed
Documentation
1 parent 8057ea2 commit 1321d52

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/mlang/m_frontend/dune

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
(:standard -open Utils -open M_ir))
1212
(libraries utils m_ir))
1313

14+
; Generates the Syntax_messages module
15+
1416
(rule
1517
(target syntax_messages.ml)
1618
(deps
@@ -21,6 +23,8 @@
2123
%{target}
2224
(run menhir %{parser} --base %{parser} --compile-errors %{msg}))))
2325

26+
; Rules to check parser updates and properly merging the changes
27+
2428
(rule
2529
(target new.messages)
2630
(deps
@@ -52,6 +56,9 @@
5256
(run menhir %{parser} --base %{parser} --merge-errors %{new}
5357
--merge-errors %{updated}))))
5458

59+
; Tests the mparser.messages file when the parser changes.
60+
; To update the file, use dune runtest --auto-update
61+
5562
(rule
5663
(alias runtest)
5764
(package mlang)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(** Parsing error messages handler.
2+
The .ml file corresponding to this mli is generated automatically generated
3+
by menhir (check the dune file) from the [mparser.messages] file. This file
4+
is the core of parsing message handling: this is where all error messages
5+
must be added.
6+
7+
The structure of the [mparser.messages] strongly depends on the parser's. If
8+
the parser changes, it may be necessary to rework on it to update the error
9+
messages. Hopefully, [menhir] comes with a way to automatically update
10+
messages when the parser changes. This can be automatically done by running
11+
[dune runtest --auto-promote]. Check the [src/mlang/m_frontend/dune] file
12+
for more information.
13+
14+
Each possible error is mapped to a state (an integer) and a custom message
15+
in the [mparser.messages] file. When the parser raises an exception, it also
16+
raises the state where it failed. This module allows to get the
17+
corresponding error message.
18+
19+
There is then three possibilities:
20+
* the state has a custom error message, which can be printed;
21+
* the state has the default error message (<"YOUR SYNTAX ERROR MESSAGE HERE>"),
22+
which has not been written yet;
23+
* the state has no error message, which should not happen unless the
24+
[mparser.messages] is not sync with [mparser.mly].
25+
*)
26+
27+
val message : int -> string
28+
(** Returns the error message corresponding to a parser error state.
29+
Raises [Not_found] if the state has no error message. *)

0 commit comments

Comments
 (0)