Skip to content

Commit

Permalink
Merge pull request #4 from Acetolyne/dev
Browse files Browse the repository at this point in the history
Python new comment style
  • Loading branch information
Acetolyne authored Jul 3, 2022
2 parents 39d8d3e + 6688c2b commit ce95a09
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ var Extensions = []CommentValues{
startMulti: "=begin",
endMulti: "=end",
},
{
ext: []string{".py"},
startSingle: "#",
},
}

// IsValid reports whether the position is valid.
Expand Down
22 changes: 22 additions & 0 deletions lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,25 @@ func TestRubyCommentsWork(t *testing.T) {
t.Fatalf("unable to use ruby comments")
}
}

func TestPythonNewStyleCommentsWork(t *testing.T) {
res := ""
var s lexer.Scanner
s.Mode = lexer.ScanComments
s.Match = "@todo"
s.Init("tests/test.py")
tok := s.Scan()
for tok != lexer.EOF {
if tok == lexer.Comment {
line := strings.ReplaceAll(s.TokenText(), "\n", " ")
res += strings.ReplaceAll(line, "\t", "")
}
tok = s.Scan()
}

want := "#@todo comment 1# @todo comment 3"
if res != want {
fmt.Println("got", res, "want", want)
t.Fatalf("unable to use ruby comments")
}
}
9 changes: 9 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/usr/python3

#@todo comment 1

a = "test"

#Some comment but not a todo item

# @todo comment 3

0 comments on commit ce95a09

Please sign in to comment.