Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

LICENSING: Add original files from Ocaml 4.00.1

  • Loading branch information...
commit 6b47aaf5fe7c243aae49034139212480c098cbe7 1 parent 9279f0b
@def-lkb def-lkb authored
Showing with 32,239 additions and 0 deletions.
  1. +627 −0 orig/ocaml/LICENSE
  2. +11 −0 orig/ocaml/README.txt
  3. +9 −0 orig/ocaml/parsing/.ignore
  4. +45 −0 orig/ocaml/parsing/asttypes.mli
  5. +43 −0 orig/ocaml/parsing/lexer.mli
  6. +561 −0 orig/ocaml/parsing/lexer.mll
  7. +286 −0 orig/ocaml/parsing/location.ml
  8. +79 −0 orig/ocaml/parsing/location.mli
  9. +43 −0 orig/ocaml/parsing/longident.ml
  10. +24 −0 orig/ocaml/parsing/longident.mli
  11. +65 −0 orig/ocaml/parsing/parse.ml
  12. +20 −0 orig/ocaml/parsing/parse.mli
  13. +1,809 −0 orig/ocaml/parsing/parser.mly
  14. +307 −0 orig/ocaml/parsing/parsetree.mli
  15. +743 −0 orig/ocaml/parsing/printast.ml
  16. +20 −0 orig/ocaml/parsing/printast.mli
  17. +52 −0 orig/ocaml/parsing/syntaxerr.ml
  18. +28 −0 orig/ocaml/parsing/syntaxerr.mli
  19. +23 −0 orig/ocaml/typing/annot.mli
  20. +561 −0 orig/ocaml/typing/btype.ml
  21. +176 −0 orig/ocaml/typing/btype.mli
  22. +93 −0 orig/ocaml/typing/cmi_format.ml
  23. +42 −0 orig/ocaml/typing/cmi_format.mli
  24. +1,010 −0 orig/ocaml/typing/cmt_format.ml
  25. +112 −0 orig/ocaml/typing/cmt_format.mli
  26. +4,126 −0 orig/ocaml/typing/ctype.ml
  27. +262 −0 orig/ocaml/typing/ctype.mli
  28. +141 −0 orig/ocaml/typing/datarepr.ml
  29. +35 −0 orig/ocaml/typing/datarepr.mli
  30. +1,335 −0 orig/ocaml/typing/env.ml
  31. +218 −0 orig/ocaml/typing/env.mli
  32. +184 −0 orig/ocaml/typing/ident.ml
  33. +59 −0 orig/ocaml/typing/ident.mli
  34. +110 −0 orig/ocaml/typing/includeclass.ml
  35. +30 −0 orig/ocaml/typing/includeclass.mli
  36. +297 −0 orig/ocaml/typing/includecore.ml
  37. +50 −0 orig/ocaml/typing/includecore.mli
  38. +471 −0 orig/ocaml/typing/includemod.ml
  39. +52 −0 orig/ocaml/typing/includemod.mli
  40. +221 −0 orig/ocaml/typing/mtype.ml
  41. +39 −0 orig/ocaml/typing/mtype.mli
  42. +490 −0 orig/ocaml/typing/oprint.ml
  43. +26 −0 orig/ocaml/typing/oprint.mli
  44. +106 −0 orig/ocaml/typing/outcometree.mli
  45. +2,093 −0 orig/ocaml/typing/parmatch.ml
  46. +67 −0 orig/ocaml/typing/parmatch.mli
  47. +56 −0 orig/ocaml/typing/path.ml
  48. +32 −0 orig/ocaml/typing/path.mli
  49. +248 −0 orig/ocaml/typing/predef.ml
  50. +66 −0 orig/ocaml/typing/predef.mli
  51. +64 −0 orig/ocaml/typing/primitive.ml
  52. +29 −0 orig/ocaml/typing/primitive.mli
  53. +1,134 −0 orig/ocaml/typing/printtyp.ml
  54. +76 −0 orig/ocaml/typing/printtyp.mli
  55. +761 −0 orig/ocaml/typing/printtyped.ml
  56. +19 −0 orig/ocaml/typing/printtyped.mli
  57. +170 −0 orig/ocaml/typing/stypes.ml
  58. +35 −0 orig/ocaml/typing/stypes.mli
  59. +339 −0 orig/ocaml/typing/subst.ml
  60. +58 −0 orig/ocaml/typing/subst.mli
  61. +1,724 −0 orig/ocaml/typing/typeclass.ml
  62. +111 −0 orig/ocaml/typing/typeclass.mli
  63. +3,213 −0 orig/ocaml/typing/typecore.ml
  64. +125 −0 orig/ocaml/typing/typecore.mli
  65. +1,175 −0 orig/ocaml/typing/typedecl.ml
  66. +83 −0 orig/ocaml/typing/typedecl.mli
  67. +466 −0 orig/ocaml/typing/typedtree.ml
  68. +400 −0 orig/ocaml/typing/typedtree.mli
  69. +1,432 −0 orig/ocaml/typing/typemod.ml
  70. +68 −0 orig/ocaml/typing/typemod.mli
  71. +219 −0 orig/ocaml/typing/types.ml
  72. +216 −0 orig/ocaml/typing/types.mli
  73. +747 −0 orig/ocaml/typing/typetexp.ml
  74. +96 −0 orig/ocaml/typing/typetexp.mli
  75. +1 −0  orig/ocaml/utils/.ignore
  76. +128 −0 orig/ocaml/utils/ccomp.ml
  77. +32 −0 orig/ocaml/utils/ccomp.mli
  78. +100 −0 orig/ocaml/utils/clflags.ml
  79. +83 −0 orig/ocaml/utils/clflags.mli
  80. +136 −0 orig/ocaml/utils/config.mlbuild
  81. +123 −0 orig/ocaml/utils/config.mli
  82. +125 −0 orig/ocaml/utils/config.mlp
  83. +57 −0 orig/ocaml/utils/consistbl.ml
  84. +60 −0 orig/ocaml/utils/consistbl.mli
  85. +226 −0 orig/ocaml/utils/misc.ml
  86. +124 −0 orig/ocaml/utils/misc.mli
  87. +114 −0 orig/ocaml/utils/tbl.ml
  88. +32 −0 orig/ocaml/utils/tbl.mli
  89. +25 −0 orig/ocaml/utils/terminfo.ml
  90. +25 −0 orig/ocaml/utils/terminfo.mli
  91. +410 −0 orig/ocaml/utils/warnings.ml
  92. +75 −0 orig/ocaml/utils/warnings.mli
