diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-05-11 17:46:28 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-05-11 17:46:28 -0300 |
commit | 3aa500b524793cf79de78c373a618d708bf22004 (patch) | |
tree | b8a8daefc49bd737db32b81d875da042ca0a2244 | |
parent | f1861ee210a9ccab5b694d97cb9434fda841ba0d (diff) | |
download | lua-3aa500b524793cf79de78c373a618d708bf22004.tar.gz lua-3aa500b524793cf79de78c373a618d708bf22004.tar.bz2 lua-3aa500b524793cf79de78c373a618d708bf22004.zip |
new pattern item '+'
-rw-r--r-- | manual.tex | 49 |
1 files changed, 29 insertions, 20 deletions
@@ -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 | ||
1727 | Some special Lua functions have exclusive interfaces. | 1727 | Some special Lua functions have exclusive interfaces. |
@@ -2459,27 +2459,27 @@ For instance, when \verb|n| is 1 only the first occurrence of | |||
2459 | 2459 | ||
2460 | Here are some examples: | 2460 | Here 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. | |||
2491 | The following combinations are allowed in describing a character class: | 2491 | The 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) --- |
2508 | represents the character \M{x}. | 2508 | represents the character \M{x}. |
2509 | This is the standard way to escape the magic characters \verb|()%.[]*-?|. | 2509 | This is the standard way to escape the magic characters \verb|()%.[]*-?|. |
2510 | It is strongly recommended that any control character (even the non magic), | ||
2511 | when used to represent itself in a pattern, should be preceded by a \verb|%|. | ||
2510 | \item[\T{[char-set]}] --- | 2512 | \item[\T{[char-set]}] --- |
2511 | Represents the class which is the union of all | 2513 | Represents the class which is the union of all |
2512 | characters in char-set. | 2514 | characters in char-set. |
@@ -2533,7 +2535,7 @@ In particular, the class \verb|[a-z]| may not be equivalent to \verb|%l|. | |||
2533 | The second form should be preferred for more portable programs. | 2535 | The second form should be preferred for more portable programs. |
2534 | 2536 | ||
2535 | \paragraph{Pattern Item:} | 2537 | \paragraph{Pattern Item:} |
2536 | a \Def{pattern item} may be: | 2538 | a \Def{pattern item} may be |
2537 | \begin{itemize} | 2539 | \begin{itemize} |
2538 | \item | 2540 | \item |
2539 | a single character class, | 2541 | a single character class, |
@@ -2541,12 +2543,16 @@ which matches any single character in the class; | |||
2541 | \item | 2543 | \item |
2542 | a single character class followed by \verb|*|, | 2544 | a single character class followed by \verb|*|, |
2543 | which matches 0 or more repetitions of characters in the class. | 2545 | which matches 0 or more repetitions of characters in the class. |
2544 | These repetition items will always match the longest possible sequence. | 2546 | These repetition items will always match the longest possible sequence; |
2547 | \item | ||
2548 | a single character class followed by \verb|+|, | ||
2549 | which matches 1 or more repetitions of characters in the class. | ||
2550 | These repetition items will always match the longest possible sequence; | ||
2545 | \item | 2551 | \item |
2546 | a single character class followed by \verb|-|, | 2552 | a single character class followed by \verb|-|, |
2547 | which also matches 0 or more repetitions of characters in the class. | 2553 | which also matches 0 or more repetitions of characters in the class. |
2548 | Unlike \verb|*|, | 2554 | Unlike \verb|*|, |
2549 | these repetition items will always match the shortest possible sequence. | 2555 | these repetition items will always match the shortest possible sequence; |
2550 | \item | 2556 | \item |
2551 | a single character class followed by \verb|?|, | 2557 | a single character class followed by \verb|?|, |
2552 | which matches 0 or 1 occurrence of a character in the class; | 2558 | which 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 | ||
2805 | A \Def{read pattern} is a sequence of read pattern items. | 2811 | A \Def{read pattern} is a sequence of read pattern items. |
2806 | An item may be a single character class | 2812 | An item may be a single character class |
2807 | or a character class followed by \verb|?| or by \verb|*|. | 2813 | or a character class followed by \verb|?|, by \verb|*|, or by \verb|+|. |
2808 | A single character class reads the next character from the input | 2814 | A single character class reads the next character from the input |
2809 | if it belongs to the class, otherwise it fails. | 2815 | if it belongs to the class, otherwise it fails. |
2810 | A character class followed by \verb|?| reads the next character | 2816 | A character class followed by \verb|?| reads the next character |
@@ -2813,6 +2819,9 @@ it never fails. | |||
2813 | A character class followed by \verb|*| reads until a character that | 2819 | A character class followed by \verb|*| reads until a character that |
2814 | does not belong to the class, or end of file; | 2820 | does not belong to the class, or end of file; |
2815 | since it can match a sequence of zero characters, it never fails. | 2821 | since it can match a sequence of zero characters, it never fails. |
2822 | A character class followed by \verb|+| reads until a character that | ||
2823 | does not belong to the class, or end of file; | ||
2824 | it fails if it cannot read at least one character. | ||
2816 | Note that the behavior of read patterns is slightly different from | 2825 | Note that the behavior of read patterns is slightly different from |
2817 | the regular pattern matching behavior, | 2826 | the regular pattern matching behavior, |
2818 | where a \verb|*| expands to the maximum length \emph{such that} | 2827 | where 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), |
2840 | skipping spaces if necessary, or \nil\ on end of file. | 2849 | skipping spaces if necessary, or \nil\ on end of file. |
2841 | It is equivalent to the pattern \verb|"{%s*}%S%S*"|. | 2850 | It 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} |