From a6f75cbc5bbf5a89ecc3ec55970bfb01785c42b2 Mon Sep 17 00:00:00 2001 From: Jonathan Acetolyne Langlois Date: Sat, 2 Jul 2022 23:17:10 -0700 Subject: [PATCH 1/2] Add suport for Python new comment style --- lexer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lexer.go b/lexer.go index d388d3c..be64b99 100644 --- a/lexer.go +++ b/lexer.go @@ -91,6 +91,10 @@ var Extensions = []CommentValues{ startMulti: "=begin", endMulti: "=end", }, + { + ext: []string{".py"}, + startSingle: "#", + }, } // IsValid reports whether the position is valid. From 6688c2b38a245ad655ae01867bc2940024b648c1 Mon Sep 17 00:00:00 2001 From: Jonathan Acetolyne Langlois Date: Sat, 2 Jul 2022 23:24:46 -0700 Subject: [PATCH 2/2] update tests to include python test --- lexer_test.go | 22 ++++++++++++++++++++++ tests/test.py | 9 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/test.py diff --git a/lexer_test.go b/lexer_test.go index d7f068e..1c0b854 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -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") + } +} diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..226a733 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,9 @@ +#! /bin/usr/python3 + +#@todo comment 1 + +a = "test" + +#Some comment but not a todo item + +# @todo comment 3 \ No newline at end of file