mirror of https://github.com/matrix-org/go-neb.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
974 lines
34 KiB
974 lines
34 KiB
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="theme-color" content="#375EAB">
|
|
|
|
<title>syntax - The Go Programming Language</title>
|
|
|
|
<link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
|
|
|
|
<link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
|
|
<script type="text/javascript">window.initFuncs = [];</script>
|
|
</head>
|
|
<body>
|
|
|
|
<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
|
|
...
|
|
</div><!-- #lowframe -->
|
|
|
|
<div id="topbar" class="wide"><div class="container">
|
|
<div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
|
|
<div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
|
|
<a href="index.html#" id="menu-button"><span id="menu-button-arrow">▽</span></a>
|
|
<form method="GET" action="http://localhost:6060/search">
|
|
<div id="menu">
|
|
<a href="http://localhost:6060/doc/">Documents</a>
|
|
<a href="http://localhost:6060/pkg/">Packages</a>
|
|
<a href="http://localhost:6060/project/">The Project</a>
|
|
<a href="http://localhost:6060/help/">Help</a>
|
|
<a href="http://localhost:6060/blog/">Blog</a>
|
|
|
|
<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
|
|
</div>
|
|
</form>
|
|
|
|
</div></div>
|
|
|
|
|
|
|
|
<div id="page" class="wide">
|
|
<div class="container">
|
|
|
|
|
|
<h1>Package syntax</h1>
|
|
|
|
|
|
|
|
|
|
<div id="nav"></div>
|
|
|
|
|
|
<!--
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
Use of this source code is governed by a BSD-style
|
|
license that can be found in the LICENSE file.
|
|
-->
|
|
<!--
|
|
Note: Static (i.e., not template-generated) href and id
|
|
attributes start with "pkg-" to make it impossible for
|
|
them to conflict with generated attributes (some of which
|
|
correspond to Go identifiers).
|
|
-->
|
|
|
|
<script type='text/javascript'>
|
|
document.ANALYSIS_DATA = null;
|
|
document.CALLGRAPH = null;
|
|
</script>
|
|
|
|
|
|
|
|
<div id="short-nav">
|
|
<dl>
|
|
<dd><code>import "regexp/syntax"</code></dd>
|
|
</dl>
|
|
<dl>
|
|
<dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
|
|
<dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
|
|
|
|
|
|
</dl>
|
|
</div>
|
|
<!-- The package's Name is printed as title by the top-level template -->
|
|
<div id="pkg-overview" class="toggleVisible">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
|
|
</div>
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
|
|
<p>
|
|
Package syntax parses regular expressions into parse trees and compiles
|
|
parse trees into programs. Most clients of regular expressions will use the
|
|
facilities of package regexp (such as Compile and Match) instead of this package.
|
|
</p>
|
|
<h3 id="hdr-Syntax">Syntax</h3>
|
|
<p>
|
|
The regular expression syntax understood by this package when parsing with the Perl flag is as follows.
|
|
Parts of the syntax can be disabled by passing alternate flags to Parse.
|
|
</p>
|
|
<p>
|
|
Single characters:
|
|
</p>
|
|
<pre>. any character, possibly including newline (flag s=true)
|
|
[xyz] character class
|
|
[^xyz] negated character class
|
|
\d Perl character class
|
|
\D negated Perl character class
|
|
[[:alpha:]] ASCII character class
|
|
[[:^alpha:]] negated ASCII character class
|
|
\pN Unicode character class (one-letter name)
|
|
\p{Greek} Unicode character class
|
|
\PN negated Unicode character class (one-letter name)
|
|
\P{Greek} negated Unicode character class
|
|
</pre>
|
|
<p>
|
|
Composites:
|
|
</p>
|
|
<pre>xy x followed by y
|
|
x|y x or y (prefer x)
|
|
</pre>
|
|
<p>
|
|
Repetitions:
|
|
</p>
|
|
<pre>x* zero or more x, prefer more
|
|
x+ one or more x, prefer more
|
|
x? zero or one x, prefer one
|
|
x{n,m} n or n+1 or ... or m x, prefer more
|
|
x{n,} n or more x, prefer more
|
|
x{n} exactly n x
|
|
x*? zero or more x, prefer fewer
|
|
x+? one or more x, prefer fewer
|
|
x?? zero or one x, prefer zero
|
|
x{n,m}? n or n+1 or ... or m x, prefer fewer
|
|
x{n,}? n or more x, prefer fewer
|
|
x{n}? exactly n x
|
|
</pre>
|
|
<p>
|
|
Implementation restriction: The counting forms x{n,m}, x{n,}, and x{n}
|
|
reject forms that create a minimum or maximum repetition count above 1000.
|
|
Unlimited repetitions are not subject to this restriction.
|
|
</p>
|
|
<p>
|
|
Grouping:
|
|
</p>
|
|
<pre>(re) numbered capturing group (submatch)
|
|
(?P<name>re) named & numbered capturing group (submatch)
|
|
(?:re) non-capturing group
|
|
(?flags) set flags within current group; non-capturing
|
|
(?flags:re) set flags during re; non-capturing
|
|
|
|
Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:
|
|
|
|
i case-insensitive (default false)
|
|
m multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
|
|
s let . match \n (default false)
|
|
U ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)
|
|
</pre>
|
|
<p>
|
|
Empty strings:
|
|
</p>
|
|
<pre>^ at beginning of text or line (flag m=true)
|
|
$ at end of text (like \z not \Z) or line (flag m=true)
|
|
\A at beginning of text
|
|
\b at ASCII word boundary (\w on one side and \W, \A, or \z on the other)
|
|
\B not at ASCII word boundary
|
|
\z at end of text
|
|
</pre>
|
|
<p>
|
|
Escape sequences:
|
|
</p>
|
|
<pre>\a bell (== \007)
|
|
\f form feed (== \014)
|
|
\t horizontal tab (== \011)
|
|
\n newline (== \012)
|
|
\r carriage return (== \015)
|
|
\v vertical tab character (== \013)
|
|
\* literal *, for any punctuation character *
|
|
\123 octal character code (up to three digits)
|
|
\x7F hex character code (exactly two digits)
|
|
\x{10FFFF} hex character code
|
|
\Q...\E literal text ... even if ... has punctuation
|
|
</pre>
|
|
<p>
|
|
Character class elements:
|
|
</p>
|
|
<pre>x single character
|
|
A-Z character range (inclusive)
|
|
\d Perl character class
|
|
[:foo:] ASCII character class foo
|
|
\p{Foo} Unicode character class Foo
|
|
\pF Unicode character class F (one-letter name)
|
|
</pre>
|
|
<p>
|
|
Named character classes as character class elements:
|
|
</p>
|
|
<pre>[\d] digits (== \d)
|
|
[^\d] not digits (== \D)
|
|
[\D] not digits (== \D)
|
|
[^\D] not not digits (== \d)
|
|
[[:name:]] named ASCII class inside character class (== [:name:])
|
|
[^[:name:]] named ASCII class inside negated character class (== [:^name:])
|
|
[\p{Name}] named Unicode property inside character class (== \p{Name})
|
|
[^\p{Name}] named Unicode property inside negated character class (== \P{Name})
|
|
</pre>
|
|
<p>
|
|
Perl character classes (all ASCII-only):
|
|
</p>
|
|
<pre>\d digits (== [0-9])
|
|
\D not digits (== [^0-9])
|
|
\s whitespace (== [\t\n\f\r ])
|
|
\S not whitespace (== [^\t\n\f\r ])
|
|
\w word characters (== [0-9A-Za-z_])
|
|
\W not word characters (== [^0-9A-Za-z_])
|
|
</pre>
|
|
<p>
|
|
ASCII character classes:
|
|
</p>
|
|
<pre>[[:alnum:]] alphanumeric (== [0-9A-Za-z])
|
|
[[:alpha:]] alphabetic (== [A-Za-z])
|
|
[[:ascii:]] ASCII (== [\x00-\x7F])
|
|
[[:blank:]] blank (== [\t ])
|
|
[[:cntrl:]] control (== [\x00-\x1F\x7F])
|
|
[[:digit:]] digits (== [0-9])
|
|
[[:graph:]] graphical (== [!-~] == [A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])
|
|
[[:lower:]] lower case (== [a-z])
|
|
[[:print:]] printable (== [ -~] == [ [:graph:]])
|
|
[[:punct:]] punctuation (== [!-/:-@[-`{-~])
|
|
[[:space:]] whitespace (== [\t\n\v\f\r ])
|
|
[[:upper:]] upper case (== [A-Z])
|
|
[[:word:]] word characters (== [0-9A-Za-z_])
|
|
[[:xdigit:]] hex digit (== [0-9A-Fa-f])
|
|
</pre>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div id="pkg-index" class="toggleVisible">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
|
|
</div>
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
|
|
|
|
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
|
|
<div id="manual-nav">
|
|
<dl>
|
|
|
|
|
|
|
|
|
|
<dd><a href="index.html#IsWordChar">func IsWordChar(r rune) bool</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#EmptyOp">type EmptyOp</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#EmptyOpContext">func EmptyOpContext(r1, r2 rune) EmptyOp</a></dd>
|
|
|
|
|
|
|
|
|
|
<dd><a href="index.html#Error">type Error</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#Error.Error">func (e *Error) Error() string</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#ErrorCode">type ErrorCode</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#ErrorCode.String">func (e ErrorCode) String() string</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#Flags">type Flags</a></dd>
|
|
|
|
|
|
|
|
|
|
<dd><a href="index.html#Inst">type Inst</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#Inst.MatchEmptyWidth">func (i *Inst) MatchEmptyWidth(before rune, after rune) bool</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Inst.MatchRune">func (i *Inst) MatchRune(r rune) bool</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Inst.MatchRunePos">func (i *Inst) MatchRunePos(r rune) int</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Inst.String">func (i *Inst) String() string</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#InstOp">type InstOp</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#InstOp.String">func (i InstOp) String() string</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#Op">type Op</a></dd>
|
|
|
|
|
|
|
|
|
|
<dd><a href="index.html#Prog">type Prog</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Compile">func Compile(re *Regexp) (*Prog, error)</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#Prog.Prefix">func (p *Prog) Prefix() (prefix string, complete bool)</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Prog.StartCond">func (p *Prog) StartCond() EmptyOp</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Prog.String">func (p *Prog) String() string</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#Regexp">type Regexp</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Parse">func Parse(s string, flags Flags) (*Regexp, error)</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#Regexp.CapNames">func (re *Regexp) CapNames() []string</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Regexp.Equal">func (x *Regexp) Equal(y *Regexp) bool</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Regexp.MaxCap">func (re *Regexp) MaxCap() int</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Regexp.Simplify">func (re *Regexp) Simplify() *Regexp</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Regexp.String">func (re *Regexp) String() string</a></dd>
|
|
|
|
|
|
|
|
</dl>
|
|
</div><!-- #manual-nav -->
|
|
|
|
|
|
|
|
|
|
<h4>Package files</h4>
|
|
<p>
|
|
<span style="font-size:90%">
|
|
|
|
<a href="http://localhost:6060/src/regexp/syntax/compile.go">compile.go</a>
|
|
|
|
<a href="http://localhost:6060/src/regexp/syntax/doc.go">doc.go</a>
|
|
|
|
<a href="http://localhost:6060/src/regexp/syntax/parse.go">parse.go</a>
|
|
|
|
<a href="http://localhost:6060/src/regexp/syntax/perl_groups.go">perl_groups.go</a>
|
|
|
|
<a href="http://localhost:6060/src/regexp/syntax/prog.go">prog.go</a>
|
|
|
|
<a href="http://localhost:6060/src/regexp/syntax/regexp.go">regexp.go</a>
|
|
|
|
<a href="http://localhost:6060/src/regexp/syntax/simplify.go">simplify.go</a>
|
|
|
|
</span>
|
|
</p>
|
|
|
|
</div><!-- .expanded -->
|
|
</div><!-- #pkg-index -->
|
|
|
|
<div id="pkg-callgraph" class="toggle" style="display: none">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
|
|
</div> <!-- .expanded -->
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
|
|
<p>
|
|
In the call graph viewer below, each node
|
|
is a function belonging to this package
|
|
and its children are the functions it
|
|
calls—perhaps dynamically.
|
|
</p>
|
|
<p>
|
|
The root nodes are the entry points of the
|
|
package: functions that may be called from
|
|
outside the package.
|
|
There may be non-exported or anonymous
|
|
functions among them if they are called
|
|
dynamically from another package.
|
|
</p>
|
|
<p>
|
|
Click a node to visit that function's source code.
|
|
From there you can visit its callers by
|
|
clicking its declaring <code>func</code>
|
|
token.
|
|
</p>
|
|
<p>
|
|
Functions may be omitted if they were
|
|
determined to be unreachable in the
|
|
particular programs or tests that were
|
|
analyzed.
|
|
</p>
|
|
<!-- Zero means show all package entry points. -->
|
|
<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
|
|
</div>
|
|
</div> <!-- #pkg-callgraph -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="IsWordChar">func <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=2213:2241#L97">IsWordChar</a></h2>
|
|
<pre>func IsWordChar(r <a href="../../builtin/index.html#rune">rune</a>) <a href="../../builtin/index.html#bool">bool</a></pre>
|
|
<p>
|
|
IsWordChar reports whether r is consider a “word character”
|
|
during the evaluation of the \b and \B zero-width assertions.
|
|
These assertions are ASCII-only: the word characters are [A-Za-z0-9_].
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="EmptyOp">type <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=1078:1096#L52">EmptyOp</a></h2>
|
|
<pre>type EmptyOp <a href="../../builtin/index.html#uint8">uint8</a></pre>
|
|
<p>
|
|
An EmptyOp specifies a kind or mixture of zero-width assertions.
|
|
</p>
|
|
|
|
|
|
|
|
<pre>const (
|
|
<span id="EmptyBeginLine">EmptyBeginLine</span> <a href="index.html#EmptyOp">EmptyOp</a> = 1 << <a href="../../builtin/index.html#iota">iota</a>
|
|
<span id="EmptyEndLine">EmptyEndLine</span>
|
|
<span id="EmptyBeginText">EmptyBeginText</span>
|
|
<span id="EmptyEndText">EmptyEndText</span>
|
|
<span id="EmptyWordBoundary">EmptyWordBoundary</span>
|
|
<span id="EmptyNoWordBoundary">EmptyNoWordBoundary</span>
|
|
)</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="EmptyOpContext">func <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=1501:1541#L69">EmptyOpContext</a></h3>
|
|
<pre>func EmptyOpContext(r1, r2 <a href="../../builtin/index.html#rune">rune</a>) <a href="index.html#EmptyOp">EmptyOp</a></pre>
|
|
<p>
|
|
EmptyOpContext returns the zero-width assertions
|
|
satisfied at the position between the runes r1 and r2.
|
|
Passing r1 == -1 indicates that the position is
|
|
at the beginning of the text.
|
|
Passing r2 == -1 indicates that the position is
|
|
at the end of the text.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Error">type <a href="http://localhost:6060/src/regexp/syntax/parse.go?s=336:386#L6">Error</a></h2>
|
|
<pre>type Error struct {
|
|
Code <a href="index.html#ErrorCode">ErrorCode</a>
|
|
Expr <a href="../../builtin/index.html#string">string</a>
|
|
}</pre>
|
|
<p>
|
|
An Error describes a failure to parse a regular expression
|
|
and gives the offending expression.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Error.Error">func (*Error) <a href="http://localhost:6060/src/regexp/syntax/parse.go?s=388:418#L11">Error</a></h3>
|
|
<pre>func (e *<a href="index.html#Error">Error</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="ErrorCode">type <a href="http://localhost:6060/src/regexp/syntax/parse.go?s=565:586#L16">ErrorCode</a></h2>
|
|
<pre>type ErrorCode <a href="../../builtin/index.html#string">string</a></pre>
|
|
<p>
|
|
An ErrorCode describes a failure to parse a regular expression.
|
|
</p>
|
|
|
|
|
|
|
|
<pre>const (
|
|
<span class="comment">// Unexpected error</span>
|
|
<span id="ErrInternalError">ErrInternalError</span> <a href="index.html#ErrorCode">ErrorCode</a> = "regexp/syntax: internal error"
|
|
|
|
<span class="comment">// Parse errors</span>
|
|
<span id="ErrInvalidCharClass">ErrInvalidCharClass</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid character class"
|
|
<span id="ErrInvalidCharRange">ErrInvalidCharRange</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid character class range"
|
|
<span id="ErrInvalidEscape">ErrInvalidEscape</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid escape sequence"
|
|
<span id="ErrInvalidNamedCapture">ErrInvalidNamedCapture</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid named capture"
|
|
<span id="ErrInvalidPerlOp">ErrInvalidPerlOp</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid or unsupported Perl syntax"
|
|
<span id="ErrInvalidRepeatOp">ErrInvalidRepeatOp</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid nested repetition operator"
|
|
<span id="ErrInvalidRepeatSize">ErrInvalidRepeatSize</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid repeat count"
|
|
<span id="ErrInvalidUTF8">ErrInvalidUTF8</span> <a href="index.html#ErrorCode">ErrorCode</a> = "invalid UTF-8"
|
|
<span id="ErrMissingBracket">ErrMissingBracket</span> <a href="index.html#ErrorCode">ErrorCode</a> = "missing closing ]"
|
|
<span id="ErrMissingParen">ErrMissingParen</span> <a href="index.html#ErrorCode">ErrorCode</a> = "missing closing )"
|
|
<span id="ErrMissingRepeatArgument">ErrMissingRepeatArgument</span> <a href="index.html#ErrorCode">ErrorCode</a> = "missing argument to repetition operator"
|
|
<span id="ErrTrailingBackslash">ErrTrailingBackslash</span> <a href="index.html#ErrorCode">ErrorCode</a> = "trailing backslash at end of expression"
|
|
<span id="ErrUnexpectedParen">ErrUnexpectedParen</span> <a href="index.html#ErrorCode">ErrorCode</a> = "unexpected )"
|
|
)</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="ErrorCode.String">func (ErrorCode) <a href="http://localhost:6060/src/regexp/syntax/parse.go?s=1554:1588#L38">String</a></h3>
|
|
<pre>func (e <a href="index.html#ErrorCode">ErrorCode</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Flags">type <a href="http://localhost:6060/src/regexp/syntax/parse.go?s=1701:1718#L43">Flags</a></h2>
|
|
<pre>type Flags <a href="../../builtin/index.html#uint16">uint16</a></pre>
|
|
<p>
|
|
Flags control the behavior of the parser and record information about regexp context.
|
|
</p>
|
|
|
|
|
|
|
|
<pre>const (
|
|
<span id="FoldCase">FoldCase</span> <a href="index.html#Flags">Flags</a> = 1 << <a href="../../builtin/index.html#iota">iota</a> <span class="comment">// case-insensitive match</span>
|
|
<span id="Literal">Literal</span> <span class="comment">// treat pattern as literal string</span>
|
|
<span id="ClassNL">ClassNL</span> <span class="comment">// allow character classes like [^a-z] and [[:space:]] to match newline</span>
|
|
<span id="DotNL">DotNL</span> <span class="comment">// allow . to match newline</span>
|
|
<span id="OneLine">OneLine</span> <span class="comment">// treat ^ and $ as only matching at beginning and end of text</span>
|
|
<span id="NonGreedy">NonGreedy</span> <span class="comment">// make repetition operators default to non-greedy</span>
|
|
<span id="PerlX">PerlX</span> <span class="comment">// allow Perl extensions</span>
|
|
<span id="UnicodeGroups">UnicodeGroups</span> <span class="comment">// allow \p{Han}, \P{Han} for Unicode group and negation</span>
|
|
<span id="WasDollar">WasDollar</span> <span class="comment">// regexp OpEndText was $, not \z</span>
|
|
<span id="Simple">Simple</span> <span class="comment">// regexp contains no counted repetition</span>
|
|
|
|
<span id="MatchNL">MatchNL</span> = <a href="index.html#ClassNL">ClassNL</a> | <a href="index.html#DotNL">DotNL</a>
|
|
|
|
<span id="Perl">Perl</span> = <a href="index.html#ClassNL">ClassNL</a> | <a href="index.html#OneLine">OneLine</a> | <a href="index.html#PerlX">PerlX</a> | <a href="index.html#UnicodeGroups">UnicodeGroups</a> <span class="comment">// as close to Perl as possible</span>
|
|
<span id="POSIX">POSIX</span> <a href="index.html#Flags">Flags</a> = 0 <span class="comment">// POSIX syntax</span>
|
|
)</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Inst">type <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=2404:2561#L102">Inst</a></h2>
|
|
<pre>type Inst struct {
|
|
Op <a href="index.html#InstOp">InstOp</a>
|
|
Out <a href="../../builtin/index.html#uint32">uint32</a> <span class="comment">// all but InstMatch, InstFail</span>
|
|
Arg <a href="../../builtin/index.html#uint32">uint32</a> <span class="comment">// InstAlt, InstAltMatch, InstCapture, InstEmptyWidth</span>
|
|
Rune []<a href="../../builtin/index.html#rune">rune</a>
|
|
}</pre>
|
|
<p>
|
|
An Inst is a single instruction in a regular expression program.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Inst.MatchEmptyWidth">func (*Inst) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=5960:6020#L252">MatchEmptyWidth</a></h3>
|
|
<pre>func (i *<a href="index.html#Inst">Inst</a>) MatchEmptyWidth(before <a href="../../builtin/index.html#rune">rune</a>, after <a href="../../builtin/index.html#rune">rune</a>) <a href="../../builtin/index.html#bool">bool</a></pre>
|
|
<p>
|
|
MatchEmptyWidth reports whether the instruction matches
|
|
an empty string between the runes before and after.
|
|
It should only be called when i.Op == InstEmptyWidth.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Inst.MatchRune">func (*Inst) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=4334:4371#L184">MatchRune</a></h3>
|
|
<pre>func (i *<a href="index.html#Inst">Inst</a>) MatchRune(r <a href="../../builtin/index.html#rune">rune</a>) <a href="../../builtin/index.html#bool">bool</a></pre>
|
|
<p>
|
|
MatchRune reports whether the instruction matches (and consumes) r.
|
|
It should only be called when i.Op == InstRune.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Inst.MatchRunePos">func (*Inst) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=4699:4738#L193">MatchRunePos</a></h3>
|
|
<pre>func (i *<a href="index.html#Inst">Inst</a>) MatchRunePos(r <a href="../../builtin/index.html#rune">rune</a>) <a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
MatchRunePos checks whether the instruction matches (and consumes) r.
|
|
If so, MatchRunePos returns the index of the matching rune pair
|
|
(or, when len(i.Rune) == 1, rune singleton).
|
|
If not, MatchRunePos returns -1.
|
|
MatchRunePos should only be called when i.Op == InstRune.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Inst.String">func (*Inst) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=6435:6465#L270">String</a></h3>
|
|
<pre>func (i *<a href="index.html#Inst">Inst</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="InstOp">type <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=519:536#L14">InstOp</a></h2>
|
|
<pre>type InstOp <a href="../../builtin/index.html#uint8">uint8</a></pre>
|
|
<p>
|
|
An InstOp is an instruction opcode.
|
|
</p>
|
|
|
|
|
|
|
|
<pre>const (
|
|
<span id="InstAlt">InstAlt</span> <a href="index.html#InstOp">InstOp</a> = <a href="../../builtin/index.html#iota">iota</a>
|
|
<span id="InstAltMatch">InstAltMatch</span>
|
|
<span id="InstCapture">InstCapture</span>
|
|
<span id="InstEmptyWidth">InstEmptyWidth</span>
|
|
<span id="InstMatch">InstMatch</span>
|
|
<span id="InstFail">InstFail</span>
|
|
<span id="InstNop">InstNop</span>
|
|
<span id="InstRune">InstRune</span>
|
|
<span id="InstRune1">InstRune1</span>
|
|
<span id="InstRuneAny">InstRuneAny</span>
|
|
<span id="InstRuneAnyNotNL">InstRuneAnyNotNL</span>
|
|
)</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="InstOp.String">func (InstOp) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=895:926#L44">String</a></h3>
|
|
<pre>func (i <a href="index.html#InstOp">InstOp</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Op">type <a href="http://localhost:6060/src/regexp/syntax/regexp.go?s=859:872#L21">Op</a></h2>
|
|
<pre>type Op <a href="../../builtin/index.html#uint8">uint8</a></pre>
|
|
<p>
|
|
An Op is a single regular expression operator.
|
|
</p>
|
|
|
|
|
|
|
|
<pre>const (
|
|
<span id="OpNoMatch">OpNoMatch</span> <a href="index.html#Op">Op</a> = 1 + <a href="../../builtin/index.html#iota">iota</a> <span class="comment">// matches no strings</span>
|
|
<span id="OpEmptyMatch">OpEmptyMatch</span> <span class="comment">// matches empty string</span>
|
|
<span id="OpLiteral">OpLiteral</span> <span class="comment">// matches Runes sequence</span>
|
|
<span id="OpCharClass">OpCharClass</span> <span class="comment">// matches Runes interpreted as range pair list</span>
|
|
<span id="OpAnyCharNotNL">OpAnyCharNotNL</span> <span class="comment">// matches any character except newline</span>
|
|
<span id="OpAnyChar">OpAnyChar</span> <span class="comment">// matches any character</span>
|
|
<span id="OpBeginLine">OpBeginLine</span> <span class="comment">// matches empty string at beginning of line</span>
|
|
<span id="OpEndLine">OpEndLine</span> <span class="comment">// matches empty string at end of line</span>
|
|
<span id="OpBeginText">OpBeginText</span> <span class="comment">// matches empty string at beginning of text</span>
|
|
<span id="OpEndText">OpEndText</span> <span class="comment">// matches empty string at end of text</span>
|
|
<span id="OpWordBoundary">OpWordBoundary</span> <span class="comment">// matches word boundary `\b`</span>
|
|
<span id="OpNoWordBoundary">OpNoWordBoundary</span> <span class="comment">// matches word non-boundary `\B`</span>
|
|
<span id="OpCapture">OpCapture</span> <span class="comment">// capturing subexpression with index Cap, optional name Name</span>
|
|
<span id="OpStar">OpStar</span> <span class="comment">// matches Sub[0] zero or more times</span>
|
|
<span id="OpPlus">OpPlus</span> <span class="comment">// matches Sub[0] one or more times</span>
|
|
<span id="OpQuest">OpQuest</span> <span class="comment">// matches Sub[0] zero or one times</span>
|
|
<span id="OpRepeat">OpRepeat</span> <span class="comment">// matches Sub[0] at least Min times, at most Max (Max == -1 is no limit)</span>
|
|
<span id="OpConcat">OpConcat</span> <span class="comment">// matches concatenation of Subs</span>
|
|
<span id="OpAlternate">OpAlternate</span> <span class="comment">// matches alternation of Subs</span>
|
|
)</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Prog">type <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=352:478#L7">Prog</a></h2>
|
|
<pre>type Prog struct {
|
|
Inst []<a href="index.html#Inst">Inst</a>
|
|
Start <a href="../../builtin/index.html#int">int</a> <span class="comment">// index of start instruction</span>
|
|
NumCap <a href="../../builtin/index.html#int">int</a> <span class="comment">// number of InstCapture insts in re</span>
|
|
}</pre>
|
|
<p>
|
|
A Prog is a compiled regular expression program.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Compile">func <a href="http://localhost:6060/src/regexp/syntax/compile.go?s=1854:1893#L70">Compile</a></h3>
|
|
<pre>func Compile(re *<a href="index.html#Regexp">Regexp</a>) (*<a href="index.html#Prog">Prog</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
|
|
<p>
|
|
Compile compiles the regexp into a program to be executed.
|
|
The regexp should have been simplified already (returned from re.Simplify).
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Prog.Prefix">func (*Prog) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=3259:3313#L139">Prefix</a></h3>
|
|
<pre>func (p *<a href="index.html#Prog">Prog</a>) Prefix() (prefix <a href="../../builtin/index.html#string">string</a>, complete <a href="../../builtin/index.html#bool">bool</a>)</pre>
|
|
<p>
|
|
Prefix returns a literal string that all matches for the
|
|
regexp must start with. Complete is true if the prefix
|
|
is the entire match.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Prog.StartCond">func (*Prog) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=3860:3894#L158">StartCond</a></h3>
|
|
<pre>func (p *<a href="index.html#Prog">Prog</a>) StartCond() <a href="index.html#EmptyOp">EmptyOp</a></pre>
|
|
<p>
|
|
StartCond returns the leading empty-width conditions that must
|
|
be true in any match. It returns ^EmptyOp(0) if no matches are possible.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Prog.String">func (*Prog) <a href="http://localhost:6060/src/regexp/syntax/prog.go?s=2563:2593#L109">String</a></h3>
|
|
<pre>func (p *<a href="index.html#Prog">Prog</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Regexp">type <a href="http://localhost:6060/src/regexp/syntax/regexp.go?s=383:807#L8">Regexp</a></h2>
|
|
<pre>type Regexp struct {
|
|
Op <a href="index.html#Op">Op</a> <span class="comment">// operator</span>
|
|
Flags <a href="index.html#Flags">Flags</a>
|
|
Sub []*<a href="index.html#Regexp">Regexp</a> <span class="comment">// subexpressions, if any</span>
|
|
Sub0 [1]*<a href="index.html#Regexp">Regexp</a> <span class="comment">// storage for short Sub</span>
|
|
Rune []<a href="../../builtin/index.html#rune">rune</a> <span class="comment">// matched runes, for OpLiteral, OpCharClass</span>
|
|
Rune0 [2]<a href="../../builtin/index.html#rune">rune</a> <span class="comment">// storage for short Rune</span>
|
|
Min, Max <a href="../../builtin/index.html#int">int</a> <span class="comment">// min, max for OpRepeat</span>
|
|
Cap <a href="../../builtin/index.html#int">int</a> <span class="comment">// capturing index, for OpCapture</span>
|
|
Name <a href="../../builtin/index.html#string">string</a> <span class="comment">// capturing name, for OpCapture</span>
|
|
}</pre>
|
|
<p>
|
|
A Regexp is a node in a regular expression syntax tree.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Parse">func <a href="http://localhost:6060/src/regexp/syntax/parse.go?s=19263:19313#L691">Parse</a></h3>
|
|
<pre>func Parse(s <a href="../../builtin/index.html#string">string</a>, flags <a href="index.html#Flags">Flags</a>) (*<a href="index.html#Regexp">Regexp</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
|
|
<p>
|
|
Parse parses a regular expression string s, controlled by the specified
|
|
Flags, and returns a regular expression parse tree. The syntax is
|
|
described in the top-level comment.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Regexp.CapNames">func (*Regexp) <a href="http://localhost:6060/src/regexp/syntax/regexp.go?s=7517:7554#L296">CapNames</a></h3>
|
|
<pre>func (re *<a href="index.html#Regexp">Regexp</a>) CapNames() []<a href="../../builtin/index.html#string">string</a></pre>
|
|
<p>
|
|
CapNames walks the regexp to find the names of capturing groups.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Regexp.Equal">func (*Regexp) <a href="http://localhost:6060/src/regexp/syntax/regexp.go?s=2525:2563#L52">Equal</a></h3>
|
|
<pre>func (x *<a href="index.html#Regexp">Regexp</a>) Equal(y *<a href="index.html#Regexp">Regexp</a>) <a href="../../builtin/index.html#bool">bool</a></pre>
|
|
<p>
|
|
Equal returns true if x and y have identical structure.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Regexp.MaxCap">func (*Regexp) <a href="http://localhost:6060/src/regexp/syntax/regexp.go?s=7276:7306#L282">MaxCap</a></h3>
|
|
<pre>func (re *<a href="index.html#Regexp">Regexp</a>) MaxCap() <a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
MaxCap walks the regexp to find the maximum capture index.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Regexp.Simplify">func (*Regexp) <a href="http://localhost:6060/src/regexp/syntax/simplify.go?s=692:728#L4">Simplify</a></h3>
|
|
<pre>func (re *<a href="index.html#Regexp">Regexp</a>) Simplify() *<a href="index.html#Regexp">Regexp</a></pre>
|
|
<p>
|
|
Simplify returns a regexp equivalent to re but without counted repetitions
|
|
and with various other simplifications, such as rewriting /(?:a+)+/ to /a+/.
|
|
The resulting regexp will execute correctly but its string representation
|
|
will not produce the same parse tree, because capturing parentheses
|
|
may have been duplicated or removed. For example, the simplified form
|
|
for /(x){1,2}/ is /(x)(x)?/ but both parentheses capture as $1.
|
|
The returned regexp may share structure with or be the original.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Regexp.String">func (*Regexp) <a href="http://localhost:6060/src/regexp/syntax/regexp.go?s=6421:6454#L235">String</a></h3>
|
|
<pre>func (re *<a href="index.html#Regexp">Regexp</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div id="footer">
|
|
Build version go1.6.<br>
|
|
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
|
|
the content of this page is licensed under the
|
|
Creative Commons Attribution 3.0 License,
|
|
and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
|
|
<a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
|
|
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
|
|
</div>
|
|
|
|
</div><!-- .container -->
|
|
</div><!-- #page -->
|
|
|
|
<!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
|
|
<script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
|
|
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
|
|
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
|
|
|
|
|
|
<script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
|
|
|
|
</body>
|
|
</html>
|
|
|