Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lark parsing work in progress #22

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"lark>=1",
"sphinx>=5.0,<7.0",
"textX>=3.0",
]
Expand Down
37 changes: 17 additions & 20 deletions src/plcdoc/documenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os.path
from abc import ABC
from typing import Tuple, List, Dict, Optional, Any, Union
from typing import Tuple, List, Dict, Optional, Any
import re

from sphinx.util import logging
Expand All @@ -13,7 +13,7 @@
)
from docutils.statemachine import StringList

from .interpreter import PlcInterpreter, PlcDeclaration, TextXMetaClass
from .interpreter import PlcInterpreter, PlcDeclaration, PlcVariableDeclaration

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -172,7 +172,7 @@ def format_name(self) -> str:
def format_args(self, **kwargs: Any) -> Optional[str]:
"""Format arguments for signature, based on auto-data."""

arg_strs = [f"{var.name}" for var in self.object.get_args()]
arg_strs = [f"{var.name}" for var in self.object.args]

return "(" + ", ".join(arg_strs) + ")"

Expand Down Expand Up @@ -205,10 +205,10 @@ def add_content(self, more_content: Optional[StringList]) -> None:

# Also add VARs from meta-model
args_block = []
for var in self.object.get_args():
line_param = f":{var.kind} {var.type.name} {var.name}:"
if var.comment and var.comment.text:
line_param += " " + var.comment.text
for var in self.object.args:
line_param = f":{var.kind} {var.ty} {var.name}:"
if var.comment:
line_param += " " + var.comment
args_block.append(line_param)

if args_block:
Expand All @@ -230,7 +230,7 @@ def get_doc(self) -> Optional[List[List[str]]]:
"""Get docstring from the meta-model."""

# Read main docblock
comment_str = self.object.get_comment()
comment_str = self.object.comment
if not comment_str:
return []

Expand Down Expand Up @@ -393,10 +393,9 @@ def document_members(self, all_members: bool = False) -> None:
member_documenters = [
PlcStructMemberDocumenter(
self.directive,
member.name,
self.indent,
parent=self.object,
member=member,
indent=self.indent,
parent=self.object,
)
for member in self.object.members
]
Expand Down Expand Up @@ -431,36 +430,34 @@ class PlcStructMemberDocumenter(PlcDataDocumenter):
def __init__(
self,
directive,
name: str,
member: PlcVariableDeclaration,
indent: str = "",
parent: PlcDeclaration = None,
member: Optional[TextXMetaClass] = None,
) -> None:
super().__init__(directive, name, indent)
super().__init__(directive, member.name, indent)

self.object = parent
self.member = member

@classmethod
def can_document_member(
cls,
member: Union[PlcDeclaration, Any],
member: PlcVariableDeclaration,
membername: str,
isattr: bool,
parent: Any,
) -> bool:
return type(member).__name__ == "Variable"
# Note: a TextX variable class is passed, not a complete PlcDeclaration
return isinstance(member, PlcVariableDeclaration) and member.kind == "member"

def import_object(self, raiseerror: bool = False) -> bool:
return self.member is not None # Expect member through constructor

def get_doc(self) -> Optional[List[List[str]]]:
# Read main docblock
if self.member is None or self.member.comment is None:
if self.member is None:
return []

comment_str = self.member.comment.text
comment_str = self.member.comment
if not comment_str:
return []

Expand All @@ -471,7 +468,7 @@ def format_signature(self, **kwargs: Any) -> str:
return ""

# Insert the known variable type
return f" : {self.member.type.name}"
return f" : {self.member.ty}"


class PlcFolderDocumenter(PlcDataDocumenter):
Expand Down
Loading