Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Regex based lexer - proof of concept
# -*- coding: utf-8 -*-
"""
RegexLexer
A regular expression based lexer
demonstrating go language syntax highlighting
Usage:
Run script to see how it works
Note: By commenting or deleting everything, including,
the <comment_or_delete> tags it is ready to be used
as an additional lexer
"""
from Npp import editor, notepad, LEXER, SCINTILLANOTIFICATION, NOTIFICATION, LANGTYPE
import re
try:
REGEX_LEXER().main()
except NameError:
class REGEX_LEXER_SINGLETON(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(REGEX_LEXER_SINGLETON, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class REGEX_LEXER(object):
__metaclass__ = REGEX_LEXER_SINGLETON
DEFAULT = 0
NUMBER_STYLE = 50
KEYWORD_STYLE = 51
OPERATOR_STYLE = 52
STRING_STYLE = 53
COMMENT_STYLE = 54
KEYWORDS = ['break', 'default', 'func', 'interface', 'select',
'case', 'defer', 'go', 'map', 'struct',
'chan', 'else', 'goto', 'package', 'switch',
'const', 'fallthrough', 'if', 'range', 'type',
'continue', 'for', 'import', 'return', 'var']
KEYWORD_REGEX = r'\w+'
NUMBER_REGEX = r'0[xX][0-9a-fA-F]+|\d*\.*\d*[eE][\+-]*\d+|\d+\.\d*|\.\d+|\d+(?=\s|\z)'
OPERATOR_REGEX = r'\s*(\+|&|\+=|&=|&&|==|!=|\(|\)|-|\||-=|\|=|\|\||<|<=|\[|\]|\*|\^|\*=|\^=|<-|>|>=|\{|\}|/|<<|/=|<<=|\+\+|=|:=|,|;|%|>>|%=|>>=|--|!|\.\.\.|\.|:|&\^|&\^=)(?=\s|\z)'
STRING_REGEX = r'".*?"|`.*?`'
LINE_COMMENT_REGEX = r'//.*'
MULTILINE_COMMENT_REGEX = r'/\*.*?\*/'
def time_function(func):
import time
def wrap(self,*args,**kwargs):
start = time.clock()
result = func(self, *args,**kwargs)
print(u'{} took {} seconds'.format(func.__name__, time.clock()-start))
return result
return wrap
def __init__(self):
print '{} init'.format(self.__class__.__name__)
editor.callbackSync(self.styleneeded_callback, [SCINTILLANOTIFICATION.STYLENEEDED])
notepad.callback(self.bufferactivated_callback, [NOTIFICATION.BUFFERACTIVATED])
notepad.callback(self.langchanged_callback, [NOTIFICATION.LANGCHANGED])
def regex_lexer(self, start_pos, end_pos):
def style_it(match, STYLE):
if match[1]-match[0] >= 0:
editor.startStyling(start_pos + match[0], 31)
editor.setStyling(match[1]-match[0], STYLE)
def do_regex(regex, flags=0):
for match in re.finditer(regex, text, flags):
yield match
def multiline_comment(start_pos,end_pos):
whole_text = editor.getCharacterPointer()
for match in [m.span(0) for m in re.finditer(self.MULTILINE_COMMENT_REGEX, whole_text, re.S)]:
if (not match[1] < start_pos) or (not match[0] > end_pos):
editor.startStyling(match[0], 31)
editor.setStyling(match[1]-match[0], self.COMMENT_STYLE)
text = editor.getRangePointer(start_pos, end_pos-start_pos)
style_it((0, end_pos-start_pos), self.DEFAULT)
for match in do_regex(self.KEYWORD_REGEX):
if match.group(0).lower() in self.KEYWORDS:
style_it(match.span(0), self.KEYWORD_STYLE)
map(lambda match: style_it(match.span(0), self.NUMBER_STYLE), do_regex(self.NUMBER_REGEX))
map(lambda match: style_it(match.span(0), self.STRING_STYLE), do_regex(self.STRING_REGEX))
map(lambda match: style_it(match.span(0), self.OPERATOR_STYLE), do_regex(self.OPERATOR_REGEX))
map(lambda match: style_it(match.span(0), self.COMMENT_STYLE), do_regex(self.LINE_COMMENT_REGEX))
multiline_comment(start_pos,end_pos)
# this needs to stay and to be the last line, to signal scintilla we are done.
editor.startStyling(end_pos,31) # end_pos !!!
def init_scintilla(self):
print ' {} init_scintilla'.format(self.__class__.__name__)
editor.setMarginWidthN(0,38)
editor.setMarginWidthN(1,14)
editor.setMarginWidthN(2,0)
if editor.getLexer() != LEXER.CONTAINER:
editor.setLexer(LEXER.CONTAINER)
editor.styleSetFore(self.NUMBER_STYLE, (255,128,128))
editor.styleSetFore(self.KEYWORD_STYLE, (54,125,198))
editor.styleSetFore(self.STRING_STYLE, (214,157,133))
editor.styleSetFore(self.OPERATOR_STYLE, (255,128,0))
editor.styleSetFore(self.COMMENT_STYLE, (87,166,74))
editor.styleSetBack(self.COMMENT_STYLE, (50,50,50))
editor.styleSetBold(self.COMMENT_STYLE, True)
editor.styleSetItalic(self.COMMENT_STYLE, True)
def set_lexer_doc(self,bool_value):
editor.setProperty(self.__class__.__name__, 1 if bool_value is True else 0)
def is_lexer_doc(self):
return True if editor.getPropertyInt(self.__class__.__name__) == 1 else False
def styleneeded_callback(self,args):
if self.is_lexer_doc():
startPos = editor.getEndStyled()
lineNumber = editor.lineFromPosition(startPos)
startPos = editor.positionFromLine(lineNumber)
self.regex_lexer(startPos, args['position'])
def bufferactivated_callback(self,args):
if self.is_lexer_doc():
self.init_scintilla()
def langchanged_callback(self,args):
if self.is_lexer_doc():
self.set_lexer_doc(False)
@time_function
def main(self):
print ' {} main'.format(self.__class__.__name__)
notepad.setLangType(LANGTYPE.TXT)
self.init_scintilla()
# start hack - prevent styleneeded_callback flood which dramatically slows down styling
currentTopLine = editor.getFirstVisibleLine()
if currentTopLine > 0:
editor.setFirstVisibleLine(0)
self.regex_lexer(0, editor.getTextLength())
# hack end - reset to the top line used when calling this
editor.setFirstVisibleLine(currentTopLine)
self.set_lexer_doc(True)
# <comment_or_delete>
notepad.new()
editor.appendText(
'''package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\\"" // same as `"`
"Hello, world!\\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"
"\"" // same as `"`
"Hello, world!\n"
`日本語`
"\u65e5本\U00008a9e"
"󜵰0FF"
package main
import (
"fmt"
"time"
)
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
time.Sleep(5 * time.Second)
t <- true
}
func main() {
t := make(chan bool)
go timeout(t)
ch := make(chan string)
go readword(ch)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}
//keywords
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//operators
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
/* multi
line
comment */
// line comment
// numbers
42
0600
0xBadFace
170141183460469231731687303715884105727
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
//string literals
`abc` // same as "abc"