185 ] |
185 ] |
186 } |
186 } |
187 |
187 |
188 def analyse_text(text): |
188 def analyse_text(text): |
189 rv = 0.0 |
189 rv = 0.0 |
190 if re.search('\{if\s+.*?\}.*?\{/if\}', text): |
190 if re.search(r'\{if\s+.*?\}.*?\{/if\}', text): |
191 rv += 0.15 |
191 rv += 0.15 |
192 if re.search('\{include\s+file=.*?\}', text): |
192 if re.search(r'\{include\s+file=.*?\}', text): |
193 rv += 0.15 |
193 rv += 0.15 |
194 if re.search('\{foreach\s+.*?\}.*?\{/foreach\}', text): |
194 if re.search(r'\{foreach\s+.*?\}.*?\{/foreach\}', text): |
195 rv += 0.15 |
195 rv += 0.15 |
196 if re.search('\{\$.*?\}', text): |
196 if re.search(r'\{\$.*?\}', text): |
197 rv += 0.01 |
197 rv += 0.01 |
198 return rv |
198 return rv |
199 |
199 |
200 |
200 |
201 class VelocityLexer(RegexLexer): |
201 class VelocityLexer(RegexLexer): |
419 mimetypes = ['application/x-myghty'] |
419 mimetypes = ['application/x-myghty'] |
420 |
420 |
421 tokens = { |
421 tokens = { |
422 'root': [ |
422 'root': [ |
423 (r'\s+', Text), |
423 (r'\s+', Text), |
424 (r'(<%(?:def|method))(\s*)(.*?)(>)(.*?)(</%\2\s*>)(?s)', |
424 (r'(?s)(<%(?:def|method))(\s*)(.*?)(>)(.*?)(</%\2\s*>)', |
425 bygroups(Name.Tag, Text, Name.Function, Name.Tag, |
425 bygroups(Name.Tag, Text, Name.Function, Name.Tag, |
426 using(this), Name.Tag)), |
426 using(this), Name.Tag)), |
427 (r'(<%\w+)(.*?)(>)(.*?)(</%\2\s*>)(?s)', |
427 (r'(?s)(<%\w+)(.*?)(>)(.*?)(</%\2\s*>)', |
428 bygroups(Name.Tag, Name.Function, Name.Tag, |
428 bygroups(Name.Tag, Name.Function, Name.Tag, |
429 using(PythonLexer), Name.Tag)), |
429 using(PythonLexer), Name.Tag)), |
430 (r'(<&[^|])(.*?)(,.*?)?(&>)', |
430 (r'(<&[^|])(.*?)(,.*?)?(&>)', |
431 bygroups(Name.Tag, Name.Function, using(PythonLexer), Name.Tag)), |
431 bygroups(Name.Tag, Name.Function, using(PythonLexer), Name.Tag)), |
432 (r'(<&\|)(.*?)(,.*?)?(&>)(?s)', |
432 (r'(?s)(<&\|)(.*?)(,.*?)?(&>)', |
433 bygroups(Name.Tag, Name.Function, using(PythonLexer), Name.Tag)), |
433 bygroups(Name.Tag, Name.Function, using(PythonLexer), Name.Tag)), |
434 (r'</&>', Name.Tag), |
434 (r'</&>', Name.Tag), |
435 (r'(<%!?)(.*?)(%>)(?s)', |
435 (r'(?s)(<%!?)(.*?)(%>)', |
436 bygroups(Name.Tag, using(PythonLexer), Name.Tag)), |
436 bygroups(Name.Tag, using(PythonLexer), Name.Tag)), |
437 (r'(?<=^)#[^\n]*(\n|\Z)', Comment), |
437 (r'(?<=^)#[^\n]*(\n|\Z)', Comment), |
438 (r'(?<=^)(%)([^\n]*)(\n|\Z)', |
438 (r'(?<=^)(%)([^\n]*)(\n|\Z)', |
439 bygroups(Name.Tag, using(PythonLexer), Other)), |
439 bygroups(Name.Tag, using(PythonLexer), Other)), |
440 (r"""(?sx) |
440 (r"""(?sx) |
536 mimetypes = ['application/x-mason'] |
536 mimetypes = ['application/x-mason'] |
537 |
537 |
538 tokens = { |
538 tokens = { |
539 'root': [ |
539 'root': [ |
540 (r'\s+', Text), |
540 (r'\s+', Text), |
541 (r'(<%doc>)(.*?)(</%doc>)(?s)', |
541 (r'(?s)(<%doc>)(.*?)(</%doc>)', |
542 bygroups(Name.Tag, Comment.Multiline, Name.Tag)), |
542 bygroups(Name.Tag, Comment.Multiline, Name.Tag)), |
543 (r'(<%(?:def|method))(\s*)(.*?)(>)(.*?)(</%\2\s*>)(?s)', |
543 (r'(?s)(<%(?:def|method))(\s*)(.*?)(>)(.*?)(</%\2\s*>)', |
544 bygroups(Name.Tag, Text, Name.Function, Name.Tag, |
544 bygroups(Name.Tag, Text, Name.Function, Name.Tag, |
545 using(this), Name.Tag)), |
545 using(this), Name.Tag)), |
546 (r'(<%\w+)(.*?)(>)(.*?)(</%\2\s*>)(?s)', |
546 (r'(?s)(<%\w+)(.*?)(>)(.*?)(</%\2\s*>)', |
547 bygroups(Name.Tag, Name.Function, Name.Tag, |
547 bygroups(Name.Tag, Name.Function, Name.Tag, |
548 using(PerlLexer), Name.Tag)), |
548 using(PerlLexer), Name.Tag)), |
549 (r'(<&[^|])(.*?)(,.*?)?(&>)(?s)', |
549 (r'(?s)(<&[^|])(.*?)(,.*?)?(&>)', |
550 bygroups(Name.Tag, Name.Function, using(PerlLexer), Name.Tag)), |
550 bygroups(Name.Tag, Name.Function, using(PerlLexer), Name.Tag)), |
551 (r'(<&\|)(.*?)(,.*?)?(&>)(?s)', |
551 (r'(?s)(<&\|)(.*?)(,.*?)?(&>)', |
552 bygroups(Name.Tag, Name.Function, using(PerlLexer), Name.Tag)), |
552 bygroups(Name.Tag, Name.Function, using(PerlLexer), Name.Tag)), |
553 (r'</&>', Name.Tag), |
553 (r'</&>', Name.Tag), |
554 (r'(<%!?)(.*?)(%>)(?s)', |
554 (r'(?s)(<%!?)(.*?)(%>)', |
555 bygroups(Name.Tag, using(PerlLexer), Name.Tag)), |
555 bygroups(Name.Tag, using(PerlLexer), Name.Tag)), |
556 (r'(?<=^)#[^\n]*(\n|\Z)', Comment), |
556 (r'(?<=^)#[^\n]*(\n|\Z)', Comment), |
557 (r'(?<=^)(%)([^\n]*)(\n|\Z)', |
557 (r'(?<=^)(%)([^\n]*)(\n|\Z)', |
558 bygroups(Name.Tag, using(PerlLexer), Other)), |
558 bygroups(Name.Tag, using(PerlLexer), Other)), |
559 (r"""(?sx) |
559 (r"""(?sx) |
605 (r'(<%)([\w.:]+)', |
605 (r'(<%)([\w.:]+)', |
606 bygroups(Comment.Preproc, Name.Builtin), 'tag'), |
606 bygroups(Comment.Preproc, Name.Builtin), 'tag'), |
607 (r'(</%)([\w.:]+)(>)', |
607 (r'(</%)([\w.:]+)(>)', |
608 bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)), |
608 bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)), |
609 (r'<%(?=([\w.:]+))', Comment.Preproc, 'ondeftags'), |
609 (r'<%(?=([\w.:]+))', Comment.Preproc, 'ondeftags'), |
610 (r'(<%(?:!?))(.*?)(%>)(?s)', |
610 (r'(?s)(<%(?:!?))(.*?)(%>)', |
611 bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)), |
611 bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)), |
612 (r'(\$\{)(.*?)(\})', |
612 (r'(\$\{)(.*?)(\})', |
613 bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)), |
613 bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)), |
614 (r'''(?sx) |
614 (r'''(?sx) |
615 (.+?) # anything, followed by: |
615 (.+?) # anything, followed by: |
757 (bygroups(Comment.Preproc, using(CheetahPythonLexer), |
757 (bygroups(Comment.Preproc, using(CheetahPythonLexer), |
758 Comment.Preproc))), |
758 Comment.Preproc))), |
759 # TODO support other Python syntax like $foo['bar'] |
759 # TODO support other Python syntax like $foo['bar'] |
760 (r'(\$)([a-zA-Z_][\w.]*\w)', |
760 (r'(\$)([a-zA-Z_][\w.]*\w)', |
761 bygroups(Comment.Preproc, using(CheetahPythonLexer))), |
761 bygroups(Comment.Preproc, using(CheetahPythonLexer))), |
762 (r'(\$\{!?)(.*?)(\})(?s)', |
762 (r'(?s)(\$\{!?)(.*?)(\})', |
763 bygroups(Comment.Preproc, using(CheetahPythonLexer), |
763 bygroups(Comment.Preproc, using(CheetahPythonLexer), |
764 Comment.Preproc)), |
764 Comment.Preproc)), |
765 (r'''(?sx) |
765 (r'''(?sx) |
766 (.+?) # anything, followed by: |
766 (.+?) # anything, followed by: |
767 (?: |
767 (?: |
940 super(HtmlGenshiLexer, self).__init__(HtmlLexer, GenshiMarkupLexer, |
940 super(HtmlGenshiLexer, self).__init__(HtmlLexer, GenshiMarkupLexer, |
941 **options) |
941 **options) |
942 |
942 |
943 def analyse_text(text): |
943 def analyse_text(text): |
944 rv = 0.0 |
944 rv = 0.0 |
945 if re.search('\$\{.*?\}', text) is not None: |
945 if re.search(r'\$\{.*?\}', text) is not None: |
946 rv += 0.2 |
946 rv += 0.2 |
947 if re.search('py:(.*?)=["\']', text) is not None: |
947 if re.search(r'py:(.*?)=["\']', text) is not None: |
948 rv += 0.2 |
948 rv += 0.2 |
949 return rv + HtmlLexer.analyse_text(text) - 0.01 |
949 return rv + HtmlLexer.analyse_text(text) - 0.01 |
950 |
950 |
951 |
951 |
952 class GenshiLexer(DelegatingLexer): |
952 class GenshiLexer(DelegatingLexer): |
965 super(GenshiLexer, self).__init__(XmlLexer, GenshiMarkupLexer, |
965 super(GenshiLexer, self).__init__(XmlLexer, GenshiMarkupLexer, |
966 **options) |
966 **options) |
967 |
967 |
968 def analyse_text(text): |
968 def analyse_text(text): |
969 rv = 0.0 |
969 rv = 0.0 |
970 if re.search('\$\{.*?\}', text) is not None: |
970 if re.search(r'\$\{.*?\}', text) is not None: |
971 rv += 0.2 |
971 rv += 0.2 |
972 if re.search('py:(.*?)=["\']', text) is not None: |
972 if re.search(r'py:(.*?)=["\']', text) is not None: |
973 rv += 0.2 |
973 rv += 0.2 |
974 return rv + XmlLexer.analyse_text(text) - 0.01 |
974 return rv + XmlLexer.analyse_text(text) - 0.01 |
975 |
975 |
976 |
976 |
977 class JavascriptGenshiLexer(DelegatingLexer): |
977 class JavascriptGenshiLexer(DelegatingLexer): |
1625 def __init__(self, **options): |
1625 def __init__(self, **options): |
1626 super(SspLexer, self).__init__(XmlLexer, JspRootLexer, **options) |
1626 super(SspLexer, self).__init__(XmlLexer, JspRootLexer, **options) |
1627 |
1627 |
1628 def analyse_text(text): |
1628 def analyse_text(text): |
1629 rv = 0.0 |
1629 rv = 0.0 |
1630 if re.search('val \w+\s*:', text): |
1630 if re.search(r'val \w+\s*:', text): |
1631 rv += 0.6 |
1631 rv += 0.6 |
1632 if looks_like_xml(text): |
1632 if looks_like_xml(text): |
1633 rv += 0.2 |
1633 rv += 0.2 |
1634 if '<%' in text and '%>' in text: |
1634 if '<%' in text and '%>' in text: |
1635 rv += 0.1 |
1635 rv += 0.1 |
1953 (r'([^\s%]+)(\s*)', bygroups(Name.Tag, Whitespace), 'tag-markup') |
1953 (r'([^\s%]+)(\s*)', bygroups(Name.Tag, Whitespace), 'tag-markup') |
1954 ], |
1954 ], |
1955 |
1955 |
1956 'output': [ |
1956 'output': [ |
1957 include('whitespace'), |
1957 include('whitespace'), |
1958 ('\}\}', Punctuation, '#pop'), # end of output |
1958 (r'\}\}', Punctuation, '#pop'), # end of output |
1959 |
1959 |
1960 (r'\|', Punctuation, 'filters') |
1960 (r'\|', Punctuation, 'filters') |
1961 ], |
1961 ], |
1962 |
1962 |
1963 'filters': [ |
1963 'filters': [ |