bash: function calls detect

Issue #1493 new
Андрей Бутырский
created an issue

Hi, is it possible to implement function calls detection for shell scripts? (e.g., highlight them).
I use Pygments as GNU GLOBAL source code tagging system plug-in parser, and this functionality would greatly improve usability of the project, allowing references to function calls, not only definitions.

Comments (2)

  1. Андрей Бутырский reporter

    I applied following hack to overcome the problem:

    --- pygments/lexers/   2017-01-23 00:01:32.000000000 +0300
    +++ /usr/lib64/python2.7/site-packages/pygments/lexers/ 2019-01-20 01:56:56.724115547 +0300
    @@ -85,7 +85,7 @@
                 (r'\|', Punctuation),
                 (r'\s+', Text),
                 (r'\d+\b', Number),
    -            (r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
    +            (r'[^=\s\[\]{}()$"\'`\\<&|;]+', Name.Function),
                 (r'<', Text),
             'string': [

    Now make test can't pass:

    FAIL: testNeedsName (test_shell.BashSessionTest)
    Traceback (most recent call last):
      File "/home/bam/test/pygments/tests/", line 141, in testNeedsName
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
    AssertionError: Lists differ: [(Token.Text, u''), (Token.Gen... != [(Token.Text, u''), (Token.Gen...
    First differing element 6:
    (Token.Text, u'hi')
    (Token.Name.Function, u'hi')
      [(Token.Text, u''),
       (Token.Generic.Prompt, u'$'),
       (Token.Text, u' '),
       (Token.Name.Builtin, u'echo'),
       (Token.Text, u' '),
       (Token.Literal.String.Escape, u'\\\n'),
    -  (Token.Text, u'hi'),
    +  (Token.Name.Function, u'hi'),
       (Token.Text, u'\n'),
       (Token.Generic.Output, u'hi\n')]
        """Fail immediately, with the given message."""
    >>  raise self.failureException("Lists differ: [(Token.Text, u''), (Token.Gen... != [(Token.Text, u''), (Token.Gen...\n\nFirst differing element 6:\n(Token.Text, u'hi')\n(Token.Name.Function, u'hi')\n\n  [(Token.Text, u''),\n   (Token.Generic.Prompt, u'$'),\n   (Token.Text, u' '),\n   (Token.Name.Builtin, u'echo'),\n   (Token.Text, u' '),\n   (Token.Literal.String.Escape, u'\\\\\\n'),\n-  (Token.Text, u'hi'),\n+  (Token.Name.Function, u'hi'),\n   (Token.Text, u'\\n'),\n   (Token.Generic.Output, u'hi\\n')]")
    Ran 2061 tests in 48.091s
    FAILED (SKIP=9, failures=1)
    Makefile:53: recipe for target 'test' failed
    make: *** [test] Error 1

    Please, help!

  2. Log in to comment