Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
da1cbe5d
Commit
da1cbe5d
authored
Dec 14, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
regexp: simplify code for brackets, per rsc suggestion
R=rsc CC=golang-dev
https://golang.org/cl/3545044
parent
f620a430
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
17 deletions
+9
-17
regexp.go
src/pkg/regexp/regexp.go
+9
-17
No files found.
src/pkg/regexp/regexp.go
View file @
da1cbe5d
...
...
@@ -98,8 +98,7 @@ const (
iCharClass
// [a-z] character class
iAny
// '.' any character including newline
iNotNL
// [^\n] special case: any character but newline
iBra
// '(' parenthesized expression
iEbra
// ')'; end of '(' parenthesized expression
iBra
// '(' parenthesized expression: 2*braNum for left, 2*braNum+1 for right
iAlt
// '|' alternation
iNop
// do nothing; makes it easy to link without patching
)
...
...
@@ -135,9 +134,11 @@ func (i *instr) print() {
case
iNotNL
:
print
(
"notnl"
)
case
iBra
:
print
(
"bra"
,
i
.
braNum
)
case
iEbra
:
print
(
"ebra"
,
i
.
braNum
)
if
i
.
braNum
&
1
==
0
{
print
(
"bra"
,
i
.
braNum
/
2
)
}
else
{
print
(
"ebra"
,
i
.
braNum
/
2
)
}
case
iAlt
:
print
(
"alt("
,
i
.
left
.
index
,
")"
)
case
iNop
:
...
...
@@ -391,12 +392,10 @@ func (p *parser) term() (start, end *instr) {
}
p
.
nlpar
--
p
.
nextc
()
bra
:=
&
instr
{
kind
:
iBra
}
bra
:=
&
instr
{
kind
:
iBra
,
braNum
:
2
*
nbra
}
p
.
re
.
add
(
bra
)
ebra
:=
&
instr
{
kind
:
i
Ebra
}
ebra
:=
&
instr
{
kind
:
i
Bra
,
braNum
:
2
*
nbra
+
1
}
p
.
re
.
add
(
ebra
)
bra
.
braNum
=
nbra
ebra
.
braNum
=
nbra
if
start
==
nil
{
if
end
==
nil
{
p
.
error
(
ErrInternal
)
...
...
@@ -709,13 +708,7 @@ func (a *matchArena) addState(s []state, inst *instr, prefixed bool, match *matc
}
return
s
case
iBra
:
n
:=
inst
.
braNum
match
.
m
[
2
*
n
]
=
pos
s
=
a
.
addState
(
s
,
inst
.
next
,
prefixed
,
match
,
pos
,
end
)
return
s
case
iEbra
:
n
:=
inst
.
braNum
match
.
m
[
2
*
n
+
1
]
=
pos
match
.
m
[
inst
.
braNum
]
=
pos
s
=
a
.
addState
(
s
,
inst
.
next
,
prefixed
,
match
,
pos
,
end
)
return
s
}
...
...
@@ -821,7 +814,6 @@ func (re *Regexp) doExecute(str string, bytestr []byte, pos int) []int {
s
[
out
]
=
arena
.
addState
(
s
[
out
],
st
.
inst
.
next
,
st
.
prefixed
,
st
.
match
,
pos
,
end
)
}
case
iBra
:
case
iEbra
:
case
iAlt
:
case
iEnd
:
// choose leftmost longest
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment