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
d5248c4a
Commit
d5248c4a
authored
Feb 24, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/scanner: support for complex (imaginary) constants
R=rsc CC=golang-dev
https://golang.org/cl/223044
parent
7c99dcbd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
2 deletions
+106
-2
src/pkg/go/parser/parser.go
src/pkg/go/parser/parser.go
+1
-1
src/pkg/go/printer/testdata/declarations.golden
src/pkg/go/printer/testdata/declarations.golden
+42
-0
src/pkg/go/printer/testdata/declarations.input
src/pkg/go/printer/testdata/declarations.input
+42
-0
src/pkg/go/scanner/scanner.go
src/pkg/go/scanner/scanner.go
+6
-1
src/pkg/go/scanner/scanner_test.go
src/pkg/go/scanner/scanner_test.go
+13
-0
src/pkg/go/token/token.go
src/pkg/go/token/token.go
+2
-0
No files found.
src/pkg/go/parser/parser.go
View file @
d5248c4a
...
@@ -959,7 +959,7 @@ func (p *parser) parseOperand() ast.Expr {
...
@@ -959,7 +959,7 @@ func (p *parser) parseOperand() ast.Expr {
case
token
.
IDENT
:
case
token
.
IDENT
:
return
p
.
findIdent
()
return
p
.
findIdent
()
case
token
.
INT
,
token
.
FLOAT
,
token
.
CHAR
,
token
.
STRING
:
case
token
.
INT
,
token
.
FLOAT
,
token
.
IMAG
,
token
.
CHAR
,
token
.
STRING
:
x
:=
&
ast
.
BasicLit
{
p
.
pos
,
p
.
tok
,
p
.
lit
}
x
:=
&
ast
.
BasicLit
{
p
.
pos
,
p
.
tok
,
p
.
lit
}
p
.
next
()
p
.
next
()
return
x
return
x
...
...
src/pkg/go/printer/testdata/declarations.golden
View file @
d5248c4a
...
@@ -68,6 +68,48 @@ import _ "io"
...
@@ -68,6 +68,48 @@ import _ "io"
var _ int
var _ int
//
printing of constant literals
const (
_ = "foobar"
_ = "a۰۱۸"
_ = "foo६४"
_ = "bar9876"
_ = 0
_ = 1
_ = 123456789012345678890
_ = 01234567
_ = 0xcafebabe
_ = 0.
_ = .0
_ = 3.14159265
_ = 1e0
_ = 1e+100
_ = 1e-100
_ = 2.71828e-1000
_ = 0i
_ = 1i
_ = 012345678901234567889i
_ = 123456789012345678890i
_ = 0.i
_ = .0i
_ = 3.14159265i
_ = 1e0i
_ = 1e+100i
_ = 1e-100i
_ = 2.71828e-1000i
_ = 'a'
_ = '\000'
_ = '\xFF'
_ = '\uff16'
_ = '\U0000ff16'
_ = `foobar`
_ = `foo
---
---
bar`
)
func _() {
func _() {
// the following decls need a semicolon at the end
// the following decls need a semicolon at the end
type _ int
type _ int
...
...
src/pkg/go/printer/testdata/declarations.input
View file @
d5248c4a
...
@@ -67,6 +67,48 @@ import _ "io"
...
@@ -67,6 +67,48 @@ import _ "io"
var _ int
var _ int
//
printing of constant literals
const (
_ = "foobar"
_ = "a۰۱۸"
_ = "foo६४"
_ = "bar9876"
_ = 0
_ = 1
_ = 123456789012345678890
_ = 01234567
_ = 0xcafebabe
_ = 0.
_ = .0
_ = 3.14159265
_ = 1e0
_ = 1e+100
_ = 1e-100
_ = 2.71828e-1000
_ = 0i
_ = 1i
_ = 012345678901234567889i
_ = 123456789012345678890i
_ = 0.i
_ = .0i
_ = 3.14159265i
_ = 1e0i
_ = 1e+100i
_ = 1e-100i
_ = 2.71828e-1000i
_ = 'a'
_ = '\000'
_ = '\xFF'
_ = '\uff16'
_ = '\U0000ff16'
_ = `foobar`
_ = `foo
---
---
bar`
)
func _() {
func _() {
// the following decls need a semicolon at the end
// the following decls need a semicolon at the end
type _ int
type _ int
...
...
src/pkg/go/scanner/scanner.go
View file @
d5248c4a
...
@@ -302,7 +302,7 @@ func (S *Scanner) scanNumber(pos token.Position, seenDecimalPoint bool) token.To
...
@@ -302,7 +302,7 @@ func (S *Scanner) scanNumber(pos token.Position, seenDecimalPoint bool) token.To
seenDecimalDigit
=
true
seenDecimalDigit
=
true
S
.
scanMantissa
(
10
)
S
.
scanMantissa
(
10
)
}
}
if
S
.
ch
==
'.'
||
S
.
ch
==
'e'
||
S
.
ch
==
'E'
{
if
S
.
ch
==
'.'
||
S
.
ch
==
'e'
||
S
.
ch
==
'E'
||
S
.
ch
==
'i'
{
goto
fraction
goto
fraction
}
}
// octal int
// octal int
...
@@ -333,6 +333,11 @@ exponent:
...
@@ -333,6 +333,11 @@ exponent:
S
.
scanMantissa
(
10
)
S
.
scanMantissa
(
10
)
}
}
if
S
.
ch
==
'i'
{
tok
=
token
.
IMAG
S
.
next
()
}
exit
:
exit
:
return
tok
return
tok
}
}
...
...
src/pkg/go/scanner/scanner_test.go
View file @
d5248c4a
...
@@ -51,6 +51,8 @@ var tokens = [...]elt{
...
@@ -51,6 +51,8 @@ var tokens = [...]elt{
elt
{
token
.
IDENT
,
"foo६४"
,
literal
},
elt
{
token
.
IDENT
,
"foo६४"
,
literal
},
elt
{
token
.
IDENT
,
"bar9876"
,
literal
},
elt
{
token
.
IDENT
,
"bar9876"
,
literal
},
elt
{
token
.
INT
,
"0"
,
literal
},
elt
{
token
.
INT
,
"0"
,
literal
},
elt
{
token
.
INT
,
"1"
,
literal
},
elt
{
token
.
INT
,
"123456789012345678890"
,
literal
},
elt
{
token
.
INT
,
"01234567"
,
literal
},
elt
{
token
.
INT
,
"01234567"
,
literal
},
elt
{
token
.
INT
,
"0xcafebabe"
,
literal
},
elt
{
token
.
INT
,
"0xcafebabe"
,
literal
},
elt
{
token
.
FLOAT
,
"0."
,
literal
},
elt
{
token
.
FLOAT
,
"0."
,
literal
},
...
@@ -60,6 +62,17 @@ var tokens = [...]elt{
...
@@ -60,6 +62,17 @@ var tokens = [...]elt{
elt
{
token
.
FLOAT
,
"1e+100"
,
literal
},
elt
{
token
.
FLOAT
,
"1e+100"
,
literal
},
elt
{
token
.
FLOAT
,
"1e-100"
,
literal
},
elt
{
token
.
FLOAT
,
"1e-100"
,
literal
},
elt
{
token
.
FLOAT
,
"2.71828e-1000"
,
literal
},
elt
{
token
.
FLOAT
,
"2.71828e-1000"
,
literal
},
elt
{
token
.
IMAG
,
"0i"
,
literal
},
elt
{
token
.
IMAG
,
"1i"
,
literal
},
elt
{
token
.
IMAG
,
"012345678901234567889i"
,
literal
},
elt
{
token
.
IMAG
,
"123456789012345678890i"
,
literal
},
elt
{
token
.
IMAG
,
"0.i"
,
literal
},
elt
{
token
.
IMAG
,
".0i"
,
literal
},
elt
{
token
.
IMAG
,
"3.14159265i"
,
literal
},
elt
{
token
.
IMAG
,
"1e0i"
,
literal
},
elt
{
token
.
IMAG
,
"1e+100i"
,
literal
},
elt
{
token
.
IMAG
,
"1e-100i"
,
literal
},
elt
{
token
.
IMAG
,
"2.71828e-1000i"
,
literal
},
elt
{
token
.
CHAR
,
"'a'"
,
literal
},
elt
{
token
.
CHAR
,
"'a'"
,
literal
},
elt
{
token
.
CHAR
,
"'
\\
000'"
,
literal
},
elt
{
token
.
CHAR
,
"'
\\
000'"
,
literal
},
elt
{
token
.
CHAR
,
"'
\\
xFF'"
,
literal
},
elt
{
token
.
CHAR
,
"'
\\
xFF'"
,
literal
},
...
...
src/pkg/go/token/token.go
View file @
d5248c4a
...
@@ -30,6 +30,7 @@ const (
...
@@ -30,6 +30,7 @@ const (
IDENT
// main
IDENT
// main
INT
// 12345
INT
// 12345
FLOAT
// 123.45
FLOAT
// 123.45
IMAG
// 123.45i
CHAR
// 'a'
CHAR
// 'a'
STRING
// "abc"
STRING
// "abc"
literal_end
literal_end
...
@@ -140,6 +141,7 @@ var tokens = map[Token]string{
...
@@ -140,6 +141,7 @@ var tokens = map[Token]string{
IDENT
:
"IDENT"
,
IDENT
:
"IDENT"
,
INT
:
"INT"
,
INT
:
"INT"
,
FLOAT
:
"FLOAT"
,
FLOAT
:
"FLOAT"
,
IMAG
:
"IMAG"
,
CHAR
:
"CHAR"
,
CHAR
:
"CHAR"
,
STRING
:
"STRING"
,
STRING
:
"STRING"
,
...
...
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