Verified Commit 9e55364e authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Update .gitignore

parent 71629dd1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
.idea
__pycache__
*.egg-info
+2 −2
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ import sys

from rpcc.version import __version__ as rpcc_version
from rpcc.parser import Parser
from rpcc.transformers.cxx import Transformer as CppTransformer
from rpcc.transformers.cxx import Transformer as CxxTransformer
from pathlib import Path


@@ -51,7 +51,7 @@ def main(args=None):
    # try:
    ast = Parser(args.rpc_proto_file).parse()
    print(ast.pretty())
    print(CppTransformer().transform(ast).pretty())
    print(CxxTransformer().transform(ast).pretty())

    # except Exception:
    #    return 1
+9 −3
Original line number Diff line number Diff line
from lark import Lark
import pathlib
from lark import Lark, Tree
from loguru import logger

GRAMMAR = r"""
@@ -26,11 +27,16 @@ GRAMMAR = r"""


class Parser:
    def __init__(self, input_file: str):
    """The main parser class

    Parameters:
        input_file: A pathlib.Path containing the path to the RPC description file to parse.
    """
    def __init__(self, input_file: pathlib.Path) -> None:
        self.input_file = input_file
        self.parser = Lark(GRAMMAR, parser='lalr')

    def parse(self):
    def parse(self) -> Tree:
        try:
            file = open(self.input_file, "r", encoding="utf-8")
        except (FileNotFoundError, EnvironmentError) as err:
+32 −1
Original line number Diff line number Diff line
from typing import List, Any
from typing import List


class Argument:
    """A remote procedure argument.

    Parameters:
        argname: a string with the argument's name.
        typename: a string with the argument's type.

    Example:
        >>> Argument("foobar", "int")
        Argument(...)
    """
    def __init__(self, argname: str, typename: str) -> None:
        self.argname = argname
        self.typename = typename
@@ -11,6 +21,16 @@ class Argument:


class ReturnVariable:
    """A remote procedure return variable.

    Parameters:
        varname: a string with the return variable's name.
        typename: a string with the return variable's type.

    Example:
        >>> ReturnVariable("barbaz", "int")
        ReturnVariable(...)
    """
    def __init__(self, varname: str, typename: str) -> None:
        self.varname = varname
        self.typename = typename
@@ -20,6 +40,17 @@ class ReturnVariable:


class RemoteProcedure:
    """A remote procedure.

    Parameters:
        name: a string with the remote procedure's name.
        args: a list of Arguments containing the remote procedure's arguments.
        retval: a ReturnVariable containing the remote procedure's return variable.

    Example:
        >>> RemoteProcedure("send_message", [Argument("message", "string")], ReturnVariable("retval", "uint32"))
        RemoteProcedure(...)
    """
    def __init__(self, name: str, args: List[Argument], retval: ReturnVariable) -> None:
        self.name = name
        self.args = args
+4 −8
Original line number Diff line number Diff line
@@ -30,8 +30,7 @@ class Transformer(lark.Transformer):
    var = tuple

    def rpc_args(self, children: List[Tuple[str, str]]) -> List[Argument]:
        """
        Transform a list of tuples returned by Lark into a list of `rpc.Arguments`. The tuples are implicitly
        """Transform a list of tuples returned by Lark into a list of `rpc.Arguments`. The tuples are implicitly
        constructed by Lark by transforming all the `var` nodes in the AST that have this particular `rpc_args` node
        as a parent.

@@ -42,8 +41,7 @@ class Transformer(lark.Transformer):

    @v_args(inline=True)
    def rpc_return(self, t: Tuple[str, str]) -> ReturnVariable:
        """
        Transform a tuple returned by Lark into a `ReturnVariable`. The tuple is implictly constructed by Lark by
        """Transform a tuple returned by Lark into a `ReturnVariable`. The tuple is implictly constructed by Lark by
        transforming the `var` node under this particular `rpc_return` node.

        :param t: A tuple describing the rpc return value
@@ -54,8 +52,7 @@ class Transformer(lark.Transformer):

    @v_args(inline=True)
    def rpc(self, name: str, args: List[Argument], retval: ReturnVariable) -> RemoteProcedure:
        """
        Transform a `rpc` node from the AST into a `RemoteProcedure` object from a name, a list of `Argument`s and a
        """Transform a `rpc` node from the AST into a `RemoteProcedure` object from a name, a list of `Argument`s and a
        `ReturnVariable`.

        :param name: A name for the remote procedure.
@@ -67,8 +64,7 @@ class Transformer(lark.Transformer):

    @v_args(inline=True)
    def rpc_name(self, name: str) -> str:
        """
        Transform a `rpc_name` node from the AST into its corresponding string. The string is extracted from the AST
        """Transform a `rpc_name` node from the AST into its corresponding string. The string is extracted from the AST
        nodes' value.

        :param name: A string value from the `rpc_name` node.