224 filenames = ['*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6', |
224 filenames = ['*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6', |
225 '*.6pm', '*.p6m', '*.pm6', '*.t'] |
225 '*.6pm', '*.p6m', '*.pm6', '*.t'] |
226 mimetypes = ['text/x-perl6', 'application/x-perl6'] |
226 mimetypes = ['text/x-perl6', 'application/x-perl6'] |
227 flags = re.MULTILINE | re.DOTALL | re.UNICODE |
227 flags = re.MULTILINE | re.DOTALL | re.UNICODE |
228 |
228 |
229 PERL6_IDENTIFIER_RANGE = "['\w:-]" |
229 PERL6_IDENTIFIER_RANGE = r"['\w:-]" |
230 |
230 |
231 PERL6_KEYWORDS = ( |
231 PERL6_KEYWORDS = ( |
232 'BEGIN', 'CATCH', 'CHECK', 'CONTROL', 'END', 'ENTER', 'FIRST', 'INIT', |
232 'BEGIN', 'CATCH', 'CHECK', 'CONTROL', 'END', 'ENTER', 'FIRST', 'INIT', |
233 'KEEP', 'LAST', 'LEAVE', 'NEXT', 'POST', 'PRE', 'START', 'TEMP', |
233 'KEEP', 'LAST', 'LEAVE', 'NEXT', 'POST', 'PRE', 'START', 'TEMP', |
234 'UNDO', 'as', 'assoc', 'async', 'augment', 'binary', 'break', 'but', |
234 'UNDO', 'as', 'assoc', 'async', 'augment', 'binary', 'break', 'but', |
487 # them, make sure you also process the corresponding one! |
487 # them, make sure you also process the corresponding one! |
488 tokens = { |
488 tokens = { |
489 'common': [ |
489 'common': [ |
490 (r'#[`|=](?P<delimiter>(?P<first_char>[' + ''.join(PERL6_BRACKETS) + r'])(?P=first_char)*)', |
490 (r'#[`|=](?P<delimiter>(?P<first_char>[' + ''.join(PERL6_BRACKETS) + r'])(?P=first_char)*)', |
491 brackets_callback(Comment.Multiline)), |
491 brackets_callback(Comment.Multiline)), |
492 (r'#[^\n]*$', Comment.Singleline), |
492 (r'#[^\n]*$', Comment.Single), |
493 (r'^(\s*)=begin\s+(\w+)\b.*?^\1=end\s+\2', Comment.Multiline), |
493 (r'^(\s*)=begin\s+(\w+)\b.*?^\1=end\s+\2', Comment.Multiline), |
494 (r'^(\s*)=for.*?\n\s*?\n', Comment.Multiline), |
494 (r'^(\s*)=for.*?\n\s*?\n', Comment.Multiline), |
495 (r'^=.*?\n\s*?\n', Comment.Multiline), |
495 (r'^=.*?\n\s*?\n', Comment.Multiline), |
496 (r'(regex|token|rule)(\s*' + PERL6_IDENTIFIER_RANGE + '+:sym)', |
496 (r'(regex|token|rule)(\s*' + PERL6_IDENTIFIER_RANGE + '+:sym)', |
497 bygroups(Keyword, Name), 'token-sym-brackets'), |
497 bygroups(Keyword, Name), 'token-sym-brackets'), |
498 (r'(regex|token|rule)(?!' + PERL6_IDENTIFIER_RANGE + ')(\s*' + PERL6_IDENTIFIER_RANGE + '+)?', |
498 (r'(regex|token|rule)(?!' + PERL6_IDENTIFIER_RANGE + r')(\s*' + PERL6_IDENTIFIER_RANGE + '+)?', |
499 bygroups(Keyword, Name), 'pre-token'), |
499 bygroups(Keyword, Name), 'pre-token'), |
500 # deal with a special case in the Perl 6 grammar (role q { ... }) |
500 # deal with a special case in the Perl 6 grammar (role q { ... }) |
501 (r'(role)(\s+)(q)(\s*)', bygroups(Keyword, Text, Name, Text)), |
501 (r'(role)(\s+)(q)(\s*)', bygroups(Keyword, Text, Name, Text)), |
502 (_build_word_match(PERL6_KEYWORDS, PERL6_IDENTIFIER_RANGE), Keyword), |
502 (_build_word_match(PERL6_KEYWORDS, PERL6_IDENTIFIER_RANGE), Keyword), |
503 (_build_word_match(PERL6_BUILTIN_CLASSES, PERL6_IDENTIFIER_RANGE, suffix='(?::[UD])?'), |
503 (_build_word_match(PERL6_BUILTIN_CLASSES, PERL6_IDENTIFIER_RANGE, suffix='(?::[UD])?'), |
556 # make sure that quotes in character classes aren't treated as strings |
556 # make sure that quotes in character classes aren't treated as strings |
557 (r'<(?:[-!?+.]\s*)?\[.*?\]>', String.Regex), |
557 (r'<(?:[-!?+.]\s*)?\[.*?\]>', String.Regex), |
558 # make sure that '#' characters in quotes aren't treated as comments |
558 # make sure that '#' characters in quotes aren't treated as comments |
559 (r"(?<!\\)'(\\\\|\\[^\\]|[^'\\])*'", String.Regex), |
559 (r"(?<!\\)'(\\\\|\\[^\\]|[^'\\])*'", String.Regex), |
560 (r'(?<!\\)"(\\\\|\\[^\\]|[^"\\])*"', String.Regex), |
560 (r'(?<!\\)"(\\\\|\\[^\\]|[^"\\])*"', String.Regex), |
561 (r'#.*?$', Comment.Singleline), |
561 (r'#.*?$', Comment.Single), |
562 (r'\{', embedded_perl6_callback), |
562 (r'\{', embedded_perl6_callback), |
563 ('.+?', String.Regex), |
563 ('.+?', String.Regex), |
564 ], |
564 ], |
565 } |
565 } |
566 |
566 |
589 |
589 |
590 saw_perl_decl = False |
590 saw_perl_decl = False |
591 rating = False |
591 rating = False |
592 |
592 |
593 # check for my/our/has declarations |
593 # check for my/our/has declarations |
594 if re.search("(?:my|our|has)\s+(?:" + Perl6Lexer.PERL6_IDENTIFIER_RANGE + |
594 if re.search(r"(?:my|our|has)\s+(?:" + Perl6Lexer.PERL6_IDENTIFIER_RANGE + |
595 "+\s+)?[$@%&(]", text): |
595 r"+\s+)?[$@%&(]", text): |
596 rating = 0.8 |
596 rating = 0.8 |
597 saw_perl_decl = True |
597 saw_perl_decl = True |
598 |
598 |
599 for line in lines: |
599 for line in lines: |
600 line = re.sub('#.*', '', line) |
600 line = re.sub('#.*', '', line) |
601 if re.match('^\s*$', line): |
601 if re.match(r'^\s*$', line): |
602 continue |
602 continue |
603 |
603 |
604 # match v6; use v6; use v6.0; use v6.0.0; |
604 # match v6; use v6; use v6.0; use v6.0.0; |
605 if re.match('^\s*(?:use\s+)?v6(?:\.\d(?:\.\d)?)?;', line): |
605 if re.match(r'^\s*(?:use\s+)?v6(?:\.\d(?:\.\d)?)?;', line): |
606 return True |
606 return True |
607 # match class, module, role, enum, grammar declarations |
607 # match class, module, role, enum, grammar declarations |
608 class_decl = re.match('^\s*(?:(?P<scope>my|our)\s+)?(?:module|class|role|enum|grammar)', line) |
608 class_decl = re.match(r'^\s*(?:(?P<scope>my|our)\s+)?(?:module|class|role|enum|grammar)', line) |
609 if class_decl: |
609 if class_decl: |
610 if saw_perl_decl or class_decl.group('scope') is not None: |
610 if saw_perl_decl or class_decl.group('scope') is not None: |
611 return True |
611 return True |
612 rating = 0.05 |
612 rating = 0.05 |
613 continue |
613 continue |