View
627 orig/ocaml/LICENSE
@@ -0,0 +1,627 @@
+In the following, "the Library" refers to all files marked "Copyright
+INRIA" in the following directories and their sub-directories:
+
+ asmrun, byterun, camlp4, config, otherlibs, stdlib, win32caml
+
+and "the Compiler" refers to all files marked "Copyright INRIA" in the
+following directories and their sub-directories:
+
+ asmcomp, boot, build, bytecomp, debugger, driver, lex, man,
+ ocamlbuild, ocamldoc, parsing, testsuite, tools, toplevel, typing,
+ utils, yacc
+
+The Compiler is distributed under the terms of the Q Public License
+version 1.0 with a change to choice of law (included below).
+
+The Library is distributed under the terms of the GNU Library General
+Public License version 2 (included below).
+
+As a special exception to the Q Public Licence, you may develop
+application programs, reusable components and other software items
+that link with the original or modified versions of the Compiler
+and are not made available to the general public, without any of the
+additional requirements listed in clause 6c of the Q Public licence.
+
+As a special exception to the GNU Library General Public License, you
+may link, statically or dynamically, a "work that uses the Library"
+with a publicly distributed version of the Library to produce an
+executable file containing portions of the Library, and distribute
+that executable file under terms of your choice, without any of the
+additional requirements listed in clause 6 of the GNU Library General
+Public License. By "a publicly distributed version of the Library",
+we mean either the unmodified Library as distributed by INRIA, or a
+modified version of the Library that is distributed under the
+conditions defined in clause 2 of the GNU Library General Public
+License. This exception does not however invalidate any other reasons
+why the executable file might be covered by the GNU Library General
+Public License.
+
+----------------------------------------------------------------------
+
+ THE Q PUBLIC LICENSE version 1.0
+
+ Copyright (C) 1999 Troll Tech AS, Norway.
+ Everyone is permitted to copy and
+ distribute this license document.
+
+The intent of this license is to establish freedom to share and change
+the software regulated by this license under the open source model.
+
+This license applies to any software containing a notice placed by the
+copyright holder saying that it may be distributed under the terms of
+the Q Public License version 1.0. Such software is herein referred to
+as the Software. This license covers modification and distribution of
+the Software, use of third-party application programs based on the
+Software, and development of free software which uses the Software.
+
+ Granted Rights
+
+1. You are granted the non-exclusive rights set forth in this license
+provided you agree to and comply with any and all conditions in this
+license. Whole or partial distribution of the Software, or software
+items that link with the Software, in any form signifies acceptance of
+this license.
+
+2. You may copy and distribute the Software in unmodified form
+provided that the entire package, including - but not restricted to -
+copyright, trademark notices and disclaimers, as released by the
+initial developer of the Software, is distributed.
+
+3. You may make modifications to the Software and distribute your
+modifications, in a form that is separate from the Software, such as
+patches. The following restrictions apply to modifications:
+
+ a. Modifications must not alter or remove any copyright notices
+ in the Software.
+
+ b. When modifications to the Software are released under this
+ license, a non-exclusive royalty-free right is granted to the
+ initial developer of the Software to distribute your
+ modification in future versions of the Software provided such
+ versions remain available under these terms in addition to any
+ other license(s) of the initial developer.
+
+4. You may distribute machine-executable forms of the Software or
+machine-executable forms of modified versions of the Software,
+provided that you meet these restrictions:
+
+ a. You must include this license document in the distribution.
+
+ b. You must ensure that all recipients of the machine-executable
+ forms are also able to receive the complete machine-readable
+ source code to the distributed Software, including all
+ modifications, without any charge beyond the costs of data
+ transfer, and place prominent notices in the distribution
+ explaining this.
+
+ c. You must ensure that all modifications included in the
+ machine-executable forms are available under the terms of this
+ license.
+
+5. You may use the original or modified versions of the Software to
+compile, link and run application programs legally developed by you or
+by others.
+
+6. You may develop application programs, reusable components and other
+software items that link with the original or modified versions of the
+Software. These items, when distributed, are subject to the following
+requirements:
+
+ a. You must ensure that all recipients of machine-executable
+ forms of these items are also able to receive and use the
+ complete machine-readable source code to the items without any
+ charge beyond the costs of data transfer.
+
+ b. You must explicitly license all recipients of your items to
+ use and re-distribute original and modified versions of the
+ items in both machine-executable and source code forms. The
+ recipients must be able to do so without any charges whatsoever,
+ and they must be able to re-distribute to anyone they choose.
+
+ c. If the items are not available to the general public, and the
+ initial developer of the Software requests a copy of the items,
+ then you must supply one.
+
+ Limitations of Liability
+
+In no event shall the initial developers or copyright holders be
+liable for any damages whatsoever, including - but not restricted to -
+lost revenue or profits or other direct, indirect, special, incidental
+or consequential damages, even if they have been advised of the
+possibility of such damages, except to the extent invariable law, if
+any, provides otherwise.
+
+ No Warranty
+
+The Software and this license document are provided AS IS with NO
+WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN,
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+
+ Choice of Law
+
+This license is governed by the Laws of France.
+
+----------------------------------------------------------------------
+
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL. It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it. You can use it for
+your libraries, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library. If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software. To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+ Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs. This
+license, the GNU Library General Public License, applies to certain
+designated libraries. This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+ The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it. Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program. However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+ Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries. We
+concluded that weaker conditions might promote sharing better.
+
+ However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves. This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them. (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.) The hope is that this
+will lead to faster development of free libraries.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+ Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License"). Each licensee is
+addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ c) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ d) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ Appendix: How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
View
11 orig/ocaml/README.txt
@@ -0,0 +1,11 @@
+Merlin uses code from Ocaml, see [http://caml.inria.fr/](The Caml language: Home).
+Files derived from the original Ocaml compiler source includes:
+- the parsing, typing and utils subdirectories
+- chunk_parser.mly, outline_parser.mly, lexer.mll, lexer.mli
+- main_args.ml, main_args.mli
+
+There you can find the original distribution:
+ http://caml.inria.fr/pub/distrib/ocaml-4.00/ocaml-4.00.1.tar.gz
+
+The Ocaml compiler is distributed under the QPL licence and is copyright INRIA.
+See LICENSE in the current directory.
View
9 orig/ocaml/parsing/.ignore
@@ -0,0 +1,9 @@
+parser.ml
+parser.mli
+lexer.ml
+lexer_tmp.mll
+lexer_tmp.ml
+linenum.ml
+parser.output
+parser.automaton
+parser.conflicts
View
45 orig/ocaml/parsing/asttypes.mli
@@ -0,0 +1,45 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: asttypes.mli 12511 2012-05-30 13:29:48Z lefessan $ *)
+
+(* Auxiliary a.s.t. types used by parsetree and typedtree. *)
+
+type constant =
+ Const_int of int
+ | Const_char of char
+ | Const_string of string
+ | Const_float of string
+ | Const_int32 of int32
+ | Const_int64 of int64
+ | Const_nativeint of nativeint
+
+type rec_flag = Nonrecursive | Recursive | Default
+
+type direction_flag = Upto | Downto
+
+type private_flag = Private | Public
+
+type mutable_flag = Immutable | Mutable
+
+type virtual_flag = Virtual | Concrete
+
+type override_flag = Override | Fresh
+
+type closed_flag = Closed | Open
+
+type label = string
+
+type 'a loc = 'a Location.loc = {
+ txt : 'a;
+ loc : Location.t;
+}
View
43 orig/ocaml/parsing/lexer.mli
@@ -0,0 +1,43 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: lexer.mli 12511 2012-05-30 13:29:48Z lefessan $ *)
+
+(* The lexical analyzer *)
+
+val init : unit -> unit
+val token: Lexing.lexbuf -> Parser.token
+val skip_sharp_bang: Lexing.lexbuf -> unit
+
+type error =
+ | Illegal_character of char
+ | Illegal_escape of string
+ | Unterminated_comment of Location.t
+ | Unterminated_string
+ | Unterminated_string_in_comment of Location.t
+ | Keyword_as_label of string
+ | Literal_overflow of string
+;;
+
+exception Error of error * Location.t
+
+open Format
+
+val report_error: formatter -> error -> unit
+
+val in_comment : unit -> bool;;
+val in_string : unit -> bool;;
+
+
+val print_warnings : bool ref
+val comments : unit -> (string * Location.t) list
+val token_with_comments : Lexing.lexbuf -> Parser.token
View
561 orig/ocaml/parsing/lexer.mll
@@ -0,0 +1,561 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: lexer.mll 12511 2012-05-30 13:29:48Z lefessan $ *)
+
+(* The lexer definition *)
+
+{
+open Lexing
+open Misc
+open Parser
+
+type error =
+ | Illegal_character of char
+ | Illegal_escape of string
+ | Unterminated_comment of Location.t
+ | Unterminated_string
+ | Unterminated_string_in_comment of Location.t
+ | Keyword_as_label of string
+ | Literal_overflow of string
+;;
+
+exception Error of error * Location.t;;
+
+(* The table of keywords *)
+
+let keyword_table =
+ create_hashtable 149 [
+ "and", AND;
+ "as", AS;
+ "assert", ASSERT;
+ "begin", BEGIN;
+ "class", CLASS;
+ "constraint", CONSTRAINT;
+ "do", DO;
+ "done", DONE;
+ "downto", DOWNTO;
+ "else", ELSE;
+ "end", END;
+ "exception", EXCEPTION;
+ "external", EXTERNAL;
+ "false", FALSE;
+ "for", FOR;
+ "fun", FUN;
+ "function", FUNCTION;
+ "functor", FUNCTOR;
+ "if", IF;
+ "in", IN;
+ "include", INCLUDE;
+ "inherit", INHERIT;
+ "initializer", INITIALIZER;
+ "lazy", LAZY;
+ "let", LET;
+ "match", MATCH;
+ "method", METHOD;
+ "module", MODULE;
+ "mutable", MUTABLE;
+ "new", NEW;
+ "object", OBJECT;
+ "of", OF;
+ "open", OPEN;
+ "or", OR;
+(* "parser", PARSER; *)
+ "private", PRIVATE;
+ "rec", REC;
+ "sig", SIG;
+ "struct", STRUCT;
+ "then", THEN;
+ "to", TO;
+ "true", TRUE;
+ "try", TRY;
+ "type", TYPE;
+ "val", VAL;
+ "virtual", VIRTUAL;
+ "when", WHEN;
+ "while", WHILE;
+ "with", WITH;
+
+ "mod", INFIXOP3("mod");
+ "land", INFIXOP3("land");
+ "lor", INFIXOP3("lor");
+ "lxor", INFIXOP3("lxor");
+ "lsl", INFIXOP4("lsl");
+ "lsr", INFIXOP4("lsr");
+ "asr", INFIXOP4("asr")
+]
+
+(* To buffer string literals *)
+
+let initial_string_buffer = String.create 256
+let string_buff = ref initial_string_buffer
+let string_index = ref 0
+
+let reset_string_buffer () =
+ string_buff := initial_string_buffer;
+ string_index := 0
+
+let store_string_char c =
+ if !string_index >= String.length (!string_buff) then begin
+ let new_buff = String.create (String.length (!string_buff) * 2) in
+ String.blit (!string_buff) 0 new_buff 0 (String.length (!string_buff));
+ string_buff := new_buff
+ end;
+ String.unsafe_set (!string_buff) (!string_index) c;
+ incr string_index
+
+let store_lexeme lexbuf =
+ let s = Lexing.lexeme lexbuf in
+ for i = 0 to String.length s - 1 do
+ store_string_char s.[i];
+ done
+
+let get_stored_string () =
+ let s = String.sub (!string_buff) 0 (!string_index) in
+ string_buff := initial_string_buffer;
+ s
+
+(* To store the position of the beginning of a string and comment *)
+let string_start_loc = ref Location.none;;
+let comment_start_loc = ref [];;
+let in_comment () = !comment_start_loc <> [];;
+let is_in_string = ref false
+let in_string () = !is_in_string
+let print_warnings = ref true
+
+(* To translate escape sequences *)
+
+let char_for_backslash = function
+ | 'n' -> '\010'
+ | 'r' -> '\013'
+ | 'b' -> '\008'
+ | 't' -> '\009'
+ | c -> c
+
+let char_for_decimal_code lexbuf i =
+ let c = 100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) +
+ 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) +
+ (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48) in
+ if (c < 0 || c > 255) then
+ if in_comment ()
+ then 'x'
+ else raise (Error(Illegal_escape (Lexing.lexeme lexbuf),
+ Location.curr lexbuf))
+ else Char.chr c
+
+let char_for_hexadecimal_code lexbuf i =
+ let d1 = Char.code (Lexing.lexeme_char lexbuf i) in
+ let val1 = if d1 >= 97 then d1 - 87
+ else if d1 >= 65 then d1 - 55
+ else d1 - 48
+ in
+ let d2 = Char.code (Lexing.lexeme_char lexbuf (i+1)) in
+ let val2 = if d2 >= 97 then d2 - 87
+ else if d2 >= 65 then d2 - 55
+ else d2 - 48
+ in
+ Char.chr (val1 * 16 + val2)
+
+(* To convert integer literals, allowing max_int + 1 (PR#4210) *)
+
+let cvt_int_literal s =
+ - int_of_string ("-" ^ s)
+let cvt_int32_literal s =
+ Int32.neg (Int32.of_string ("-" ^ String.sub s 0 (String.length s - 1)))
+let cvt_int64_literal s =
+ Int64.neg (Int64.of_string ("-" ^ String.sub s 0 (String.length s - 1)))
+let cvt_nativeint_literal s =
+ Nativeint.neg (Nativeint.of_string ("-" ^ String.sub s 0 (String.length s - 1)))
+
+(* Remove underscores from float literals *)
+
+let remove_underscores s =
+ let l = String.length s in
+ let rec remove src dst =
+ if src >= l then
+ if dst >= l then s else String.sub s 0 dst
+ else
+ match s.[src] with
+ '_' -> remove (src + 1) dst
+ | c -> s.[dst] <- c; remove (src + 1) (dst + 1)
+ in remove 0 0
+
+(* Update the current location with file name and line number. *)
+
+let update_loc lexbuf file line absolute chars =
+ let pos = lexbuf.lex_curr_p in
+ let new_file = match file with
+ | None -> pos.pos_fname
+ | Some s -> s
+ in
+ lexbuf.lex_curr_p <- { pos with
+ pos_fname = new_file;
+ pos_lnum = if absolute then line else pos.pos_lnum + line;
+ pos_bol = pos.pos_cnum - chars;
+ }
+;;
+
+(* Error report *)
+
+open Format
+
+let report_error ppf = function
+ | Illegal_character c ->
+ fprintf ppf "Illegal character (%s)" (Char.escaped c)
+ | Illegal_escape s ->
+ fprintf ppf "Illegal backslash escape in string or character (%s)" s
+ | Unterminated_comment _ ->
+ fprintf ppf "Comment not terminated"
+ | Unterminated_string ->
+ fprintf ppf "String literal not terminated"
+ | Unterminated_string_in_comment _ ->
+ fprintf ppf "This comment contains an unterminated string literal"
+ | Keyword_as_label kwd ->
+ fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd
+ | Literal_overflow ty ->
+ fprintf ppf "Integer literal exceeds the range of representable integers of type %s" ty
+;;
+
+}
+
+let newline = ('\010' | '\013' | "\013\010")
+let blank = [' ' '\009' '\012']
+let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_']
+let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222']
+let identchar =
+ ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9']
+let symbolchar =
+ ['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~']
+let decimal_literal =
+ ['0'-'9'] ['0'-'9' '_']*
+let hex_literal =
+ '0' ['x' 'X'] ['0'-'9' 'A'-'F' 'a'-'f']['0'-'9' 'A'-'F' 'a'-'f' '_']*
+let oct_literal =
+ '0' ['o' 'O'] ['0'-'7'] ['0'-'7' '_']*
+let bin_literal =
+ '0' ['b' 'B'] ['0'-'1'] ['0'-'1' '_']*
+let int_literal =
+ decimal_literal | hex_literal | oct_literal | bin_literal
+let float_literal =
+ ['0'-'9'] ['0'-'9' '_']*
+ ('.' ['0'-'9' '_']* )?
+ (['e' 'E'] ['+' '-']? ['0'-'9'] ['0'-'9' '_']*)?
+
+rule token = parse
+ | newline
+ { update_loc lexbuf None 1 false 0;
+ token lexbuf
+ }
+ | blank +
+ { token lexbuf }
+ | "_"
+ { UNDERSCORE }
+ | "~"
+ { TILDE }
+ | "~" lowercase identchar * ':'
+ { let s = Lexing.lexeme lexbuf in
+ let name = String.sub s 1 (String.length s - 2) in
+ if Hashtbl.mem keyword_table name then
+ raise (Error(Keyword_as_label name, Location.curr lexbuf));
+ LABEL name }
+ | "?" { QUESTION }
+ | "??" { QUESTIONQUESTION }
+ | "?" lowercase identchar * ':'
+ { let s = Lexing.lexeme lexbuf in
+ let name = String.sub s 1 (String.length s - 2) in
+ if Hashtbl.mem keyword_table name then
+ raise (Error(Keyword_as_label name, Location.curr lexbuf));
+ OPTLABEL name }
+ | lowercase identchar *
+ { let s = Lexing.lexeme lexbuf in
+ try
+ Hashtbl.find keyword_table s
+ with Not_found ->
+ LIDENT s }
+ | uppercase identchar *
+ { UIDENT(Lexing.lexeme lexbuf) } (* No capitalized keywords *)
+ | int_literal
+ { try
+ INT (cvt_int_literal (Lexing.lexeme lexbuf))
+ with Failure _ ->
+ raise (Error(Literal_overflow "int", Location.curr lexbuf))
+ }
+ | float_literal
+ { FLOAT (remove_underscores(Lexing.lexeme lexbuf)) }
+ | int_literal "l"
+ { try
+ INT32 (cvt_int32_literal (Lexing.lexeme lexbuf))
+ with Failure _ ->
+ raise (Error(Literal_overflow "int32", Location.curr lexbuf)) }
+ | int_literal "L"
+ { try
+ INT64 (cvt_int64_literal (Lexing.lexeme lexbuf))
+ with Failure _ ->
+ raise (Error(Literal_overflow "int64", Location.curr lexbuf)) }
+ | int_literal "n"
+ { try
+ NATIVEINT (cvt_nativeint_literal (Lexing.lexeme lexbuf))
+ with Failure _ ->
+ raise (Error(Literal_overflow "nativeint", Location.curr lexbuf)) }
+ | "\""
+ { reset_string_buffer();
+ is_in_string := true;
+ let string_start = lexbuf.lex_start_p in
+ string_start_loc := Location.curr lexbuf;
+ string lexbuf;
+ is_in_string := false;
+ lexbuf.lex_start_p <- string_start;
+ STRING (get_stored_string()) }
+ | "'" newline "'"
+ { update_loc lexbuf None 1 false 1;
+ CHAR (Lexing.lexeme_char lexbuf 1) }
+ | "'" [^ '\\' '\'' '\010' '\013'] "'"
+ { CHAR(Lexing.lexeme_char lexbuf 1) }
+ | "'\\" ['\\' '\'' '"' 'n' 't' 'b' 'r' ' '] "'"
+ { CHAR(char_for_backslash (Lexing.lexeme_char lexbuf 2)) }
+ | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
+ { CHAR(char_for_decimal_code lexbuf 2) }
+ | "'\\" 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F'] "'"
+ { CHAR(char_for_hexadecimal_code lexbuf 3) }
+ | "'\\" _
+ { let l = Lexing.lexeme lexbuf in
+ let esc = String.sub l 1 (String.length l - 1) in
+ raise (Error(Illegal_escape esc, Location.curr lexbuf))
+ }
+ | "(*"
+ { let start_loc = Location.curr lexbuf in
+ comment_start_loc := [start_loc];
+ reset_string_buffer ();
+ let end_loc = comment lexbuf in
+ let s = get_stored_string () in
+ reset_string_buffer ();
+ COMMENT (s, { start_loc with Location.loc_end = end_loc.Location.loc_end })
+ }
+ | "(*)"
+ { let loc = Location.curr lexbuf in
+ if !print_warnings then
+ Location.prerr_warning loc Warnings.Comment_start;
+ comment_start_loc := [loc];
+ reset_string_buffer ();
+ let end_loc = comment lexbuf in
+ let s = get_stored_string () in
+ reset_string_buffer ();
+ COMMENT (s, { loc with Location.loc_end = end_loc.Location.loc_end })
+ }
+ | "*)"
+ { let loc = Location.curr lexbuf in
+ Location.prerr_warning loc Warnings.Comment_not_end;
+ lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1;
+ let curpos = lexbuf.lex_curr_p in
+ lexbuf.lex_curr_p <- { curpos with pos_cnum = curpos.pos_cnum - 1 };
+ STAR
+ }
+ | "#" [' ' '\t']* (['0'-'9']+ as num) [' ' '\t']*
+ ("\"" ([^ '\010' '\013' '"' ] * as name) "\"")?
+ [^ '\010' '\013'] * newline
+ { update_loc lexbuf name (int_of_string num) true 0;
+ token lexbuf
+ }
+ | "#" { SHARP }
+ | "&" { AMPERSAND }
+ | "&&" { AMPERAMPER }
+ | "`" { BACKQUOTE }
+ | "'" { QUOTE }
+ | "(" { LPAREN }
+ | ")" { RPAREN }
+ | "*" { STAR }
+ | "," { COMMA }
+ | "->" { MINUSGREATER }
+ | "." { DOT }
+ | ".." { DOTDOT }
+ | ":" { COLON }
+ | "::" { COLONCOLON }
+ | ":=" { COLONEQUAL }
+ | ":>" { COLONGREATER }
+ | ";" { SEMI }
+ | ";;" { SEMISEMI }
+ | "<" { LESS }
+ | "<-" { LESSMINUS }
+ | "=" { EQUAL }
+ | "[" { LBRACKET }
+ | "[|" { LBRACKETBAR }
+ | "[<" { LBRACKETLESS }
+ | "[>" { LBRACKETGREATER }
+ | "]" { RBRACKET }
+ | "{" { LBRACE }
+ | "{<" { LBRACELESS }
+ | "|" { BAR }
+ | "||" { BARBAR }
+ | "|]" { BARRBRACKET }
+ | ">" { GREATER }
+ | ">]" { GREATERRBRACKET }
+ | "}" { RBRACE }
+ | ">}" { GREATERRBRACE }
+ | "!" { BANG }
+
+ | "!=" { INFIXOP0 "!=" }
+ | "+" { PLUS }
+ | "+." { PLUSDOT }
+ | "-" { MINUS }
+ | "-." { MINUSDOT }
+
+ | "!" symbolchar +
+ { PREFIXOP(Lexing.lexeme lexbuf) }
+ | ['~' '?'] symbolchar +
+ { PREFIXOP(Lexing.lexeme lexbuf) }
+ | ['=' '<' '>' '|' '&' '$'] symbolchar *
+ { INFIXOP0(Lexing.lexeme lexbuf) }
+ | ['@' '^'] symbolchar *
+ { INFIXOP1(Lexing.lexeme lexbuf) }
+ | ['+' '-'] symbolchar *
+ { INFIXOP2(Lexing.lexeme lexbuf) }
+ | "**" symbolchar *
+ { INFIXOP4(Lexing.lexeme lexbuf) }
+ | ['*' '/' '%'] symbolchar *
+ { INFIXOP3(Lexing.lexeme lexbuf) }
+ | eof { EOF }
+ | _
+ { raise (Error(Illegal_character (Lexing.lexeme_char lexbuf 0),
+ Location.curr lexbuf))
+ }
+
+and comment = parse
+ "(*"
+ { comment_start_loc := (Location.curr lexbuf) :: !comment_start_loc;
+ store_lexeme lexbuf;
+ comment lexbuf;
+ }
+ | "*)"
+ { match !comment_start_loc with
+ | [] -> assert false
+ | [_] -> comment_start_loc := []; Location.curr lexbuf
+ | _ :: l -> comment_start_loc := l;
+ store_lexeme lexbuf;
+ comment lexbuf;
+ }
+ | "\""
+ {
+ string_start_loc := Location.curr lexbuf;
+ store_string_char '"';
+ is_in_string := true;
+ begin try string lexbuf
+ with Error (Unterminated_string, _) ->
+ match !comment_start_loc with
+ | [] -> assert false
+ | loc :: _ ->
+ let start = List.hd (List.rev !comment_start_loc) in
+ comment_start_loc := [];
+ raise (Error (Unterminated_string_in_comment start, loc))
+ end;
+ is_in_string := false;
+ store_string_char '"';
+ comment lexbuf }
+ | "''"
+ { store_lexeme lexbuf; comment lexbuf }
+ | "'" newline "'"
+ { update_loc lexbuf None 1 false 1;
+ store_lexeme lexbuf;
+ comment lexbuf
+ }
+ | "'" [^ '\\' '\'' '\010' '\013' ] "'"
+ { store_lexeme lexbuf; comment lexbuf }
+ | "'\\" ['\\' '"' '\'' 'n' 't' 'b' 'r' ' '] "'"
+ { store_lexeme lexbuf; comment lexbuf }
+ | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
+ { store_lexeme lexbuf; comment lexbuf }
+ | "'\\" 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F'] "'"
+ { store_lexeme lexbuf; comment lexbuf }
+ | eof
+ { match !comment_start_loc with
+ | [] -> assert false
+ | loc :: _ ->
+ let start = List.hd (List.rev !comment_start_loc) in
+ comment_start_loc := [];
+ raise (Error (Unterminated_comment start, loc))
+ }
+ | newline
+ { update_loc lexbuf None 1 false 0;
+ store_lexeme lexbuf;
+ comment lexbuf
+ }
+ | _
+ { store_lexeme lexbuf; comment lexbuf }
+
+and string = parse
+ '"'
+ { () }
+ | '\\' newline ([' ' '\t'] * as space)
+ { update_loc lexbuf None 1 false (String.length space);
+ string lexbuf
+ }
+ | '\\' ['\\' '\'' '"' 'n' 't' 'b' 'r' ' ']
+ { store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1));
+ string lexbuf }
+ | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9']
+ { store_string_char(char_for_decimal_code lexbuf 1);
+ string lexbuf }
+ | '\\' 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F']
+ { store_string_char(char_for_hexadecimal_code lexbuf 2);
+ string lexbuf }
+ | '\\' _
+ { if in_comment ()
+ then string lexbuf
+ else begin
+(* Should be an error, but we are very lax.
+ raise (Error (Illegal_escape (Lexing.lexeme lexbuf),
+ Location.curr lexbuf))
+*)
+ let loc = Location.curr lexbuf in
+ Location.prerr_warning loc Warnings.Illegal_backslash;
+ store_string_char (Lexing.lexeme_char lexbuf 0);
+ store_string_char (Lexing.lexeme_char lexbuf 1);
+ string lexbuf
+ end
+ }
+ | newline
+ { if not (in_comment ()) then
+ Location.prerr_warning (Location.curr lexbuf) Warnings.Eol_in_string;
+ update_loc lexbuf None 1 false 0;
+ store_lexeme lexbuf;
+ string lexbuf
+ }
+ | eof
+ { is_in_string := false;
+ raise (Error (Unterminated_string, !string_start_loc)) }
+ | _
+ { store_string_char(Lexing.lexeme_char lexbuf 0);
+ string lexbuf }
+
+and skip_sharp_bang = parse
+ | "#!" [^ '\n']* '\n' [^ '\n']* "\n!#\n"
+ { update_loc lexbuf None 3 false 0 }
+ | "#!" [^ '\n']* '\n'
+ { update_loc lexbuf None 1 false 0 }
+ | "" { () }
+
+{
+ let token_with_comments = token
+
+ let last_comments = ref []
+ let rec token lexbuf =
+ match token_with_comments lexbuf with
+ COMMENT (s, comment_loc) ->
+ last_comments := (s, comment_loc) :: !last_comments;
+ token lexbuf
+ | tok -> tok
+ let comments () = List.rev !last_comments
+ let init () =
+ is_in_string := false;
+ last_comments := [];
+ comment_start_loc := []
+
+}
View
286 orig/ocaml/parsing/location.ml
@@ -0,0 +1,286 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: location.ml 12511 2012-05-30 13:29:48Z lefessan $ *)
+
+open Lexing
+
+let absname = ref false
+ (* This reference should be in Clflags, but it would create an additional
+ dependency and make bootstrapping Camlp4 more difficult. *)
+
+type t = { loc_start: position; loc_end: position; loc_ghost: bool };;
+
+let in_file name =
+ let loc = {
+ pos_fname = name;
+ pos_lnum = 1;
+ pos_bol = 0;
+ pos_cnum = -1;
+ } in
+ { loc_start = loc; loc_end = loc; loc_ghost = true }
+;;
+
+let none = in_file "_none_";;
+
+let curr lexbuf = {
+ loc_start = lexbuf.lex_start_p;
+ loc_end = lexbuf.lex_curr_p;
+ loc_ghost = false
+};;
+
+let init lexbuf fname =
+ lexbuf.lex_curr_p <- {
+ pos_fname = fname;
+ pos_lnum = 1;
+ pos_bol = 0;
+ pos_cnum = 0;
+ }
+;;
+
+let symbol_rloc () = {
+ loc_start = Parsing.symbol_start_pos ();
+ loc_end = Parsing.symbol_end_pos ();
+ loc_ghost = false;
+};;
+
+let symbol_gloc () = {
+ loc_start = Parsing.symbol_start_pos ();
+ loc_end = Parsing.symbol_end_pos ();
+ loc_ghost = true;
+};;
+
+let rhs_loc n = {
+ loc_start = Parsing.rhs_start_pos n;
+ loc_end = Parsing.rhs_end_pos n;
+ loc_ghost = false;
+};;
+
+let input_name = ref "_none_"
+let input_lexbuf = ref (None : lexbuf option)
+
+(* Terminal info *)
+
+let status = ref Terminfo.Uninitialised
+
+let num_loc_lines = ref 0 (* number of lines already printed after input *)
+
+(* Highlight the locations using standout mode. *)
+
+let highlight_terminfo ppf num_lines lb loc1 loc2 =
+ Format.pp_print_flush ppf (); (* avoid mixing Format and normal output *)
+ (* Char 0 is at offset -lb.lex_abs_pos in lb.lex_buffer. *)
+ let pos0 = -lb.lex_abs_pos in
+ (* Do nothing if the buffer does not contain the whole phrase. *)
+ if pos0 < 0 then raise Exit;
+ (* Count number of lines in phrase *)
+ let lines = ref !num_loc_lines in
+ for i = pos0 to lb.lex_buffer_len - 1 do
+ if lb.lex_buffer.[i] = '\n' then incr lines
+ done;
+ (* If too many lines, give up *)
+ if !lines >= num_lines - 2 then raise Exit;
+ (* Move cursor up that number of lines *)
+ flush stdout; Terminfo.backup !lines;
+ (* Print the input, switching to standout for the location *)
+ let bol = ref false in
+ print_string "# ";
+ for pos = 0 to lb.lex_buffer_len - pos0 - 1 do
+ if !bol then (print_string " "; bol := false);
+ if pos = loc1.loc_start.pos_cnum || pos = loc2.loc_start.pos_cnum then
+ Terminfo.standout true;
+ if pos = loc1.loc_end.pos_cnum || pos = loc2.loc_end.pos_cnum then
+ Terminfo.standout false;
+ let c = lb.lex_buffer.[pos + pos0] in
+ print_char c;
+ bol := (c = '\n')
+ done;
+ (* Make sure standout mode is over *)
+ Terminfo.standout false;
+ (* Position cursor back to original location *)
+ Terminfo.resume !num_loc_lines;
+ flush stdout
+
+(* Highlight the location by printing it again. *)
+
+let highlight_dumb ppf lb loc =
+ (* Char 0 is at offset -lb.lex_abs_pos in lb.lex_buffer. *)
+ let pos0 = -lb.lex_abs_pos in
+ (* Do nothing if the buffer does not contain the whole phrase. *)
+ if pos0 < 0 then raise Exit;
+ let end_pos = lb.lex_buffer_len - pos0 - 1 in
+ (* Determine line numbers for the start and end points *)
+ let line_start = ref 0 and line_end = ref 0 in
+ for pos = 0 to end_pos do
+ if lb.lex_buffer.[pos + pos0] = '\n' then begin
+ if loc.loc_start.pos_cnum > pos then incr line_start;
+ if loc.loc_end.pos_cnum > pos then incr line_end;
+ end
+ done;
+ (* Print character location (useful for Emacs) *)
+ Format.fprintf ppf "Characters %i-%i:@."
+ loc.loc_start.pos_cnum loc.loc_end.pos_cnum;
+ (* Print the input, underlining the location *)
+ Format.pp_print_string ppf " ";
+ let line = ref 0 in
+ let pos_at_bol = ref 0 in
+ for pos = 0 to end_pos do
+ let c = lb.lex_buffer.[pos + pos0] in
+ if c <> '\n' then begin
+ if !line = !line_start && !line = !line_end then
+ (* loc is on one line: print whole line *)
+ Format.pp_print_char ppf c
+ else if !line = !line_start then
+ (* first line of multiline loc: print ... before loc_start *)
+ if pos < loc.loc_start.pos_cnum
+ then Format.pp_print_char ppf '.'
+ else Format.pp_print_char ppf c
+ else if !line = !line_end then
+ (* last line of multiline loc: print ... after loc_end *)
+ if pos < loc.loc_end.pos_cnum
+ then Format.pp_print_char ppf c
+ else Format.pp_print_char ppf '.'
+ else if !line > !line_start && !line < !line_end then
+ (* intermediate line of multiline loc: print whole line *)
+ Format.pp_print_char ppf c
+ end else begin
+ if !line = !line_start && !line = !line_end then begin
+ (* loc is on one line: underline location *)
+ Format.fprintf ppf "@. ";
+ for i = !pos_at_bol to loc.loc_start.pos_cnum - 1 do
+ Format.pp_print_char ppf ' '
+ done;
+ for i = loc.loc_start.pos_cnum to loc.loc_end.pos_cnum - 1 do
+ Format.pp_print_char ppf '^'
+ done
+ end;
+ if !line >= !line_start && !line <= !line_end then begin
+ Format.fprintf ppf "@.";
+ if pos < loc.loc_end.pos_cnum then Format.pp_print_string ppf " "
+ end;
+ incr line;
+ pos_at_bol := pos + 1;
+ end
+ done
+
+(* Highlight the location using one of the supported modes. *)
+
+let rec highlight_locations ppf loc1 loc2 =
+ match !status with
+ Terminfo.Uninitialised ->
+ status := Terminfo.setup stdout; highlight_locations ppf loc1 loc2
+ | Terminfo.Bad_term ->
+ begin match !input_lexbuf with
+ None -> false
+ | Some lb ->
+ let norepeat =
+ try Sys.getenv "TERM" = "norepeat" with Not_found -> false in
+ if norepeat then false else
+ try highlight_dumb ppf lb loc1; true
+ with Exit -> false
+ end
+ | Terminfo.Good_term num_lines ->
+ begin match !input_lexbuf with
+ None -> false
+ | Some lb ->
+ try highlight_terminfo ppf num_lines lb loc1 loc2; true
+ with Exit -> false
+ end
+
+(* Print the location in some way or another *)
+
+open Format
+
+let absolute_path s = (* This function could go into Filename *)
+ let open Filename in
+ let s = if is_relative s then concat (Sys.getcwd ()) s else s in
+ (* Now simplify . and .. components *)
+ let rec aux s =
+ let base = basename s in
+ let dir = dirname s in
+ if dir = s then dir
+ else if base = current_dir_name then aux dir
+ else if base = parent_dir_name then dirname (aux dir)
+ else concat (aux dir) base
+ in
+ aux s
+
+let show_filename file =
+ if !absname then absolute_path file else file
+
+let print_filename ppf file =
+ Format.fprintf ppf "%s" (show_filename file)
+
+let reset () =
+ num_loc_lines := 0
+
+let (msg_file, msg_line, msg_chars, msg_to, msg_colon) =
+ ("File \"", "\", line ", ", characters ", "-", ":")
+
+(* return file, line, char from the given position *)
+let get_pos_info pos =
+ (pos.pos_fname, pos.pos_lnum, pos.pos_cnum - pos.pos_bol)
+;;
+
+let print_loc ppf loc =
+ let (file, line, startchar) = get_pos_info loc.loc_start in
+ let endchar = loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + startchar in
+ if file = "//toplevel//" then begin
+ if highlight_locations ppf loc none then () else
+ fprintf ppf "Characters %i-%i"
+ loc.loc_start.pos_cnum loc.loc_end.pos_cnum
+ end else begin
+ fprintf ppf "%s%a%s%i" msg_file print_filename file msg_line line;
+ if startchar >= 0 then
+ fprintf ppf "%s%i%s%i" msg_chars startchar msg_to endchar
+ end
+;;
+
+let print ppf loc =
+ if loc.loc_start.pos_fname = "//toplevel//"
+ && highlight_locations ppf loc none then ()
+ else fprintf ppf "%a%s@." print_loc loc msg_colon
+;;
+
+let print_error ppf loc =
+ print ppf loc;
+ fprintf ppf "Error: ";
+;;
+
+let print_error_cur_file ppf = print_error ppf (in_file !input_name);;
+
+let print_warning loc ppf w =
+ if Warnings.is_active w then begin
+ let printw ppf w =
+ let n = Warnings.print ppf w in
+ num_loc_lines := !num_loc_lines + n
+ in
+ print ppf loc;
+ fprintf ppf "Warning %a@." printw w;
+ pp_print_flush ppf ();
+ incr num_loc_lines;
+ end
+;;
+
+let prerr_warning loc w = print_warning loc err_formatter w;;
+
+let echo_eof () =
+ print_newline ();
+ incr num_loc_lines
+
+type 'a loc = {
+ txt : 'a;
+ loc : t;
+}
+
+let mkloc txt loc = { txt ; loc }
+let mknoloc txt = mkloc txt none
View
79 orig/ocaml/parsing/location.mli
@@ -0,0 +1,79 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: location.mli 12800 2012-07-30 18:59:07Z doligez $ *)
+
+(* Source code locations (ranges of positions), used in parsetree. *)
+
+open Format
+
+type t = {
+ loc_start: Lexing.position;
+ loc_end: Lexing.position;
+ loc_ghost: bool;
+}
+
+(* Note on the use of Lexing.position in this module.
+ If [pos_fname = ""], then use [!input_name] instead.
+ If [pos_lnum = -1], then [pos_bol = 0]. Use [pos_cnum] and
+ re-parse the file to get the line and character numbers.
+ Else all fields are correct.
+*)
+
+val none : t
+(** An arbitrary value of type [t]; describes an empty ghost range. *)
+val in_file : string -> t;;
+(** Return an empty ghost range located in a given file. *)
+val init : Lexing.lexbuf -> string -> unit
+(** Set the file name and line number of the [lexbuf] to be the start
+ of the named file. *)
+val curr : Lexing.lexbuf -> t
+(** Get the location of the current token from the [lexbuf]. *)
+
+val symbol_rloc: unit -> t
+val symbol_gloc: unit -> t
+
+(** [rhs_loc n] returns the location of the symbol at position [n], starting
+ at 1, in the current parser rule. *)
+val rhs_loc: int -> t
+
+val input_name: string ref
+val input_lexbuf: Lexing.lexbuf option ref
+
+val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)
+val print_loc: formatter -> t -> unit
+val print_error: formatter -> t -> unit
+val print_error_cur_file: formatter -> unit
+val print_warning: t -> formatter -> Warnings.t -> unit
+val prerr_warning: t -> Warnings.t -> unit
+val echo_eof: unit -> unit
+val reset: unit -> unit
+
+val highlight_locations: formatter -> t -> t -> bool
+
+type 'a loc = {
+ txt : 'a;
+ loc : t;
+}
+
+val mknoloc : 'a -> 'a loc
+val mkloc : 'a -> t -> 'a loc
+
+val print: formatter -> t -> unit
+val print_filename: formatter -> string -> unit
+
+val show_filename: string -> string
+ (** In -absname mode, return the absolute path for this filename.
+ Otherwise, returns the filename unchanged. *)
+
+
+val absname: bool ref
View
43 orig/ocaml/parsing/longident.ml
@@ -0,0 +1,43 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: longident.ml 11252 2011-10-28 21:21:55Z weis $ *)
+
+type t =
+ Lident of string
+ | Ldot of t * string
+ | Lapply of t * t
+
+let rec flat accu = function
+ Lident s -> s :: accu
+ | Ldot(lid, s) -> flat (s :: accu) lid
+ | Lapply(_, _) -> Misc.fatal_error "Longident.flat"
+
+let flatten lid = flat [] lid
+
+let last = function
+ Lident s -> s
+ | Ldot(_, s) -> s
+ | Lapply(_, _) -> Misc.fatal_error "Longident.last"
+
+let rec split_at_dots s pos =
+ try
+ let dot = String.index_from s pos '.' in
+ String.sub s pos (dot - pos) :: split_at_dots s (dot + 1)
+ with Not_found ->
+ [String.sub s pos (String.length s - pos)]
+
+let parse s =
+ match split_at_dots s 0 with
+ [] -> Lident "" (* should not happen, but don't put assert false
+ so as not to crash the toplevel (see Genprintval) *)
+ | hd :: tl -> List.fold_left (fun p s -> Ldot(p, s)) (Lident hd) tl
View
24 orig/ocaml/parsing/longident.mli
@@ -0,0 +1,24 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: longident.mli 11156 2011-07-27 14:17:02Z doligez $ *)
+
+(* Long identifiers, used in parsetree. *)
+
+type t =
+ Lident of string
+ | Ldot of t * string
+ | Lapply of t * t
+
+val flatten: t -> string list
+val last: t -> string
+val parse: string -> t
View
65 orig/ocaml/parsing/parse.ml
@@ -0,0 +1,65 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: parse.ml 12511 2012-05-30 13:29:48Z lefessan $ *)
+
+(* Entry points in the parser *)
+
+open Location
+
+(* Skip tokens to the end of the phrase *)
+
+let rec skip_phrase lexbuf =
+ try
+ match Lexer.token lexbuf with
+ Parser.SEMISEMI | Parser.EOF -> ()
+ | _ -> skip_phrase lexbuf
+ with
+ | Lexer.Error (Lexer.Unterminated_comment _, _) -> ()
+ | Lexer.Error (Lexer.Unterminated_string, _) -> ()
+ | Lexer.Error (Lexer.Unterminated_string_in_comment _, _) -> ()
+ | Lexer.Error (Lexer.Illegal_character _, _) -> skip_phrase lexbuf
+;;
+
+let maybe_skip_phrase lexbuf =
+ if Parsing.is_current_lookahead Parser.SEMISEMI
+ || Parsing.is_current_lookahead Parser.EOF
+ then ()
+ else skip_phrase lexbuf
+
+let wrap parsing_fun lexbuf =
+ try
+ Lexer.init ();
+ let ast = parsing_fun Lexer.token lexbuf in
+ Parsing.clear_parser();
+ ast
+ with
+ | Lexer.Error(Lexer.Unterminated_comment _, _) as err -> raise err
+ | Lexer.Error(Lexer.Unterminated_string, _) as err -> raise err
+ | Lexer.Error(Lexer.Unterminated_string_in_comment _, _) as err -> raise err
+ | Lexer.Error(Lexer.Illegal_character _, _) as err ->
+ if !Location.input_name = "//toplevel//" then skip_phrase lexbuf;
+ raise err
+ | Syntaxerr.Error _ as err ->
+ if !Location.input_name = "//toplevel//" then maybe_skip_phrase lexbuf;
+ raise err
+ | Parsing.Parse_error | Syntaxerr.Escape_error ->
+ let loc = Location.curr lexbuf in
+ if !Location.input_name = "//toplevel//"
+ then maybe_skip_phrase lexbuf;
+ raise(Syntaxerr.Error(Syntaxerr.Other loc))
+;;
+
+let implementation = wrap Parser.implementation
+and interface = wrap Parser.interface
+and toplevel_phrase = wrap Parser.toplevel_phrase
+and use_file = wrap Parser.use_file
View
20 orig/ocaml/parsing/parse.mli
@@ -0,0 +1,20 @@
+(***********************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: parse.mli 11156 2011-07-27 14:17:02Z doligez $ *)
+
+(* Entry points in the parser *)
+
+val implementation : Lexing.lexbuf -> Parsetree.structure
+val interface : Lexing.lexbuf -> Parsetree.signature
+val toplevel_phrase : Lexing.lexbuf -> Parsetree.toplevel_phrase
+val use_file : Lexing.lexbuf -> Parsetree.toplevel_phrase list
View
1,809 orig/ocaml/parsing/parser.mly
@@ -0,0 +1,1809 @@
+/***********************************************************************/
+/* */
+/* OCaml */
+/* */
+/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 1996 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the Q Public License version 1.0. */
+/* */
+/***********************************************************************/
+
+/* $Id: parser.mly 12800 2012-07-30 18:59:07Z doligez $ */
+
+/* The parser definition */
+
+%{
+open Location
+open Asttypes
+open Longident
+open Parsetree
+
+let mktyp d =
+ { ptyp_desc = d; ptyp_loc = symbol_rloc() }
+let mkpat d =
+ { ppat_desc = d; ppat_loc = symbol_rloc() }
+let mkexp d =
+ { pexp_desc = d; pexp_loc = symbol_rloc() }
+let mkmty d =
+ { pmty_desc = d; pmty_loc = symbol_rloc() }
+let mksig d =
+ { psig_desc = d; psig_loc = symbol_rloc() }
+let mkmod d =
+ { pmod_desc = d; pmod_loc = symbol_rloc() }
+let mkstr d =
+ { pstr_desc = d; pstr_loc = symbol_rloc() }
+let mkfield d =
+ { pfield_desc = d; pfield_loc = symbol_rloc() }
+let mkclass d =
+ { pcl_desc = d; pcl_loc = symbol_rloc() }
+let mkcty d =
+ { pcty_desc = d; pcty_loc = symbol_rloc() }
+let mkctf d =
+ { pctf_desc = d; pctf_loc = symbol_rloc () }
+let mkcf d =
+ { pcf_desc = d; pcf_loc = symbol_rloc () }
+let mkrhs rhs pos = mkloc rhs (rhs_loc pos)
+let mkoption d =
+ { ptyp_desc = Ptyp_constr(mknoloc (Ldot (Lident "*predef*", "option")), [d]);
+ ptyp_loc = d.ptyp_loc}
+
+let reloc_pat x = { x with ppat_loc = symbol_rloc () };;
+let reloc_exp x = { x with pexp_loc = symbol_rloc () };;
+
+let mkoperator name pos =
+ let loc = rhs_loc pos in
+ { pexp_desc = Pexp_ident(mkloc (Lident name) loc); pexp_loc = loc }
+
+let mkpatvar name pos =
+ { ppat_desc = Ppat_var (mkrhs name pos); ppat_loc = rhs_loc pos }
+
+(*
+ Ghost expressions and patterns:
+ expressions and patterns that do not appear explicitly in the
+ source file they have the loc_ghost flag set to true.
+ Then the profiler will not try to instrument them and the
+ -stypes option will not try to display their type.
+
+ Every grammar rule that generates an element with a location must
+ make at most one non-ghost element, the topmost one.
+
+ How to tell whether your location must be ghost:
+ A location corresponds to a range of characters in the source file.
+ If the location contains a piece of code that is syntactically
+ valid (according to the documentation), and corresponds to the
+ AST node, then the location must be real; in all other cases,
+ it must be ghost.
+*)
+let ghexp d = { pexp_desc = d; pexp_loc = symbol_gloc () };;
+let ghpat d = { ppat_desc = d; ppat_loc = symbol_gloc () };;
+let ghtyp d = { ptyp_desc = d; ptyp_loc = symbol_gloc () };;
+
+let mkassert e =
+ match e with
+ | {pexp_desc = Pexp_construct ({ txt = Lident "false" }, None , false);
+ pexp_loc = _ } ->
+ mkexp (Pexp_assertfalse)
+ | _ -> mkexp (Pexp_assert (e))
+;;
+
+let mkinfix arg1 name arg2 =
+ mkexp(Pexp_apply(mkoperator name 2, ["", arg1; "", arg2]))
+
+let neg_float_string f =
+ if String.length f > 0 && f.[0] = '-'
+ then String.sub f 1 (String.length f - 1)
+ else "-" ^ f
+
+let mkuminus name arg =
+ match name, arg.pexp_desc with
+ | "-", Pexp_constant(Const_int n) ->
+ mkexp(Pexp_constant(Const_int(-n)))
+ | "-", Pexp_constant(Const_int32 n) ->
+ mkexp(Pexp_constant(Const_int32(Int32.neg n)))
+ | "-", Pexp_constant(Const_int64 n) ->
+ mkexp(Pexp_constant(Const_int64(Int64.neg n)))
+ | "-", Pexp_constant(Const_nativeint n) ->
+ mkexp(Pexp_constant(Const_nativeint(Nativeint.neg n)))
+ | ("-" | "-."), Pexp_constant(Const_float f) ->
+ mkexp(Pexp_constant(Const_float(neg_float_string f)))
+ | _ ->
+ mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, ["", arg]))
+
+let mkuplus name arg =
+ let desc = arg.pexp_desc in
+ match name, desc with
+ | "+", Pexp_constant(Const_int _)
+ | "+", Pexp_constant(Const_int32 _)
+ | "+", Pexp_constant(Const_int64 _)
+ | "+", Pexp_constant(Const_nativeint _)
+ | ("+" | "+."), Pexp_constant(Const_float _) -> mkexp desc
+ | _ ->
+ mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, ["", arg]))
+
+let mkexp_cons args loc =
+ {pexp_desc = Pexp_construct(mkloc (Lident "::") Location.none,
+ Some args, false); pexp_loc = loc}
+
+let mkpat_cons args loc =
+ {ppat_desc = Ppat_construct(mkloc (Lident "::") Location.none,
+ Some args, false); ppat_loc = loc}
+
+let rec mktailexp = function
+ [] ->
+ ghexp(Pexp_construct(mkloc (Lident "[]") Location.none, None, false))
+ | e1 :: el ->
+ let exp_el = mktailexp el in
+ let l = {loc_start = e1.pexp_loc.loc_start;
+ loc_end = exp_el.pexp_loc.loc_end;
+ loc_ghost = true}
+ in
+ let arg = {pexp_desc = Pexp_tuple [e1; exp_el]; pexp_loc = l} in
+ mkexp_cons arg l
+
+let rec mktailpat = function
+ [] ->
+ ghpat(Ppat_construct(mkloc (Lident "[]") Location.none, None, false))
+ | p1 :: pl ->
+ let pat_pl = mktailpat pl in
+ let l = {loc_start = p1.ppat_loc.loc_start;
+ loc_end = pat_pl.ppat_loc.loc_end;
+ loc_ghost = true}
+ in
+ let arg = {ppat_desc = Ppat_tuple [p1; pat_pl]; ppat_loc = l} in
+ mkpat_cons arg l
+
+let ghstrexp e =
+ { pstr_desc = Pstr_eval e; pstr_loc = {e.pexp_loc with loc_ghost = true} }
+
+let array_function str name =
+ mknoloc (Ldot(Lident str, (if !Clflags.fast then "unsafe_" ^ name else name)))
+
+let rec deep_mkrangepat c1 c2 =
+ if c1 = c2 then ghpat(Ppat_constant(Const_char c1)) else
+ ghpat(Ppat_or(ghpat(Ppat_constant(Const_char c1)),
+ deep_mkrangepat (Char.chr(Char.code c1 + 1)) c2))
+
+let rec mkrangepat c1 c2 =
+ if c1 > c2 then mkrangepat c2 c1 else
+ if c1 = c2 then mkpat(Ppat_constant(Const_char c1)) else
+ reloc_pat (deep_mkrangepat c1 c2)
+
+let syntax_error () =
+ raise Syntaxerr.Escape_error
+
+let unclosed opening_name opening_num closing_name closing_num =
+ raise(Syntaxerr.Error(Syntaxerr.Unclosed(rhs_loc opening_num, opening_name,
+ rhs_loc closing_num, closing_name)))
+
+let bigarray_function str name =
+ mkloc (Ldot(Ldot(Lident "Bigarray", str), name)) Location.none
+
+let bigarray_untuplify = function
+ { pexp_desc = Pexp_tuple explist; pexp_loc = _ } -> explist
+ | exp -> [exp]
+
+let bigarray_get arr arg =
+ let get = if !Clflags.fast then "unsafe_get" else "get" in
+ match bigarray_untuplify arg with
+ [c1] ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" get)),
+ ["", arr; "", c1]))
+ | [c1;c2] ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" get)),
+ ["", arr; "", c1; "", c2]))
+ | [c1;c2;c3] ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" get)),
+ ["", arr; "", c1; "", c2; "", c3]))
+ | coords ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "get")),
+ ["", arr; "", ghexp(Pexp_array coords)]))
+
+let bigarray_set arr arg newval =
+ let set = if !Clflags.fast then "unsafe_set" else "set" in
+ match bigarray_untuplify arg with
+ [c1] ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" set)),
+ ["", arr; "", c1; "", newval]))
+ | [c1;c2] ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" set)),
+ ["", arr; "", c1; "", c2; "", newval]))
+ | [c1;c2;c3] ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" set)),
+ ["", arr; "", c1; "", c2; "", c3; "", newval]))
+ | coords ->
+ mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "set")),
+ ["", arr;
+ "", ghexp(Pexp_array coords);
+ "", newval]))
+
+let lapply p1 p2 =
+ if !Clflags.applicative_functors
+ then Lapply(p1, p2)
+ else raise (Syntaxerr.Error(Syntaxerr.Applicative_path (symbol_rloc())))
+
+let exp_of_label lbl pos =
+ mkexp (Pexp_ident(mkrhs (Lident(Longident.last lbl)) pos))
+
+let pat_of_label lbl pos =
+ mkpat (Ppat_var (mkrhs (Longident.last lbl) pos))
+
+let check_variable vl loc v =
+ if List.mem v vl then
+ raise Syntaxerr.(Error(Variable_in_scope(loc,v)))
+
+let varify_constructors var_names t =
+ let rec loop t =
+ let desc =
+ match t.ptyp_desc with
+ | Ptyp_any -> Ptyp_any
+ | Ptyp_var x ->
+ check_variable var_names t.ptyp_loc x;
+ Ptyp_var x
+ | Ptyp_arrow (label,core_type,core_type') ->
+ Ptyp_arrow(label, loop core_type, loop core_type')
+ | Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst)
+ | Ptyp_constr( { txt = Lident s }, []) when List.mem s var_names ->
+ Ptyp_var s
+ | Ptyp_constr(longident, lst) ->
+ Ptyp_constr(longident, List.map loop lst)
+ | Ptyp_object lst ->
+ Ptyp_object (List.map loop_core_field lst)
+ | Ptyp_class (longident, lst, lbl_list) ->
+ Ptyp_class (longident, List.map loop lst, lbl_list)
+ | Ptyp_alias(core_type, string) ->
+ check_variable var_names t.ptyp_loc string;
+ Ptyp_alias(loop core_type, string)
+ | Ptyp_variant(row_field_list, flag, lbl_lst_option) ->
+ Ptyp_variant(List.map loop_row_field row_field_list,
+ flag, lbl_lst_option)
+ | Ptyp_poly(string_lst, core_type) ->
+ List.iter (check_variable var_names t.ptyp_loc) string_lst;
+ Ptyp_poly(string_lst, loop core_type)
+ | Ptyp_package(longident,lst) ->
+ Ptyp_package(longident,List.map (fun (n,typ) -> (n,loop typ) ) lst)
+ in
+ {t with ptyp_desc = desc}
+ and loop_core_field t =
+ let desc =
+ match t.pfield_desc with
+ | Pfield(n,typ) ->
+ Pfield(n,loop typ)
+ | Pfield_var ->
+ Pfield_var
+ in
+ { t with pfield_desc=desc}
+ and loop_row_field =
+ function
+ | Rtag(label,flag,lst) ->
+ Rtag(label,flag,List.map loop lst)
+ | Rinherit t ->
+ Rinherit (loop t)
+ in
+ loop t
+
+let wrap_type_annotation newtypes core_type body =
+ let exp = mkexp(Pexp_constraint(body,Some core_type,None)) in
+ let exp =
+ List.fold_right (fun newtype exp -> mkexp (Pexp_newtype (newtype, exp)))
+ newtypes exp
+ in
+ (exp, ghtyp(Ptyp_poly(newtypes,varify_constructors newtypes core_type)))
+
+%}
+
+/* Tokens */
+
+%token AMPERAMPER
+%token AMPERSAND
+%token AND
+%token AS
+%token ASSERT
+%token BACKQUOTE
+%token BANG
+%token BAR
+%token BARBAR
+%token BARRBRACKET
+%token BEGIN
+%token <char> CHAR
+%token CLASS
+%token COLON
+%token COLONCOLON
+%token COLONEQUAL
+%token COLONGREATER
+%token COMMA
+%token CONSTRAINT
+%token DO
+%token DONE
+%token DOT
+%token DOTDOT
+%token DOWNTO
+%token ELSE
+%token END
+%token EOF
+%token EQUAL
+%token EXCEPTION
+%token EXTERNAL
+%token FALSE
+%token <string> FLOAT
+%token FOR
+%token FUN
+%token FUNCTION
+%token FUNCTOR
+%token GREATER
+%token GREATERRBRACE
+%token GREATERRBRACKET
+%token IF
+%token IN
+%token INCLUDE
+%token <string> INFIXOP0
+%token <string> INFIXOP1
+%token <string> INFIXOP2
+%token <string> INFIXOP3
+%token <string> INFIXOP4
+%token INHERIT
+%token INITIALIZER
+%token <int> INT
+%token <int32> INT32
+%token <int64> INT64
+%token <string> LABEL
+%token LAZY
+%token LBRACE
+%token LBRACELESS
+%token LBRACKET
+%token LBRACKETBAR
+%token LBRACKETLESS
+%token LBRACKETGREATER
+%token LESS
+%token LESSMINUS
+%token LET
+%token <string> LIDENT
+%token LPAREN
+%token MATCH
+%token METHOD
+%token MINUS
+%token MINUSDOT
+%token MINUSGREATER
+%token MODULE
+%token MUTABLE
+%token <nativeint> NATIVEINT
+%token NEW
+%token OBJECT
+%token OF
+%token OPEN
+%token <string> OPTLABEL
+%token OR
+/* %token PARSER */
+%token PLUS
+%token PLUSDOT
+%token <string> PREFIXOP
+%token PRIVATE
+%token QUESTION
+%token QUESTIONQUESTION
+%token QUOTE
+%token RBRACE
+%token RBRACKET
+%token REC
+%token RPAREN
+%token SEMI
+%token SEMISEMI
+%token SHARP
+%token SIG
+%token STAR
+%token <string> STRING
+%token STRUCT
+%token THEN
+%token TILDE
+%token TO
+%token TRUE
+%token TRY
+%token TYPE
+%token <string> UIDENT
+%token UNDERSCORE
+%token VAL
+%token VIRTUAL
+%token WHEN
+%token WHILE
+%token WITH
+%token <string * Location.t> COMMENT
+