scanner: // style comments are implemented too

This commit is contained in:
Fatih Arslan 2015-10-05 13:26:18 +03:00
parent 2216cd81e9
commit a299665100
2 changed files with 8 additions and 7 deletions

View File

@ -120,7 +120,7 @@ func (s *Scanner) Scan() (tok token.Token) {
case '"':
tok = token.STRING
s.scanString()
case '#':
case '#', '/':
tok = token.COMMENT
s.scanComment(ch)
case '.':
@ -156,7 +156,7 @@ func (s *Scanner) Scan() (tok token.Token) {
}
func (s *Scanner) scanComment(ch rune) {
if ch == '#' {
if ch == '#' || ch == '/' {
// line comment
ch = s.next()
for ch != '\n' && ch >= 0 {

View File

@ -42,11 +42,12 @@ func testTokenList(t *testing.T, tokenList []tokenPair) {
func TestComment(t *testing.T) {
var tokenList = []tokenPair{
// {token.COMMENT, "//"},
// {token.COMMENT, "////"},
// {token.COMMENT, "// comment"},
// {token.COMMENT, "// /* comment */"},
// {token.COMMENT, "// // comment //"},
{token.COMMENT, "//"},
{token.COMMENT, "////"},
{token.COMMENT, "// comment"},
{token.COMMENT, "// /* comment */"},
{token.COMMENT, "// // comment //"},
{token.COMMENT, "//" + f100},
{token.COMMENT, "#"},
{token.COMMENT, "##"},
{token.COMMENT, "# comment"},