aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-05-11 17:46:28 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-05-11 17:46:28 -0300
commit3aa500b524793cf79de78c373a618d708bf22004 (patch)
treeb8a8daefc49bd737db32b81d875da042ca0a2244
parentf1861ee210a9ccab5b694d97cb9434fda841ba0d (diff)
downloadlua-3aa500b524793cf79de78c373a618d708bf22004.tar.gz
lua-3aa500b524793cf79de78c373a618d708bf22004.tar.bz2
lua-3aa500b524793cf79de78c373a618d708bf22004.zip
new pattern item '+'
-rw-r--r--manual.tex49
1 files changed, 29 insertions, 20 deletions
diff --git a/manual.tex b/manual.tex
index e9bf4b42..1ad30d34 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.30 1999/04/14 20:47:12 roberto Exp roberto $ 1% $Id: manual.tex,v 1.31 1999/05/05 19:21:57 roberto Exp roberto $
2 2
3\documentclass[11pt]{article} 3\documentclass[11pt]{article}
4\usepackage{fullpage,bnf} 4\usepackage{fullpage,bnf}
@@ -41,7 +41,7 @@ Waldemar Celes
41\tecgraf\ --- Computer Science Department --- PUC-Rio 41\tecgraf\ --- Computer Science Department --- PUC-Rio
42} 42}
43 43
44\date{{\small \tt\$Date: 1999/04/14 20:47:12 $ $}} 44\date{{\small \tt\$Date: 1999/05/05 19:21:57 $ $}}
45 45
46\maketitle 46\maketitle
47 47
@@ -1719,9 +1719,9 @@ equivalent to the Lua code:
1719 lua_pushnumber(4); /* 3rd argument */ 1719 lua_pushnumber(4); /* 3rd argument */
1720 lua_callfunction(lua_getglobal("f")); /* call Lua function */ 1720 lua_callfunction(lua_getglobal("f")); /* call Lua function */
1721 lua_pushobject(lua_getresult(1)); /* push first result of the call */ 1721 lua_pushobject(lua_getresult(1)); /* push first result of the call */
1722 lua_setglobal("a"); /* sets global variable 'a' */ 1722 lua_setglobal("a"); /* set global variable 'a' */
1723 lua_pushobject(lua_getresult(2)); /* push second result of the call */ 1723 lua_pushobject(lua_getresult(2)); /* push second result of the call */
1724 lua_setglobal("b"); /* sets global variable 'b' */ 1724 lua_setglobal("b"); /* set global variable 'b' */
1725\end{verbatim} 1725\end{verbatim}
1726 1726
1727Some special Lua functions have exclusive interfaces. 1727Some special Lua functions have exclusive interfaces.
@@ -2459,27 +2459,27 @@ For instance, when \verb|n| is 1 only the first occurrence of
2459 2459
2460Here are some examples: 2460Here are some examples:
2461\begin{verbatim} 2461\begin{verbatim}
2462 x = gsub("hello world", "(%w%w*)", "%1 %1") 2462 x = gsub("hello world", "(%w+)", "%1 %1")
2463 --> x="hello hello world world" 2463 --> x="hello hello world world"
2464 2464
2465 x = gsub("hello world", "(%w%w*)", "%1 %1", 1) 2465 x = gsub("hello world", "(%w+)", "%1 %1", 1)
2466 --> x="hello hello world" 2466 --> x="hello hello world"
2467 2467
2468 x = gsub("hello world from Lua", "(%w%w*)%s*(%w%w*)", "%2 %1") 2468 x = gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")
2469 --> x="world hello Lua from" 2469 --> x="world hello Lua from"
2470 2470
2471 x = gsub("home = $HOME, user = $USER", "$(%w%w*)", getenv) 2471 x = gsub("home = $HOME, user = $USER", "%$(%w+)", getenv)
2472 --> x="home = /home/roberto, user = roberto" (for instance) 2472 --> x="home = /home/roberto, user = roberto" (for instance)
2473 2473
2474 x = gsub("4+5 = $return 4+5$", "$(.-)%$", dostring) 2474 x = gsub("4+5 = $return 4+5$", "%$(.-)%$", dostring)
2475 --> x="4+5 = 9" 2475 --> x="4+5 = 9"
2476 2476
2477 local t = {name="lua", version="3.1"} 2477 local t = {name="lua", version="3.2"}
2478 x = gsub("$name - $version", "$(%w%w*)", function (v) return %t[v] end) 2478 x = gsub("$name - $version", "%$(%w+)", function (v) return %t[v] end)
2479 --> x="lua - 3.1" 2479 --> x="lua - 3.2"
2480 2480
2481 t = {n=0} 2481 t = {n=0}
2482 gsub("first second word", "(%w%w*)", function (w) tinsert(%t, w) end) 2482 gsub("first second word", "(%w+)", function (w) tinsert(%t, w) end)
2483 --> t={"first", "second", "word"; n=3} 2483 --> t={"first", "second", "word"; n=3}
2484\end{verbatim} 2484\end{verbatim}
2485 2485
@@ -2491,7 +2491,7 @@ a \Def{character class} is used to represent a set of characters.
2491The following combinations are allowed in describing a character class: 2491The following combinations are allowed in describing a character class:
2492\begin{description} 2492\begin{description}
2493\item[\emph{x}] (where \emph{x} is any character not in the list 2493\item[\emph{x}] (where \emph{x} is any character not in the list
2494\verb|()%.[]*-?|) 2494\verb|^$()%.[]*+-?|)
2495--- represents the character \emph{x} itself. 2495--- represents the character \emph{x} itself.
2496\item[\T{.}] --- (a dot) represents all characters. 2496\item[\T{.}] --- (a dot) represents all characters.
2497\item[\T{\%a}] --- represents all letters. 2497\item[\T{\%a}] --- represents all letters.
@@ -2507,6 +2507,8 @@ The following combinations are allowed in describing a character class:
2507\item[\T{\%\M{x}}] (where \M{x} is any non alphanumeric character) --- 2507\item[\T{\%\M{x}}] (where \M{x} is any non alphanumeric character) ---
2508represents the character \M{x}. 2508represents the character \M{x}.
2509This is the standard way to escape the magic characters \verb|()%.[]*-?|. 2509This is the standard way to escape the magic characters \verb|()%.[]*-?|.
2510It is strongly recommended that any control character (even the non magic),
2511when used to represent itself in a pattern, should be preceded by a \verb|%|.
2510\item[\T{[char-set]}] --- 2512\item[\T{[char-set]}] ---
2511Represents the class which is the union of all 2513Represents the class which is the union of all
2512characters in char-set. 2514characters in char-set.
@@ -2533,7 +2535,7 @@ In particular, the class \verb|[a-z]| may not be equivalent to \verb|%l|.
2533The second form should be preferred for more portable programs. 2535The second form should be preferred for more portable programs.
2534 2536
2535\paragraph{Pattern Item:} 2537\paragraph{Pattern Item:}
2536a \Def{pattern item} may be: 2538a \Def{pattern item} may be
2537\begin{itemize} 2539\begin{itemize}
2538\item 2540\item
2539a single character class, 2541a single character class,
@@ -2541,12 +2543,16 @@ which matches any single character in the class;
2541\item 2543\item
2542a single character class followed by \verb|*|, 2544a single character class followed by \verb|*|,
2543which matches 0 or more repetitions of characters in the class. 2545which matches 0 or more repetitions of characters in the class.
2544These repetition items will always match the longest possible sequence. 2546These repetition items will always match the longest possible sequence;
2547\item
2548a single character class followed by \verb|+|,
2549which matches 1 or more repetitions of characters in the class.
2550These repetition items will always match the longest possible sequence;
2545\item 2551\item
2546a single character class followed by \verb|-|, 2552a single character class followed by \verb|-|,
2547which also matches 0 or more repetitions of characters in the class. 2553which also matches 0 or more repetitions of characters in the class.
2548Unlike \verb|*|, 2554Unlike \verb|*|,
2549these repetition items will always match the shortest possible sequence. 2555these repetition items will always match the shortest possible sequence;
2550\item 2556\item
2551a single character class followed by \verb|?|, 2557a single character class followed by \verb|?|,
2552which matches 0 or 1 occurrence of a character in the class; 2558which matches 0 or 1 occurrence of a character in the class;
@@ -2804,7 +2810,7 @@ it uses a default pattern that reads the next line
2804 2810
2805A \Def{read pattern} is a sequence of read pattern items. 2811A \Def{read pattern} is a sequence of read pattern items.
2806An item may be a single character class 2812An item may be a single character class
2807or a character class followed by \verb|?| or by \verb|*|. 2813or a character class followed by \verb|?|, by \verb|*|, or by \verb|+|.
2808A single character class reads the next character from the input 2814A single character class reads the next character from the input
2809if it belongs to the class, otherwise it fails. 2815if it belongs to the class, otherwise it fails.
2810A character class followed by \verb|?| reads the next character 2816A character class followed by \verb|?| reads the next character
@@ -2813,6 +2819,9 @@ it never fails.
2813A character class followed by \verb|*| reads until a character that 2819A character class followed by \verb|*| reads until a character that
2814does not belong to the class, or end of file; 2820does not belong to the class, or end of file;
2815since it can match a sequence of zero characters, it never fails. 2821since it can match a sequence of zero characters, it never fails.
2822A character class followed by \verb|+| reads until a character that
2823does not belong to the class, or end of file;
2824it fails if it cannot read at least one character.
2816Note that the behavior of read patterns is slightly different from 2825Note that the behavior of read patterns is slightly different from
2817the regular pattern matching behavior, 2826the regular pattern matching behavior,
2818where a \verb|*| expands to the maximum length \emph{such that} 2827where a \verb|*| expands to the maximum length \emph{such that}
@@ -2838,7 +2847,7 @@ It is equivalent to the pattern \verb|".*"|.
2838\item[``*w''] returns the next word 2847\item[``*w''] returns the next word
2839(maximal sequence of non white-space characters), 2848(maximal sequence of non white-space characters),
2840skipping spaces if necessary, or \nil\ on end of file. 2849skipping spaces if necessary, or \nil\ on end of file.
2841It is equivalent to the pattern \verb|"{%s*}%S%S*"|. 2850It is equivalent to the pattern \verb|"{%s*}%S+"|.
2842\end{description} 2851\end{description}
2843 2852
2844\subsubsection*{\ff \T{write ([filehandle, ] value1, ...)}}\Deffunc{write} 2853\subsubsection*{\ff \T{write ([filehandle, ] value1, ...)}}\Deffunc{write}