diff --git a/ChangeLog b/ChangeLog index 92c11ad1645..498bc328714 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-12-13 Glenn Morris + + * info/dir: Add bovine, srecode, wisent. + +2012-12-13 Andreas Schwab + + * Makefile.in (install-info): Use `${MAKE} -s' for echo-info. + (uninstall): Likewise. (Bug#13143) + 2012-12-11 Paul Eggert Merge from gnulib for 'inline' (Bug#13040), incorporating: diff --git a/Makefile.in b/Makefile.in index 9b7bf795b84..bc9b01c95e4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -603,7 +603,7 @@ install-info: info [ -f dir ] || \ (cd $${thisdir}; \ ${INSTALL_DATA} ${srcdir}/info/dir $(DESTDIR)${infodir}/dir) ; \ - info_misc=`cd $${thisdir}/doc/misc; ${MAKE} echo-info | sed '/ing directory/d'`; \ + info_misc=`cd $${thisdir}/doc/misc; ${MAKE} -s echo-info`; \ cd ${srcdir}/info ; \ for elt in ${INFO_NONMISC} $${info_misc}; do \ test "$(HAVE_MAKEINFO)" = "no" && test ! -f $$elt && continue; \ @@ -690,7 +690,7 @@ uninstall: done -rm -rf $(DESTDIR)${libexecdir}/emacs/${version} thisdir=`/bin/pwd`; \ - (info_misc=`cd doc/misc; ${MAKE} echo-info | sed '/ing directory/d'`; \ + (info_misc=`cd doc/misc; ${MAKE} -s echo-info`; \ if cd $(DESTDIR)${infodir}; then \ for elt in ${INFO_NONMISC} $${info_misc}; do \ (cd $${thisdir}; \ diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 9de75390937..225f9c6964d 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog @@ -1,3 +1,61 @@ +2012-12-13 Glenn Morris + + * wisent.texi: Small edits. Set copyright to FSF, update license to + GFDL 1.3+. + * Makefile.in (INFO_TARGETS, DVI_TARGETS, PDF_TARGETS): Add wisent. + (wisent, $(buildinfodir)/wisent$(INFO_EXT), wisent.dvi, wisent.pdf): + New targets. + * makefile.w32-in (INFO_TARGETS, DVI_TARGETS, clean): Add wisent. + ($(infodir)/wisent$(INFO_EXT), wisent.dvi): New targets. + + * bovine.texi: Small edits. Set copyright to FSF, update license to + GFDL 1.3+, remove empty index. + * Makefile.in (INFO_TARGETS, DVI_TARGETS, PDF_TARGETS): Add bovine. + (bovine, $(buildinfodir)/bovine$(INFO_EXT), bovine.dvi, bovine.pdf): + New targets. + * makefile.w32-in (INFO_TARGETS, DVI_TARGETS, clean): Add bovine. + ($(infodir)/bovine$(INFO_EXT), bovine.dvi): New targets. + +2012-12-13 Eric Ludlam + David Ponce + Richard Kim + + * bovine.texi, wisent.texi: New files, imported from CEDET trunk. + +2012-12-13 Glenn Morris + + * flymake.texi (Customizable variables, Locating the buildfile): + Remove refs to flymake-buildfile-dirs, removed 2007-07-20. (Bug#13148) + + * srecode.texi: Small edits. Set copyright to FSF, add explicit + GFDL 1.3+ license, fix up index. + * Makefile.in (INFO_TARGETS, DVI_TARGETS, PDF_TARGETS): Add srecode. + (srecode, $(buildinfodir)/srecode$(INFO_EXT), srecode.dvi) + (srecode.pdf): New targets. + * makefile.w32-in (INFO_TARGETS, DVI_TARGETS, clean): Add srecode. + ($(infodir)/srecode$(INFO_EXT), srecode.dvi): New targets. + +2012-12-13 Eric Ludlam + + * srecode.texi: New file, imported from CEDET trunk. + +2012-12-13 Bastien Guerry + + * org.texi (Summary, Code block specific header arguments) + (Code block specific header arguments) + (Header arguments in function calls, var, noweb) + (Results of evaluation, Code evaluation security): + Small reformatting: add a blank line before some example. + + * org.texi (System-wide header arguments) + (Header arguments in Org mode properties, Conflicts) + (Dynamic blocks, Using the mapping API): + Fix indentation of Elisp code examples. + + * org.texi (Comment lines): Fix description of the comment syntax. + + * org.texi (Installation): Mention "make test" in the correct section. + 2012-12-06 Paul Eggert * doclicense.texi, gpl.texi: Update to latest version from FSF. diff --git a/doc/misc/Makefile.in b/doc/misc/Makefile.in index ea1e87333bd..c99657fb9bb 100644 --- a/doc/misc/Makefile.in +++ b/doc/misc/Makefile.in @@ -41,19 +41,20 @@ INFO_OPTS=@INFO_OPTS@ MAKEINFO = @MAKEINFO@ MAKEINFO_OPTS = --force -I$(emacsdir) -INFO_TARGETS = ada-mode auth autotype calc ccmode cl \ +INFO_TARGETS = ada-mode auth autotype bovine calc ccmode cl \ dbus dired-x ebrowse ede ediff edt eieio \ emacs-mime epa erc ert eshell eudc efaq \ flymake forms gnus emacs-gnutls idlwave info.info \ mairix-el message mh-e newsticker nxml-mode \ org pcl-cvs pgg rcirc remember reftex sasl \ - sc semantic ses sieve smtpmail speedbar tramp \ - url vip viper widget woman + sc semantic ses sieve smtpmail speedbar srecode tramp \ + url vip viper widget wisent woman DVI_TARGETS = \ ada-mode.dvi \ auth.dvi \ autotype.dvi \ + bovine.dvi \ calc.dvi \ cc-mode.dvi \ cl.dvi \ @@ -95,17 +96,20 @@ DVI_TARGETS = \ sieve.dvi \ smtpmail.dvi \ speedbar.dvi \ + srecode.dvi \ tramp.dvi \ url.dvi \ vip.dvi \ viper.dvi \ widget.dvi \ + wisent.dvi \ woman.dvi PDF_TARGETS = \ ada-mode.pdf \ auth.pdf \ autotype.pdf \ + bovine.pdf \ calc.pdf \ cc-mode.pdf \ cl.pdf \ @@ -147,11 +151,13 @@ PDF_TARGETS = \ sieve.pdf \ smtpmail.pdf \ speedbar.pdf \ + srecode.pdf \ tramp.pdf \ url.pdf \ vip.pdf \ viper.pdf \ widget.pdf \ + wisent.pdf \ woman.pdf HTML_TARGETS = emacs-faq.html @@ -218,6 +224,15 @@ autotype.dvi: ${srcdir}/autotype.texi autotype.pdf: ${srcdir}/autotype.texi $(ENVADD) $(TEXI2PDF) ${srcdir}/autotype.texi +bovine : $(buildinfodir)/bovine$(INFO_EXT) +$(buildinfodir)/bovine$(INFO_EXT): ${srcdir}/bovine.texi + $(mkinfodir) + $(MAKEINFO) $(MAKEINFO_OPTS) $(INFO_OPTS) -o $@ ${srcdir}/bovine.texi +bovine.dvi: ${srcdir}/bovine.texi + $(ENVADD) $(TEXI2DVI) ${srcdir}/bovine.texi +bovine.pdf: ${srcdir}/bovine.texi + $(ENVADD) $(TEXI2PDF) ${srcdir}/bovine.texi + calc : $(buildinfodir)/calc$(INFO_EXT) $(buildinfodir)/calc$(INFO_EXT): ${srcdir}/calc.texi $(emacsdir)/emacsver.texi $(mkinfodir) @@ -606,6 +621,15 @@ speedbar.dvi: ${srcdir}/speedbar.texi speedbar.pdf: ${srcdir}/speedbar.texi $(ENVADD) $(TEXI2PDF) ${srcdir}/speedbar.texi +srecode : $(buildinfodir)/srecode$(INFO_EXT) +$(buildinfodir)/srecode$(INFO_EXT): ${srcdir}/srecode.texi + $(mkinfodir) + $(MAKEINFO) $(MAKEINFO_OPTS) $(INFO_OPTS) -o $@ ${srcdir}/srecode.texi +srecode.dvi: ${srcdir}/srecode.texi + $(ENVADD) $(TEXI2DVI) ${srcdir}/srecode.texi +srecode.pdf: ${srcdir}/srecode.texi + $(ENVADD) $(TEXI2PDF) ${srcdir}/srecode.texi + tramp : $(buildinfodir)/tramp$(INFO_EXT) $(buildinfodir)/tramp$(INFO_EXT): ${srcdir}/tramp.texi ${srcdir}/trampver.texi $(mkinfodir) @@ -651,6 +675,15 @@ widget.dvi: ${srcdir}/widget.texi widget.pdf: ${srcdir}/widget.texi $(ENVADD) $(TEXI2PDF) ${srcdir}/widget.texi +wisent : $(buildinfodir)/wisent$(INFO_EXT) +$(buildinfodir)/wisent$(INFO_EXT): ${srcdir}/wisent.texi + $(mkinfodir) + $(MAKEINFO) $(MAKEINFO_OPTS) $(INFO_OPTS) -o $@ ${srcdir}/wisent.texi +wisent.dvi: ${srcdir}/wisent.texi + $(ENVADD) $(TEXI2DVI) ${srcdir}/wisent.texi +wisent.pdf: ${srcdir}/wisent.texi + $(ENVADD) $(TEXI2PDF) ${srcdir}/wisent.texi + woman : $(buildinfodir)/woman$(INFO_EXT) $(buildinfodir)/woman$(INFO_EXT): ${srcdir}/woman.texi $(mkinfodir) diff --git a/doc/misc/bovine.texi b/doc/misc/bovine.texi new file mode 100644 index 00000000000..a263cadabae --- /dev/null +++ b/doc/misc/bovine.texi @@ -0,0 +1,475 @@ +\input texinfo @c -*-texinfo-*- +@c %**start of header +@setfilename ../../info/bovine +@set TITLE Bovine parser development +@set AUTHOR Eric M. Ludlam, David Ponce, and Richard Y. Kim +@settitle @value{TITLE} + +@c ************************************************************************* +@c @ Header +@c ************************************************************************* + +@c Merge all indexes into a single index for now. +@c We can always separate them later into two or more as needed. +@syncodeindex vr cp +@syncodeindex fn cp +@syncodeindex ky cp +@syncodeindex pg cp +@syncodeindex tp cp + +@c @footnotestyle separate +@c @paragraphindent 2 +@c @@smallbook +@c %**end of header + +@copying +Copyright @copyright{} 1999-2004, 2012 Free Software Foundation, Inc. + +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with no +Invariant Sections, with the Front-Cover texts being ``A GNU Manual,'' +and with the Back-Cover Texts as in (a) below. A copy of the license +is included in the section entitled ``GNU Free Documentation License''. + +(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and +modify this GNU manual. Buying copies from the FSF supports it in +developing GNU and promoting software freedom.'' +@end quotation +@end copying + +@dircategory Emacs misc features +@direntry +* Bovine: (bovine). Semantic bovine parser development. +@end direntry + +@iftex +@finalout +@end iftex + +@c @setchapternewpage odd +@c @setchapternewpage off + +@titlepage +@sp 10 +@title @value{TITLE} +@author by @value{AUTHOR} +@page +@vskip 0pt plus 1 fill +@insertcopying +@end titlepage +@page + +@macro semantic{} +@i{Semantic} +@end macro + +@c ************************************************************************* +@c @ Document +@c ************************************************************************* +@contents + +@node top +@top @value{TITLE} + +The @dfn{bovine} parser is the original @semantic{} parser, and is an +implementation of an @acronym{LL} parser. It is good for simple +languages. It has many conveniences making grammar writing easy. The +conveniences make it less powerful than a Bison-like @acronym{LALR} +parser. For more information, @inforef{top, the Wisent Parser Manual, +wisent}. + +Bovine @acronym{LL} grammars are stored in files with a @file{.by} +extension. When compiled, the contents is converted into a file of +the form @file{NAME-by.el}. This, in turn is byte compiled. +@inforef{top, Grammar Framework Manual, grammar-fw}. + +@ifnottex +@insertcopying +@end ifnottex + +@menu +* Starting Rules:: The starting rules for the grammar. +* Bovine Grammar Rules:: Rules used to parse a language. +* Optional Lambda Expression:: Actions to take when a rule is matched. +* Bovine Examples:: Simple Samples. +* GNU Free Documentation License:: The license for this documentation. +@c * Index:: +@end menu + +@node Starting Rules +@chapter Starting Rules + +In Bison, one and only one nonterminal is designated as the ``start'' +symbol. In @semantic{}, one or more nonterminals can be designated as +the ``start'' symbol. They are declared following the @code{%start} +keyword separated by spaces. @inforef{start Decl, ,grammar-fw}. + +If no @code{%start} keyword is used in a grammar, then the very first +is used. Internally the first start nonterminal is targeted by the +reserved symbol @code{bovine-toplevel}, so it can be found by the +parser harness. + +To find locally defined variables, the local context handler needs to +parse the body of functional code. The @code{scopestart} declaration +specifies the name of a nonterminal used as the goal to parse a local +context, @inforef{scopestart Decl, ,grammar-fw}. Internally the +scopestart nonterminal is targeted by the reserved symbol +@code{bovine-inner-scope}, so it can be found by the parser harness. + +@node Bovine Grammar Rules +@chapter Bovine Grammar Rules + +The rules are what allow the compiler to create tags from a language +file. Once the setup is done in the prologue, you can start writing +rules. @inforef{Grammar Rules, ,grammar-fw}. + +@example +@var{result} : @var{components1} @var{optional-semantic-action1}) + | @var{components2} @var{optional-semantic-action2} + ; +@end example + +@var{result} is a nonterminal, that is a symbol synthesized in your grammar. +@var{components} is a list of elements that are to be matched if @var{result} +is to be made. @var{optional-semantic-action} is an optional sequence +of simplified Emacs Lisp expressions for concocting the parse tree. + +In bison, each time an element of @var{components} is found, it is +@dfn{shifted} onto the parser stack. (The stack of matched elements.) +When all @var{components}' elements have been matched, it is +@dfn{reduced} to @var{result}. @xref{(bison)Algorithm}. + +A particular @var{result} written into your grammar becomes +the parser's goal. It is designated by a @code{%start} statement +(@pxref{Starting Rules}). The value returned by the associated +@var{optional-semantic-action} is the parser's result. It should be +a tree of @semantic{} @dfn{tags}, @inforef{Semantic Tags, , +semantic-appdev}. + +@var{components} is made up of symbols. A symbol such as @code{FOO} +means that a syntactic token of class @code{FOO} must be matched. + +@menu +* How Lexical Tokens Match:: +* Grammar-to-Lisp Details:: +* Order of components in rules:: +@end menu + +@node How Lexical Tokens Match +@section How Lexical Tokens Match + +A lexical rule must be used to define how to match a lexical token. + +For instance: + +@example +%keyword FOO "foo" +@end example + +Means that @code{FOO} is a reserved language keyword, matched as such +by looking up into a keyword table, @inforef{keyword Decl, +,grammar-fw}. This is because @code{"foo"} will be converted to +@code{FOO} in the lexical analysis stage. Thus the symbol @code{FOO} +won't be available any other way. + +If we specify our token in this way: + +@example +%token FOO "foo" +@end example + +then @code{FOO} will match the string @code{"foo"} explicitly, but it +won't do so at the lexical level, allowing use of the text +@code{"foo"} in other forms of regular expressions. + +In that case, @code{FOO} is a @code{symbol}-type token. To match, a +@code{symbol} must first be encountered, and then it must +@code{string-match "foo"}. + +@table @strong +@item Caution: +Be especially careful to remember that @code{"foo"}, and more +generally the %token's match-value string, is a regular expression! +@end table + +Non symbol tokens are also allowed. For example: + +@example +%token PERIOD "[.]" + +filename : symbol PERIOD symbol + ; +@end example + +@code{PERIOD} is a @code{punctuation}-type token that will explicitly +match one period when used in the above rule. + +@table @strong +@item Please Note: +@code{symbol}, @code{punctuation}, etc., are predefined lexical token +types, based on the @dfn{syntax class}-character associations +currently in effect. +@end table + +@node Grammar-to-Lisp Details +@section Grammar-to-Lisp Details + +For the bovinator, lexical token matching patterns are @emph{inlined}. +When the grammar-to-lisp converter encounters a lexical token +declaration of the form: + +@example +%token <@var{type}> @var{token-name} @var{match-value} +@end example + +It substitutes every occurrences of @var{token-name} in rules, by its +expanded form: + +@example +@var{type} @var{match-value} +@end example + +For example: + +@example +%token MOOSE "moose" + +find_a_moose: MOOSE + ; +@end example + +Will generate this pseudo equivalent-rule: + +@example +find_a_moose: symbol "moose" ;; invalid syntax! + ; +@end example + +Thus, from the bovinator point of view, the @var{components} part of a +rule is made up of symbols and strings. A string in the mix means +that the previous symbol must have the additional constraint of +exactly matching it, as described in @ref{How Lexical Tokens Match}. + +@table @strong +@item Please Note: +For the bovinator, this task was mixed into the language definition to +simplify implementation, though Bison's technique is more efficient. +@end table + +@node Order of components in rules +@section Order of components in rules + +If a rule has multiple components, order is important, for example + +@example +headerfile : symbol PERIOD symbol + | symbol + ; +@end example + +would match @samp{foo.h} or the @acronym{C++} header @samp{foo}. +The bovine parser will first attempt to match the long form, and then +the short form. If they were in reverse order, then the long form +would never be tested. + +@c @xref{Default syntactic tokens}. + +@node Optional Lambda Expression +@chapter Optional Lambda Expressions + +The @acronym{OLE} (@dfn{Optional Lambda Expression}) is converted into +a bovine lambda. This lambda has special short-cuts to simplify +reading the semantic action definition. An @acronym{OLE} like this: + +@example +( $1 ) +@end example + +results in a lambda return which consists entirely of the string +or object found by matching the first (zeroth) element of match. +An @acronym{OLE} like this: + +@example +( ,(foo $1) ) +@end example + +executes @code{foo} on the first argument, and then splices its return +into the return list whereas: + +@example +( (foo $1) ) +@end example + +executes @code{foo}, and that is placed in the return list. + +Here are other things that can appear inline: + +@table @code +@item $1 +The first object matched. + +@item ,$1 +The first object spliced into the list (assuming it is a list from a +non-terminal). + +@item '$1 +The first object matched, placed in a list. i.e. @code{( $1 )}. + +@item foo +The symbol @code{foo} (exactly as displayed). + +@item (foo) +A function call to foo which is stuck into the return list. + +@item ,(foo) +A function call to foo which is spliced into the return list. + +@item '(foo) +A function call to foo which is stuck into the return list in a list. + +@item (EXPAND @var{$1} @var{nonterminal} @var{depth}) +A list starting with @code{EXPAND} performs a recursive parse on the +token passed to it (represented by @samp{$1} above.) The +@dfn{semantic list} is a common token to expand, as there are often +interesting things in the list. The @var{nonterminal} is a symbol in +your table which the bovinator will start with when parsing. +@var{nonterminal}'s definition is the same as any other nonterminal. +@var{depth} should be at least @samp{1} when descending into a +semantic list. + +@item (EXPANDFULL @var{$1} @var{nonterminal} @var{depth}) +Is like @code{EXPAND}, except that the parser will iterate over +@var{nonterminal} until there are no more matches. (The same way the +parser iterates over the starting rule (@pxref{Starting Rules}). This +lets you have much simpler rules in this specific case, and also lets +you have positional information in the returned tokens, and error +skipping. + +@item (ASSOC @var{symbol1} @var{value1} @var{symbol2} @var{value2} @dots{}) +This is used for creating an association list. Each @var{symbol} is +included in the list if the associated @var{value} is non-@code{nil}. +While the items are all listed explicitly, the created structure is an +association list of the form: + +@example +((@var{symbol1} . @var{value1}) (@var{symbol2} . @var{value2}) @dots{}) +@end example + +@item (TAG @var{name} @var{class} [@var{attributes}]) +This creates one tag in the current buffer. + +@table @var +@item name +Is a string that represents the tag in the language. + +@item class +Is the kind of tag being create, such as @code{function}, or +@code{variable}, though any symbol will work. + +@item attributes +Is an optional set of labeled values such as @w{@code{:constant-flag t :parent +"parenttype"}}. +@end table + +@item (TAG-VARIABLE @var{name} @var{type} @var{default-value} [@var{attributes}]) +@itemx (TAG-FUNCTION @var{name} @var{type} @var{arg-list} [@var{attributes}]) +@itemx (TAG-TYPE @var{name} @var{type} @var{members} @var{parents} [@var{attributes}]) +@itemx (TAG-INCLUDE @var{name} @var{system-flag} [@var{attributes}]) +@itemx (TAG-PACKAGE @var{name} @var{detail} [@var{attributes}]) +@itemx (TAG-CODE @var{name} @var{detail} [@var{attributes}]) +Create a tag with @var{name} of respectively the class +@code{variable}, @code{function}, @code{type}, @code{include}, +@code{package}, and @code{code}. +See @inforef{Creating Tags, , semantic-appdev} for the lisp +functions these translate into. +@end table + +If the symbol @code{%quotemode backquote} is specified, then use +@code{,@@} to splice a list in, and @code{,} to evaluate the expression. +This lets you send @code{$1} as a symbol into a list instead of having +it expanded inline. + +@node Bovine Examples +@chapter Examples + +The rule: + +@example +any-symbol: symbol + ; +@end example + +is equivalent to + +@example +any-symbol: symbol + ( $1 ) + ; +@end example + +which, if it matched the string @samp{"A"}, would return + +@example +( "A" ) +@end example + +If this rule were used like this: + +@example +%token EQUAL "=" +@dots{} +assign: any-symbol EQUAL any-symbol + ( $1 $3 ) + ; +@end example + +it would match @samp{"A=B"}, and return + +@example +( ("A") ("B") ) +@end example + +The letters @samp{A} and @samp{B} come back in lists because +@samp{any-symbol} is a nonterminal, not an actual lexical element. + +To get a better result with nonterminals, use @asis{,} to splice lists +in like this: + +@example +%token EQUAL "=" +@dots{} +assign: any-symbol EQUAL any-symbol + ( ,$1 ,$3 ) + ; +@end example + +which would return + +@example +( "A" "B" ) +@end example + +@node GNU Free Documentation License +@appendix GNU Free Documentation License + +@include doclicense.texi + +@c There is nothing to index at the moment. +@ignore +@node Index +@unnumbered Index +@printindex cp +@end ignore + +@iftex +@contents +@summarycontents +@end iftex + +@bye + +@c Following comments are for the benefit of ispell. + +@c LocalWords: bovinator inlined diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index 98279c8dae3..e82bfdfa6c5 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -291,9 +291,11 @@ A list of @code{(filename-regexp, init-function, cleanup-function getfname-function)} for configuring syntax check tools. @xref{Adding support for a new syntax check tool}. +@ignore @item flymake-buildfile-dirs A list of directories (relative paths) for searching a buildfile. @xref{Locating the buildfile}. +@end ignore @item flymake-master-file-dirs A list of directories for searching a master file. @xref{Locating a @@ -675,10 +677,13 @@ buildfile to reference the 'project configuration' file. Special function, @code{flymake-find-buildfile} is provided for locating buildfiles. Searching for a buildfile is done in a manner similar to that of searching -for possible master files. A customizable variable +for possible master files. +@ignore +A customizable variable @code{flymake-buildfile-dirs} holds a list of relative paths to the -buildfile. They are checked sequentially until a buildfile is found. In case -there's no build file, syntax check is aborted. +buildfile. They are checked sequentially until a buildfile is found. +@end ignore +In case there's no build file, syntax check is aborted. Buildfile values are also cached. diff --git a/doc/misc/makefile.w32-in b/doc/misc/makefile.w32-in index 9e577c351b7..84ad720052e 100644 --- a/doc/misc/makefile.w32-in +++ b/doc/misc/makefile.w32-in @@ -54,7 +54,9 @@ INFO_TARGETS = $(infodir)/ccmode$(INFO_EXT) \ $(infodir)/remember$(INFO_EXT) $(infodir)/nxml-mode$(INFO_EXT) \ $(infodir)/epa$(INFO_EXT) $(infodir)/mairix-el$(INFO_EXT) $(infodir)/sasl$(INFO_EXT) \ $(infodir)/auth$(INFO_EXT) $(infodir)/eieio$(INFO_EXT) $(infodir)/ede$(INFO_EXT) \ - $(infodir)/semantic$(INFO_EXT) $(infodir)/edt$(INFO_EXT) $(infodir)/emacs-gnutls$(INFO_EXT) + $(infodir)/semantic$(INFO_EXT) $(infodir)/edt$(INFO_EXT) $(infodir)/emacs-gnutls$(INFO_EXT) \ + $(infodir)/srecode$(INFO_EXT) $(infodir)/bovine$(INFO_EXT) \ + $(infodir)/wisent$(INFO_EXT) DVI_TARGETS = calc.dvi cc-mode.dvi cl.dvi dbus.dvi dired-x.dvi \ ediff.dvi forms.dvi gnus.dvi message.dvi emacs-mime.dvi \ sieve.dvi pgg.dvi mh-e.dvi \ @@ -65,7 +67,8 @@ DVI_TARGETS = calc.dvi cc-mode.dvi cl.dvi dbus.dvi dired-x.dvi \ newsticker.dvi rcirc.dvi erc.dvi ert.dvi \ remember.dvi nxml-mode.dvi \ epa.dvi mairix-el.dvi sasl.dvi auth.dvi eieio.dvi ede.dvi \ - semantic.dvi edt.dvi emacs-gnutls.dvi + semantic.dvi edt.dvi emacs-gnutls.dvi srecode.dvi bovine.dvi \ + wisent.dvi INFOSOURCES = info.texi # The following rule does not work with all versions of `make'. @@ -358,6 +361,21 @@ $(infodir)/emacs-gnutls$(INFO_EXT): emacs-gnutls.texi doclicense.texi emacs-gnutls.dvi: emacs-gnutls.texi doclicense.texi $(ENVADD) $(TEXI2DVI) $(srcdir)/emacs-gnutls.texi +$(infodir)/srecode$(INFO_EXT): srecode.texi doclicense.texi + $(MAKEINFO) $(MAKEINFO_OPTS) $(INFO_OPTS) -o $@ srecode.texi +srecode.dvi: srecode.texi doclicense.texi + $(ENVADD) $(TEXI2DVI) $(srcdir)/srecode.texi + +$(infodir)/bovine$(INFO_EXT): bovine.texi doclicense.texi + $(MAKEINFO) $(MAKEINFO_OPTS) $(INFO_OPTS) -o $@ bovine.texi +bovine.dvi: bovine.texi doclicense.texi + $(ENVADD) $(TEXI2DVI) $(srcdir)/bovine.texi + +$(infodir)/wisent$(INFO_EXT): wisent.texi doclicense.texi + $(MAKEINFO) $(MAKEINFO_OPTS) $(INFO_OPTS) -o $@ wisent.texi +wisent.dvi: wisent.texi doclicense.texi + $(ENVADD) $(TEXI2DVI) $(srcdir)/wisent.texi + mostlyclean: - $(DEL) *.log *.cp *.fn *.ky *.pg *.vr core *.tp *.core gnustmp.* @@ -385,7 +403,9 @@ clean: mostlyclean $(infodir)/epa* $(infodir)/sasl* \ $(infodir)/mairix-el* $(infodir)/auth* \ $(infodir)/eieio* $(infodir)/ede* \ - $(infodir)/semantic* $(infodir)edt* $(infodir)/emacs-gnutls* + $(infodir)/semantic* $(infodir)edt* \ + $(infodir)/emacs-gnutls* $(infodir)/srecode* \ + $(infodir)/bovine* $(infodir)/wisent* distclean: clean - $(DEL) makefile diff --git a/doc/misc/org.texi b/doc/misc/org.texi index 700dffd26bf..b8c385fab29 100644 --- a/doc/misc/org.texi +++ b/doc/misc/org.texi @@ -834,7 +834,6 @@ ends, for example: @r{@bullet{} an environment for literate programming} @end example - @cindex FAQ There is a website for Org which provides links to the newest version of Org, as well as additional information, frequently asked @@ -879,8 +878,6 @@ Lisp and Info files will be installed. If the Emacs binary is not in your path, give the full path to the executable. Avoid spaces in any path names. @item Run @code{make config} again to check the configuration. -@item Optionally run @code{make test} -to build Org mode and then run the full testsuite. @item Run @code{make install} or @code{sudo make install} to build and install Org mode on your system. @end itemize @@ -903,6 +900,8 @@ Emacs binary is not in your path, you must give the full path to the executable. Avoid spaces in any path names. @item Run @code{make config} to check the configuration. +@item Optionally run @code{make test} +to build Org mode and then run the full testsuite. @item Run @code{make update2} or @code{make up2} to update the Git repository and build and install Org mode. The latter invocation runs the complete test suite before installation and installs only @@ -947,7 +946,7 @@ description on Worg}. Installing Info files is system dependent, because of differences in the @file{install-info} program. The Info documentation is installed together with the rest of Org mode. If you don't install Org mode, it is possible to -install the Info documentation separately (you need to have +install the Info documentation seperately (you need to have install-info@footnote{The output from install-info (if any) is system dependent. In particular Debian and its derivatives use two different versions of install-info and you may see the message: @@ -9222,11 +9221,11 @@ a horizontal line (@samp{
} in HTML and @code{\hrule} in @LaTeX{}). @cindex exporting, not @cindex #+BEGIN_COMMENT -Lines starting with zero or more whitespace characters followed by @samp{#} -are treated as comments and will never be exported. Also entire subtrees -starting with the word @samp{COMMENT} will never be exported. Finally, -regions surrounded by @samp{#+BEGIN_COMMENT} ... @samp{#+END_COMMENT} will -not be exported. +Lines starting with zero or more whitespace characters followed by one +@samp{#} and a whitespace are treated as comments and will never be exported. +Also entire subtrees starting with the word @samp{COMMENT} will never be +exported. Finally, regions surrounded by @samp{#+BEGIN_COMMENT} +... @samp{#+END_COMMENT} will not be exported. @table @kbd @kindex C-c ; @@ -13155,8 +13154,8 @@ blocks. @lisp (setq org-babel-default-header-args -(cons '(:noweb . "yes") -(assq-delete-all :noweb org-babel-default-header-args))) + (cons '(:noweb . "yes") + (assq-delete-all :noweb org-babel-default-header-args))) @end lisp @node Language-specific header arguments, Buffer-wide header arguments, System-wide header arguments, Using header arguments @@ -13201,9 +13200,9 @@ blocks in the subtree rooted at the following heading: @example * outline header -:PROPERTIES: -:cache: yes -:END: + :PROPERTIES: + :cache: yes + :END: @end example @kindex C-c C-x p @@ -13247,6 +13246,7 @@ Code block header arguments can span multiple lines using @code{#+HEADER:} or @cindex #+HEADERS: Multi-line header arguments on an un-named code block: + @example #+HEADERS: :var data1=1 #+BEGIN_SRC emacs-lisp :var data2=2 @@ -13258,6 +13258,7 @@ Multi-line header arguments on an un-named code block: @end example Multi-line header arguments on a named code block: + @example #+NAME: named-block #+HEADER: :var data=2 @@ -13280,12 +13281,14 @@ blocks}. The following will apply the @code{:exports results} header argument to the evaluation of the @code{#+CALL:} line. + @example #+CALL: factorial(n=5) :exports results @end example The following will apply the @code{:session special} header argument to the evaluation of the @code{factorial} code block. + @example #+CALL: factorial[:session special](n=5) @end example @@ -13366,6 +13369,7 @@ Here are examples of passing values by reference: @item table an Org mode table named with either a @code{#+NAME:} or @code{#+TBLNAME:} line + @example #+TBLNAME: example-table | 1 | @@ -13948,7 +13952,6 @@ This code block: -- <> @end example - expands to: @example @@ -14331,6 +14334,7 @@ process. For example, compare the following two blocks: @end example In non-session mode, the `2' is not printed and does not appear. + @example #+BEGIN_SRC python :results output :session print "hello" @@ -14705,6 +14709,7 @@ ask and nil not to ask. For example, here is how to execute "ditaa" code (which is considered safe) without asking: + @example (defun my-org-confirm-babel-evaluate (lang body) (not (string= lang "ditaa"))) ; don't ask for ditaa @@ -14806,7 +14811,7 @@ buffer, most useful for specifying the allowed values of a property. @item #+SETUPFILE: file This line defines a file that holds more in-buffer setup. Normally this is entirely ignored. Only when the buffer is parsed for option-setting lines -(i.e., when starting Org mode for a file, when pressing @kbd{C-c C-c} in a +(i.e.@: when starting Org mode for a file, when pressing @kbd{C-c C-c} in a settings line, or when exporting), then the contents of this file are parsed as if they had been included in the buffer. In particular, the file can be any other Org mode file with internal setup. You can visit the file the @@ -15168,7 +15173,7 @@ example using the color @code{grey90} on a white background. Things become cleaner still if you skip all the even levels and use only odd levels 1, 3, 5..., effectively adding two stars to go from one outline level to the next@footnote{When you need to specify a level for a property search -or refile targets, @samp{LEVEL=2} will correspond to 3 stars, etc.}. In this +or refile targets, @samp{LEVEL=2} will correspond to 3 stars, etc@.}. In this way we get the outline view shown at the beginning of this section. In order to make the structure editing and export commands handle this convention correctly, configure the variable @code{org-odd-levels-only}, or set this on @@ -15259,7 +15264,7 @@ names for natural constants or units. Instead of defining your own constants in the variable @code{org-table-formula-constants}, install the @file{constants} package which defines a large number of constants and units, and lets you use unit prefixes like @samp{M} for -@samp{Mega}, etc. You will need version 2.0 of this package, available +@samp{Mega}, etc@. You will need version 2.0 of this package, available at @url{http://www.astro.uva.nl/~dominik/Tools}. Org checks for the function @code{constants-get}, which has to be autoloaded in your setup. See the installation instructions in the file @@ -15401,7 +15406,7 @@ function: @lisp (defun yas/org-very-safe-expand () - (let ((yas/fallback-behavior 'return-nil)) (yas/expand))) + (let ((yas/fallback-behavior 'return-nil)) (yas/expand))) @end lisp Then, tell Org mode what to do with the new function: @@ -15409,10 +15414,10 @@ Then, tell Org mode what to do with the new function: @lisp (add-hook 'org-mode-hook (lambda () - (make-variable-buffer-local 'yas/trigger-key) - (setq yas/trigger-key [tab]) - (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand) - (define-key yas/keymap [tab] 'yas/next-field))) + (make-variable-buffer-local 'yas/trigger-key) + (setq yas/trigger-key [tab]) + (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand) + (define-key yas/keymap [tab] 'yas/next-field))) @end lisp @item @file{windmove.el} by Hovav Shacham @@ -16053,9 +16058,9 @@ The corresponding block writer function could look like this: @lisp (defun org-dblock-write:block-update-time (params) - (let ((fmt (or (plist-get params :format) "%d. %m. %Y"))) - (insert "Last block update at: " - (format-time-string fmt (current-time))))) + (let ((fmt (or (plist-get params :format) "%d. %m. %Y"))) + (insert "Last block update at: " + (format-time-string fmt (current-time))))) @end lisp If you want to make sure that all dynamic blocks are always up-to-date, @@ -16450,8 +16455,8 @@ Entries in comment trees and in archive trees will be ignored. @lisp (org-map-entries - '(org-todo "UPCOMING") - "+TOMORROW" 'file 'archive 'comment) + '(org-todo "UPCOMING") + "+TOMORROW" 'file 'archive 'comment) @end lisp The following example counts the number of entries with TODO keyword @@ -16693,7 +16698,7 @@ on @file{org-element.el} and @file{org-export.el} has been outstanding, and opened the doors for many new ideas and features. @item Jambunathan K -Jambunathan contributed the ODT exporter, definitely a killer feature of +Jambunathan contributed the ODT exporter, definitly a killer feature of Org mode. He also contributed the new HTML exporter, which is another core feature of Org. Here too, I knew I could rely on him to fix bugs in these areas and to patiently explain the users what was the problems and solutions. @@ -16701,7 +16706,7 @@ areas and to patiently explain the users what was the problems and solutions. @item Achim Gratz Achim rewrote the building process of Org, turning some @emph{ad hoc} tools into a flexible and conceptually clean process. He patiently coped with the -many hiccups that such a change can create for users. +many hicups that such a change can create for users. @item Nick Dokos The Org mode mailing list would not be such a nice place without Nick, who diff --git a/doc/misc/srecode.texi b/doc/misc/srecode.texi new file mode 100644 index 00000000000..10a0d8770dc --- /dev/null +++ b/doc/misc/srecode.texi @@ -0,0 +1,1799 @@ +\input texinfo +@c %**start of header +@setfilename ../../info/srecode +@set TITLE SRecoder Manual +@set AUTHOR Eric M. Ludlam +@settitle @value{TITLE} + +@c Merge all indexes into a single index for now. +@c We can always separate them later into two or more as needed. +@syncodeindex vr cp +@syncodeindex fn cp +@syncodeindex ky cp +@syncodeindex pg cp +@syncodeindex tp cp +@c %**end of header + +@copying +Copyright @copyright{} 2007-2012 Free Software Foundation, Inc. + +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with no +Invariant Sections, with the Front-Cover texts being ``A GNU Manual,'' +and with the Back-Cover Texts as in (a) below. A copy of the license +is included in the section entitled ``GNU Free Documentation License''. + +(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and +modify this GNU manual. Buying copies from the FSF supports it in +developing GNU and promoting software freedom.'' +@end quotation +@end copying + +@dircategory Emacs misc features +@direntry +* SRecode: (srecode). Template code generator. +@end direntry + +@titlepage +@sp 10 +@center @titlefont{SRecode} +@vskip 0pt plus 1 fill +@center by @value{AUTHOR} +@end titlepage + +@macro semantic{} +@i{Semantic} +@end macro + +@macro EIEIO{} +@i{EIEIO} +@end macro + +@macro srecode{} +@i{SRecode} +@end macro + +@node Top +@top @value{TITLE} + +@srecode{} is the @i{Semantic Recoder}. Where @semantic{} will parse +source files into lists of tags, the @i{Semantic Recoder} will aid in +converting @semantic{} tags and various other information back into +various types of code. + +While the @srecode{} tool provides a template language, templates for +several languages, and even a sequence of heuristics that aid the user +in choosing a template to insert, this is not the main goal of +@srecode{}. + +The goal of @srecode{} is to provide an application framework where +someone can write a complex code generator, and the underlying +template commonality allows it to work in multiple languages with +ease. + +@ifnottex +@insertcopying +@end ifnottex + +@menu +* Quick Start:: Basic Setup for template insertion. +* User Templates:: Custom User Templates +* Parts of SRecode:: Parts of the system +* SRecode Minor Mode:: A minor mode for using templates +* Template Writing:: How to write a template +* Dictionaries:: How dictionaries work +* Developing Template Functions:: How to write your own template insert functions. +* Template Naming Conventions:: Creating a set of core templates +* Inserting Tag Lists:: Inserting Semantic tags via templates +* Application Writing:: Writing an @srecode{}r application +* GNU Free Documentation License:: The license for this documentation. +* Index:: +@end menu + + +@node Quick Start +@chapter Quick Start + +When you install CEDET and enable @srecode{}, an @code{SRecoder} menu +item should appear. + +To toggle @srecode{} minor mode on and off use: + +@example +M-x srecode-minor-mode RET +@end example +or +@example +M-x global-srecode-minor-mode RET +@end example + +or add + +@example +(srecode-minor-mode 1) +@end example + +into a language hook function to force it on (which is the default) or +pass in @code{-1} to force it off. + +See @ref{SRecode Minor Mode} for more on using the minor mode. + +Use the menu to insert templates into the current file. + +You can add your own templates in @file{~/.srecode}, or update the +template map path: + +@deffn Option srecode-map-load-path +@anchor{srecode-map-load-path} +Global load path for SRecode template files. +@end deffn + + +Once installed, you can start inserting templates using the menu, or +the command: + +@deffn Command srecode-insert template-name &rest dict-entries +@anchor{srecode-insert} +Insert the template @var{template-name} into the current buffer at point. +@var{dict-entries} are additional dictionary values to add. +@end deffn + +SRecode Insert will prompt for a template name. Template names are +specific to each major mode. A typical name is of the form: +@code{CONTEXT:NAME} where a @var{CONTEXT} might be something like +@code{file} or @code{declaration}. The same @var{NAME} can occur in +multiple contexts. + +@node User Templates +@chapter User Templates + +@srecode{} builds and maintains a map of all template files. The root +template files resides in the @srecode{} distribution. User written +templates files are saved in @file{~/.srecode}, along with the +@srecode{} map file. + +@defvar srecode-map-save-file +@anchor{srecode-map-save-file} +The save location for SRecode's map file. +@end defvar + +Template files end with a @file{.srt} extension. Details on how to +write templates are in @ref{Template Writing}. + +Each template file you write is dedicated to a single major mode. In +it, you can write templates within the same context and with the same +name as core templates. You can force your templates to override the +core templates for a particular major mode by setting the +priority. See @ref{Special Variables}. + +To get going quickly, open a new @file{.srt} file. It will start in +the @srecode{} template writing mode. Use the @srecode{} minor mode +menu to insert the @code{empty} file template. + +When using templates in other modes (such as C++ or Emacs Lisp +templates), use the ``Edit Template'' menu to find a template you +would like to update. Copy it into your user template file, and +change it. + +If you were to update @code{declaration:function} in your user +template file, then you would get this new template instead of the one +that comes with @srecode{}. Higher level applications should always +use @code{declaration:function} when generating their own code, so +higher level templates will then adopt your changes to +@code{declaration:function} into themselves. + +You can also override variables. Core variables are stored in the +@srecode{} root template file @file{default.srt}, and that contains +the copyright usually used, and some basic file setup formats. +Override variables like this by specifying a @code{mode} of +@code{default} like this: + +@example +set mode "default" +@end example + +@node Parts of SRecode +@chapter Parts of SRecode + +The @srecode{} system is made up of several layers which work together +to generate code. + +@section Template Layer +The template layer provides a way to write, and compile templates. The +template layer is the scheme used to insert text into an Emacs buffer. + +The @srecode{} template layer is more advanced than other modes like the +Emacs packages @code{skeleton} or @code{tempo} in that it allows +multiple layers of templates to be created with the same names. This +means that @srecode{} can provide a wide range of templates, and users +can override only the small sections they want, instead of either +accepting someone else's template, or writing large new templates of +their own. + +Templates are written in @file{.srt} files. You can learn how to +author new @file{.srt} files @ref{Template Writing}. + +While the template system was designed for @srecode{} based +applications it can also be used independently for simple template +insertion during typical coding. + +@section Template Manager +Once templates have been written, a scheme for loading and selecting +templates is needed. The template manager has a loader for finding +template files, and determining which templates are relevant to the +current buffer. Template files are sorted by priority, with user +templates being found first, and system level default templates last. +Templates are also sorted by application. Each application has its +own templates, and are kept seperate from the generic templates. + +@section Dictionary +Dictionaries contain values associated with variable. Variables are +used in macros in a template. Variables are what allows a generic +template such as a function to be made specific, such as a function +named foo. The value of a variable can be one of three things; a +string, a list of more dictionaries, or a special +@code{srecode-dictionary-compound-value} object subclass. See +@ref{Variables} for more. + +@section Template Insertion +The template insertion layer involves extensions to the basic template +layer. A wide range of custom variables are available for mixing derived +data as macros into the plain text of a template. + +In addition, templates can be declared with arguments. These +arguments represent predetermined sets of dictionary values, such as +features of the current file name, user name, time, etc. + +Some arguments are major-mode specific, such as the @code{:el} or +@code{:cpp} arguments. +@refill + +@section Template Insertion Context +A context can be provided for templates in a file. This helps +auto-selection of templates by name, or allows templates in different +contexts to have the same name. Some standard contexts are +@code{file}, @code{declaration}, and @code{classdecl}. + +A context can be automatically derived as well based on the parsing +state from @i{Semantic}. @inforef{Top, Semantic Manual, semantic}. +@refill + +@section Applications +Commands that do a particular user task which involves also writing +Emacs Lisp code. Applications are at the top layer. These +applications have their own template files and logic needed to fill in +dictionaries or position a cursor. SRecode comes with an example +@code{srecode-document} application for creating comments for Semantic +tags. The CEDET application @i{EDE} has a project type that is an +@srecode{} application. + +@section Field Editing +If the variable @code{srecode-insert-ask-variable-method} is set to +'field, then variables that would normally ask a question, will +instead create ``fields'' in the buffer. A field-editing layer +provides simple interaction through the fields. Typing in a field +will cause all variable locations that are the same to edit at the +same time. Pressing TAB on a field will move you to the next field. + +@node SRecode Minor Mode +@chapter SRecode Minor Mode + +The Semantic Recode minor mode enables a keymap and menu that provides +simple access to different templates or template applications. + +The key prefix is @key{C-c /}. + +If the variable @code{srecode-takeover-INS-key} is set, then the key +@key{} can also be used. + +The most important key is bound to @code{srecode-insert} which is +@key{C-c / /}, or @key{insert insert}. @ref{Quick Start}. + +Major keybindings are: + +@table @key +@item C-c / / +Insert a template whose name is typed into the minibuffer. +@item C-c / +Reserved for direct binding of simple templates to keys using a +keybinding command in the template file. +@item C-c / +Reserved for template applications (Such as comment or get/set inserter.) +@item C-c / E +Edit the code of a template. +@item C-c / . +Insert template again. This will cause the previously inserted +template to be inserted again. +@end table + +@section Field Editing + +By default, when inserting a template, if the user needs to enter text +to fill in a part of the template, then the minibuffer is used to +query for that information. SRecode also supports a field-edting mode +that can be used instead. To enable it set: + +@defun srecode-insert-ask-variable-method +@anchor{srecode-insert-ask-variable-method} +Determine how to ask for a dictionary value when inserting a template. +Only the @var{ASK} style inserter will query the user for a value. +Dictionary value references that ask begin with the ? character. +Possible values are: +@table @code +@item ask +Prompt in the minibuffer as the value is inserted. +@item field +Use the dictionary macro name as the inserted value, +and place a field there. Matched fields change together. +@end table + +@b{NOTE}: The field feature does not yet work with XEmacs. +@end defun + +Field editing mode is supported in newer versions of Emacs. You +will not be prompted to fill in values while the template is +inserted. Instead, short regions will be highlighted, and the cursor +placed in a field. Typing in the field will then fill in the value. +Several fields might be linked together. In that case, typing in one +area will modify the other linked areas. Pressing TAB will move +between editable fields in the template. + +Once the cursor moves out of the are inserted by the template, all the +fields are cancelled. + +@b{NOTE}: Some conveniences in templates, such as completion, or +character restrictins are lost when using field editing mode. + +@node Template Writing +@chapter Template Writing +@anchor{@code{SRecode-template-mode}} + +@code{srecode-template-mode} is the major mode used for designing new +templates. @srecode{} files (Extension @file{.srt}) are made up of +variable settings and template declarations. + +Here is an overview of the terminology you will need for the next few +sections: + +@table @asis +@item template file +A file with a @file{.srt} extension which contains settings, +variables, and templates. +@item template +One named entity which represents a block of text that will be +inserted. The text is compiled into a sequence of insertable +entities. The entities are string constants, and macros. +@item macro +A macro is a text sequence within template text that is replaced with +some other value. +@item dictionary +A table of variable names and values. +@item subdictionary +A dictionary that is subordinate under another dictionary as a value +to some variable. +@item variable +A variable is an entry in a dictionary which has a value. +@end table + +@menu +* Variables:: Creating special and regular variables. +* Templates:: Creating templates +* Contexts:: Templates are grouped by context +* Prompts:: Setting prompts for interactive insert macros +@end menu + +@node Variables +@section Variables + +Variables can be set up and used in templates. Many variables you may +use are set up via template arguments, but some may be preferences a +user can set up that are used in system templates. + +When expanding a template, variables are stored in a @dfn{dictionary}. +Dictionary entries are variables. Variables defined in templates can +have string like values. + +A variable can be set like this: +@example +set VARNAME "some value" +@end example + +Note that a VARIABLE is a name in a dictionary that can be used in a +MACRO in a template. The macro referernces some variable by name. + +@menu +* String Values:: Basic Variable values +* Multi-string Values:: Complex variable values +* Section Show:: Enabling the display of a named section. +* Special Variables:: Variables with special names +* Automatic Loop Variables:: Variables automatically set in section loops. +* Compound Variable Values:: Compound Variable Values +@end menu + +@node String Values +@subsection String Values + +Variables can be set to strings. Strings may contain newlines or any +other characters. Strings are interpreted by the Emacs Lisp reader so +@code{\n}, @code{\t}, and @code{\"} work. + +When a string is inserted as part of a template, nothing within the +string is interperted, such as template escape characters. + +@node Multi-string Values +@subsection Multi-string Values + +A variable can be set to multiple strings. A compound value is +usually used when you want to use dictionary entries as part of a +variable later on. + +Multi-string variable values are set like string values except there +are more than one. For example + +@example +set NAME "this" "-mode" +@end example + +These two strings will be concatenated together. + +A more useful thing is to include dictionary variables and concatenate +those into the string. Use the ``macro'' keyword to include the name +of a variable. This is like macros in a template. For example: + +@example +set NAME macro "MODE" "-mode" +@end example + +will extract the value of the dictionary variable MODE and append +``-mode'' to the end. + +@node Section Show +@subsection Section Show + +To set a variable to show a template section, use the @code{show} +command. Sections are blocks of a template wrapped in section macros. +If there is a section macro using @var{NAME} it will be shown for each +dictionary associated with the @var{NAME} macro. + +@example +show NAME +@end example + +This will enable that section. + + +NOTE: May 11, 2008 - I haven't used this yet, so I don't know if it works. + + +@node Special Variables +@subsection Special Variables + +Some variables have special meaning that changes attributes when +templates are compiled, including: + +@table @code +@item escape-start +This is the character sequence that escapes from raw text to template +macro names. The ability to change the escape characters are key for +enabling @srecode{} templates to work across many kinds of languages. +@item escape-end +This is the character sequence that escapes the end of a template +macro name. + +Example: +@example +set escape_start "$" +set escape_end "$" +@end example +@item mode +This is the major mode, as a string with the full Emacs Lisp symbol in +it. All templates in this file will be installed into the template +table for this major mode. + +Multiple template files can use the same mode, and all those templates +will be available in buffers of that mode. + +Example: +@example +set mode "emacs-lisp-mode" +@end example + +@item priority +The priority of a file is a number in a string constant that +indicates where it lies in the template search order. System +templates default to low priority numbers. User templates default to +high priority numbers. You can specify the priority of your template +to insert it anywhere in the template search list. + +If there are multiple templates with the same context and name, the +template with the highest priority number will be used. + +If multiple files have the same priority, then then sort order is +unpredictable. If no template names match, then it doesn't matter. + +Example: +@example +set priority "35" +@end example + +@item application +If a template file contains templates only needed for a particular +application, then specify an application. Template files for an +application are stored in the template repository, but are not used in +the generic template insertion case. + +The application with a particular name will access these templates +from Lisp code. + +Example: +@example +set application "document" +@end example + +@item project +If a template file contains templates, or template overrides specific +to a set of files under a particular directory, then that template +file can specify a ``project'' that it belongs to. + +Set the ``project'' special variable to a directory name. Only files +under that directory will be able to access the templates in that +file. + +Any template file that has a project specified will get have a +priority that is set between SRecode base templates, and user defined +templates. + +Templates can be compiled via a project system, such as EDE. EDE +loaded templates will get a @var{project} set automatically. + +Example: +@example +set project "/tmp/testproject" +@end example + +@end table + +If you need to insert the characters that belong to the variables +@code{escape_start} or @code{escape_end}, then place those into +a variable. For example + +@example +set escape_start "$" +set escape_end "$" +set DOLLAR "$" +@end example + +@node Automatic Loop Variables +@subsection Automatic Loop Variables + +When section macros are used, that section is repeated for each +subdictionary bound to the loop variable. + +Each dictionary added will automatically get values for positional +macros which will enable different @var{sections}. The automatic +section variables are. + +@itemize @bullet +@item @var{first} - The first entry in the table. +@item @var{notfirst} - Not the first entry in the table. +@item @var{last} - The last entry in the table +@item @var{notlast} - Not the last entry in the table. +@end itemize + +@node Compound Variable Values +@subsection Compound Variable Values + +A variable can also have a compound value. This means the value of +the variable is an @EIEIO{} object, which is a subclass of +@code{srecode-dictionary-compound-value}. + +New compound variables can only be setup from Lisp code. See +@ref{Compound Dictionary Values} for details on setting up compound +variables from Lisp. + +@node Templates +@section Templates + +A template represents a text pattern that can be inserted into +a buffer. + +A basic template is declaired like this: + +@example +template TEMPLATENAME :arg1 :arg2 +"Optional documentation string" +---- +The text to your template goes here. +---- +bind "a" +@end example + +Templates are stored in a template table by name, and are inserted by +the @var{templatename} provided. + +The documentation string is optional. This documentation string will +be used to aid users in selecting which template they want to use. + +The code that makes up the raw template occurs between the lines that +contain the text "-----". + +@menu +* Template Section Dictionaries:: Template Scoped Macro values +* Template Macros:: Macros occuring in template patterns +@end menu + +@node Template Section Dictionaries +@subsection Template Section Dictionaries + +To add variable values to section dictionaries used within a specific +template, you can add them to the beginning of the template +declaration like this: + +@example +template TEMPLATENAME :arg1 :arg2 +"Optional documentation string" +sectiondictionary "A" +set NAME "foo" +---- +A beginning line @{@{NAME@}@} +@{@{#A@}@}Optional string @{@{NAME@}@} here@{@{/A@}@} +An end line +---- +@end example + +In this example, the @var{NAME} variable gets the value ``foo'', but +only while it is inside section macro A. The outer scoped NAME will +be empty. + +This is particularly useful while using an include macro to pull in a +second template. In this way, you can pass values known from one +template to a subordinate template where some value is not known. + +From the Emacs Lisp default template file, a syntax table is just a +variable with a specialized value. + +If a variable is declared like this (where $ is the escape character): + +@example +template variable :el +"Insert a variable. +DOC is optional." +---- +(defvar $?NAME$ $^$ + "$DOC$") +---- +@end example + +then you can see that there is a NAME and DOC that is needed. +The @code{^} point inserter is also a handy key here. + +The syntax table wants a variable, but knows the values of some of +these variables, and can recast the problem like this by using +template specific @code{sectiondictionary} macro declarations. + +@example +template syntax-table +"Create a syntax table." +sectiondictionary "A" +set NAME macro "?MODESYM" "-mode-syntax-table" +set DOC "Syntax table used in " macro "?MODESYM" " buffers." +---- +$'' will include another template. Include +macros would look like this: + +@example +@{@{>FOO:defun@}@} +@end example + +where @code{FOO} is the dictionary variable for the sub-dictionary used for +expanding the template @code{defun}. The @code{defun} template will +be looked up in the template repository for the current mode, or in +any inherited modes. + +Another way to include another template is with an include macro that +will also wrap section text. The includewrap insertion method looks +like this: + +@example +@{@{FOO:declaration:function@}@} +@end example + +@node Contexts +@section Context + +Each template belongs to a context. When promting for a template by +name, such as with @kbd{C-c / /}, the name is prefixed by the current +context. If there is no context, it defaults to @code{declaration}. + +You can change context like this: + +@example +context NAME +@end example + +where @var{name} is some symbol that represents any context. + +A context resides over all templates that come after it until the next +context statement. Thus: + +@example +context C1 + +template foo +"Foo template in C1" +---- +---- + +context C2 + +temlate foo +"Foo template in C2" +---- +---- +@end example + +creates two @code{foo} templates. The first one is when in context +C1. The second is available in context C2. + +This is useful if there are multiple ways to declare something like a +function or variable that differ only by where it is in the syntax of +the lanugage. The name @code{foo} is not ambiguous because each is in +a different context. + +@node Prompts +@section Prompt + +Some templates use promtping macro insertion. A macro that needs a +prompt looks like this: + +@example +@{@{?NAME@}@} +@end example + +where ? comes after the first escape character. + +by default, it will use a prompt like this when it is encountered: + +@example +Specify NAME: +@end example + +For such macros, you can pre-define prompts for any dictionary entry. +When that dictionary entry is first encountered, the user is prompted, +and subsequent occurances of that dictionary entry use the same value. + +To get a different prompt, use a prompt command like this: + +@example +prompt VARNAME "Nice Way to ask for VARNAME: " +@end example + +Now, if you put this in a template: + +@example +template variable +---- +(defvar @{@{?VARNAME@}@} nil + "") +---- +@end example + +when VARNAME is encountered, it will use the nice prompt. + +Prompts can be extended as well. For example: + +@example +prompt VARNAME "VARNAME: " default "srecode" read y-or-n-p +@end example + +In this case, the @code{default} keyword indicates that +@code{"srecode"} is the default string to use, and @code{y-or-n-p} is +the function to use to ask the question. + +For @code{y-or-n-p} if you type ``y'' it inserts the default string, +otherwise it inserts empty. + +For any other symbol that occurs after the @code{read} token, it is +expected to take the same argument list as @code{read-string}. As +such, you can create your own prompts that do completing reads on +deterministic values. + +To have the default be calculated later from a dictionary entry, you +need to use the @code{defaultmacro} keyword instead. + +@example +prompt VARNAME "Varname: " defaultmacro "PREFIX" +@end example + +now, when it attempts to read in VARNAME, it will pre-populte the text +editing section with whatever the value of PREFIX is. + +Some language arguments may supply possible prefixes for prompts. +Look for these when creating your prompts. + +@node Dictionaries +@chapter Dictionaries + +Dictionaries are a set of variables. The values associated with the +variable names could be anything, but how it is handled is dependent +on the type of macro being inserted. + +Most of this chapter is for writing Lisp programs that use @srecode{}. +If you only want to write template files, then you only need to read +the @ref{Template Argument Dictionary Entries} section. + +@menu +* Create a Dictionary:: +* Setting Dictionary Values:: Basic dictionary values +* Compound Dictionary Values:: Complex dictionary values +* Argument Resolution:: Automatic template argument resolution +* Creating new Arguments:: Create new arguments for use in templates +* Querying a Dictionary:: Querying a dictionary for values. +* Template Argument Dictionary Entries:: Catalog of arguments +@end menu + +@node Create a Dictionary +@section Create a Dictionary + +@defun srecode-create-dictionary &optional buffer +@anchor{srecode-create-dictionary} +Create a dictionary for @var{buffer}. +If @var{buffer} is not specified, use the current buffer. +The dictionary is initialized with no variables or enabled sections. +Any variables defined with @code{set} in the template, however, +becomes a name in the dictionary. +@end defun + +@node Setting Dictionary Values +@section Setting Dictionary Values + +When building an @srecode{} based application, you will need to setup +your dictionary values yourself. There are several utility functions +for this. + +In the simplest form, you can assocate a string with a variable. + +@defun srecode-dictionary-set-value dict name value +@anchor{srecode-dictionary-set-value} +In dictionary @var{dict}, set @var{name} to have @var{value}. +@end defun + +For section macros, you can have alternate values. A section can +either be toggled as visible, or it can act as a loop. + +@defun srecode-dictionary-show-section dict name +@anchor{srecode-dictionary-show-section} +In dictionary @var{dict}, indicate that the section @var{name} should be exposed. +@end defun + + +@defun srecode-dictionary-add-section-dictionary dict name show-only +@anchor{srecode-dictionary-add-section-dictionary} +In dictionary @var{DICT}, add a section dictionary for section macro @var{NAME}. +Return the new dictionary. + +You can add several dictionaries to the same section entry. +For each dictionary added to a variable, the block of codes in +the template will be repeated. + +If optional argument @var{SHOW-ONLY} is non-@code{nil}, then don't add a new dictionarly +if there is already one in place. Also, don't add @var{FIRST}/@var{LAST} entries. +These entries are not needed when we are just showing a section. + +Each dictionary added will automatically get values for positional macros +which will enable @var{SECTIONS} to be enabled. + +@table @var +@item first +The first entry in the table. +@item notfirst +Not the first entry in the table. +@item last +The last entry in the table +@item notlast +Not the last entry in the table. +@end table + +Adding a new dictionary will alter these values in previously +inserted dictionaries. +@end defun + +@node Compound Dictionary Values +@section Compound Dictionary Values + +If you want to associate a non-string value with a dictionary +variable, then you will need to use a compound value. Compound +dictionary values are derived using @EIEIO{} from a base class for +handling arbitrary data in a macro. + +@deffn Type srecode-dictionary-compound-value +@anchor{srecode-dictionary-compound-value} +A compound dictionary value. +Values stored in a dictionary must be a @var{string}, +a dictionary for showing sections, or an instance of a subclass +of this class. + +Compound dictionary values derive from this class, and must +provide a sequence of method implementations to convert into +a string. +@end deffn + +Your new subclass of the compound value needs to implement these +methods: + +@defun srecode-compound-toString cp function dictionary +@anchor{srecode-compound-toString} +Convert the compound dictionary value @var{cp} to a string. +If @var{function} is non-@code{nil}, then @var{function} is somehow applied to an aspect +of the compound value. The @var{function} could be a fraction +of some function symbol with a logical prefix excluded. +@end defun + +The next method is for dumping out tables during debugging. + +@defun srecode-dump cp &optional indent +@anchor{srecode-dump} +Display information about this compound value. +@end defun + + +Here is an example of wrapping a semantic tag in a compound value: + +@example +(defclass srecode-semantic-tag (srecode-dictionary-compound-value) + ((prime :initarg :prime + :type semantic-tag + :documentation + "This is the primary insertion tag.") + ) + "Wrap up a collection of semantic tag information. +This class will be used to derive dictionary values.") + +(defmethod srecode-compound-toString((cp srecode-semantic-tag) + function + dictionary) + "Convert the compound dictionary value CP to a string. +If FUNCTION is non-nil, then FUNCTION is somehow applied to an +aspect of the compound value." + (if (not function) + ;; Just format it in some handy dandy way. + (semantic-format-tag-prototype (oref cp :prime)) + ;; Otherwise, apply the function to the tag itself. + (funcall function (oref cp :prime)) + )) +@end example + +@node Argument Resolution +@section Argument Resolution + +Some dictionary entries can be set via template arguments in the +template declaration. For examples of template arguments, see +@ref{Template Argument Dictionary Entries}. + + You can resolve an argument list into a dictionary with: + +@defun srecode-resolve-arguments temp dict +@anchor{srecode-resolve-arguments} +Resolve all the arguments needed by the template @var{temp}. +Apply anything learned to the dictionary @var{dict}. +@end defun + +@node Creating new Arguments +@section Creating new Arguments + +You can create new arguments for use in template files by writing new +Emacs Lisp functions. Doing so is easy. Here is an example for the +@code{:user} argument: + +@example +(defun srecode-semantic-handle-:user (dict) + "Add macros into the dictionary DICT based on the current :user." + (srecode-dictionary-set-value dict "AUTHOR" (user-full-name)) + (srecode-dictionary-set-value dict "LOGIN" (user-login-name)) + ;; ... + ) +@end example + +In this case, a function with the name prefix +@code{srecode-semantic-handle-} that ends in @code{:user} creates a +new argument @code{:user} that can be used in a template. + +Your argument handler must take one argument @var{dict}, which is the +dictionary to fill in. Inside your function, you can do whatever you +want, but adding dictionary values is the right thing. + +@node Querying a Dictionary +@section Querying a Dictionary + +When creating a new argument, it may be useful to ask the dicitonary +what entries are already set there, and conditionally create new +entries based on those. + +In this way, a template author can get additional logic through more +advanced arguments. + +@defun srecode-dictionary-lookup-name dict name +@anchor{srecode-dictionary-lookup-name} +Return information about the current @var{DICT}'s value for @var{NAME}. +@var{DICT} is a dictionary, and @var{NAME} is a string that is the name of +a symbol in the dictionary. +This function derives values for some special NAMEs, such as @var{FIRST} +and '@var{LAST}'. +@end defun + + + +@node Template Argument Dictionary Entries +@section Template Argument Dictionary Entries + +When a dictionary is initialized for a template, then the dictionary +will be initialized with a predefined set of macro values. + +A template of the form: + +@example +template template-name :arg1 :arg2 +---- +Your template goes here +---- +@end example + +specifies two arguments :arg1, and :arg2. + +The following built-in simple arguments are available: + +@menu +* Base Arguments:: +* Semantic Arguments:: +* Language Arguments:: +@end menu + +@node Base Arguments +@subsection Base Arguments + +@subsubsection Argument :indent + +Supplies the @code{INDENT} macro. When @code{INDENT} is non-nil, then +each line is individually indented with +@code{indent-according-to-mode} during macro processing. + +@subsubsection Argument :blank + +Specifying this argument adds a special @code{:blank} handler at the +beginning and end of the template. This handler will insert @code{\n} +if the insertion point is not on a line by itself. + +@subsubsection Argument :region + +If there is an active region via @code{transient-mark-mode}, or +@code{mouse-drag-region}, then the @code{REGION} section will be +enabled. + +In addition, @code{REGIONTEXT} will be set the the text in the region, +and that region of text will be ``killed'' from the current buffer. + +If standard-output is NOT the current buffer, then the region will not +be deleted. In this way, you can safely use @code{:region} using +templates in arbitrary output streams. + +@subsubsection Argument :user + +Sets up variables about the current user. + +@table @code +@item AUTHOR +Value of the Emacs function @code{user-full-name} +@item EMAIL +Current Emacs user's email address. +@item LOGIN +Current Emacs user's login name. +@item UID +Current Emacs user's login ID. +@item EMACSINITFILE +This Emacs sessions' init file. +@end table + +@subsubsection Argument :time + +Sets up variables with the current date and time. + +@table @code +@item YEAR +The current year. +@item MONTH +The current month as a number. +@item MONTHNAME +The current month name, unabbreviated. +@item DAY +The current day as a number. +@item WEEKDAY +The current day of the week as an abbreviated name +@item HOUR +The current hour in 24 hour format. +@item HOUR12 +The current hour in 12 hour format. +@item AMPM +Locale equivalent of AM or PM. Usefule with HOUR12. +@item MINUTE +The current minute. +@item SECOND +The current second. +@item TIMEZONE +The timezone string. +@item DATE +The Locale supported date (%D). +@item TIME +The Locale supported time format (%X). +@end table + +@subsubsection Argument :file + +Sets up variables with details about the current file. + +@table @code +@item FILENAME +The filename without the directory part of the current buffer. +@item FILE +The filename without the directory or extension +@item EXTENSION +The filename extension. +@item DIRECTORY +The directory in which the current buffer resides. +@item MODE +Major mode of this buffer. +@item SHORTMODE +Major mode of this buffer without ``-mode''. +Useful for inserting the Emacs mode specifier. +@item section RCS +Show the section RCS if there is a CVS or RCS directory here. +@end table + +@subsubsection Argument :system + +Sets up variables with computer system information. + +@table @code +@item SYSTEMCONF +The ``system-configuration''. +@item SYSTEMTYPE +The ``system-type''. +@item SYSTEMNAME +The ``system-name''. +@item MAILHOST +The name of the machine Emacs derived mail ``comes from''. +@end table + +@subsubsection Argument :kill + +@table @code +@item KILL +The top-most item from the kill ring. +@item KILL2 +The second item in the kill ring. +@item KILL3 +The third item in the kill ring. +@item KILL4 +The fourth item in the kill ring. +@end table + +@node Semantic Arguments +@subsection Semantic Arguments + +@subsubsection Argument :tag + +The :tag argument is filled in with information from Semantic. +The tag in question is queried from the senator tag ring, or passed +in from @srecode{} utilities that use tags in templates. + +@table @code +@item TAG +This is a compound value for the tag in the current senator kill ring, +or something handled via the variable +@code{srecode-semantic-selected-tag}. + +@defvar srecode-semantic-selected-tag +@anchor{srecode-semantic-selected-tag} +The tag selected by a @code{:tag} template argument. +If this is @code{nil}, then @code{senator-tag-ring} is used. +@end defvar + +Use the function part of a macro insert to extract obscure parts +of the tag. +@item NAME +The name of the tag as a string. +@item TYPE +The data type of the tag as a string. +@end table + +If @var{tag} is a function, you will get these additional dictionary +entries. + +@table @code +@item ARGS +A Loop macro value. Each argument is inserted in ARGS. To create a +comma separated list of arguments, you might do this: + +@example +@{@{#ARGS@}@}@{@{TYPE@}@} @{@{NAME@}@}@{@{#NOTLAST@}@},@{@{/NOTLAST@}@}@{@{/ARGS@}@} +@end example + +Within the section dictionaries for each argument, you will find both +@var{NAME} and @var{TYPE}, in addition to the automatic section values +for @var{FIRST}, @var{LAST}, @var{NOTFIRST}, and @var{NOTLAST}. +@item PARENT +The string name of the parent of this function, if the function is a +method of some class. +@item THROWS +In each @var{THROWS} entry, the @var{NAME} of the signal thrown is specified. +@end table + +If @var{tag} is a variable, you will get these dictionary entries. + +@table @code +@item DEFAULTVALUE +Enabled if there is a @var{VALUE}. +@item VALUE +An entry in the @var{HAVEDEFAULT} subdictionary that represents the +textual representation of the default value of this variable. +@end table + +If @var{tag} is a datatype, you will get these dictionary entries. + +@table @code +@item PARENTS +Section dictionaries for the parents of this class. Each parent will +have a @var{NAME}. +@item INTERFACES +Section dictionaries for all the implemented interfaces of this +class. Each interface will have a @var{NAME}. +@end table + +Note that data type templates should always have a @code{@{@{^@}@}} +macro in it where the core contents of that type will go. This is why +data types don't have subdictionaries full of the slots in the classes +or structs. + +@node Language Arguments +@subsection language Arguments + +Each language typically has its own argument. These arguments can be +used to fill in language specific values that will be useful. + +@subsubsection Argument :srt + +Used for SRecoder template files. + +@table @code +@item ESCAPE_START +The characters used for an escape start +@item ESCAPE_END +The characters used for an escape end +@end table + +@subsubsection Argument :cpp + +@table @code +@item HEADER +Shows this section if the current file is a header file. +@item NOTHEADER +The opposite of @code{HEADER}. +@item FILENAME_SYMBOL +The current filename reformatted as a C friendly symbol. +@end table + +@subsection Argument :java + +@table @code +@item FILENAME_AS_PACKAGE +Converts the filename into text that would be suitable as a package +name. +@item FILENAME_AS_CLASS +Converts the filename into text that would be suitable as a class-name +for the main class in the file. +@item CURRENT_PACKAGE +Finds the occurance of ``package'' and gets its value. +@end table + +@subsubsection Argument :el + +Sets @code{PRENAME}. This would be a common prefix from all the +tags in the current buffer. + +Most Emacs Lisp packages have some common prefix used in a way similar +to namespaces in other languages. + +@subsubsection Argument :el-custom + +@table @code +@item GROUP +The name of the Emacs Custom group that instances of @code{defcustom} +ought to use. +@item FACEGROUP +The name of the Emacs Custom group that faces delcared with +@code{defface} ought to use. +@end table + +@subsubsection Argument :texi + +@table @code +@item LEVEL +The current section level, such as @code{chapter} or @code{section}. +@item NEXTLEVEL +The next level down, so if @code{LEVEL} is @code{chapter}, then +@code{NEXTLEVEL} would be @code{section}. +@end table + +@subsubsection Argument :texitag + +The @code{:texitag} argument is like the @code{:tag} argument, except that +additional variable @code{TAGDOC} is provided for each tag. + +The @code{TAGDOC} is filled with derived documentation from the tag in +question, and that documentation is also reformatted to be mostly +texinfo compatible. + +@subsection Argument :android + +The @code{:android} argument pulls in information from your current +project. + +@@TODO - add more here. + +@node Developing Template Functions +@chapter Developing Template Functions + +You can develop your own custom template insertion functions. +Doing so is relatively simple, and requires that you write an Emacs +Lisp command. + +If the built in commands don't provide enough options, you will need +to write your own function in order to provide your dictionaries with +the values needed for custom templates. + +In this way, you can build your own code generator for any language +based on a set of predefined macros whos values you need to derive +from Emacs Lisp code yourself. + +For example: + +@example +(defun my-srecode-insert (template-name) + "Insert the template TEMPLATE-NAME into the current buffer at point." + + ;; Read in a template name. + (interactive (list (srecode-read-template-name "Template Name: "))) + (if (not (srecode-table)) + (error "No template table found for mode %s" major-mode)) + (let ((temp (srecode-template-get-table (srecode-table) template-name)) + + ;; Create a new dictionary + (newdict (srecode-create-dictionary))) + + (if (not temp) + (error "No Template named %s" template-name)) + + ;; Add some values into the dictionary! + (srecode-dictionary-set-value newdict "FOO" (my-get-value-of-foo)) + ;; Optionally show a section + (srecode-dictionary-show-section newdict "BLARG") + + ;; Add in several items over a loop + (let ((my-stuff (get-my-stuff-list))) + (while my-stuff + (let ((subdict (srecode-dictionary-add-section-dictionary + newdict "LOOP"))) + (srecode-dictionary-set-value subdict "NAME" (nth 0 my-stuff)) + (srecode-dictionary-set-value subdict "ARG" (nth 1 my-stuff)) + (srecode-dictionary-set-value subdict "MOOSE" (nth 2 my-stuff)) + ) + (setq my-stuff (cdr my-stuff))) + + ;; Some templates have arguments that need to be resolved. + (srecode-resolve-arguments temp newdict) + + ;; Do the expansion + (srecode-insert-fcn temp newdict) + )) +@end example + +Lets look at the key functions involved above: + +@section Interactive Completion: + +@defun srecode-read-template-name prompt +@anchor{srecode-read-template-name} +Completing read for Semantic Recoder template names. +@var{prompt} is used to query for the name of the template desired. +@end defun + +@section Template Lookup + +Even if your program does not query the user for a template name, you +will need to locate a template. First, you need to locate the table +to look the template up in. + +@defun srecode-table &optional mode +@anchor{srecode-table} +Return the currently active Semantic Recoder table for this buffer. +Optional argument @var{MODE} specifies the mode table to use. +@end defun + + +@defun srecode-template-get-table tab template-name &optional context application +@anchor{srecode-template-get-table} +Find in the template in mode table @var{TAB}, the template with @var{TEMPLATE-NAME}. +Optional argument @var{CONTEXT} specifies a context a particular template +would belong to. +Optional argument @var{APPLICATION} restricts searches to only template tables +belonging to a specific application. If @var{APPLICATION} is @code{nil}, then only +tables that do not belong to an application will be searched. +@end defun + +For purposes of an @srecode{} application, it is important to decide +what to call yoru application, and use that with this method call. + +@section Creating dictionaries + +Several dictionary calls are made in this example, including: +@table @code +@item srecode-create-dictionary +@item srecode-dictionary-set-value +@item srecode-dictionary-show-section +@item srecode-dictionary-add-section-dictionary +@end table + +These are documented more fully @ref{Dictionaries}. + +Also used is @code{srecode-resolve-arguments}. To learn more about +that, see @ref{Argument Resolution}. + +@section Template Insertion Commands + +There are several ways to insert a template. It is easiest to just +start with the main entry point. + +@defun srecode-insert-fcn template dictionary &optional stream +@anchor{srecode-insert-fcn} +Insert @var{template} using @var{dictionary} into @var{stream}. +If @var{stream} is nil, then use the current buffer. +@end defun + +@node Template Naming Conventions +@chapter Template Naming Conventions + +For @srecode{} to work across langauges reliably, templates need to +follow a predictable pattern. For every language of similar nature +(OO, functional, doc based) if they all provide the same base +templates, then an application can be written against the base +templates, and it will work in each of the supported language. + +Having consistent templates also makes it easy to use those templates +from a user perspective during basic interactive insertion via +@code{srecode-minor-mode}. + + +NOTES ON THIS CHAPTER: + +These conventions are being worked on. Check w/ CEDET-DEVEL mailing +list if you want to support a language, or write an application and +provide your opinions on this topic. Any help is appreciated. + + +@section Context: File + +Each language should support the @code{file:empty} template. This +will generally use the default copyright insertion mechanism. + +@section Context: Declaration + +Functional languages should attempt to support the following: + +@table @code +@item function +A standalone function. Not a method, external method, or other. +@item method +A method belonging to some class declaired outside the textual bounds +of that class' declaration. +@item variable +A global variable. +@item type +A data type. If the language supports several types of datatypes +then do not use this, use more specific ones instead. +@item class +For OO languages, use this instead of @code{type}. +@item include +Include files. +@end table + +For any @semantic{} tag class in your language, you will likely want +to have a corresponding template. + +In order for the @srecode{} function +@code{srecode-semantic-insert-tag} to work, you can create templates +similar to those mentioned above, except with @code{-tag} appended to +the end. This lets a template like @code{function} have user +conveniences when referencing @code{function-tag}, while also +allowing the tag inserter to do its job with a simpler template. + +@section Context: Classdef + +Inside a class definition. These are to be inserted inside the +textual bounds of a class declaration. + +@table @code +@item function +This would be a method of the class being inserted into. +@item constructor +@itemx destructor +Like @code{function} but specific to alloc/delete of an object. +@item variable +This would be a field of the class being inserted into. +@end table + +@section Context: Code + +Inside a body of code, such as a function or method body. + + - no conventions yet. + +@section Standard Dictionary Values + +For these variables to be useful, standard names should be used. +These values could be provided directly from a Semantic tag, or by an +application. + +@table @var +@item NAME +The name of the declaration being created. +@item PARENT +If the item belongs to some parent type, it would be the full name of +that type, including namespaces. +@item TYPE +A datatype name for a variable, or the return value of a function. +@item DOC +If there is some documentation associated with the item, then DOC +should contain the value. (Optional) +@item ARGS +The ARGS variable defines a section for 0 or more arguments to a function +or method. Each entry in ARGS will follow the rest of these naming +conventions, such as for NAME and TYPE. +@end table + +For templates used by @code{srecode-semantic-insert-tag}, there is +also the following useful dictionary values. + +@table @var +@item TAG +A special insertion value TAG. You can use semantic functions to turn +the tag into a string. +@item HAVEDEFAULT +@itemx DEFAULT +Default value for a variable. +@end table + +@node Inserting Tag Lists +@chapter Inserting Tag Lists + +Since @srecode{} is the @i{Semantic Recoder}, the ultimate goal for +@srecode{} is to convert lists of tags, as produced by @semantic{} +back into code. + +A single function provides the interface for programs to do this, but +it requires any particular language to have provided the correct +templates to make it work. + +@defun srecode-semantic-insert-tag tag &optional style-option point-insert-fcn &rest dict-entries +@anchor{srecode-semantic-insert-tag} +Insert @var{tag} into a buffer using srecode templates at point. + +Optional @var{style-option} is a list of minor configuration of styles, +such as the symbol @code{'prototype} for prototype functions, or +@code{'system} for system includes, and @code{'doxygen}, for a doxygen style +comment. + +Optional third argument @var{point-insert-fcn} is a hook that is run after +@var{tag} is inserted that allows an opportunity to fill in the body of +some thing. This hook function is called with one argument, the @var{tag} +being inserted. + +The rest of the arguments are @var{dict-entries}. @var{dict-entries} +is of the form ( @var{name1} @var{value1} @var{name2} @var{value2} @dots{} NAMEn VALUEn). + +The exact template used is based on the current context. +The template used is found within the toplevel context as calculated +by @dfn{srecode-calculate-context}, such as @code{declaration}, @code{classdecl}, +or @code{code}. + +For various conditions, this function looks for a template with +the name @var{class}-tag, where @var{class} is the tag class. If it cannot +find that, it will look for that template in the +@code{declaration}context (if the current context was not @code{declaration}). + +If @var{prototype} is specified, it will first look for templates with +the name @var{class}-tag-prototype, or @var{class}-prototype as above. + +See @dfn{srecode-semantic-apply-tag-to-dict} for details on what is in +the dictionary when the templates are called. + +This function returns to location in the buffer where the +inserted tag @var{ends}, and will leave point inside the inserted +text based on any occurrence of a point-inserter. Templates such +as @dfn{function} will leave point where code might be inserted. +@end defun + + +@node Application Writing +@chapter Application Writing + +The main goal of @srecode{} is to provide a strong platform for +writing code generating applications. + +Any templates that are application specific should make an application +declaration for each template file they use. This prevents those +templates from being used outside of that application. + +For example, add this to a file: +@example +set application "getset" +@end example + +In your application Emacs Lisp code, you would then load those +templates. A typical initialization would look like this: + +@example + (srecode-load-tables-for-mode major-mode) + (srecode-load-tables-for-mode major-mode 'getset) +@end example + +These two lines will load in the base templates for the major mode, +and then the application specific templates. + +@defun srecode-load-tables-for-mode mmode &optional appname +@anchor{srecode-load-tables-for-mode} +Load all the template files for @var{mmode}. +Templates are found in the SRecode Template Map. +See @dfn{srecode-get-maps} for more. +@var{appname} is the name of an application. In this case, +all template files for that application will be loaded. +@end defun + + + todo - Add examples. Most core stuff is already described above. + + +@node GNU Free Documentation License +@appendix GNU Free Documentation License +@include doclicense.texi + + +@node Index +@unnumbered Index +@printindex cp + +@iftex +@contents +@summarycontents +@end iftex + +@bye diff --git a/doc/misc/wisent.texi b/doc/misc/wisent.texi new file mode 100644 index 00000000000..6237e74eeb6 --- /dev/null +++ b/doc/misc/wisent.texi @@ -0,0 +1,2048 @@ +\input texinfo @c -*-texinfo-*- +@c %**start of header +@setfilename ../../info/wisent +@set TITLE Wisent Parser Development +@set AUTHOR Eric M. Ludlam, David Ponce, and Richard Y. Kim +@settitle @value{TITLE} + +@c ************************************************************************* +@c @ Header +@c ************************************************************************* + +@c Merge all indexes into a single index for now. +@c We can always separate them later into two or more as needed. +@syncodeindex vr cp +@syncodeindex fn cp +@syncodeindex ky cp +@syncodeindex pg cp +@syncodeindex tp cp + +@c @footnotestyle separate +@c @paragraphindent 2 +@c @@smallbook +@c %**end of header + +@copying +Copyright @copyright{} 1988-1993, 1995, 1998-2004, 2007, 2012 +Free Software Foundation, Inc. + +@c Since we are both GNU manuals, we do not need to ack each other here. +@ignore +Some texts are borrowed or adapted from the manual of Bison version +1.35. The text in section entitled ``Understanding the automaton'' is +adapted from the section ``Understanding Your Parser'' in the manual +of Bison version 1.49. +@end ignore + +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with no +Invariant Sections, with the Front-Cover texts being ``A GNU Manual,'' +and with the Back-Cover Texts as in (a) below. A copy of the license +is included in the section entitled ``GNU Free Documentation License''. + +(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and +modify this GNU manual. Buying copies from the FSF supports it in +developing GNU and promoting software freedom.'' +@end quotation +@end copying + +@dircategory Emacs misc features +@direntry +* Wisent: (wisent). Semantic Wisent parser development. +@end direntry + +@iftex +@finalout +@end iftex + +@c @setchapternewpage odd +@c @setchapternewpage off + +@titlepage +@sp 10 +@title @value{TITLE} +@author by @value{AUTHOR} +@page +@vskip 0pt plus 1 fill +@insertcopying +@end titlepage +@page + +@macro semantic{} +@i{Semantic} +@end macro + +@c ************************************************************************* +@c @ Document +@c ************************************************************************* +@contents + +@node top +@top @value{TITLE} + +Wisent (the European Bison ;-) is an Emacs Lisp implementation of the +GNU Compiler Compiler Bison. + +This manual describes how to use Wisent to develop grammars for +programming languages, and how to use grammars to parse language +source in Emacs buffers. + +It also describes how Wisent is used with the @semantic{} tool set +described in the @ref{Top, Semantic Manual, Semantic Manual, semantic}. + +@ifnottex +@insertcopying +@end ifnottex + +@menu +* Wisent Overview:: +* Wisent Grammar:: +* Wisent Parsing:: +* Wisent Semantic:: +* GNU Free Documentation License:: +* Index:: +@end menu + +@node Wisent Overview +@chapter Wisent Overview + +@dfn{Wisent} (the European Bison) is an implementation in Emacs Lisp +of the GNU Compiler Compiler Bison. Its code is a port of the C code +of GNU Bison 1.28 & 1.31. + +For more details on the basic concepts for understanding Wisent, it is +worthwhile to read the @ref{Top, Bison Manual, bison}. +@ifhtml +@uref{http://www.gnu.org/manual/bison/html_node/index.html}. +@end ifhtml + +Wisent can generate compilers compatible with the @semantic{} tool set. +See the @ref{Top, Semantic Manual, , semantic}. + +It benefits from these Bison features: + +@itemize @bullet +@item +It uses a fast but not so space-efficient encoding for the parse +tables, described in Corbett's PhD thesis from Berkeley: +@quotation +@cite{Static Semantics in Compiler Error Recovery}@* +June 1985, Report No. UCB/CSD 85/251. +@end quotation + +@item +For generating the lookahead sets, Wisent uses the well-known +technique of F. DeRemer and A. Pennello they described in: +@quotation +@cite{Efficient Construction of LALR(1) Lookahead Sets}@* +October 1982, ACM TOPLS Vol 4 No 4. +@end quotation + +@item +Wisent resolves shift/reduce conflicts using operator precedence and +associativity. + +@item +Parser error recovery is accomplished using rules which match the +special token @code{error}. +@end itemize + +Nevertheless there are some fundamental differences between Bison and +Wisent. + +@itemize +@item +Wisent is intended to be used in Emacs. It reads and produces Emacs +Lisp data structures. All the additional code used in grammars is +Emacs Lisp code. + +@item +Contrary to Bison, Wisent does not generate a parser which combines +Emacs Lisp code and grammar constructs. They exist separately. +Wisent reads the grammar from a Lisp data structure and then generates +grammar constructs as tables. Afterward, the derived tables can be +included and byte-compiled in separate Emacs Lisp files, and be used +at a later time by the Wisent's parser engine. + +@item +Wisent allows multiple start nonterminals and allows a call to the +parsing function to be made for a particular start nonterminal. For +example, this is particularly useful to parse a region of an Emacs +buffer. @semantic{} heavily depends on the availability of this feature. +@end itemize + +@node Wisent Grammar +@chapter Wisent Grammar + +@cindex context-free grammar +@cindex rule +In order for Wisent to parse a language, it must be described by a +@dfn{context-free grammar}. That is a grammar specified as rules that +can be applied regardless of context. For more information, see +@ref{Language and Grammar, , , bison}, in the Bison manual. + +@cindex terminal +@cindex nonterminal +The formal grammar is formulated using @dfn{terminal} and +@dfn{nonterminal} items. Terminals can be Emacs Lisp symbols or +characters, and nonterminals are symbols only. + +@cindex token +Terminals (also known as @dfn{tokens}) represent the lexical +elements of the language like numbers, strings, etc.. + +For example @samp{PLUS} can represent the operator @samp{+}. + +Nonterminal symbols are described by rules: + +@example +@group +RESULT @equiv{} COMPONENTS@dots{} +@end group +@end example + +@samp{RESULT} is a nonterminal that this rule describes and +@samp{COMPONENTS} are various terminals and nonterminals that are put +together by this rule. + +For example, this rule: + +@example +@group +exp @equiv{} exp PLUS exp +@end group +@end example + +Says that two groupings of type @samp{exp}, with a @samp{PLUS} token +in between, can be combined into a larger grouping of type @samp{exp}. + +@menu +* Grammar format:: +* Example:: +* Compiling a grammar:: +* Conflicts:: +@end menu + +@node Grammar format, Example, Wisent Grammar, Wisent Grammar +@comment node-name, next, previous, up +@section Grammar format + +@cindex grammar format +To be acceptable by Wisent a context-free grammar must respect a +particular format. That is, must be represented as an Emacs Lisp list +of the form: + +@code{(@var{terminals} @var{assocs} . @var{non-terminals})} + +@table @var +@item terminals +Is the list of terminal symbols used in the grammar. + +@cindex associativity +@item assocs +Specify the associativity of @var{terminals}. It is @code{nil} when +there is no associativity defined, or an alist of +@w{@code{(@var{assoc-type} . @var{assoc-value})}} elements. + +@var{assoc-type} must be one of the @code{default-prec}, +@code{nonassoc}, @code{left} or @code{right} symbols. When +@var{assoc-type} is @code{default-prec}, @var{assoc-value} must be +@code{nil} or @code{t} (the default). Otherwise it is a list of +tokens which must have been previously declared in @var{terminals}. + +For details, see @ref{Contextual Precedence, , , bison}, in the +Bison manual. + +@item non-terminals +Is the list of nonterminal definitions. Each definition has the form: + +@code{(@var{nonterm} . @var{rules})} + +Where @var{nonterm} is the nonterminal symbol defined and +@var{rules} the list of rules that describe this nonterminal. Each +rule is a list: + +@code{(@var{components} [@var{precedence}] [@var{action}])} + +Where: + +@table @var +@item components +Is a list of various terminals and nonterminals that are put together +by this rule. + +For example, + +@example +@group +(exp ((exp ?+ exp)) ;; exp: exp '+' exp + ) ;; ; +@end group +@end example + +Says that two groupings of type @samp{exp}, with a @samp{+} token in +between, can be combined into a larger grouping of type @samp{exp}. + +@cindex grammar coding conventions +By convention, a nonterminal symbol should be in lower case, such as +@samp{exp}, @samp{stmt} or @samp{declaration}. Terminal symbols +should be upper case to distinguish them from nonterminals: for +example, @samp{INTEGER}, @samp{IDENTIFIER}, @samp{IF} or +@samp{RETURN}. A terminal symbol that represents a particular keyword +in the language is conventionally the same as that keyword converted +to upper case. The terminal symbol @code{error} is reserved for error +recovery. + +@cindex middle-rule actions +Scattered among the components can be @dfn{middle-rule} actions. +Usually only @var{action} is provided (@pxref{action}). + +If @var{components} in a rule is @code{nil}, it means that the rule +can match the empty string. For example, here is how to define a +comma-separated sequence of zero or more @samp{exp} groupings: + +@example +@group +(expseq (nil) ;; expseq: ;; empty + ((expseq1)) ;; | expseq1 + ) ;; ; + +(expseq1 ((exp)) ;; expseq1: exp + ((expseq1 ?, exp)) ;; | expseq1 ',' exp + ) ;; ; +@end group +@end example + +@cindex precedence level +@item precedence +Assign the rule the precedence of the given terminal item, overriding +the precedence that would be deduced for it, that is the one of the +last terminal in it. Notice that only terminals declared in +@var{assocs} have a precedence level. The altered rule precedence +then affects how conflicts involving that rule are resolved. + +@var{precedence} is an optional vector of one terminal item. + +Here is how @var{precedence} solves the problem of unary minus. +First, declare a precedence for a fictitious terminal symbol named +@code{UMINUS}. There are no tokens of this type, but the symbol +serves to stand for its precedence: + +@example +@dots{} +((default-prec t) ;; This is the default + (left '+' '-') + (left '*') + (left UMINUS)) +@end example + +Now the precedence of @code{UMINUS} can be used in specific rules: + +@example +@group +(exp @dots{} ;; exp: @dots{} + ((exp ?- exp)) ;; | exp '-' exp + @dots{} ;; @dots{} + ((?- exp) [UMINUS]) ;; | '-' exp %prec UMINUS + @dots{} ;; @dots{} + ) ;; ; +@end group +@end example + +If you forget to append @code{[UMINUS]} to the rule for unary minus, +Wisent silently assumes that minus has its usual precedence. This +kind of problem can be tricky to debug, since one typically discovers +the mistake only by testing the code. + +Using @code{(default-prec nil)} declaration makes it easier to +discover this kind of problem systematically. It causes rules that +lack a @var{precedence} modifier to have no precedence, even if the +last terminal symbol mentioned in their components has a declared +precedence. + +If @code{(default-prec nil)} is in effect, you must specify +@var{precedence} for all rules that participate in precedence conflict +resolution. Then you will see any shift/reduce conflict until you +tell Wisent how to resolve it, either by changing your grammar or by +adding an explicit precedence. This will probably add declarations to +the grammar, but it helps to protect against incorrect rule +precedences. + +The effect of @code{(default-prec nil)} can be reversed by giving +@code{(default-prec t)}, which is the default. + +For more details, see @ref{Contextual Precedence, , , bison}, in the +Bison manual. + +It is important to understand that @var{assocs} declarations defines +associativity but also assign a precedence level to terminals. All +terminals declared in the same @code{left}, @code{right} or +@code{nonassoc} association get the same precedence level. The +precedence level is increased at each new association. + +On the other hand, @var{precedence} explicitly assign the precedence +level of the given terminal to a rule. + +@cindex semantic actions +@item @anchor{action}action +An action is an optional Emacs Lisp function call, like this: + +@code{(identity $1)} + +The result of an action determines the semantic value of a rule. + +From an implementation standpoint, the function call will be embedded +in a lambda expression, and several useful local variables will be +defined: + +@table @code +@vindex $N +@item $@var{n} +Where @var{n} is a positive integer. Like in Bison, the value of +@code{$@var{n}} is the semantic value of the @var{n}th element of +@var{components}, starting from 1. It can be of any Lisp data +type. + +@vindex $region@var{n} +@item $regionN +Where @var{n} is a positive integer. For each @code{$@var{n}} +variable defined there is a corresponding @code{$region@var{n}} +variable. Its value is a pair @code{(@var{start-pos} . +@var{end-pos})} that represent the start and end positions (in the +lexical input stream) of the @code{$@var{n}} value. It can be +@code{nil} when the component positions are not available, like for an +empty string component for example. + +@vindex $region +@item $region +Its value is the leftmost and rightmost positions of input data +matched by all @var{components} in the rule. This is a pair +@code{(@var{leftmost-pos} . @var{rightmost-pos})}. It can be +@code{nil} when components positions are not available. + +@vindex $nterm +@item $nterm +This variable is initialized with the nonterminal symbol +(@var{nonterm}) the rule belongs to. It could be useful to improve +error reporting or debugging. It is also used to automatically +provide incremental re-parse entry points for @semantic{} tags +(@pxref{Wisent Semantic}). + +@vindex $action +@item $action +The value of @code{$action} is the symbolic name of the current +semantic action (@pxref{Debugging actions}). +@end table + +When an action is not specified a default value is supplied, it is +@code{(identity $1)}. This means that the default semantic value of a +rule is the value of its first component. Excepted for a rule +matching the empty string, for which the default action is to return +@code{nil}. +@end table +@end table + +@node Example, Compiling a grammar, Grammar format, Wisent Grammar +@comment node-name, next, previous, up +@section Example + +@cindex grammar example +Here is an example to parse simple infix arithmetic expressions. See +@ref{Infix Calc, , , bison}, in the Bison manual for details. + +@lisp +@group +'( + ;; Terminals + (NUM) + + ;; Terminal associativity & precedence + ((nonassoc ?=) + (left ?- ?+) + (left ?* ?/) + (left NEG) + (right ?^)) + + ;; Rules + (input + ((line)) + ((input line) + (format "%s %s" $1 $2)) + ) + + (line + ((?;) + (progn ";")) + ((exp ?;) + (format "%s;" $1)) + ((error ?;) + (progn "Error;"))) + ) + + (exp + ((NUM) + (string-to-number $1)) + ((exp ?= exp) + (= $1 $3)) + ((exp ?+ exp) + (+ $1 $3)) + ((exp ?- exp) + (- $1 $3)) + ((exp ?* exp) + (* $1 $3)) + ((exp ?/ exp) + (/ $1 $3)) + ((?- exp) [NEG] + (- $2)) + ((exp ?^ exp) + (expt $1 $3)) + ((?\( exp ?\)) + (progn $2)) + ) + ) +@end group +@end lisp + +In the bison-like @dfn{WY} format (@pxref{Wisent Semantic}) the +grammar looks like this: + +@example +@group +%token NUM + +%nonassoc '=' ;; comparison +%left '-' '+' +%left '*' '/' +%left NEG ;; negation--unary minus +%right '^' ;; exponentiation + +%% + +input: + line + | input line + (format "%s %s" $1 $2) + ; + +line: + ';' + @{";"@} + | exp ';' + (format "%s;" $1) + | error ';' + @{"Error;"@} + ; + +exp: + NUM + (string-to-number $1) + | exp '=' exp + (= $1 $3) + | exp '+' exp + (+ $1 $3) + | exp '-' exp + (- $1 $3) + | exp '*' exp + (* $1 $3) + | exp '/' exp + (/ $1 $3) + | '-' exp %prec NEG + (- $2) + | exp '^' exp + (expt $1 $3) + | '(' exp ')' + @{$2@} + ; + +%% +@end group +@end example + +@node Compiling a grammar, Conflicts, Example, Wisent Grammar +@comment node-name, next, previous, up +@section Compiling a grammar + +@cindex automaton +After providing a context-free grammar in a suitable format, it must +be translated into a set of tables (an @dfn{automaton}) that will be +used to derive the parser. Like Bison, Wisent translates grammars that +must be @dfn{LALR(1)}. + +@cindex LALR(1) grammar +@cindex look-ahead token +A grammar is @acronym{LALR(1)} if it is possible to tell how to parse +any portion of an input string with just a single token of look-ahead: +the @dfn{look-ahead token}. See @ref{Language and Grammar, , , +bison}, in the Bison manual for more information. + +@cindex grammar compilation +Grammar translation (compilation) is achieved by the function: + +@cindex compiling a grammar +@vindex wisent-single-start-flag +@findex wisent-compile-grammar +@defun wisent-compile-grammar grammar &optional start-list +Compile @var{grammar} and return an @acronym{LALR(1)} automaton. + +Optional argument @var{start-list} is a list of start symbols +(nonterminals). If @code{nil} the first nonterminal defined in the +grammar is the default start symbol. If @var{start-list} contains +only one element, it defines the start symbol. If @var{start-list} +contains more than one element, all are defined as potential start +symbols, unless @code{wisent-single-start-flag} is non-@code{nil}. In +that case the first element of @var{start-list} defines the start +symbol and others are ignored. + +The @acronym{LALR(1)} automaton is a vector of the form: + +@code{[@var{actions gotos starts functions}]} + +@table @var +@item actions +A state/token matrix telling the parser what to do at every state +based on the current look-ahead token. That is shift, reduce, accept +or error. See also @ref{Wisent Parsing}. + +@item gotos +A state/nonterminal matrix telling the parser the next state to go to +after reducing with each rule. + +@item starts +An alist which maps the allowed start symbols (nonterminals) to +lexical tokens that will be first shifted into the parser stack. + +@item functions +An obarray of semantic action symbols. A semantic action is actually +an Emacs Lisp function (lambda expression). +@end table +@end defun + +@node Conflicts, , Compiling a grammar, Wisent Grammar +@comment node-name, next, previous, up +@section Conflicts + +Normally, a grammar should produce an automaton where at each state +the parser has only one action to do (@pxref{Wisent Parsing}). + +@cindex ambiguous grammar +In certain cases, a grammar can produce an automaton where, at some +states, there are more than one action possible. Such a grammar is +@dfn{ambiguous}, and generates @dfn{conflicts}. + +@cindex deterministic automaton +The parser can't be driven by an automaton which isn't completely +@dfn{deterministic}, that is which contains conflicts. It is +necessary to resolve the conflicts to eliminate them. Wisent resolves +conflicts like Bison does. + +@cindex grammar conflicts +@cindex conflicts resolution +There are two sorts of conflicts: + +@table @dfn +@cindex shift/reduce conflicts +@item shift/reduce conflicts +When either a shift or a reduction would be valid at the same state. + +Such conflicts are resolved by choosing to shift, unless otherwise +directed by operator precedence declarations. +See @ref{Shift/Reduce , , , bison}, in the Bison manual for more +information. + +@cindex reduce/reduce conflicts +@item reduce/reduce conflicts +That occurs if there are two or more rules that apply to the same +sequence of input. This usually indicates a serious error in the +grammar. + +Such conflicts are resolved by choosing to use the rule that appears +first in the grammar, but it is very risky to rely on this. Every +reduce/reduce conflict must be studied and usually eliminated. See +@ref{Reduce/Reduce , , , bison}, in the Bison manual for more +information. +@end table + +@menu +* Grammar Debugging:: +* Understanding the automaton:: +@end menu + +@node Grammar Debugging +@subsection Grammar debugging + +@cindex grammar debugging +@cindex grammar verbose description +To help writing a new grammar, @code{wisent-compile-grammar} can +produce a verbose report containing a detailed description of the +grammar and parser (equivalent to what Bison reports with the +@option{--verbose} option). + +To enable the verbose report you can set to non-@code{nil} the +variable: + +@vindex wisent-verbose-flag +@deffn Option wisent-verbose-flag +non-@code{nil} means to report verbose information on generated parser. +@end deffn + +Or interactively use the command: + +@findex wisent-toggle-verbose-flag +@deffn Command wisent-toggle-verbose-flag +Toggle whether to report verbose information on generated parser. +@end deffn + +The verbose report is printed in the temporary buffer +@code{*wisent-log*} when running interactively, or in file +@file{wisent.output} when running in batch mode. Different +reports are separated from each other by a line like this: + +@example +@group +*** Wisent @var{source-file} - 2002-06-27 17:33 +@end group +@end example + +where @var{source-file} is the name of the Emacs Lisp file from which +the grammar was read. See @ref{Understanding the automaton}, for +details on the verbose report. + +@table @strong +@item Please Note +To help debugging the grammar compiler itself, you can set this +variable to print the content of some internal data structures: + +@vindex wisent-debug-flag +@defvar wisent-debug-flag +non-@code{nil} means enable some debug stuff. +@end defvar +@end table + +@node Understanding the automaton +@subsection Understanding the automaton + +@cindex understanding the automaton +This section (took from the manual of Bison 1.49) describes how to use +the verbose report printed by @code{wisent-compile-grammar} to +understand the generated automaton, to tune or fix a grammar. + +We will use the following example: + +@example +@group +(let ((wisent-verbose-flag t)) ;; Print a verbose report! + (wisent-compile-grammar + '((NUM STR) ; %token NUM STR + + ((left ?+ ?-) ; %left '+' '-'; + (left ?*)) ; %left '*' + + (exp ; exp: + ((exp ?+ exp)) ; exp '+' exp + ((exp ?- exp)) ; | exp '-' exp + ((exp ?* exp)) ; | exp '*' exp + ((exp ?/ exp)) ; | exp '/' exp + ((NUM)) ; | NUM + ) ; ; + + (useless ; useless: + ((STR)) ; STR + ) ; ; + ) + 'nil) ; no %start declarations + ) +@end group +@end example + +When evaluating the above expression, grammar compilation first issues +the following two clear messages: + +@example +@group +Grammar contains 1 useless nonterminals and 1 useless rules +Grammar contains 7 shift/reduce conflicts +@end group +@end example + +The @samp{*wisent-log*} buffer details things! + +The first section reports conflicts that were solved using precedence +and/or associativity: + +@example +@group +Conflict in state 7 between rule 1 and token '+' resolved as reduce. +Conflict in state 7 between rule 1 and token '-' resolved as reduce. +Conflict in state 7 between rule 1 and token '*' resolved as shift. +Conflict in state 8 between rule 2 and token '+' resolved as reduce. +Conflict in state 8 between rule 2 and token '-' resolved as reduce. +Conflict in state 8 between rule 2 and token '*' resolved as shift. +Conflict in state 9 between rule 3 and token '+' resolved as reduce. +Conflict in state 9 between rule 3 and token '-' resolved as reduce. +Conflict in state 9 between rule 3 and token '*' resolved as reduce. +@end group +@end example + +The next section reports useless tokens, nonterminal and rules (note +that useless tokens might be used by the scanner): + +@example +@group +Useless nonterminals: + + useless + + +Terminals which are not used: + + STR + + +Useless rules: + +#6 useless: STR; +@end group +@end example + +The next section lists states that still have conflicts: + +@example +@group +State 7 contains 1 shift/reduce conflict. +State 8 contains 1 shift/reduce conflict. +State 9 contains 1 shift/reduce conflict. +State 10 contains 4 shift/reduce conflicts. +@end group +@end example + +The next section reproduces the grammar used: + +@example +@group +Grammar + + Number, Rule + 1 exp -> exp '+' exp + 2 exp -> exp '-' exp + 3 exp -> exp '*' exp + 4 exp -> exp '/' exp + 5 exp -> NUM +@end group +@end example + +And reports the uses of the symbols: + +@example +@group +Terminals, with rules where they appear + +$EOI (-1) +error (1) +NUM (2) 5 +STR (3) 6 +'+' (4) 1 +'-' (5) 2 +'*' (6) 3 +'/' (7) 4 + + +Nonterminals, with rules where they appear + +exp (8) + on left: 1 2 3 4 5, on right: 1 2 3 4 +@end group +@end example + +The report then details the automaton itself, describing each state +with it set of @dfn{items}, also known as @dfn{pointed rules}. Each +item is a production rule together with a point (marked by @samp{.}) +that the input cursor. + +@example +@group +state 0 + + NUM shift, and go to state 1 + + exp go to state 2 +@end group +@end example + +State 0 corresponds to being at the very beginning of the parsing, in +the initial rule, right before the start symbol (@samp{exp}). When +the parser returns to this state right after having reduced a rule +that produced an @samp{exp}, it jumps to state 2. If there is no such +transition on a nonterminal symbol, and the lookahead is a @samp{NUM}, +then this token is shifted on the parse stack, and the control flow +jumps to state 1. Any other lookahead triggers a parse error. + +In the state 1... + +@example +@group +state 1 + + exp -> NUM . (rule 5) + + $default reduce using rule 5 (exp) +@end group +@end example + +the rule 5, @samp{exp: NUM;}, is completed. Whatever the lookahead +(@samp{$default}), the parser will reduce it. If it was coming from +state 0, then, after this reduction it will return to state 0, and +will jump to state 2 (@samp{exp: go to state 2}). + +@example +@group +state 2 + + exp -> exp . '+' exp (rule 1) + exp -> exp . '-' exp (rule 2) + exp -> exp . '*' exp (rule 3) + exp -> exp . '/' exp (rule 4) + + $EOI shift, and go to state 11 + '+' shift, and go to state 3 + '-' shift, and go to state 4 + '*' shift, and go to state 5 + '/' shift, and go to state 6 +@end group +@end example + +In state 2, the automaton can only shift a symbol. For instance, +because of the item @samp{exp -> exp . '+' exp}, if the lookahead if +@samp{+}, it will be shifted on the parse stack, and the automaton +control will jump to state 3, corresponding to the item +@samp{exp -> exp . '+' exp}: + +@example +@group +state 3 + + exp -> exp '+' . exp (rule 1) + + NUM shift, and go to state 1 + + exp go to state 7 +@end group +@end example + +Since there is no default action, any other token than those listed +above will trigger a parse error. + +The interpretation of states 4 to 6 is straightforward: + +@example +@group +state 4 + + exp -> exp '-' . exp (rule 2) + + NUM shift, and go to state 1 + + exp go to state 8 + + + +state 5 + + exp -> exp '*' . exp (rule 3) + + NUM shift, and go to state 1 + + exp go to state 9 + + + +state 6 + + exp -> exp '/' . exp (rule 4) + + NUM shift, and go to state 1 + + exp go to state 10 +@end group +@end example + +As was announced in beginning of the report, @samp{State 7 contains 1 +shift/reduce conflict.}: + +@example +@group +state 7 + + exp -> exp . '+' exp (rule 1) + exp -> exp '+' exp . (rule 1) + exp -> exp . '-' exp (rule 2) + exp -> exp . '*' exp (rule 3) + exp -> exp . '/' exp (rule 4) + + '*' shift, and go to state 5 + '/' shift, and go to state 6 + + '/' [reduce using rule 1 (exp)] + $default reduce using rule 1 (exp) +@end group +@end example + +Indeed, there are two actions associated to the lookahead @samp{/}: +either shifting (and going to state 6), or reducing rule 1. The +conflict means that either the grammar is ambiguous, or the parser +lacks information to make the right decision. Indeed the grammar is +ambiguous, as, since we did not specify the precedence of @samp{/}, +the sentence @samp{NUM + NUM / NUM} can be parsed as @samp{NUM + (NUM +/ NUM)}, which corresponds to shifting @samp{/}, or as @samp{(NUM + +NUM) / NUM}, which corresponds to reducing rule 1. + +Because in @acronym{LALR(1)} parsing a single decision can be made, +Wisent arbitrarily chose to disable the reduction, see +@ref{Conflicts}. Discarded actions are reported in between square +brackets. + +Note that all the previous states had a single possible action: either +shifting the next token and going to the corresponding state, or +reducing a single rule. In the other cases, i.e., when shifting +@emph{and} reducing is possible or when @emph{several} reductions are +possible, the lookahead is required to select the action. State 7 is +one such state: if the lookahead is @samp{*} or @samp{/} then the +action is shifting, otherwise the action is reducing rule 1. In other +words, the first two items, corresponding to rule 1, are not eligible +when the lookahead is @samp{*}, since we specified that @samp{*} has +higher precedence that @samp{+}. More generally, some items are +eligible only with some set of possible lookaheads. + +States 8 to 10 are similar: + +@example +@group +state 8 + + exp -> exp . '+' exp (rule 1) + exp -> exp . '-' exp (rule 2) + exp -> exp '-' exp . (rule 2) + exp -> exp . '*' exp (rule 3) + exp -> exp . '/' exp (rule 4) + + '*' shift, and go to state 5 + '/' shift, and go to state 6 + + '/' [reduce using rule 2 (exp)] + $default reduce using rule 2 (exp) + + + +state 9 + + exp -> exp . '+' exp (rule 1) + exp -> exp . '-' exp (rule 2) + exp -> exp . '*' exp (rule 3) + exp -> exp '*' exp . (rule 3) + exp -> exp . '/' exp (rule 4) + + '/' shift, and go to state 6 + + '/' [reduce using rule 3 (exp)] + $default reduce using rule 3 (exp) + + + +state 10 + + exp -> exp . '+' exp (rule 1) + exp -> exp . '-' exp (rule 2) + exp -> exp . '*' exp (rule 3) + exp -> exp . '/' exp (rule 4) + exp -> exp '/' exp . (rule 4) + + '+' shift, and go to state 3 + '-' shift, and go to state 4 + '*' shift, and go to state 5 + '/' shift, and go to state 6 + + '+' [reduce using rule 4 (exp)] + '-' [reduce using rule 4 (exp)] + '*' [reduce using rule 4 (exp)] + '/' [reduce using rule 4 (exp)] + $default reduce using rule 4 (exp) +@end group +@end example + +Observe that state 10 contains conflicts due to the lack of precedence +of @samp{/} wrt @samp{+}, @samp{-}, and @samp{*}, but also because the +associativity of @samp{/} is not specified. + +Finally, the state 11 (plus 12) is named the @dfn{final state}, or the +@dfn{accepting state}: + +@example +@group +state 11 + + $EOI shift, and go to state 12 + + + +state 12 + + $default accept +@end group +@end example + +The end of input is shifted @samp{$EOI shift,} and the parser exits +successfully (@samp{go to state 12}, that terminates). + +@node Wisent Parsing +@chapter Wisent Parsing + +@cindex bottom-up parser +@cindex shift-reduce parser +The Wisent's parser is what is called a @dfn{bottom-up} or +@dfn{shift-reduce} parser which repeatedly: + +@table @dfn +@cindex shift +@item shift +That is pushes the value of the last lexical token read (the +look-ahead token) into a value stack, and reads a new one. + +@cindex reduce +@item reduce +That is replaces a nonterminal by its semantic value. The values of +the components which form the right hand side of a rule are popped +from the value stack and reduced by the semantic action of this rule. +The result is pushed back on top of value stack. +@end table + +The parser will stop on: + +@table @dfn +@cindex accept +@item accept +When all input has been successfully parsed. The semantic value of +the start nonterminal is on top of the value stack. + +@cindex syntax error +@item error +When a syntax error (an unexpected token in input) has been detected. +At this point the parser issues an error message and either stops or +calls a recovery routine to try to resume parsing. +@end table + +@cindex table-driven parser +The above elementary actions are driven by the @acronym{LALR(1)} +automaton built by @code{wisent-compile-grammar} from a context-free +grammar. + +The Wisent's parser is entered by calling the function: + +@findex wisent-parse +@defun wisent-parse automaton lexer &optional error start +Parse input using the automaton specified in @var{automaton}. + +@table @var +@item automaton +Is an @acronym{LALR(1)} automaton generated by +@code{wisent-compile-grammar} (@pxref{Wisent Grammar}). + +@item lexer +Is a function with no argument called by the parser to obtain the next +terminal (token) in input (@pxref{Writing a lexer}). + +@item error +Is an optional reporting function called when a parse error occurs. +It receives a message string to report. It defaults to the function +@code{wisent-message} (@pxref{Report errors}). + +@item start +Specify the start symbol (nonterminal) used by the parser as its goal. +It defaults to the start symbol defined in the grammar +(@pxref{Wisent Grammar}). +@end table +@end defun + +The following two normal hooks permit to do some useful processing +respectively before to start parsing, and after the parser terminated. + +@vindex wisent-pre-parse-hook +@defvar wisent-pre-parse-hook +Normal hook run just before entering the @var{LR} parser engine. +@end defvar + +@vindex wisent-post-parse-hook +@defvar wisent-post-parse-hook +Normal hook run just after the @var{LR} parser engine terminated. +@end defvar + +@menu +* Writing a lexer:: +* Actions goodies:: +* Report errors:: +* Error recovery:: +* Debugging actions:: +@end menu + +@node Writing a lexer +@section What the parser must receive + +It is important to understand that the parser does not parse +characters, but lexical tokens, and does not know anything about +characters in text streams! + +@cindex lexical analysis +@cindex lexer +@cindex scanner +Reading input data to produce lexical tokens is performed by a lexer +(also called a scanner) in a lexical analysis step, before the syntax +analysis step performed by the parser. The parser automatically calls +the lexer when it needs the next token to parse. + +@cindex lexical tokens +A Wisent's lexer is an Emacs Lisp function with no argument. It must +return a valid lexical token of the form: + +@code{(@var{token-class value} [@var{start} . @var{end}])} + +@table @var +@item token-class +Is a category of lexical token identifying a terminal as specified in +the grammar (@pxref{Wisent Grammar}). It can be a symbol or a character +literal. + +@item value +Is the value of the lexical token. It can be of any valid Emacs Lisp +data type. + +@item start +@itemx end +Are the optionals beginning and end positions of @var{value} in the +input stream. +@end table + +When there are no more tokens to read the lexer must return the token +@code{(list wisent-eoi-term)} to each request. + +@vindex wisent-eoi-term +@defvar wisent-eoi-term +Predefined constant, End-Of-Input terminal symbol. +@end defvar + +@code{wisent-lex} is an example of a lexer that reads lexical tokens +produced by a @semantic{} lexer, and translates them into lexical tokens +suitable to the Wisent parser. See also @ref{Wisent Lex}. + +To call the lexer in a semantic action use the function +@code{wisent-lexer}. See also @ref{Actions goodies}. + +@node Actions goodies +@section Variables and macros useful in grammar actions. + +@vindex wisent-input +@defvar wisent-input +The last token read. +This variable only has meaning in the scope of @code{wisent-parse}. +@end defvar + +@findex wisent-lexer +@defun wisent-lexer +Obtain the next terminal in input. +@end defun + +@findex wisent-region +@defun wisent-region &rest positions +Return the start/end positions of the region including +@var{positions}. Each element of @var{positions} is a pair +@w{@code{(@var{start-pos} . @var{end-pos})}} or @code{nil}. The +returned value is the pair @w{@code{(@var{min-start-pos} . +@var{max-end-pos})}} or @code{nil} if no @var{positions} are +available. +@end defun + +@node Report errors +@section The error reporting function + +@cindex error reporting +When the parser encounters a syntax error it calls a user-defined +function. It must be an Emacs Lisp function with one argument: a +string containing the message to report. + +By default the parser uses this function to report error messages: + +@findex wisent-message +@defun wisent-message string &rest args +Print a one-line message if @code{wisent-parse-verbose-flag} is set. +Pass @var{string} and @var{args} arguments to @dfn{message}. +@end defun + +@table @strong +@item Please Note: +@code{wisent-message} uses the following function to print lexical +tokens: + +@defun wisent-token-to-string token +Return a printed representation of lexical token @var{token}. +@end defun + +The general printed form of a lexical token is: + +@w{@code{@var{token}(@var{value})@@@var{location}}} +@end table + +To control the verbosity of the parser you can set to non-@code{nil} +this variable: + +@vindex wisent-parse-verbose-flag +@deffn Option wisent-parse-verbose-flag +non-@code{nil} means to issue more messages while parsing. +@end deffn + +Or interactively use the command: + +@findex wisent-parse-toggle-verbose-flag +@deffn Command wisent-parse-toggle-verbose-flag +Toggle whether to issue more messages while parsing. +@end deffn + +When the error reporting function is entered the variable +@code{wisent-input} contains the unexpected token as returned by the +lexer. + +The error reporting function can be called from a semantic action too +using the special macro @code{wisent-error}. When called from a +semantic action entered by error recovery (@pxref{Error recovery}) the +value of the variable @code{wisent-recovering} is non-@code{nil}. + +@node Error recovery +@section Error recovery + +@cindex error recovery +The error recovery mechanism of the Wisent's parser conforms to the +one Bison uses. See @ref{Error Recovery, , , bison}, in the Bison +manual for details. + +@cindex error token +To recover from a syntax error you must write rules to recognize the +special token @code{error}. This is a terminal symbol that is +automatically defined and reserved for error handling. + +When the parser encounters a syntax error, it pops the state stack +until it finds a state that allows shifting the @code{error} token. +After it has been shifted, if the old look-ahead token is not +acceptable to be shifted next, the parser reads tokens and discards +them until it finds a token which is acceptable. + +@cindex error recovery strategy +Strategies for error recovery depend on the choice of error rules in +the grammar. A simple and useful strategy is simply to skip the rest +of the current statement if an error is detected: + +@example +@group +(stmnt (( error ?; )) ;; on error, skip until ';' is read + ) +@end group +@end example + +It is also useful to recover to the matching close-delimiter of an +opening-delimiter that has already been parsed: + +@example +@group +(primary (( ?@{ expr ?@} )) + (( ?@{ error ?@} )) + @dots{} + ) +@end group +@end example + +@cindex error recovery actions +Note that error recovery rules may have actions, just as any other +rules can. Here are some predefined hooks, variables, functions or +macros, useful in such actions: + +@vindex wisent-nerrs +@defvar wisent-nerrs +The number of parse errors encountered so far. +@end defvar + +@vindex wisent-recovering +@defvar wisent-recovering +non-@code{nil} means that the parser is recovering. +This variable only has meaning in the scope of @code{wisent-parse}. +@end defvar + +@findex wisent-error +@defun wisent-error msg +Call the user supplied error reporting function with message +@var{msg} (@pxref{Report errors}). + +For an example of use, @xref{wisent-skip-token}. +@end defun + +@findex wisent-errok +@defun wisent-errok +Resume generating error messages immediately for subsequent syntax +errors. + +The parser suppress error message for syntax errors that happens +shortly after the first, until three consecutive input tokens have +been successfully shifted. + +Calling @code{wisent-errok} in an action, make error messages resume +immediately. No error messages will be suppressed if you call it in +an error rule's action. + +For an example of use, @xref{wisent-skip-token}. +@end defun + +@findex wisent-clearin +@defun wisent-clearin +Discard the current lookahead token. +This will cause a new lexical token to be read. + +In an error rule's action the previous lookahead token is reanalyzed +immediately. @code{wisent-clearin} may be called to clear this token. + +For example, suppose that on a parse error, an error handling routine +is called that advances the input stream to some point where parsing +should once again commence. The next symbol returned by the lexical +scanner is probably correct. The previous lookahead token ought to +be discarded with @code{wisent-clearin}. + +For an example of use, @xref{wisent-skip-token}. +@end defun + +@findex wisent-abort +@defun wisent-abort +Abort parsing and save the lookahead token. +@end defun + +@findex wisent-set-region +@defun wisent-set-region start end +Change the region of text matched by the current nonterminal. +@var{start} and @var{end} are respectively the beginning and end +positions of the region occupied by the group of components associated +to this nonterminal. If @var{start} or @var{end} values are not a +valid positions the region is set to @code{nil}. + +For an example of use, @xref{wisent-skip-token}. +@end defun + +@vindex wisent-discarding-token-functions +@defvar wisent-discarding-token-functions +List of functions to be called when discarding a lexical token. +These functions receive the lexical token discarded. +When the parser encounters unexpected tokens, it can discards them, +based on what directed by error recovery rules. Either when the +parser reads tokens until one is found that can be shifted, or when an +semantic action calls the function @code{wisent-skip-token} or +@code{wisent-skip-block}. +For language specific hooks, make sure you define this as a local +hook. + +For example, in @semantic{}, this hook is set to the function +@code{wisent-collect-unmatched-syntax} to collect unmatched lexical +tokens (@pxref{Useful functions}). +@end defvar + +@findex wisent-skip-token +@defun wisent-skip-token +@anchor{wisent-skip-token} +Skip the lookahead token in order to resume parsing. +Return nil. +Must be used in error recovery semantic actions. + +It typically looks like this: + +@lisp +@group +(wisent-message "%s: skip %s" $action + (wisent-token-to-string wisent-input)) +(run-hook-with-args + 'wisent-discarding-token-functions wisent-input) +(wisent-clearin) +(wisent-errok))) +@end group +@end lisp +@end defun + +@findex wisent-skip-block +@defun wisent-skip-block +Safely skip a block in order to resume parsing. +Return nil. +Must be used in error recovery semantic actions. + +A block is data between an open-delimiter (syntax class @code{(}) and +a matching close-delimiter (syntax class @code{)}): + +@example +@group +(a parenthesized block) +[a block between brackets] +@{a block between braces@} +@end group +@end example + +The following example uses @code{wisent-skip-block} to safely skip a +block delimited by @samp{LBRACE} (@code{@{}) and @samp{RBRACE} +(@code{@}}) tokens, when a syntax error occurs in +@samp{other-components}: + +@example +@group +(block ((LBRACE other-components RBRACE)) + ((LBRACE RBRACE)) + ((LBRACE error) + (wisent-skip-block)) + ) +@end group +@end example +@end defun + +@node Debugging actions +@section Debugging semantic actions + +@cindex semantic action symbols +Each semantic action is represented by a symbol interned in an +@dfn{obarray} that is part of the @acronym{LALR(1)} automaton +(@pxref{Compiling a grammar}). @code{symbol-function} on a semantic +action symbol return the semantic action lambda expression. + +A semantic action symbol name has the form +@code{@var{nonterminal}:@var{index}}, where @var{nonterminal} is the +name of the nonterminal symbol the action belongs to, and @var{index} +is an action sequence number within the scope of @var{nonterminal}. +For example, this nonterminal definition: + +@example +@group +input: + line [@code{input:0}] + | input line + (format "%s %s" $1 $2) [@code{input:1}] + ; +@end group +@end example + +Will produce two semantic actions, and associated symbols: + +@table @code +@item input:0 +A default action that returns @code{$1}. + +@item input:1 +That returns @code{(format "%s %s" $1 $2)}. +@end table + +@cindex debugging semantic actions +Debugging uses the Lisp debugger to investigate what is happening +during execution of semantic actions. +Three commands are available to debug semantic actions. They receive +two arguments: + +@itemize @bullet +@item The automaton that contains the semantic action. + +@item The semantic action symbol. +@end itemize + +@findex wisent-debug-on-entry +@deffn Command wisent-debug-on-entry automaton function +Request @var{automaton}'s @var{function} to invoke debugger each time it is called. +@var{function} must be a semantic action symbol that exists in @var{automaton}. +@end deffn + +@findex wisent-cancel-debug-on-entry +@deffn Command wisent-cancel-debug-on-entry automaton function +Undo effect of @code{wisent-debug-on-entry} on @var{automaton}'s @var{function}. +@var{function} must be a semantic action symbol that exists in @var{automaton}. +@end deffn + +@findex wisent-debug-show-entry +@deffn Command wisent-debug-show-entry automaton function +Show the source of @var{automaton}'s semantic action @var{function}. +@var{function} must be a semantic action symbol that exists in @var{automaton}. +@end deffn + +@node Wisent Semantic +@chapter How to use Wisent with Semantic + +@cindex tags +This section presents how the Wisent's parser can be used to produce +@dfn{tags} for the @semantic{} tool set. + +@semantic{} tags form a hierarchy of Emacs Lisp data structures that +describes a program in a way independent of programming languages. +Tags map program declarations, like functions, methods, variables, +data types, classes, includes, grammar rules, etc.. + +@cindex WY grammar format +To use the Wisent parser with @semantic{} you have to define +your grammar in @dfn{WY} form, a grammar format very close +to the one used by Bison. + +Please @inforef{top, Semantic Grammar Framework Manual, grammar-fw} +for more information on @semantic{} grammars. + +@menu +* Grammar styles:: +* Wisent Lex:: +@end menu + +@node Grammar styles +@section Grammar styles + +@cindex grammar styles +@semantic{} parsing heavily depends on how you wrote the grammar. +There are mainly two styles to write a Wisent's grammar intended to be +used with the @semantic{} tool set: the @dfn{Iterative style} and the +@dfn{Bison style}. Each one has pros and cons, and in certain cases +it can be worth a mix of the two styles! + +@menu +* Iterative style:: +* Bison style:: +* Mixed style:: +* Start nonterminals:: +* Useful functions:: +@end menu + +@node Iterative style, Bison style, Grammar styles, Grammar styles +@subsection Iterative style + +@cindex grammar iterative style +The @dfn{iterative style} is the preferred style to use with @semantic{}. +It relies on an iterative parser back-end mechanism which parses start +nonterminals one at a time and automagically skips unexpected lexical +tokens in input. + +Compared to rule-based iterative functions (@pxref{Bison style}), +iterative parsers are better in that they can handle obscure errors +more cleanly. + +@cindex raw tag +Each start nonterminal must produces a @dfn{raw tag} by calling a +@code{TAG}-like grammar macro with appropriate parameters. See also +@ref{Start nonterminals}. + +@cindex expanded tag +Then, each parsing iteration automatically translates a raw tag into +@dfn{expanded tags}, updating the raw tag structure with internal +properties and buffer related data. + +After parsing completes, it results in a tree of expanded tags. + +The following example is a snippet of the iterative style Java grammar +provided in the @semantic{} distribution in the file +@file{semantic/wisent/java-tags.wy}. + +@example +@group +@dots{} +;; Alternate entry points +;; - Needed by partial re-parse +%start formal_parameter +@dots{} +;; - Needed by EXPANDFULL clauses +%start formal_parameters +@dots{} + +formal_parameter_list + : PAREN_BLOCK + (EXPANDFULL $1 formal_parameters) + ; + +formal_parameters + : LPAREN + () + | RPAREN + () + | formal_parameter COMMA + | formal_parameter RPAREN + ; + +formal_parameter + : formal_parameter_modifier_opt type variable_declarator_id + (VARIABLE-TAG $3 $2 nil :typemodifiers $1) + ; +@end group +@end example + +@findex EXPANDFULL +It shows the use of the @code{EXPANDFULL} grammar macro to parse a +@samp{PAREN_BLOCK} which contains a @samp{formal_parameter_list}. +@code{EXPANDFULL} tells to recursively parse @samp{formal_parameters} +inside @samp{PAREN_BLOCK}. The parser iterates until it digested all +available input data inside the @samp{PAREN_BLOCK}, trying to match +any of the @samp{formal_parameters} rules: + +@itemize +@item @samp{LPAREN} + +@item @samp{RPAREN} + +@item @samp{formal_parameter COMMA} + +@item @samp{formal_parameter RPAREN} +@end itemize + +At each iteration it will return a @samp{formal_parameter} raw tag, +or @code{nil} to skip unwanted (single @samp{LPAREN} or @samp{RPAREN} +for example) or unexpected input data. Those raw tags will be +automatically expanded by the iterative back-end parser. + +@node Bison style +@subsection Bison style + +@cindex grammar bison style +What we call the @dfn{Bison style} is the traditional style of Bison's +grammars. Compared to iterative style, it is not straightforward to +use grammars written in Bison style in @semantic{}. Mainly because such +grammars are designed to parse the whole input data in one pass, and +don't use the iterative parser back-end mechanism (@pxref{Iterative +style}). With Bison style the parser is called once to parse the +grammar start nonterminal. + +The following example is a snippet of the Bison style Java grammar +provided in the @semantic{} distribution in the file +@file{semantic/wisent/java.wy}. + +@example +@group +%start formal_parameter +@dots{} + +formal_parameter_list + : formal_parameter_list COMMA formal_parameter + (cons $3 $1) + | formal_parameter + (list $1) + ; + +formal_parameter + : formal_parameter_modifier_opt type variable_declarator_id + (EXPANDTAG + (VARIABLE-TAG $3 $2 :typemodifiers $1) + ) + ; +@end group +@end example + +The first consequence is that syntax errors are not automatically +handled by @semantic{}. Thus, it is necessary to explicitly handle +them at the grammar level, providing error recovery rules to skip +unexpected input data. + +The second consequence is that the iterative parser can't do automatic +tag expansion, except for the start nonterminal value. It is +necessary to explicitly expand tags from concerned semantic actions by +calling the grammar macro @code{EXPANDTAG} with a raw tag as +parameter. See also @ref{Start nonterminals}, for incremental +re-parse considerations. + +@node Mixed style +@subsection Mixed style + +@cindex grammar mixed style +@example +@group +%start grammar +;; Reparse +%start prologue epilogue declaration nonterminal rule +@dots{} + +%% + +grammar: + prologue + | epilogue + | declaration + | nonterminal + | PERCENT_PERCENT + ; +@dots{} + +nonterminal: + SYMBOL COLON rules SEMI + (TAG $1 'nonterminal :children $3) + ; + +rules: + lifo_rules + (apply 'nconc (nreverse $1)) + ; + +lifo_rules: + lifo_rules OR rule + (cons $3 $1) + | rule + (list $1) + ; + +rule: + rhs + (let* ((rhs $1) + name type comps prec action elt) + @dots{} + (EXPANDTAG + (TAG name 'rule :type type :value comps :prec prec :expr action) + )) + ; +@end group +@end example + +This example shows how iterative and Bison styles can be combined in +the same grammar to obtain a good compromise between grammar +complexity and an efficient parsing strategy in an interactive +environment. + +@samp{nonterminal} is parsed using iterative style via the main +@samp{grammar} rule. The semantic action uses the @code{TAG} macro to +produce a raw tag, automagically expanded by @semantic{}. + +But @samp{rules} part is parsed in Bison style! Why? + +Rule delimiters are the colon (@code{:}), that follows the nonterminal +name, and a final semicolon (@code{;}). Unfortunately these +delimiters are not @code{open-paren}/@code{close-paren} type, and the +Emacs' syntactic analyzer can't easily isolate data between them to +produce a @samp{RULES_PART} parenthesis-block-like lexical token. +Consequently it is not possible to use @code{EXPANDFULL} to iterate in +@samp{RULES_PART}, like this: + +@example +@group +nonterminal: + SYMBOL COLON rules SEMI + (TAG $1 'nonterminal :children $3) + ; + +rules: + RULES_PART ;; @strong{Map a parenthesis-block-like lexical token} + (EXPANDFULL $1 'rules) + ; + +rules: + COLON + () + OR + () + SEMI + () + rhs + rhs + (let* ((rhs $1) + name type comps prec action elt) + @dots{} + (TAG name 'rule :type type :value comps :prec prec :expr action) + ) + ; +@end group +@end example + +In such cases, when it is difficult for Emacs to obtain +parenthesis-block-like lexical tokens, the best solution is to use the +traditional Bison style with error recovery! + +In some extreme cases, it can also be convenient to extend the lexer, +to deliver new lexical tokens, to simplify the grammar. + +@node Start nonterminals +@subsection Start nonterminals + +@cindex start nonterminals +@cindex @code{reparse-symbol} property +When you write a grammar for @semantic{}, it is important to carefully +indicate the start nonterminals. Each one defines an entry point in +the grammar, and after parsing its semantic value is returned to the +back-end iterative engine. Consequently: + +@strong{The semantic value of a start nonterminal must be a produced +by a TAG like grammar macro}. + +Start nonterminals are declared by @code{%start} statements. When +nothing is specified the first nonterminal that appears in the grammar +is the start nonterminal. + +Generally, the following nonterminals must be declared as start +symbols: + +@itemize @bullet +@item The main grammar entry point +@quotation +Of course! +@end quotation + +@item nonterminals passed to @code{EXPAND}/@code{EXPANDFULL} +@quotation +These grammar macros recursively parse a part of input data, based on +rules of the given nonterminal. + +For example, the following will parse @samp{PAREN_BLOCK} data using +the @samp{formal_parameters} rules: + +@example +@group +formal_parameter_list + : PAREN_BLOCK + (EXPANDFULL $1 formal_parameters) + ; +@end group +@end example + +The semantic value of @samp{formal_parameters} becomes the value of +the @code{EXPANDFULL} expression. It is a list of @semantic{} tags +spliced in the tags tree. + +Because the automaton must know that @samp{formal_parameters} is a +start symbol, you must declare it like this: + +@example +@group +%start formal_parameters +@end group +@end example +@end quotation +@end itemize + +@cindex incremental re-parse +@cindex reparse-symbol +The @code{EXPANDFULL} macro has a side effect it is important to know, +related to the incremental re-parse mechanism of @semantic{}: the +nonterminal symbol parameter passed to @code{EXPANDFULL} also becomes +the @code{reparse-symbol} property of the tag returned by the +@code{EXPANDFULL} expression. + +When buffer's data mapped by a tag is modified, @semantic{} +schedules an incremental re-parse of that data, using the tag's +@code{reparse-symbol} property as start nonterminal. + +@strong{The rules associated to such start symbols must be carefully +reviewed to ensure that the incremental parser will work!} + +Things are a little bit different when the grammar is written in Bison +style. + +@strong{The @code{reparse-symbol} property is set to the nonterminal +symbol the rule that explicitly uses @code{EXPANDTAG} belongs to.} + +For example: + +@example +@group +rule: + rhs + (let* ((rhs $1) + name type comps prec action elt) + @dots{} + (EXPANDTAG + (TAG name 'rule :type type :value comps :prec prec :expr action) + )) + ; +@end group +@end example + +Set the @code{reparse-symbol} property of the expanded tag to +@samp{rule}. A important consequence is that: + +@strong{Every nonterminal having any rule that calls @code{EXPANDTAG} +in a semantic action, should be declared as a start symbol!} + +@node Useful functions +@subsection Useful functions + +Here is a description of some predefined functions it might be useful +to know when writing new code to use Wisent in @semantic{}: + +@findex wisent-collect-unmatched-syntax +@defun wisent-collect-unmatched-syntax input +Add @var{input} lexical token to the cache of unmatched tokens, in +variable @code{semantic-unmatched-syntax-cache}. + +See implementation of the function @code{wisent-skip-token} in +@ref{Error recovery}, for an example of use. +@end defun + +@node Wisent Lex +@section The Wisent Lex lexer + +@findex semantic-lex +The lexical analysis step of @semantic{} is performed by the general +function @code{semantic-lex}. For more information, @inforef{Writing +Lexers, ,semantic-langdev}. + +@code{semantic-lex} produces lexical tokens of the form: + +@example +@group +@code{(@var{token-class start} . @var{end})} +@end group +@end example + +@table @var +@item token-class +Is a symbol that identifies a lexical token class, like @code{symbol}, +@code{string}, @code{number}, or @code{PAREN_BLOCK}. + +@item start +@itemx end +Are the start and end positions of mapped data in the input buffer. +@end table + +The Wisent's parser doesn't depend on the nature of analyzed input +stream (buffer, string, etc.), and requires that lexical tokens have a +different form (@pxref{Writing a lexer}): + +@example +@group +@code{(@var{token-class value} [@var{start} . @var{end}])} +@end group +@end example + +@cindex lexical token mapping +@code{wisent-lex} is the default Wisent's lexer used in @semantic{}. + +@vindex wisent-lex-istream +@findex wisent-lex +@defun wisent-lex +Return the next available lexical token in Wisent's form. + +The variable @code{wisent-lex-istream} contains the list of lexical +tokens produced by @code{semantic-lex}. Pop the next token available +and convert it to a form suitable for the Wisent's parser. +@end defun + +Mapping of lexical tokens as produced by @code{semantic-lex} into +equivalent Wisent lexical tokens is straightforward: + +@example +@group +(@var{token-class start} . @var{end}) + @result{} (@var{token-class value start} . @var{end}) +@end group +@end example + +@var{value} is the input @code{buffer-substring} from @var{start} to +@var{end}. + +@node GNU Free Documentation License +@appendix GNU Free Documentation License + +@include doclicense.texi + +@node Index +@unnumbered Index +@printindex cp + +@iftex +@contents +@summarycontents +@end iftex + +@bye + +@c Following comments are for the benefit of ispell. + +@c LocalWords: Wisent automagically wisent Wisent's LALR obarray diff --git a/info/dir b/info/dir index cf039593d52..4fa837e6a1e 100644 --- a/info/dir +++ b/info/dir @@ -79,6 +79,9 @@ Emacs misc features and citations. * Remember: (remember). Simple information manager for Emacs. * Semantic: (semantic). Source code parser library and utilities. +* Bovine: (bovine). Semantic bovine parser development. +* SRecode: (srecode). Template code generator. +* Wisent: (wisent). Semantic Wisent parser development. * SES: (ses). Simple Emacs Spreadsheet. * Speedbar: (speedbar). File/Tag summarizing utility. * VIP: (vip). An older VI-emulation for Emacs. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 97b44b22975..3390a2e8e7c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2012-12-13 Alan Mackenzie + + Make CC Mode not hang when _some_ lines end in CRLF. Bug #11841. + * progmodes/cc-engine.el (c-backward-comments): Add code to work + around `forward-comment' not recognizing ^M as whitespace. + +2012-12-13 Fabián Ezequiel Gallina + + * progmodes/python.el (python-skeleton-class) + (python-skeleton-def): Do not add space after defun name. + 2012-12-13 Stefan Monnier * emacs-lisp/cl.el (letf): Make it an alias of cl-letf. diff --git a/lisp/org/ChangeLog b/lisp/org/ChangeLog index 98383e56532..f7715198464 100644 --- a/lisp/org/ChangeLog +++ b/lisp/org/ChangeLog @@ -1,3 +1,89 @@ +2012-12-13 Bastien Guerry + + * org-latex.el (org-export-latex-links): Escape raw path when + exporting links to files. + + * org-src.el (org-src-native-tab-command-maybe): Fix bug: the + S-TAB key should not trigger a native TAB command. + + * org.el (org-open-at-point): Allow to open any link within + footnotes definition, not only bracket links. + + * org.el (org-sort-entries): Bugfix: keep track of the clock + marker when sorting entries. Enhance the docstring. + + * org-clock.el (org-clock-out): Use `user-error' when the user + tries to clock out while there is no running clock. + + * org-table.el (org-table-sort-lines): Ensure coordinates are + correctly displayed when sorting. + + * org.el (org-do-sort): Enhance prompt. + + * org-agenda.el (org-agenda-finalize): Also activate plain links. + + * org-timer.el (org-timer-stop): Add message. + + * org-agenda.el (org-agenda-schedule, org-agenda-deadline): + Fix redundant messages. + + * org-agenda.el (org-agenda-finalize): Fix clock highlighting. + + * org.el (org-additional-option-like-keywords): Add "INDEX:". + + * org-install.el: Enhance warning. + +2012-12-13 Erik Hetzner (tiny change) + + * org.el (org-log-into-drawer): Honor the nil value for the + :LOG_INTO_DRAWER: property. + +2012-12-13 Le Wang (tiny change) + + * org-src.el (org-edit-src-exit): Fix editing source section with + blank lines. + +2012-12-13 Le Wang + + * org-src.el (org-edit-src-code): Use marker with insertion type + t to track end and remove hack requiring delete from beg to (1- end). + +2012-12-13 Nicolas Goaziou + + * org-element.el (org-element-context): When point is between two + objects, be sure to return the second one. + + * org-list.el (org-list-separating-blank-lines-number): When + computing number of blank lines separating items, also count those + in unparsed blocks, like example blocks. + + * org.el (org-end-of-line): When visual line mode is on, really + move by visual lines. Small refactoring. + + * org.el (org-end-of-line): On a hidden block make sure to + delegate motion to `end-of-line' instead of `move-end-of-line' in + order to stay on the current line. + +2012-12-13 Rafael Laboissiere (tiny change) + + * org-bibtex.el: In the documentation section of the file, fix the + broken URL to Andrew Roberts' document on BibTeX entries. + + * org-remember.el (org-remember-handler): Correctly strip the + comment lines in the temporary buffer *Remember* when handling a + remember note. + + * org-remember.el (org-remember-apply-template): Start the + commented lines in the Remember temporary buffer with the + appropriate characters. + +2012-12-13 Toby S. Cubitt + + * org.el (org-beginning-of-line): Check `visual-line-mode' instead + of `line-visual-mode' to determine whether to move by visual lines. + + * org.el (org-kill-line): Use the `org-bound-and-true-p' macro. + 2012-12-04 Chong Yidong * org-bibtex.el (org-bibtex-ask): Use visual-line-mode instead of diff --git a/lisp/org/org-agenda.el b/lisp/org/org-agenda.el index 36f3fcb9974..a2e919f5944 100644 --- a/lisp/org/org-agenda.el +++ b/lisp/org/org-agenda.el @@ -3517,6 +3517,9 @@ generating a new one." (while (org-activate-bracket-links (point-max)) (add-text-properties (match-beginning 0) (match-end 0) '(face org-link))) + (while (org-activate-plain-links (point-max)) + (add-text-properties (match-beginning 0) (match-end 0) + '(face org-link))) (org-agenda-align-tags) (unless org-agenda-with-colors (remove-text-properties (point-min) (point-max) '(face nil)))) @@ -3531,7 +3534,11 @@ generating a new one." (org-agenda-fontify-priorities)) (when (and org-agenda-dim-blocked-tasks org-blocker-hook) (org-agenda-dim-blocked-tasks)) - (org-agenda-mark-clocking-task) + ;; We need to widen when `org-agenda-finalize' is called from + ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in') + (save-restriction + (widen) + (org-agenda-mark-clocking-task)) (when org-agenda-entry-text-mode (org-agenda-entry-text-hide) (org-agenda-entry-text-show)) @@ -8602,7 +8609,7 @@ ARG is passed through to `org-schedule'." (goto-char pos) (setq ts (org-schedule arg time))) (org-agenda-show-new-time marker ts "S")) - (message "Item scheduled for %s" ts))) + (message "%s" ts))) (defun org-agenda-deadline (arg &optional time) "Schedule the item at point. @@ -8622,7 +8629,7 @@ ARG is passed through to `org-deadline'." (goto-char pos) (setq ts (org-deadline arg time))) (org-agenda-show-new-time marker ts "D")) - (message "Deadline for this item set to %s" ts))) + (message "%s" ts))) (defun org-agenda-clock-in (&optional arg) "Start the clock on the currently selected item." diff --git a/lisp/org/org-bibtex.el b/lisp/org/org-bibtex.el index aaae8d52de8..bd84107161b 100644 --- a/lisp/org/org-bibtex.el +++ b/lisp/org/org-bibtex.el @@ -88,7 +88,7 @@ ;; ;; - All Bibtex information is taken from the document compiled by ;; Andrew Roberts from the Bibtex manual, available at -;; http://www.andy-roberts.net/misc/latex/sessions/bibtex/bibentries.pdf +;; http://www.andy-roberts.net/res/writing/latex/bibentries.pdf ;; ;;; History: ;; diff --git a/lisp/org/org-clock.el b/lisp/org/org-clock.el index 3f252fd8c32..e8ced67e694 100644 --- a/lisp/org/org-clock.el +++ b/lisp/org/org-clock.el @@ -1447,7 +1447,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'." (delq 'org-mode-line-string global-mode-string)) (setq frame-title-format org-frame-title-format-backup) (force-mode-line-update) - (if fail-quietly (throw 'exit t) (error "No active clock"))) + (if fail-quietly (throw 'exit t) (user-error "No active clock"))) (let ((org-clock-out-switch-to-state (if switch-to-state (completing-read "Switch to state: " diff --git a/lisp/org/org-element.el b/lisp/org/org-element.el index 5da2dec3fb3..51b89585010 100644 --- a/lisp/org/org-element.el +++ b/lisp/org/org-element.el @@ -4316,18 +4316,22 @@ and :post-blank properties." (funcall (intern (format "org-element-%s-parser" (car closest-cand)))))) (cbeg (org-element-property :contents-begin object)) - (cend (org-element-property :contents-end object))) + (cend (org-element-property :contents-end object)) + (obj-end (org-element-property :end object))) (cond ;; ORIGIN is after OBJECT, so skip it. - ((< (org-element-property :end object) origin) - (goto-char (org-element-property :end object))) - ;; ORIGIN is within a non-recursive object or at an - ;; object boundaries: Return that object. + ((<= obj-end origin) + (if (/= obj-end end) (goto-char obj-end) + (throw 'exit + (org-element-put-property + object :parent parent)))) + ;; ORIGIN is within a non-recursive object or at + ;; an object boundaries: Return that object. ((or (not cbeg) (> cbeg origin) (< cend origin)) (throw 'exit (org-element-put-property object :parent parent))) - ;; Otherwise, move within current object and restrict - ;; search to the end of its contents. + ;; Otherwise, move within current object and + ;; restrict search to the end of its contents. (t (goto-char cbeg) (org-element-put-property object :parent parent) (setq parent object diff --git a/lisp/org/org-latex.el b/lisp/org/org-latex.el index 9ce84f14e92..a53470df8be 100644 --- a/lisp/org/org-latex.el +++ b/lisp/org/org-latex.el @@ -2291,14 +2291,13 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (concat type ":" raw-path)) ((equal type "file") (if (and (org-file-image-p - (expand-file-name - raw-path) + (expand-file-name (org-link-unescape raw-path)) org-export-latex-inline-image-extensions) - (or (get-text-property 0 'org-no-description - raw-path) + (or (get-text-property 0 'org-no-description raw-path) (equal desc full-raw-path))) (setq imgp t) - (progn (when (string-match "\\(.+\\)::.+" raw-path) + (progn (setq raw-path (org-link-unescape raw-path)) + (when (string-match "\\(.+\\)::.+" raw-path) (setq raw-path (match-string 1 raw-path))) (if (file-exists-p raw-path) (concat type "://" (expand-file-name raw-path)) diff --git a/lisp/org/org-list.el b/lisp/org/org-list.el index 10f5e6ec6a9..993272aeb98 100644 --- a/lisp/org/org-list.el +++ b/lisp/org/org-list.el @@ -1230,7 +1230,9 @@ some heuristics to guess the result." ;; Are there blank lines inside the list so far? ((save-excursion (goto-char (org-list-get-top-point struct)) - (org-list-search-forward + ;; Do not use `org-list-search-forward' so blank lines + ;; in blocks can be counted in. + (re-search-forward "^[ \t]*$" (org-list-get-item-end-before-blank item struct) t)) 1) ;; Default choice: no blank line. diff --git a/lisp/org/org-remember.el b/lisp/org/org-remember.el index d555ca65d21..5cfe70f7af6 100644 --- a/lisp/org/org-remember.el +++ b/lisp/org/org-remember.el @@ -472,12 +472,12 @@ to be run from that hook to function properly." (erase-buffer) (insert (substitute-command-keys (format - "## %s \"%s\" -> \"* %s\" -## C-u C-c C-c like C-c C-c, and immediately visit note at target location -## C-0 C-c C-c \"%s\" -> \"* %s\" -## %s to select file and header location interactively. -## C-2 C-c C-c as child (C-3: as sibling) of the currently clocked item -## To switch templates, use `\\[org-remember]'. To abort use `C-c C-k'.\n\n" + "# %s \"%s\" -> \"* %s\" +# C-u C-c C-c like C-c C-c, and immediately visit note at target location +# C-0 C-c C-c \"%s\" -> \"* %s\" +# %s to select file and header location interactively. +# C-2 C-c C-c as child (C-3: as sibling) of the currently clocked item +# To switch templates, use `\\[org-remember]'. To abort use `C-c C-k'.\n\n" (if org-remember-store-without-prompt " C-c C-c" " C-1 C-c C-c") (abbreviate-file-name (or file org-default-notes-file)) (or headline "") @@ -840,12 +840,12 @@ See also the variable `org-reverse-note-order'." (if (= end beg) (setq beg (1- beg))) (put-text-property beg end 'org-position-cursor t))) (goto-char (point-min)) - (while (looking-at "^[ \t]*\n\\|^##.*\n") + (while (looking-at "^[ \t]*\n\\|^# .*\n") (replace-match "")) (when org-remember-delete-empty-lines-at-end (goto-char (point-max)) (beginning-of-line 1) - (while (and (looking-at "[ \t]*$\\|##.*") (> (point) 1)) + (while (and (looking-at "[ \t]*$\\|[ \t]*# .*") (> (point) 1)) (delete-region (1- (point)) (point-max)) (beginning-of-line 1))) (catch 'quit diff --git a/lisp/org/org-src.el b/lisp/org/org-src.el index b4d4c0489a9..f91da19ec32 100644 --- a/lisp/org/org-src.el +++ b/lisp/org/org-src.el @@ -215,11 +215,22 @@ buffer." (setq org-edit-src-saved-temp-window-config (current-window-configuration))) (let* ((mark (and (org-region-active-p) (mark))) (case-fold-search t) - (info (org-edit-src-find-region-and-lang)) + (info + ;; If the src region consists in no lines, we insert a blank + ;; line. + (let* ((temp (org-edit-src-find-region-and-lang)) + (beg (nth 0 temp)) + (end (nth 1 temp))) + (if (>= end beg) temp + (goto-char beg) + (insert "\n") + (org-edit-src-find-region-and-lang)))) (full-info (org-babel-get-src-block-info 'light)) (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive (beg (make-marker)) - (end (make-marker)) + ;; Move marker with inserted text for case when src block is + ;; just one empty line, i.e. beg == end. + (end (copy-marker nil t)) (allow-write-back-p (null code)) block-nindent total-nindent ovl lang lang-f single lfmt buffer msg begline markline markcol line col transmitted-variables) @@ -689,10 +700,9 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"." (kill-buffer buffer)) (goto-char beg) (when allow-write-back-p - (delete-region beg (max beg (1- end))) - (unless (string-match "^[ \t]*$" code) - (insert code) - (delete-char 1)) + (delete-region beg (max beg end)) + (unless (string-match "\\`[ \t]*\\'" code) + (insert code)) (goto-char beg) (if single (just-one-space))) (if (memq t (mapcar (lambda (overlay) @@ -820,6 +830,7 @@ issued in the language major mode buffer." Alter code block according to effect of TAB in the language major mode." (and org-src-tab-acts-natively + (not (equal this-command 'org-shifttab)) (let ((org-src-strip-leading-and-trailing-blank-lines nil)) (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB"))))) diff --git a/lisp/org/org-table.el b/lisp/org/org-table.el index 0555041231b..f7cae3c8bf2 100644 --- a/lisp/org/org-table.el +++ b/lisp/org/org-table.el @@ -1594,6 +1594,7 @@ should be done in reverse order." (interactive "P") (let* ((thisline (org-current-line)) (thiscol (org-table-current-column)) + (otc org-table-overlay-coordinates) beg end bcol ecol tend tbeg column lns pos) (when (equal thiscol 0) (if (org-called-interactively-p 'any) @@ -1642,12 +1643,15 @@ should be done in reverse order." x)) (org-split-string (buffer-substring beg end) "\n"))) (setq lns (org-do-sort lns "Table" with-case sorting-type)) + (when org-table-overlay-coordinates + (org-table-toggle-coordinate-overlays)) (delete-region beg end) (move-marker beg nil) (move-marker end nil) (insert (mapconcat 'cdr lns "\n") "\n") (org-goto-line thisline) (org-table-goto-column thiscol) + (when otc (org-table-toggle-coordinate-overlays)) (message "%d lines sorted, based on column %d" (length lns) column))) ;;;###autoload diff --git a/lisp/org/org-timer.el b/lisp/org/org-timer.el index a314564b94a..8a5b599eca2 100644 --- a/lisp/org/org-timer.el +++ b/lisp/org/org-timer.el @@ -162,7 +162,8 @@ With prefix arg STOP, stop it entirely." (run-hooks 'org-timer-stop-hook) (setq org-timer-start-time nil org-timer-pause-time nil) - (org-timer-set-mode-line 'off)) + (org-timer-set-mode-line 'off) + (message "Timer stopped")) ;;;###autoload (defun org-timer (&optional restart no-insert-p) diff --git a/lisp/org/org-version.el b/lisp/org/org-version.el index 564b49a5cea..de434885b12 100644 --- a/lisp/org/org-version.el +++ b/lisp/org/org-version.el @@ -11,7 +11,7 @@ (defun org-git-version () "The Git version of org-mode. Inserted by installing org-mode or when a release is made." - (let ((org-git-version "7.9.2+-GNU-Emacs-24-3")) + (let ((org-git-version "7.9.2+-GNU-Emacs-24-3 (commit 488eea)")) org-git-version)) ;;;###autoload (defvar org-odt-data-dir "/usr/share/emacs/etc/org" diff --git a/lisp/org/org.el b/lisp/org/org.el index 45dbe2754e8..60e2a8be550 100644 --- a/lisp/org/org.el +++ b/lisp/org/org.el @@ -2498,9 +2498,10 @@ a subtree." "Return the value of `org-log-into-drawer', but let properties overrule. If the current entry has or inherits a LOG_INTO_DRAWER property, it will be used instead of the default value." - (let ((p (org-entry-get nil "LOG_INTO_DRAWER" 'inherit))) + (let ((p (org-entry-get nil "LOG_INTO_DRAWER" 'inherit t))) (cond - ((or (not p) (equal p "nil")) org-log-into-drawer) + ((not p) org-log-into-drawer) + ((equal p "nil") nil) ((equal p "t") "LOGBOOK") (t p)))) @@ -8016,11 +8017,12 @@ a time stamp, by a property or by priority. The command prompts for the sorting type unless it has been given to the function through the SORTING-TYPE argument, which needs to be a character, -\(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the +\(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?o ?O ?r ?R ?f ?F). Here is the precise meaning of each character: n Numerically, by converting the beginning of the entry/item to a number. a Alphabetically, ignoring the TODO keyword and the priority, if any. +o By order of TODO keywords. t By date/time, either the first active time stamp in the entry, or, if none exist, by the first inactive one. s By the scheduled date/time. @@ -8040,6 +8042,13 @@ Comparing entries ignores case by default. However, with an optional argument WITH-CASE, the sorting considers case as well." (interactive "P") (let ((case-func (if with-case 'identity 'downcase)) + (cmstr + ;; The clock marker is lost when using `sort-subr', let's + ;; store the clocking string. + (when (equal (marker-buffer org-clock-marker) (current-buffer)) + (save-excursion + (goto-char org-clock-marker) + (looking-back "^.*") (match-string-no-properties 0)))) start beg end stars re re2 txt what tmp) ;; Find beginning and end of region to sort @@ -8096,7 +8105,7 @@ WITH-CASE, the sorting considers case as well." (message "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc [t]ime [s]cheduled [d]eadline [c]reated - A/N/T/S/D/C/P/O/F means reversed:" + A/N/P/R/O/F/T/S/D/C means reversed:" what) (setq sorting-type (read-char-exclusive)) @@ -8193,6 +8202,12 @@ WITH-CASE, the sorting considers case as well." ((= dcst ?f) compare-func) ((member dcst '(?p ?t ?s ?d ?c)) '<))))) (run-hooks 'org-after-sorting-entries-or-items-hook) + ;; Reset the clock marker if needed + (when cmstr + (save-excursion + (goto-char start) + (search-forward cmstr nil t) + (move-marker org-clock-marker (point)))) (message "Sorting entries...done"))) (defun org-do-sort (table what &optional with-case sorting-type) @@ -8204,7 +8219,7 @@ the car of the elements of the table. If WITH-CASE is non-nil, the sorting will be case-sensitive." (unless sorting-type (message - "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:" + "Sort %s: [a]lphabetic, [n]umeric, [t]ime. A/N/T means reversed:" what) (setq sorting-type (read-char-exclusive))) (let ((dcst (downcase sorting-type)) @@ -9644,7 +9659,7 @@ application the system uses for this file type." (not (org-in-regexp org-bracket-link-regexp))) (org-follow-timestamp-link)) ((and (or (org-footnote-at-reference-p) (org-footnote-at-definition-p)) - (not (org-in-regexp org-bracket-link-regexp))) + (not (org-in-regexp org-any-link-re))) (org-footnote-action)) (t (let (type path link line search (pos (point))) @@ -11219,7 +11234,7 @@ This function can be used in a hook." "COLUMNS:" "PROPERTY:" "CAPTION:" "LABEL:" "SETUPFILE:" - "INCLUDE:" + "INCLUDE:" "INDEX:" "BIND:" "MACRO:")) @@ -21270,7 +21285,7 @@ beyond the end of the headline." (car org-special-ctrl-a/e) org-special-ctrl-a/e)) refpos) - (if (org-bound-and-true-p line-move-visual) + (if (org-bound-and-true-p visual-line-mode) (beginning-of-visual-line 1) (beginning-of-line 1)) (if (and arg (fboundp 'move-beginning-of-line)) @@ -21331,36 +21346,33 @@ the cursor is already beyond the end of the headline." (interactive "P") (let ((special (if (consp org-special-ctrl-a/e) (cdr org-special-ctrl-a/e) org-special-ctrl-a/e)) - (type (org-element-type - (save-excursion (beginning-of-line) (org-element-at-point))))) - (cond - ((or (not special) arg) - (call-interactively - (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line))) - ((memq type '(headline inlinetask)) - (let ((pos (point))) - (beginning-of-line 1) - (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\)?$")) - (if (eq special t) - (if (or (< pos (match-beginning 1)) (= pos (match-end 0))) - (goto-char (match-beginning 1)) - (goto-char (match-end 0))) - (if (or (< pos (match-end 0)) - (not (eq this-command last-command))) - (goto-char (match-end 0)) - (goto-char (match-beginning 1)))) - (call-interactively - (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line))))) - ((memq type - '(center-block comment-block drawer dynamic-block example-block - export-block item plain-list property-drawer - quote-block special-block src-block verse-block)) - ;; Never move past the ellipsis. - (or (eolp) (move-end-of-line 1)) - (when (org-invisible-p2) (backward-char))) - (t - (call-interactively - (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line)))) + (move-fun (cond ((org-bound-and-true-p visual-line-mode) + 'end-of-visual-line) + ((fboundp 'move-end-of-line) 'move-end-of-line) + (t 'end-of-line)))) + (if (or (not special) arg) (call-interactively move-fun) + (let* ((element (save-excursion (beginning-of-line) + (org-element-at-point))) + (type (org-element-type element))) + (cond + ((memq type '(headline inlinetask)) + (let ((pos (point))) + (beginning-of-line 1) + (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\)?$")) + (if (eq special t) + (if (or (< pos (match-beginning 1)) (= pos (match-end 0))) + (goto-char (match-beginning 1)) + (goto-char (match-end 0))) + (if (or (< pos (match-end 0)) + (not (eq this-command last-command))) + (goto-char (match-end 0)) + (goto-char (match-beginning 1)))) + (call-interactively move-fun)))) + ((org-element-property :hiddenp element) + ;; If element is hidden, `move-end-of-line' would put point + ;; after it. Use `end-of-line' to stay on current line. + (call-interactively 'end-of-line)) + (t (call-interactively move-fun))))) (org-no-warnings (and (featurep 'xemacs) (setq zmacs-region-stays t))))) (define-key org-mode-map "\C-a" 'org-beginning-of-line) @@ -21400,7 +21412,7 @@ depending on context." (not (y-or-n-p "Kill hidden subtree along with headline? "))) (error "C-k aborted - would kill hidden subtree"))) (call-interactively - (if (and (boundp 'visual-line-mode) visual-line-mode) 'kill-visual-line 'kill-line))) + (if (org-bound-and-true-p visual-line-mode) 'kill-visual-line 'kill-line))) ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$")) (kill-region (point) (match-beginning 1)) (org-set-tags nil t)) diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 10355451480..f7248e2d2d3 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -1452,8 +1452,21 @@ comment at the start of cc-engine.el for more info." ;; return t when moving backwards at bob. (not (bobp)) - (if (let (open-paren-in-column-0-is-defun-start) - (forward-comment -1)) + (if (let (open-paren-in-column-0-is-defun-start moved-comment) + (while + (and (not (setq moved-comment (forward-comment -1))) + ;; Cope specifically with ^M^J here - + ;; forward-comment sometimes gets stuck after ^Ms, + ;; sometimes after ^M^J. + (or + (when (eq (char-before) ?\r) + (backward-char) + t) + (when (and (eq (char-before) ?\n) + (eq (char-before (1- (point))) ?\r)) + (backward-char 2) + t)))) + moved-comment) (if (looking-at "\\*/") ;; Emacs <= 20 and XEmacs move back over the ;; closer of a block comment that lacks an opener. diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index a2c8453a011..67388c0339b 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2692,17 +2692,17 @@ The skeleton will be bound to python-skeleton-NAME." (python-skeleton-define def nil "Function name: " - "def " str " (" ("Parameter, %s: " - (unless (equal ?\( (char-before)) ", ") - str) "):" \n - "\"\"\"" - "\"\"\"" \n - > _ \n) + "def " str "(" ("Parameter, %s: " + (unless (equal ?\( (char-before)) ", ") + str) "):" \n + "\"\"\"" - "\"\"\"" \n + > _ \n) (python-skeleton-define class nil "Class name: " - "class " str " (" ("Inheritance, %s: " - (unless (equal ?\( (char-before)) ", ") - str) + "class " str "(" ("Inheritance, %s: " + (unless (equal ?\( (char-before)) ", ") + str) & ")" | -2 ":" \n "\"\"\"" - "\"\"\"" \n diff --git a/src/ChangeLog b/src/ChangeLog index 53c0d93f512..b7bb772d266 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2012-12-13 Eli Zaretskii + + * search.c (search_buffer): Check the inverse translations of each + character in pattern when the buffer being searched is unibyte. + (Bug#13084) + +2012-12-13 Paul Eggert + + * fileio.c (Fvisited_file_modtime): Return (-1 ...) for nonexistent + files, fixing a regression from 24.2. + (Fverify_visited_file_modtime): Don't read uninitialized st.st_size. + 2012-12-13 Paul Eggert * fileio.c (Fcopy_file): Make fstat failure as serious as open failure. diff --git a/src/fileio.c b/src/fileio.c index d9029d29168..874162c5bb6 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -5126,8 +5126,8 @@ See Info node `(elisp)Modification Time' for more details. */) ? get_stat_mtime (&st) : time_error_value (errno)); if (EMACS_TIME_EQ (mtime, b->modtime) - && (st.st_size == b->modtime_size - || b->modtime_size < 0)) + && (b->modtime_size < 0 + || st.st_size == b->modtime_size)) return Qt; return Qnil; } @@ -5154,7 +5154,15 @@ See Info node `(elisp)Modification Time' for more details. */) (void) { if (EMACS_NSECS (current_buffer->modtime) < 0) - return make_number (0); + { + if (EMACS_NSECS (current_buffer->modtime) == NONEXISTENT_MODTIME_NSECS) + { + /* make_lisp_time won't work here if time_t is unsigned. */ + return list4 (make_number (-1), make_number (65535), + make_number (0), make_number (0)); + } + return make_number (0); + } return make_lisp_time (current_buffer->modtime); } diff --git a/src/search.c b/src/search.c index aacdbe33eef..7f26601cc69 100644 --- a/src/search.c +++ b/src/search.c @@ -1406,7 +1406,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, char_base = 0; while (--len >= 0) { - int c, translated; + int c, translated, inverse; /* If we got here and the RE flag is set, it's because we're dealing with a regexp known to be trivial, so the backslash @@ -1420,6 +1420,20 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, c = *base_pat++; TRANSLATE (translated, trt, c); *pat++ = translated; + /* Check that none of C's equivalents violates the + assumptions of boyer_moore. */ + TRANSLATE (inverse, inverse_trt, c); + while (1) + { + if (inverse >= 0200) + { + boyer_moore_ok = 0; + break; + } + if (c == inverse) + break; + TRANSLATE (inverse, inverse_trt, inverse); + } } }