Commit 49be8565 authored by Dr. Michael Petter's avatar Dr. Michael Petter

initial fork

parents
Changes from 1.7 to -with-syntaxtree branch:
--------------------------------------------
New feature, 'syntaxtree generation' makes it possible to automatically
generate a semantics class that creates a syntaxtree, compatible to the
java-cup 0.11b parser generator. Its format is a generic DOM format, that
can be queried and processed with XML/XSL as well as custom tree
transformers in Java.
Changes from distribution 1.6.1 to 1.7:
---------------------------------------
New feature, 'deferred actions' makes it possible to construct messages
that can be revoked in case of backtracking.
The feature uses lambda expressions of Java, which means it requires
Java version 1.8 (JSE 8).
The manual is revised, with added references to new literature about
converting EBNF to PEG.
Some code clean-up and restructuring has been done, with class Phrase
separated form ParserBase.
Changes from distribution 1.6 to 1.6.1:
---------------------------------------
Classes for Mouse tools: Generate, TestParser, TestPEG, TryParser,
and MakeRuntime are made public.
Option --mode=755 is added to the 'tar' command used to create
Mouse-1.6.1.tar. This should set the correct permission bits
when the archive is unpacked under Unix. (The original files
and directories are under Windows, and have different permissions,
not copied by 'tar'.)
Changes from distribution 1.5.1 to 1.6:
---------------------------------------
'TestParser' can optionally write its output in the form of
comma-separated values (CSV) that can be imported into a spreadsheet
application. This is controlled by option '-C'.
'TryParser' and 'TestParser' may optionally write timing information.
This is controlled by option '-t'.
The output format of both 'TryParser' and 'TestParser' is slightly
changed: file name precedes output from the parser under test.
Three bugs fixed:
- A semicolon generated after 'while' caused infinite
loop in an internal parsing procedure with a body
consisting of a '*+' expression only.
- Omitted '-S' option to Generate ignored the package specified
by '-r' when defining SemanticBase.
- 'rhsText' did not return empty string for empty range.
Changes from distribution 1.5 to 1.5.1:
---------------------------------------
Bug fix and clean-up due to Stephen P. Owens (steve@doitnext.com).
Fixed bug: after parser failure, printed a blank line if the error message
was intercepted by semantics and error info cleared using errClear().
Clean-up: removed unused variables and imports from six source files.
Changes from distribution 1.4 to 1.5:
-------------------------------------
Identity of rule that created a Phrase made available
to semantic procedures via helper methods 'rule' and 'isTerm'.
Bug fixed in the generated parser:
incorrect handling of ^[s] when s has length 1.
Build file provided for compiling the source and making the jars:
'build.xml' for Apache Ant. Invocation is described in a comment.
Changes from distribution 1.3.1 to 1.4:
---------------------------------------
Shorthand forms introduced for three frequently used
constructions. They are easier to read and have
a more efficient implementation.
- e1*+ e2. A shorthand for (!e2 e1)*e2:
iterate e1 until e2.
- e1++ e2. A shorthand for (!e2 e1)+e2:
iterate e1 at least once until e2.
- ^[s]. A shorthand for ![s]_:
consume character NOT appearing in string s.
Position of a Phrase in source text made available
to semantic procedures via helper method 'where'.
(Feature request 3298666.)
A slightly better formulation for messages
about failing predicate !e.
Changes from distribution 1.3a to 1.3.1:
----------------------------------------
Two bugs fixed in the generated parser:
- the error message for failing predicate &e was
'expected not e' instead of 'expected e'.
- an attempt to print error position at the end of file
resulted in an infinite loop.
One bug fixed in Generate:
- printed extra message 'expected : or end of input'
for syntax error after last semicolon.
Two errors corrected in the sample grammar for Java 1.6.
Sample grammar for Java 1.7 added.
Change from distribution 1.3 to 1.3a:
-------------------------------------
Revised version of user's manual.
Changes from distribution 1.2 to 1.3:
-------------------------------------
In the generated parser, do not check for success
of expressions that never fail.
Default character encoding is assumed for the input file
(version 1.2 assumed ISO 8859_1).
Can be changed by modifying 'runtime.SourceFile'.
The generated Java code uses ASCII encoding.
Helper method 'errMsg' returns a 'readable' string:
all characters outside the range 32-255 are represented
by Java escapes.
Improved diagnostics from TestPEG.
Minor bug fixes.
Sample grammars for Java and C are included in the package.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
===========================================================================
*
* INVOCATION
*
* Stand in the distribution directory Mouse-1.7 and invoke Apache Ant:
*
* ant -Ddest=<destdir> <targets>
*
* where <destdir> is name of the directory to contain the result.
* This directory will be deleted if it exists and then re-created.
* If you omit -D option, destdir is the subdirectory 'build' of Mouse-1.7.
*
* <targets> are one or more of:
* full-jar - build complete Mouse-1.7.jar
* runtime-jar - build Mouse-1.7.runtime.jar
* compile - compile all source to subdirectory 'mouse'
* of destdir. It is included in the preceding two.
* Default is all of above.
*
* 2011-11-08 Created.
* 2012-01-06 Updated for version 1.5.1.
* 2013-04-15 Updated for version 1.6.
* 2014-04-13 Updated for version 1.6.1.
* 2015-07-25 Updated for version 1.7.
*
* =========================================================================
-->
<project name="MakeMouse" basedir="." default="all" >
<property name="dest" value="${basedir}/build" />
<target name="all" depends="full-jar, runtime-jar" />
<target name="full-jar" depends="compile, rtsource">
<jar basedir="${dest}" destfile="${dest}/Mouse-1.7.jar" />
<delete dir="${dest}/rtsource" />
</target>
<target name="runtime-jar" depends="compile">
<jar basedir="${dest}/mouse/runtime"
destfile="${dest}/Mouse-1.7.runtime.jar" />
</target>
<target name="compile" depends="init">
<javac srcdir="${basedir}/src" destdir="${dest}" includeAntRuntime="no" />
</target>
<target name="rtsource" depends="rtdir" >
<copy todir="${dest}/rtsource">
<fileset dir="${basedir}/src/mouse/runtime" />
</copy>
</target>
<target name="rtdir" depends="init">
<mkdir dir="${dest}/rtsource"/>
</target>
<target name="init" depends="clean">
<mkdir dir="${dest}"/>
</target>
<target name="clean">
<delete dir="${dest}"/>
</target>
</project>
\newpage
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
\section{Appendix: The grammar of \Mouse\ PEG}
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
\small
\begin{Verbatim}[frame=single,framesep=2mm,samepage=true,xleftmargin=15mm,xrightmargin=15mm,baselinestretch=0.8]
Grammar = Space (Rule/Skip)*+ EOT ;
Rule = Name EQUAL RuleRhs DiagName? SEMI ;
Skip = SEMI
/ _++ (SEMI/EOT) ;
RuleRhs = Sequence Actions (SLASH Sequence Actions)* ;
Choice = Sequence (SLASH Sequence)* ;
Sequence = Prefixed+ ;
Prefixed = PREFIX? Suffixed ;
Suffixed = Primary (UNTIL Primary / SUFFIX)? ;
Primary = Name
/ LPAREN Choice RPAREN
/ ANY
/ StringLit
/ Range
/ CharClass ;
Actions = OnSucc OnFail ;
OnSucc = (LWING AND? Name? RWING)? ;
OnFail = (TILDA LWING Name? RWING)? ;
Name = Letter (Letter / Digit)* Space ;
DiagName = "<" Char++ ">" Space ;
StringLit = ["] Char++ ["] Space ;
CharClass = ("[" / "^[") Char++ "]" Space ;
Range = "[" Char "-" Char "]" Space ;
Char = Escape
/ ^[\r\n\\] ;
Escape = "\\u" HexDigit HexDigit HexDigit HexDigit
/ "\\t"
/ "\\n"
/ "\\r"
/ !"\\u""\\"_ ;
Letter = [a-z] / [A-Z] ;
Digit = [0-9] ;
HexDigit = [0-9] / [a-f] / [A-F] ;
PREFIX = [&!] Space ;
SUFFIX = [?*+] Space ;
UNTIL = ("*+" / "++") Space ;
EQUAL = "=" Space ;
SEMI = ";" Space ;
SLASH = "/" Space ;
AND = "&" Space ;
LPAREN = "(" Space ;
RPAREN = ")" Space ;
LWING = "{" Space ;
RWING = "}" Space ;
TILDA = "~" Space ;
ANY = "_" Space ;
Space = ([ \r\n\t] / Comment)* ;
Comment = "//" _*+ EOL ;
EOL = [\r]? [\n] / !_ ;
EOT = !_ ;
\end{Verbatim}
\normalsize
\newpage
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
\section{Appendix: Helper methods\label{helper}}
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
These methods provide access to the environment seen by a semantic action.
The following four methods
are inherited from \tx{mouse.runtime.Semantics}.\newline
They call back the parser to access the relevant \Phrase\ objects.
\ul
\item[\tx{Phrase }\textbf{lhs}\tx{()}]\upsp\newline
Returns the left-hand side object.
\item[\tx{int }\textbf{rhsSize}\tx{()}]\upsp\newline
Returns the number of right-hand side objects.
\item[\tx{Phrase }\textbf{rhs}\tx{(int i)}]\upsp\newline
Returns the $i$-th element on the right-hand side, $0\le i <\,$\tx{rhsSize()}.
\item[\tx{String }\textbf{rhsText}\tx{(int i,int j)}]\upsp\newline
Returns as one \tx{String} the text
represented by the right-hand side objects $i$ through $j-1$,\newline
where $0\leq i < j \le\,$\tx{rhsSize()}.
\eul
The following fifteen methods can be applied to a \Phrase\ object:
\ul
\item[\tx{void }\textbf{put}\tx{(Object v)}]\upsp \newline
Inserts $v$ as the semantic value of this \Phrase.
\item[\tx{Object }\textbf{get}\tx{()}]\upsp \newline
Returns the semantic value of this \Phrase.
\item[\tx{String }\textbf{text}\tx{()}]\upsp \newline
Returns the text represented by this \tx{Phrase}.
\item[\tx{char }\textbf{charAt}\tx{(int i)}]\upsp \newline
Returns the $i$-th character of the text represented by this \tx{Phrase}.
\item[\tx{String }\textbf{rule}\tx{()}]\upsp \newline
Returns name of the rule that created this \tx{Phrase}.
\item[\tx{boolean }\textbf{isA}\tx{(String name)}]\upsp \newline
Returns \tx{true} if this \tx{Phrase} was created by rule \textit{name}.
\item[\tx{boolean }\textbf{isTerm}\tx{()}]\upsp \newline
Returns \tx{true} if this \tx{Phrase} was created by a terminal.
\item[\tx{boolean }\textbf{isEmpty}\tx{()}]\upsp \newline
Returns \tx{true} if the text represented by this \tx{Phrase} is empty.
\item[\tx{String }\textbf{where}\tx{(int i)}]\upsp \newline
Returns a printable string describing where in the text being parsed\newline
find the i-th character
of text represented by this \tx{Phrase}.
\item[\tx{String }\textbf{errMsg}\tx{()}]\upsp \newline
Returns the error message contained in this \tx{Phrase}.
\item[\tx{void }\textbf{errClear}\tx{()}]\upsp \newline
Erases the error message contained in this \tx{Phrase}.
\item[\tx{void }\textbf{errAdd}\tx{(String expr,int i)}]\upsp \newline
Updates error message contained in this \tx{Phrase} with information\newline
that expression \textit{expr} failed at the i-th character
of text represented by this \tx{Phrase}.
\item[\tx{void }\textbf{actAdd}\tx{(Deferred act)}]\upsp \newline
Adds to this \Phrase deferred action \tx{act}: a lambda expression implementing
the interface \tx{Deferred}.
\item[\tx{void }\textbf{actClear}\tx{()}]\upsp \newline
Removes all deferred actions saved in this \Phrase.
\item[\tx{void }\textbf{actExec}\tx{()}]\upsp \newline
Executes and removes all deferred actions saved in this \Phrase.
\eul
\newpage
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
\section{Appendix: Your parser class\label{DocPars}}
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
These are the methods you can apply to your generated parser.\newline
"\tx{Parser}" and
"\tx{Semantics}" are names of your parser and semantics classes,
respectively.
\ul
\item[\textbf{Parser}\texttt{()}]\upsp \newline
Parser constructor. Instantiates your parser and semantics,
connects semantics object to the parser,
and returns the resulting parser object.\dnsp
\item[\texttt{boolean }\textbf{parse}\texttt{(Source src)}]\upsp \newline
Parses input wrapped into a \tx{Source} object \textit{src}.\newline
Returns \tx{true} if the parse was successful, or \tx{false} otherwise.\dnsp
\item[\texttt{Semantics }\textbf{semantics}\texttt{()}]\upsp \newline
Returns the semantics object associated with the parser.\dnsp
\item[\texttt{void }\textbf{setTrace}\texttt{(String s)}]\upsp \newline
Assigns $s$ to the \tx{trace} field in semantics object.\dnsp
\item[\texttt{void }\textbf{setMemo}\texttt{(int n)}]\upsp \newline
Sets the amount of memoization to $n$, $0 \le n \le 9$.\newline
Can only be applied to a parser generated with option \tx{-M} or \tx{-T}
(see \tx{mouse.Generate} tool).
\eul
\newpage
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
\section{Appendix: \Mouse\ tools\label{tools}}
%HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
\fbox{ \textbf{mouse.Generate}\textit{ arguments}\prop}
\medskip
Generates parser.\newline
The \textit{arguments} are specified as options according to POSIX syntax:
%
\ul