Menu

#159 Support 5.20+ method signatures

Next Release
open
nobody
None
5
2016-05-12
2016-05-11
No

It would be cool if we could add additional method metadata from parsing the (still experimental) method signature. See http://www.effectiveperlprogramming.com/2015/04/use-v5-20-subroutine-signatures/ At the moment the parser seems to get a bit confused, e.g. the first argument is uncolored as indication that the parser could not identify this token.

1 Attachments

Discussion

  • Oliver Trosien

    Oliver Trosien - 2016-05-11

    To visualize, here is a perl file and how the parser sees it... (token 14 "PROTO" and 15 "WORD" are the interesting ones..)

    use experimental qw(signatures);
    sub hello($subject, $object) { }
    hello("a","b");

    workspace/EPICTest/test_MethodSignatures.pl: 0:<KEYWORD_USE>,line=1,col=1:"use" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 1:<WS>,line=1,col=4:" " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 2:<WORD>,line=1,col=5:"experimental" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 3:<WS>,line=1,col=17:" " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 4:<MATCH_EXPR>,line=1,col=18:"qw" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 5:<OPEN_QUOTE>,line=1,col=20:"(" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 6:<STRING_BODY>,line=1,col=21:"signatures" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 7:<CLOSE_QUOTE>,line=1,col=31:")" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 8:<SEMI>,line=1,col=32:";" class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 9:<WS>,line=1,col=33:"
    " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 10:<KEYWORD_SUB>,line=2,col=1:"sub" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 11:<WS>,line=2,col=4:" " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 12:<WORD>,line=2,col=5:"hello" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 13:<OPEN_PAREN>,line=2,col=10:"(" class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 14:<PROTO>,line=2,col=11:"$" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 15:<WORD>,line=2,col=12:"subject" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 16:<OPER_COMMA>,line=2,col=19:"," class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 17:<WS>,line=2,col=20:" " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 18:<VAR>,line=2,col=21:"$object" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 19:<CLOSE_PAREN>,line=2,col=28:")" class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 20:<WS>,line=2,col=29:" " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 21:<OPEN_CURLY>,line=2,col=30:"{" class org.epic.core.parser.CurlyToken
    workspace/EPICTest/test_MethodSignatures.pl: 22:<WS>,line=2,col=31:" " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 23:<CLOSE_CURLY>,line=2,col=32:"}" class org.epic.core.parser.CurlyToken
    workspace/EPICTest/test_MethodSignatures.pl: 24:<WS>,line=2,col=33:"
    " class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 25:<WORD>,line=3,col=1:"hello" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 26:<OPEN_PAREN>,line=3,col=6:"(" class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 27:<OPEN_DQUOTE>,line=3,col=7:""" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 28:<STRING_BODY>,line=3,col=8:"a" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 29:<CLOSE_QUOTE>,line=3,col=9:""" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 30:<OPER_COMMA>,line=3,col=10:"," class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 31:<OPEN_DQUOTE>,line=3,col=11:""" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 32:<STRING_BODY>,line=3,col=12:"b" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 33:<CLOSE_QUOTE>,line=3,col=13:""" class org.epic.core.parser.PerlToken
    workspace/EPICTest/test_MethodSignatures.pl: 34:<CLOSE_PAREN>,line=3,col=14:")" class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 35:<SEMI>,line=3,col=15:";" class org.epic.core.parser.OperatorToken
    workspace/EPICTest/test_MethodSignatures.pl: 36:<WS>,line=3,col=16:"
    " class org.epic.core.parser.PerlToken

     
  • Jan Ploski

    Jan Ploski - 2016-05-11

    Basically in perl.g:337 when an open paren after sub keyword is encountered it switches into "expect traditional prototype" mode (proto = true). If that mode switch was suppressed, the tokens would look better for the version with signatures. But then the traditional prototypes ($$$ or some such) would be parsed wrong.

    Perhaps the switch should be conditional on whether "use feature qw(signatures);" was encountered earlier in the file? Of course it's hard to make it reliable as you can apparently enable this feature in multiple ways.

     

Log in to post a comment.