[Pkg-ocaml-maint-commits] [menhir] 01/04: Imported Upstream version 20140422.dfsg
Mehdi Dogguy
mehdi at moszumanska.debian.org
Sun Apr 27 12:53:15 UTC 2014
This is an automated email from the git hooks/post-receive script.
mehdi pushed a commit to branch master
in repository menhir.
commit d8b2ca80132eb9946583e2e021e7547869561023
Author: Mehdi Dogguy <mehdi at debian.org>
Date: Sun Apr 27 14:48:14 2014 +0200
Imported Upstream version 20140422.dfsg
---
CHANGES | 14 ++++++++++++++
INSTALLATION | 4 +++-
Makefile | 2 +-
demos/calc-param/calc.ml | 40 +++++++++++++++++++++++++++-------------
demos/calc-param/lexer.mll | 19 +++++++++++++++----
demos/calc-two/calc.ml | 42 ++++++++++++++++++++++++++++--------------
demos/calc-two/lexer.mll | 19 +++++++++++++++----
demos/calc/calc.ml | 40 +++++++++++++++++++++++++++-------------
demos/calc/lexer.mll | 19 +++++++++++++++----
src/META | 2 +-
src/Makefile | 2 +-
src/coqBackend.ml | 12 ++++++------
src/lexer.mll | 5 +++--
src/version.ml | 2 +-
14 files changed, 157 insertions(+), 65 deletions(-)
diff --git a/CHANGES b/CHANGES
index 4a7d761..1f25c53 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,17 @@
+2014/02/18:
+In the Coq backend, use ' instead of _ as separator in identifiers.
+Also, correct a serious bug that was inadvertently introduced on
+2013/03/01 (r319).
+
+2014/02/14
+Lexer fix so as to support an open variant type [> ...] within
+a %type<...> declaration.
+
+2013/12/16
+Updated the Makefile so that install no longer depends on all.
+Updated the demos so that the lexer does not invoke "exit 0"
+when encoutering eof. (This should be more intuitive.)
+
2013/09/11:
Fixed a newline conversion problem that would prevent Menhir from
building on Windows when using ocaml 4.01.
diff --git a/INSTALLATION b/INSTALLATION
index ca2d387..c0780e9 100644
--- a/INSTALLATION
+++ b/INSTALLATION
@@ -8,14 +8,16 @@ If you wish to install via ocamlfind, make sure that ocamlfind is in
your PATH. (Remember that prefixing a command with sudo affects its
PATH.)
-Run the following command:
+Run the following commands:
+ make PREFIX=/usr/local all
make PREFIX=/usr/local install
If your machine does not have the native code Objective Caml compiler
(ocamlopt), but does have the bytecode compiler (ocamlc), then instead
of the above command, use:
+ make PREFIX=/usr/local TARGET=byte all
make PREFIX=/usr/local TARGET=byte install
The value of the PREFIX variable can be changed to control where
diff --git a/Makefile b/Makefile
index f457e1a..aed992b 100644
--- a/Makefile
+++ b/Makefile
@@ -90,7 +90,7 @@ all:
# The directory where things have been built (by make all, above).
BUILDDIR := src/_stage2
-install: all
+install:
mkdir -p $(bindir)
mkdir -p $(libdir)
mkdir -p $(docdir)
diff --git a/demos/calc-param/calc.ml b/demos/calc-param/calc.ml
index 812a168..f8b7b3c 100644
--- a/demos/calc-param/calc.ml
+++ b/demos/calc-param/calc.ml
@@ -37,17 +37,31 @@ module FloatParser =
(* The rest is as usual. *)
+let process (line : string) =
+ let linebuf = Lexing.from_string line in
+ try
+ (* Run the parser on this line of input. *)
+ Printf.printf "%f\n%!" (FloatParser.main Lexer.token linebuf)
+ with
+ | Lexer.Error msg ->
+ Printf.fprintf stderr "%s%!" msg
+ | FloatParser.Error ->
+ Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf)
+
+let process (optional_line : string option) =
+ match optional_line with
+ | None ->
+ ()
+ | Some line ->
+ process line
+
+let rec repeat channel =
+ (* Attempt to read one line. *)
+ let optional_line, continue = Lexer.line channel in
+ process optional_line;
+ if continue then
+ repeat channel
+
let () =
- let stdinbuf = Lexing.from_channel stdin in
- while true do
- (* Read line by line. *)
- let linebuf = Lexing.from_string (Lexer.line stdinbuf) in
- try
- (* Run the parser on a single line of input. *)
- Printf.printf "%.1f\n%!" (FloatParser.main Lexer.token linebuf)
- with
- | Lexer.Error msg ->
- Printf.fprintf stderr "%s%!" msg
- | FloatParser.Error ->
- Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf)
- done
+ repeat (Lexing.from_channel stdin)
+
diff --git a/demos/calc-param/lexer.mll b/demos/calc-param/lexer.mll
index d52f36e..1f68ee0 100644
--- a/demos/calc-param/lexer.mll
+++ b/demos/calc-param/lexer.mll
@@ -19,11 +19,24 @@
}
+(* This rule looks for a single line, terminated with '\n' or eof.
+ It returns a pair of an optional string (the line that was found)
+ and a Boolean flag (false if eof was reached). *)
+
rule line = parse
| ([^'\n']* '\n') as line
- { line }
+ (* Normal case: one line, no eof. *)
+ { Some line, true }
| eof
- { exit 0 }
+ (* Normal case: no data, eof. *)
+ { None, false }
+| ([^'\n']+ as line) eof
+ (* Special case: some data but missing '\n', then eof.
+ Consider this as the last line, and add the missing '\n'. *)
+ { Some (line ^ "\n"), false }
+
+(* This rule analyzes a single line and turns it into a stream of
+ tokens. *)
and token = parse
| [' ' '\t']
@@ -44,8 +57,6 @@ and token = parse
{ LPAREN }
| ')'
{ RPAREN }
-| eof
- { exit 0 }
| _
{ raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
diff --git a/demos/calc-two/calc.ml b/demos/calc-two/calc.ml
index 5ff7ed4..01827d6 100644
--- a/demos/calc-two/calc.ml
+++ b/demos/calc-two/calc.ml
@@ -27,18 +27,32 @@ let main =
else
Reverse.main
+let process (line : string) =
+ let linebuf = Lexing.from_string line in
+ try
+ (* Run the parser on this line of input. *)
+ Printf.printf "%d\n%!" (main Lexer.token linebuf)
+ with
+ | Lexer.Error msg ->
+ Printf.fprintf stderr "%s%!" msg
+ | Algebraic.Error
+ | Reverse.Error ->
+ Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf)
+
+let process (optional_line : string option) =
+ match optional_line with
+ | None ->
+ ()
+ | Some line ->
+ process line
+
+let rec repeat channel =
+ (* Attempt to read one line. *)
+ let optional_line, continue = Lexer.line channel in
+ process optional_line;
+ if continue then
+ repeat channel
+
let () =
- let stdinbuf = Lexing.from_channel stdin in
- while true do
- (* Read line by line. *)
- let linebuf = Lexing.from_string (Lexer.line stdinbuf) in
- try
- (* Run the parser on a single line of input. *)
- Printf.printf "%d\n%!" (main Lexer.token linebuf)
- with
- | Lexer.Error msg ->
- Printf.fprintf stderr "%s%!" msg
- | Algebraic.Error
- | Reverse.Error ->
- Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf)
- done
+ repeat (Lexing.from_channel stdin)
+
diff --git a/demos/calc-two/lexer.mll b/demos/calc-two/lexer.mll
index d52f36e..1f68ee0 100644
--- a/demos/calc-two/lexer.mll
+++ b/demos/calc-two/lexer.mll
@@ -19,11 +19,24 @@
}
+(* This rule looks for a single line, terminated with '\n' or eof.
+ It returns a pair of an optional string (the line that was found)
+ and a Boolean flag (false if eof was reached). *)
+
rule line = parse
| ([^'\n']* '\n') as line
- { line }
+ (* Normal case: one line, no eof. *)
+ { Some line, true }
| eof
- { exit 0 }
+ (* Normal case: no data, eof. *)
+ { None, false }
+| ([^'\n']+ as line) eof
+ (* Special case: some data but missing '\n', then eof.
+ Consider this as the last line, and add the missing '\n'. *)
+ { Some (line ^ "\n"), false }
+
+(* This rule analyzes a single line and turns it into a stream of
+ tokens. *)
and token = parse
| [' ' '\t']
@@ -44,8 +57,6 @@ and token = parse
{ LPAREN }
| ')'
{ RPAREN }
-| eof
- { exit 0 }
| _
{ raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
diff --git a/demos/calc/calc.ml b/demos/calc/calc.ml
index cc54679..34ed5ba 100644
--- a/demos/calc/calc.ml
+++ b/demos/calc/calc.ml
@@ -12,17 +12,31 @@
(* *)
(**************************************************************************)
+let process (line : string) =
+ let linebuf = Lexing.from_string line in
+ try
+ (* Run the parser on this line of input. *)
+ Printf.printf "%d\n%!" (Parser.main Lexer.token linebuf)
+ with
+ | Lexer.Error msg ->
+ Printf.fprintf stderr "%s%!" msg
+ | Parser.Error ->
+ Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf)
+
+let process (optional_line : string option) =
+ match optional_line with
+ | None ->
+ ()
+ | Some line ->
+ process line
+
+let rec repeat channel =
+ (* Attempt to read one line. *)
+ let optional_line, continue = Lexer.line channel in
+ process optional_line;
+ if continue then
+ repeat channel
+
let () =
- let stdinbuf = Lexing.from_channel stdin in
- while true do
- (* Read line by line. *)
- let linebuf = Lexing.from_string (Lexer.line stdinbuf) in
- try
- (* Run the parser on a single line of input. *)
- Printf.printf "%d\n%!" (Parser.main Lexer.token linebuf)
- with
- | Lexer.Error msg ->
- Printf.fprintf stderr "%s%!" msg
- | Parser.Error ->
- Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf)
- done
+ repeat (Lexing.from_channel stdin)
+
diff --git a/demos/calc/lexer.mll b/demos/calc/lexer.mll
index 686391e..6ca1efc 100644
--- a/demos/calc/lexer.mll
+++ b/demos/calc/lexer.mll
@@ -19,11 +19,24 @@
}
+(* This rule looks for a single line, terminated with '\n' or eof.
+ It returns a pair of an optional string (the line that was found)
+ and a Boolean flag (false if eof was reached). *)
+
rule line = parse
| ([^'\n']* '\n') as line
- { line }
+ (* Normal case: one line, no eof. *)
+ { Some line, true }
| eof
- { exit 0 }
+ (* Normal case: no data, eof. *)
+ { None, false }
+| ([^'\n']+ as line) eof
+ (* Special case: some data but missing '\n', then eof.
+ Consider this as the last line, and add the missing '\n'. *)
+ { Some (line ^ "\n"), false }
+
+(* This rule analyzes a single line and turns it into a stream of
+ tokens. *)
and token = parse
| [' ' '\t']
@@ -44,8 +57,6 @@ and token = parse
{ LPAREN }
| ')'
{ RPAREN }
-| eof
- { exit 0 }
| _
{ raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
diff --git a/src/META b/src/META
index 8b56009..786025d 100644
--- a/src/META
+++ b/src/META
@@ -2,4 +2,4 @@ requires = ""
description = "Runtime support for code generated by Menhir"
archive(byte) = "menhirLib.cmo"
archive(native) = "menhirLib.cmx"
-version = "20130911"
+version = "20140422"
diff --git a/src/Makefile b/src/Makefile
index cbf0388..0e87728 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -19,7 +19,7 @@ endif
# ----------------------------------------------------------------------------
# Ocamlbuild tool and settings.
-OCAMLBUILD := ocamlbuild -classic-display -use-ocamlfind -j 0
+OCAMLBUILD := ocamlbuild -classic-display -j 0
# ----------------------------------------------------------------------------
# For everyday development.
diff --git a/src/coqBackend.ml b/src/coqBackend.ml
index 91ca40f..63c6dfa 100644
--- a/src/coqBackend.ml
+++ b/src/coqBackend.ml
@@ -19,10 +19,10 @@ module Run (T: sig end) = struct
let print_term t =
assert (not (Terminal.pseudo t));
- sprintf "%s_t" (Terminal.print t)
+ sprintf "%s't" (Terminal.print t)
let print_nterm nt =
- sprintf "%s_nt" (Nonterminal.print true nt)
+ sprintf "%s'nt" (Nonterminal.print true nt)
let print_symbol = function
| Symbol.N nt -> sprintf "NT %s" (print_nterm nt)
@@ -53,10 +53,10 @@ module Run (T: sig end) = struct
Lr1.foldx (fun accu node -> if not (is_final_state node) then f accu node else accu)
let print_nis nis =
- sprintf "Nis_%d" (Lr1.number nis)
+ sprintf "Nis'%d" (Lr1.number nis)
let print_init init =
- sprintf "Init_%d" (Lr1.number init)
+ sprintf "Init'%d" (Lr1.number init)
let print_st st =
match Lr1.incoming_symbol st with
@@ -71,7 +71,7 @@ module Run (T: sig end) = struct
(ProductionMap.empty, SymbolMap.empty)
let print_prod p =
- sprintf "Prod_%s_%d" (Nonterminal.print true (Production.nt p)) (ProductionMap.find p prod_ids)
+ sprintf "Prod'%s'%d" (Nonterminal.print true (Production.nt p)) (ProductionMap.find p prod_ids)
let () =
if not Settings.coq_no_actions then
@@ -383,7 +383,7 @@ module Run (T: sig end) = struct
let first = ref true in
Item.Map.iter (fun item lookaheads ->
let prod, pos = Item.export item in
- if Production.is_start prod then begin
+ if not (Production.is_start prod) then begin
if !first then first := false
else fprintf f ";\n ";
fprintf f "{| prod_item := %s;\n" (print_prod prod);
diff --git a/src/lexer.mll b/src/lexer.mll
index a4a37c8..4795249 100644
--- a/src/lexer.mll
+++ b/src/lexer.mll
@@ -340,11 +340,12 @@ and comment openingpos = parse
{ comment openingpos lexbuf }
(* Collect an O'Caml type delimited by angle brackets. Angle brackets can
- appear as part of O'Caml function types. They might also appear as part
- of O'Caml variant types, but we ignore that possibility for the moment. *)
+ appear as part of O'Caml function types and variant types, so we must
+ recognize them and *not* treat them as a closing bracket. *)
and ocamltype openingpos = parse
| "->"
+| "[>"
{ ocamltype openingpos lexbuf }
| '>'
{ OCAMLTYPE (Stretch.Declared (mk_stretch true openingpos (lexeme_start_p lexbuf) [])) }
diff --git a/src/version.ml b/src/version.ml
index 1d0d14b..608e811 100644
--- a/src/version.ml
+++ b/src/version.ml
@@ -1 +1 @@
-let version = "20130911"
+let version = "20140422"
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/menhir.git
More information about the Pkg-ocaml-maint-commits
mailing list