ramile icon indicating copy to clipboard operation
ramile copied to clipboard

Add Python language support and fix processors intialization

Open Dectinc opened this issue 5 years ago • 3 comments

Feature:

  • general comment block filter and Python multiline docstrings filter
  • sharp("#") comment filter for Python
  • Python processor

Update:

  • move filters to another package named filters

Fix:

  • processor initialization

filters was a class property of FilterProcessorBase and not re-defined in subclassess. In each subclass, some filters were appended to this class property, led to all subclasses shared the class property from their base class but using their own.

`filters` 是基类 `FilterProcessorBase` 的一个类属性, 但是并没有在各子类中重新定义,
而是在子类的初始化方法中添加元素;而且子类均没有调用基类的初始化方法。
这导致每一个子类最终的 `filter` 属性都包含所有被添加过的 filter,与预期行为应该是不一致的。

originally

class FileProcessorBase(object):
    """ Base class for file processors. The processor for each lanuage should inherit from this class.
    """
    expected_extensions = []
    filters = []

    def __init__(self):
        # by default, processors of all languages will always starts with a blank line filter
        self.filters.append(BlankLineFilter())
        return

class JsProcessor(FileProcessorBase):
    expected_extensions = ['.js', '.jsx', '.vue']
    expected_extensions = ['.js', '.jsx', '.vue', '.wpy']

    def __init__(self):
        self.filters.append(BlankLineFilter())
        self.filters.append(CStyleCommentBlockFilter())
        self.filters.append(DoubleSlashCommentFilter())
        return

fixed

class FileProcessorBase(object):
    """ Base class for file processors. The processor for each lanuage should inherit from this class.
    """
    expected_extensions = []

    def __init__(self):
        # by default, processors of all languages will always starts with a blank line filter
        self.filters = []
        self.filters.append(BlankLineFilter())
        return

class JsProcessor(FileProcessorBase):
    expected_extensions = ['.js', '.jsx', '.vue', '.wpy']

    def __init__(self):
        super().__init__()
        self.filters.append(CStyleCommentBlockFilter())
        self.filters.append(DoubleSlashCommentFilter())

Dectinc avatar Oct 28 '19 05:10 Dectinc

Hi, @Dectinc. Thanks for your contribution.

But it fails when comments start with just a line-break. See fix in PR https://github.com/Dectinc/ramile/pull/1.

Would you kindly merge it into this PR if it is possible.

huandzh avatar Dec 02 '20 09:12 huandzh

Hi, @Dectinc. Thanks for your contribution.

But it fails when comments start with just a line-break. See fix in PR Dectinc#1.

Would you kindly merge it into this PR if it is possible.

Thanks, merged.

Dectinc avatar Dec 02 '20 10:12 Dectinc

Thx!

huandzh avatar Dec 03 '20 00:12 huandzh