Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
47ba59dd
Commit
47ba59dd
authored
Mar 10, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- adjustments due to changed tabwriter interface
- more comments in parser R=r OCL=26060 CL=26060
parent
4cbfcae3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
4 deletions
+30
-4
usr/gri/pretty/compilation.go
usr/gri/pretty/compilation.go
+1
-1
usr/gri/pretty/parser.go
usr/gri/pretty/parser.go
+23
-1
usr/gri/pretty/printer.go
usr/gri/pretty/printer.go
+5
-1
usr/gri/pretty/untab.go
usr/gri/pretty/untab.go
+1
-1
No files found.
usr/gri/pretty/compilation.go
View file @
47ba59dd
...
...
@@ -123,7 +123,7 @@ func Compile(src_file string, flags *Flags) (*AST.Program, int) {
scanner
.
Init
(
src
,
&
err
,
true
);
var
parser
Parser
.
Parser
;
parser
.
Open
(
&
scanner
,
&
err
,
flags
.
Verbose
);
parser
.
Init
(
&
scanner
,
&
err
,
flags
.
Verbose
);
prog
:=
parser
.
ParseProgram
();
...
...
usr/gri/pretty/parser.go
View file @
47ba59dd
...
...
@@ -2,6 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// A parser for Go source text. The input is a stream of lexical tokens
// provided via the Scanner interface. The output is an abstract syntax
// tree (AST) representing the Go source.
//
// A client may parse the entire program (ParseProgram), only the package
// clause (ParsePackageClause), or the package clause and the import
// declarations (ParseImportDecls). The resulting AST represents the part
// of the program that is parsed.
//
package
Parser
import
(
...
...
@@ -12,16 +21,29 @@ import (
)
// An implementation of an ErrorHandler must be provided to the Parser.
// If a syntax error is encountered, Error is called with the exact
// token position (the byte position of the token in the source) and the
// error message.
//
type
ErrorHandler
interface
{
Error
(
pos
int
,
msg
string
);
}
// An implementation of a Scanner must be provided to the Parser.
// The parser calls Scan repeatedly to get a sequential stream of
// tokens. The source end is indicated by token.EOF.
//
type
Scanner
interface
{
Scan
()
(
pos
,
tok
int
,
lit
[]
byte
);
}
// A Parser holds the parser's internal state while processing
// a given text. It can be allocated as part of another data
// structure but must be initialized via Init before use.
//
type
Parser
struct
{
scanner
Scanner
;
err
ErrorHandler
;
...
...
@@ -125,7 +147,7 @@ func (P *Parser) next() {
}
func
(
P
*
Parser
)
Open
(
scanner
Scanner
,
err
ErrorHandler
,
trace
bool
)
{
func
(
P
*
Parser
)
Init
(
scanner
Scanner
,
err
ErrorHandler
,
trace
bool
)
{
P
.
scanner
=
scanner
;
P
.
err
=
err
;
...
...
usr/gri/pretty/printer.go
View file @
47ba59dd
...
...
@@ -1124,7 +1124,11 @@ func Print(writer io.Write, html bool, prog *ast.Program) {
if
*
usetabs
{
padchar
=
'\t'
;
}
text
:=
tabwriter
.
New
(
writer
,
*
tabwidth
,
1
,
padchar
,
true
,
html
);
flags
:=
uint
(
0
);
if
html
{
flags
|=
tabwriter
.
FilterHTML
;
}
text
:=
tabwriter
.
NewWriter
(
writer
,
*
tabwidth
,
1
,
padchar
,
flags
);
P
.
Init
(
text
,
html
,
prog
.
Comments
);
if
P
.
html
{
...
...
usr/gri/pretty/untab.go
View file @
47ba59dd
...
...
@@ -40,7 +40,7 @@ func main() {
if
*
usetabs
{
padchar
=
'\t'
;
}
dst
:=
tabwriter
.
New
(
os
.
Stdout
,
*
tabwidth
,
1
,
padchar
,
true
,
false
);
dst
:=
tabwriter
.
New
Writer
(
os
.
Stdout
,
*
tabwidth
,
1
,
padchar
,
0
);
if
flag
.
NArg
()
>
0
{
for
i
:=
0
;
i
<
flag
.
NArg
();
i
++
{
name
:=
flag
.
Arg
(
i
);
...
...
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