Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion gtwrap/interface_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def fixed_get_attr(self, item):
for _rule, _context, _priority in _DIAGNOSTIC_RULES:
_track_rule(_rule, _context, _priority)

pyparsing.ParserElement.enablePackrat()
pyparsing.ParserElement.enable_packrat()
14 changes: 7 additions & 7 deletions gtwrap/interface_parser/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Hello {
+ RPAREN #
+ Optional(CONST("is_const")) #
+ SEMI_COLON # BR
).setParseAction(lambda t: Method(t.template, t.name, t.return_type, t.
).set_parse_action(lambda t: Method(t.template, t.name, t.return_type, t.
args_list, t.is_const))

def __init__(self,
Expand Down Expand Up @@ -98,7 +98,7 @@ class Hello {
+ ArgumentList.rule("args_list") #
+ RPAREN #
+ SEMI_COLON # BR
).setParseAction(
).set_parse_action(
lambda t: StaticMethod(t.name, t.return_type, t.args_list, t.template))

def __init__(self,
Expand Down Expand Up @@ -134,7 +134,7 @@ class Constructor:
+ ArgumentList.rule("args_list") #
+ RPAREN #
+ SEMI_COLON # BR
).setParseAction(lambda s, loc, t: Constructor(
).set_parse_action(lambda s, loc, t: Constructor(
t.name, t.args_list, t.template, source=s, location=loc))

def __init__(self,
Expand Down Expand Up @@ -175,7 +175,7 @@ class Overload {
+ RPAREN #
+ CONST("is_const") #
+ SEMI_COLON # BR
).setParseAction(lambda s, loc, t: Operator(
).set_parse_action(lambda s, loc, t: Operator(
t.name,
t.operator,
t.return_type,
Expand Down Expand Up @@ -258,7 +258,7 @@ class DunderMethod:
+ ArgumentList.rule("args_list") #
+ RPAREN #
+ SEMI_COLON # BR
).setParseAction(lambda t: DunderMethod(t.name, t.args_list))
).set_parse_action(lambda t: DunderMethod(t.name, t.args_list))

def __init__(self, name: str, args: ArgumentList):
self.name = name
Expand Down Expand Up @@ -291,7 +291,7 @@ class Members:
^ Variable.rule #
^ Operator.rule #
^ Enum.rule #
).setParseAction(lambda t: Class.Members(t.asList()))
).set_parse_action(lambda t: Class.Members(t.as_list()))

def __init__(self, members: List[Union[Constructor, Method,
StaticMethod, Variable,
Expand Down Expand Up @@ -330,7 +330,7 @@ def __init__(self, members: List[Union[Constructor, Method,
+ Members.rule("members") #
+ RBRACE #
+ SEMI_COLON # BR
).setParseAction(lambda t: Class(
).set_parse_action(lambda t: Class(
t.template, t.is_virtual, t.name, t.parent_class, t.members.ctors, t.
members.methods, t.members.static_methods, t.members.dunder_methods, t.
members.properties, t.members.operators, t.members.enums))
Expand Down
4 changes: 2 additions & 2 deletions gtwrap/interface_parser/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Include:
Rule to parse #include directives.
"""
rule = (INCLUDE + LOPBRACK + CharsNotIn('>')("header") +
ROPBRACK).setParseAction(lambda t: Include(t.header))
ROPBRACK).set_parse_action(lambda t: Include(t.header))

def __init__(self, header: CharsNotIn, parent: str = ''):
self.header = header
Expand All @@ -39,7 +39,7 @@ class ForwardDeclaration:
"""
rule = (Optional(VIRTUAL("is_virtual")) + CLASS + Typename.rule("name") +
Optional(COLON + Typename.rule("parent_type")) +
SEMI_COLON).setParseAction(lambda t: ForwardDeclaration(
SEMI_COLON).set_parse_action(lambda t: ForwardDeclaration(
t.name, t.parent_type, t.is_virtual))

def __init__(self,
Expand Down
8 changes: 4 additions & 4 deletions gtwrap/interface_parser/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Author: Varun Agrawal
"""

from pyparsing import delimitedList # type: ignore
from pyparsing import DelimitedList # type: ignore

from .tokens import ENUM, IDENT, LBRACE, RBRACE, SEMI_COLON
from .type import Typename
Expand All @@ -22,7 +22,7 @@ class Enumerator:
Rule to parse an enumerator inside an enum.
"""
rule = (IDENT.copy().set_name("enumerator name")("enumerator")
).setParseAction(lambda t: Enumerator(t.enumerator))
).set_parse_action(lambda t: Enumerator(t.enumerator))

def __init__(self, name):
self.name = name
Expand All @@ -45,8 +45,8 @@ class Enum:
"""

rule = (ENUM + IDENT("name") + LBRACE +
delimitedList(Enumerator.rule)("enumerators") + RBRACE +
SEMI_COLON).setParseAction(lambda t: Enum(t.name, t.enumerators))
DelimitedList(Enumerator.rule)("enumerators") + RBRACE +
SEMI_COLON).set_parse_action(lambda t: Enum(t.name, t.enumerators))

def __init__(self, name, enumerators, parent=''):
self.name = name
Expand Down
12 changes: 6 additions & 6 deletions gtwrap/interface_parser/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from typing import Any, Iterable, List, Union

from pyparsing import Literal, Optional, ParseResults, delimitedList
from pyparsing import Literal, Optional, ParseResults, DelimitedList

from .template import Template
from .tokens import (COMMA, DEFAULT_ARG, EQUAL, IDENT, LOPBRACK, LPAREN, PAIR,
Expand All @@ -32,7 +32,7 @@ class Argument:
rule = ((Type.rule ^ TemplatedType.rule)("ctype") #
+ IDENT.copy().set_name("argument name")("name") #
+ Optional(EQUAL + DEFAULT_ARG)("default")
).setParseAction(lambda t: Argument(
).set_parse_action(lambda t: Argument(
t.ctype, #
t.name, #
t.default[0] if isinstance(t.default, ParseResults) else None))
Expand Down Expand Up @@ -61,7 +61,7 @@ class ArgumentList:
"""
List of Argument objects for all arguments in a function.
"""
rule = Optional(delimitedList(Argument.rule)("args_list")).setParseAction(
rule = Optional(DelimitedList(Argument.rule)("args_list")).set_parse_action(
lambda t: ArgumentList.from_parse_result(t.args_list))

def __init__(self, args_list: List[Argument]):
Expand All @@ -76,7 +76,7 @@ def __init__(self, args_list: List[Argument]):
def from_parse_result(parse_result: ParseResults):
"""Return the result of parsing."""
if parse_result:
return ArgumentList(parse_result.asList())
return ArgumentList(parse_result.as_list())
else:
return ArgumentList([])

Expand Down Expand Up @@ -116,7 +116,7 @@ class ReturnType:
+ ROPBRACK #
)
rule = (_pair ^
(Type.rule ^ TemplatedType.rule)("type1")).setParseAction( # BR
(Type.rule ^ TemplatedType.rule)("type1")).set_parse_action( # BR
lambda t: ReturnType(t.type1, t.type2))

def __init__(self, type1: Union[Type, TemplatedType], type2: Type):
Expand Down Expand Up @@ -162,7 +162,7 @@ class GlobalFunction:
+ ArgumentList.rule("args_list") #
+ RPAREN #
+ SEMI_COLON #
).setParseAction(lambda t: GlobalFunction(t.name, t.return_type, t.
).set_parse_action(lambda t: GlobalFunction(t.name, t.return_type, t.
args_list, t.template))

def __init__(self,
Expand Down
12 changes: 6 additions & 6 deletions gtwrap/interface_parser/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# pylint: disable=unnecessary-lambda, unused-import, expression-not-assigned, no-else-return, protected-access, too-few-public-methods, too-many-arguments

from pyparsing import (ParseBaseException, ParseResults, ZeroOrMore, # type: ignore
cppStyleComment, stringEnd)
cpp_style_comment, string_end)

from .classes import Class
from .declaration import ForwardDeclaration, Include
Expand Down Expand Up @@ -45,13 +45,13 @@ class Module:
^ Enum.rule #
^ Variable.rule #
^ Namespace.rule #
).setParseAction(lambda t: Namespace('', t.asList())) +
stringEnd)
).set_parse_action(lambda t: Namespace('', t.as_list())) +
string_end)

rule.ignore(cppStyleComment)
rule.ignore(cpp_style_comment)

@staticmethod
def parseString(s: str, source_name: str = "<string>") -> ParseResults:
def parse_string(s: str, source_name: str = "<string>") -> ParseResults:
Comment thread
Copilot marked this conversation as resolved.
Outdated
"""Parse source text and report any failure at its best known location."""
# Imported here to avoid adding the diagnostic machinery to the grammar's
# import cycle.
Expand All @@ -60,7 +60,7 @@ def parseString(s: str, source_name: str = "<string>") -> ParseResults:

context, token = begin_diagnostics(s, source_name)
try:
return Module.rule.parseString(s)[0]
return Module.rule.parse_string(s)[0]
except InterfaceParseError:
raise
except ParseBaseException as error:
Expand Down
4 changes: 2 additions & 2 deletions gtwrap/interface_parser/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Namespace:
^ rule #
)("content") # BR
+ RBRACE #
).setParseAction(lambda t: Namespace.from_parse_result(t))
).set_parse_action(lambda t: Namespace.from_parse_result(t))

def __init__(self, name: str, content: ZeroOrMore, parent=''):
self.name = name
Expand All @@ -87,7 +87,7 @@ def __init__(self, name: str, content: ZeroOrMore, parent=''):
def from_parse_result(t: ParseResults):
"""Return the result of parsing."""
if t.content:
content = t.content.asList()
content = t.content.as_list()
else:
content = []
return Namespace(t.name, content)
Expand Down
14 changes: 7 additions & 7 deletions gtwrap/interface_parser/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from typing import List

from pyparsing import Optional, ParseResults, delimitedList # type: ignore
from pyparsing import Optional, ParseResults, DelimitedList # type: ignore

from .tokens import (EQUAL, IDENT, LBRACE, LOPBRACK, RBRACE, ROPBRACK,
SEMI_COLON, TEMPLATE, TYPEDEF)
Expand All @@ -38,10 +38,10 @@ class TypenameAndInstantiations:
+ Optional( #
EQUAL #
+ LBRACE #
+ ((delimitedList(TemplatedType.rule ^ Typename.rule)
+ ((DelimitedList(TemplatedType.rule ^ Typename.rule)
("instantiations"))) #
+ RBRACE #
)).setParseAction(lambda t: Template.TypenameAndInstantiations(
)).set_parse_action(lambda t: Template.TypenameAndInstantiations(
t.typename, t.instantiations))

def __init__(self, typename: str, instantiations: ParseResults):
Expand All @@ -57,11 +57,11 @@ def __init__(self, typename: str, instantiations: ParseResults):
rule = ( # BR
TEMPLATE #
+ LOPBRACK #
+ delimitedList(TypenameAndInstantiations.rule)(
+ DelimitedList(TypenameAndInstantiations.rule)(
"typename_and_instantiations_list") #
+ ROPBRACK # BR
).setParseAction(
lambda t: Template(t.typename_and_instantiations_list.asList()))
).set_parse_action(
lambda t: Template(t.typename_and_instantiations_list.as_list()))

def __init__(
self,
Expand All @@ -85,7 +85,7 @@ class TypedefTemplateInstantiation:
"""
rule = (TYPEDEF + TemplatedType.rule("templated_type") +
IDENT("new_name") +
SEMI_COLON).setParseAction(lambda t: TypedefTemplateInstantiation(
SEMI_COLON).set_parse_action(lambda t: TypedefTemplateInstantiation(
t.templated_type[0], t.new_name))

def __init__(self,
Expand Down
16 changes: 8 additions & 8 deletions gtwrap/interface_parser/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from pyparsing import Or # type: ignore
from pyparsing import (Keyword, Literal, OneOrMore, QuotedString, Suppress,
Word, alphanums, alphas, nestedExpr, nums,
originalTextFor, printables)
Word, alphanums, alphas, nested_expr, nums,
original_text_for, printables)

# rule for identifiers (e.g. variable names)
IDENT = Word(alphas + '_', alphanums + '_') ^ Word(nums)
Expand All @@ -28,15 +28,15 @@
# Allow anything up to ',' or ';' except when they
# appear inside matched expressions such as
# (a, b) {c, b} "hello, world", templates, initializer lists, etc.
DEFAULT_ARG = originalTextFor(
DEFAULT_ARG = original_text_for(
OneOrMore(
QuotedString('"') ^ # parse double quoted strings
QuotedString("'") ^ # parse single quoted strings
Word(printables, excludeChars="(){}[]<>,;") ^ # parse arbitrary words
nestedExpr(opener='(', closer=')') ^ # parse expression in parentheses
nestedExpr(opener='[', closer=']') ^ # parse expression in brackets
nestedExpr(opener='{', closer='}') ^ # parse expression in braces
nestedExpr(opener='<', closer='>') # parse template expressions
Word(printables, exclude_chars="(){}[]<>,;") ^ # parse arbitrary words
nested_expr(opener='(', closer=')') ^ # parse expression in parentheses
nested_expr(opener='[', closer=']') ^ # parse expression in brackets
nested_expr(opener='{', closer='}') ^ # parse expression in braces
nested_expr(opener='<', closer='>') # parse template expressions
))

CONST, VIRTUAL, CLASS, STATIC, PAIR, TEMPLATE, TYPEDEF, INCLUDE = map(
Expand Down
18 changes: 9 additions & 9 deletions gtwrap/interface_parser/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import List, Sequence, Union

from pyparsing import ParseResults # type: ignore
from pyparsing import Forward, Optional, Or, delimitedList
from pyparsing import Forward, Optional, Or, DelimitedList

from .tokens import (BASIC_TYPES, CONST, IDENT, LOPBRACK, RAW_POINTER, REF,
ROPBRACK, SHARED_POINTER)
Expand All @@ -39,10 +39,10 @@ class Typename:
instantiations: Template parameters to the type.
"""

namespaces_name_rule = delimitedList(IDENT, "::")
namespaces_name_rule = DelimitedList(IDENT, "::")
rule = (
namespaces_name_rule("namespaces_and_name") #
).setParseAction(lambda t: Typename.from_parse_result(t))
).set_parse_action(lambda t: Typename.from_parse_result(t))

def __init__(self,
name: str,
Expand All @@ -59,7 +59,7 @@ def __init__(self,
if isinstance(instantiations, Sequence):
self.instantiations = instantiations # type: ignore
else:
self.instantiations = instantiations.asList()
self.instantiations = instantiations.as_list()
else:
self.instantiations = []

Expand Down Expand Up @@ -152,7 +152,7 @@ class BasicType:
```
"""

rule = (Or(BASIC_TYPES)("typename")).setParseAction(lambda t: BasicType(t))
rule = (Or(BASIC_TYPES)("typename")).set_parse_action(lambda t: BasicType(t))

def __init__(self, t: ParseResults):
self.typename = Typename.from_parse_result(t)
Expand All @@ -171,7 +171,7 @@ class CustomType:
Here `gtsam::Matrix` is a custom type.
"""

rule = (Typename.rule("typename")).setParseAction(lambda t: CustomType(t))
rule = (Typename.rule("typename")).set_parse_action(lambda t: CustomType(t))

def __init__(self, t: ParseResults):
self.typename = Typename.from_parse_result(t)
Expand All @@ -193,7 +193,7 @@ class Type:
+ Optional(
SHARED_POINTER("is_shared_ptr") | RAW_POINTER("is_ptr")
| REF("is_ref")) #
).setParseAction(lambda t: Type.from_parse_result(t))
).set_parse_action(lambda t: Type.from_parse_result(t))

def __init__(self, typename: Typename, is_const: str, is_shared_ptr: str,
is_ptr: str, is_ref: str, is_basic: bool):
Expand Down Expand Up @@ -278,12 +278,12 @@ class TemplatedType:
+ Typename.rule("typename") #
+ (
LOPBRACK #
+ delimitedList(Type.rule ^ rule, ",")("template_params") #
+ DelimitedList(Type.rule ^ rule, ",")("template_params") #
+ ROPBRACK) #
+ Optional(
SHARED_POINTER("is_shared_ptr") | RAW_POINTER("is_ptr")
| REF("is_ref")) #
).setParseAction(lambda t: TemplatedType.from_parse_result(t))
).set_parse_action(lambda t: TemplatedType.from_parse_result(t))

def __init__(self, typename: Typename, template_params: List[Type],
is_const: str, is_shared_ptr: str, is_ptr: str, is_ref: str):
Expand Down
2 changes: 1 addition & 1 deletion gtwrap/interface_parser/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Hello {
+ IDENT("name") #
+ Optional(EQUAL + DEFAULT_ARG)("default") #
+ SEMI_COLON #
).setParseAction(lambda t: Variable(
).set_parse_action(lambda t: Variable(
t.ctype, #
t.name, #
t.default[0] if isinstance(t.default, ParseResults) else None))
Expand Down
2 changes: 1 addition & 1 deletion gtwrap/matlab_wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,7 @@ def wrap(self, files, path):

# Parse the contents of the interface file
source_name = files[0] if len(files) == 1 else ";".join(files)
parsed_result = parser.Module.parseString(
parsed_result = parser.Module.parse_string(
content, source_name=source_name)

# Instantiate the module
Expand Down
Loading
Loading