MCPcopy Index your code
hub / github.com/idank/explainshell / visitfunction

Method visitfunction

explainshell/matcher.py:748–806  ·  view source on GitHub ↗
(self, node, name, body, parts)

Source from the content-addressed store, hash-verified

746 _visitword(node, word)
747
748 def visitfunction(self, node, name, body, parts):
749 self.functions.add(name.word)
750
751 def _iscompoundopenclosecurly(compound):
752 first, last = compound.list[0], compound.list[-1]
753 if (
754 first.kind == "reservedword"
755 and last.kind == "reservedword"
756 and first.word == "{"
757 and last.word == "}"
758 ):
759 return True
760
761 # if the compound command we have there is { }, let's include the
762 # {} as part of the function declaration. normally it would be
763 # treated as a group command, but that seems less informative in this
764 # context
765 if _iscompoundopenclosecurly(body):
766 # create a matchresult until after the first {
767 mr = MatchResult(
768 node.pos[0],
769 body.list[0].pos[1],
770 help_constants._function,
771 None,
772 {"kind": "function"},
773 )
774 self.groups[0].results.append(mr)
775
776 # create a matchresult for the closing }
777 mr = MatchResult(
778 body.list[-1].pos[0],
779 body.list[-1].pos[1],
780 help_constants._function,
781 None,
782 {"kind": "function"},
783 )
784 self.groups[0].results.append(mr)
785
786 # visit anything in between the { }
787 for part in body.list[1:-1]:
788 self.visit(part)
789 else:
790 beforebody = bashlex.ast.findfirstkind(parts, "compound") - 1
791 assert beforebody > 0
792 beforebody = parts[beforebody]
793
794 # create a matchresult ending at the node before body
795 mr = MatchResult(
796 node.pos[0],
797 beforebody.pos[1],
798 help_constants._function,
799 None,
800 {"kind": "function"},
801 )
802 self.groups[0].results.append(mr)
803
804 self.visit(body)
805

Callers

nothing calls this directly

Calls 2

MatchResultClass · 0.85
addMethod · 0.80

Tested by

no test coverage detected