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
eea6b0d8
Commit
eea6b0d8
authored
Sep 03, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify extractEBNF code
R=rsc DELTA=15 (3 added, 2 deleted, 10 changed) OCL=34307 CL=34314
parent
d3ffc5e6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
ebnflint.go
src/cmd/ebnflint/ebnflint.go
+13
-12
No files found.
src/cmd/ebnflint/ebnflint.go
View file @
eea6b0d8
...
...
@@ -38,33 +38,34 @@ var (
func
extractEBNF
(
src
[]
byte
)
[]
byte
{
var
buf
bytes
.
Buffer
;
for
i
,
j
,
n
:=
0
,
0
,
len
(
src
);
;
{
// i = beginning of EBNF
section
i
=
bytes
.
Index
(
src
[
j
:
n
]
,
open
);
for
{
// i = beginning of EBNF
text
i
:=
bytes
.
Index
(
src
,
open
);
if
i
<
0
{
break
;
break
;
// no EBNF found - we are done
}
i
+=
j
+
len
(
open
);
i
+=
len
(
open
);
// write as many newlines as found in the excluded text
// to maintain correct line numbers in error messages
for
_
,
ch
:=
range
src
[
j
:
i
]
{
for
_
,
ch
:=
range
src
[
0
:
i
]
{
if
ch
==
'\n'
{
buf
.
WriteByte
(
'\n'
);
}
}
// j = end of EBNF
section
j
=
bytes
.
Index
(
src
[
i
:
n
],
close
);
// j = end of EBNF
text (or end of source)
j
:=
bytes
.
Index
(
src
[
i
:
len
(
src
)],
close
);
// close marker
if
j
<
0
{
// missing closing
// TODO(gri) should this be an error?
j
=
n
-
i
;
j
=
len
(
src
)
-
i
;
}
j
+=
i
;
// copy EBNF
section
// copy EBNF
text
buf
.
Write
(
src
[
i
:
j
]);
// advance
src
=
src
[
j
:
len
(
src
)];
}
return
buf
.
Data
();
...
...
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