1659 ], |
1661 ], |
1660 'namespace': [ |
1662 'namespace': [ |
1661 (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop') |
1663 (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop') |
1662 ], |
1664 ], |
1663 } |
1665 } |
|
1666 |
|
1667 |
|
1668 class OocLexer(RegexLexer): |
|
1669 """ |
|
1670 For `Ooc <http://ooc-lang.org/>`_ source code |
|
1671 |
|
1672 *New in Pygments 1.2.* |
|
1673 """ |
|
1674 name = 'Ooc' |
|
1675 aliases = ['ooc'] |
|
1676 filenames = ['*.ooc'] |
|
1677 mimetypes = ['text/x-ooc'] |
|
1678 |
|
1679 tokens = { |
|
1680 'root': [ |
|
1681 (r'\b(class|interface|implement|abstract|extends|from|' |
|
1682 r'this|super|new|const|final|static|import|use|extern|' |
|
1683 r'inline|proto|break|continue|fallthrough|operator|if|else|for|' |
|
1684 r'while|do|switch|case|as|in|version|return|true|false|null)\b', |
|
1685 Keyword), |
|
1686 (r'include\b', Keyword, 'include'), |
|
1687 (r'(cover)([ \t]+)(from)([ \t]+)([a-zA-Z0-9_]+[*@]?)', |
|
1688 bygroups(Keyword, Text, Keyword, Text, Name.Class)), |
|
1689 (r'(func)((?:[ \t]|\\\n)+)(~[a-z_][a-zA-Z0-9_]*)', |
|
1690 bygroups(Keyword, Text, Name.Function)), |
|
1691 (r'\bfunc\b', Keyword), |
|
1692 # Note: %= and ^= not listed on http://ooc-lang.org/syntax |
|
1693 (r'//.*', Comment), |
|
1694 (r'(?s)/\*.*?\*/', Comment.Multiline), |
|
1695 (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|' |
|
1696 r'&&?|\|\|?|\^=?)', Operator), |
|
1697 (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text, |
|
1698 Name.Function)), |
|
1699 (r'[A-Z][A-Z0-9_]+', Name.Constant), |
|
1700 (r'[A-Z][a-zA-Z0-9_]*([@*]|\[[ \t]*\])?', Name.Class), |
|
1701 |
|
1702 (r'([a-z][a-zA-Z0-9_]*(?:~[a-z][a-zA-Z0-9_]*)?)((?:[ \t]|\\\n)*)(?=\()', |
|
1703 bygroups(Name.Function, Text)), |
|
1704 (r'[a-z][a-zA-Z0-9_]*', Name.Variable), |
|
1705 |
|
1706 # : introduces types |
|
1707 (r'[:(){}\[\];,]', Punctuation), |
|
1708 |
|
1709 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
1710 (r'0c[0-9]+', Number.Octal), |
|
1711 (r'0b[01]+', Number.Binary), |
|
1712 (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float), |
|
1713 (r'[0-9_]+', Number.Decimal), |
|
1714 |
|
1715 (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\"])*"', |
|
1716 String.Double), |
|
1717 (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", |
|
1718 String.Char), |
|
1719 (r'@', Punctuation), # pointer dereference |
|
1720 (r'\.', Punctuation), # imports or chain operator |
|
1721 |
|
1722 (r'\\[ \t\n]', Text), |
|
1723 (r'[ \t]+', Text), |
|
1724 ], |
|
1725 'include': [ |
|
1726 (r'[\w/]+', Name), |
|
1727 (r',', Punctuation), |
|
1728 (r'[ \t]', Text), |
|
1729 (r'[;\n]', Text, '#pop'), |
|
1730 ], |
|
1731 } |
|
1732 |
|
1733 |
|
1734 class GoLexer(RegexLexer): |
|
1735 """ |
|
1736 For `Go <http://golang.org>`_ source. |
|
1737 """ |
|
1738 name = 'Go' |
|
1739 filenames = ['*.go'] |
|
1740 aliases = ['go'] |
|
1741 mimetypes = ['text/x-gosrc'] |
|
1742 |
|
1743 tokens = { |
|
1744 'root': [ |
|
1745 (r'\n', Text), |
|
1746 (r'\s+', Text), |
|
1747 (r'\\\n', Text), # line continuations |
|
1748 (r'//(.*?)\n', Comment.Single), |
|
1749 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
1750 (r'(break|default|func|interface|select' |
|
1751 r'|case|defer|go|map|struct' |
|
1752 r'|chan|else|goto|package|switch' |
|
1753 r'|const|fallthrough|if|range|type' |
|
1754 r'|continue|for|import|return|var)\b', Keyword |
|
1755 ), |
|
1756 # It seems the builtin types aren't actually keywords. |
|
1757 (r'(uint8|uint16|uint32|uint64' |
|
1758 r'|int8|int16|int32|int64' |
|
1759 r'|float32|float64|byte' |
|
1760 r'|uint|int|float|uintptr' |
|
1761 r'|string|close|closed|len|cap|new|make)\b', Name.Builtin |
|
1762 ), |
|
1763 # float_lit |
|
1764 (r'\d+(\.\d+[eE][+\-]?\d+|' |
|
1765 r'\.\d*|[eE][+\-]?\d+)', Number.Float), |
|
1766 (r'\.\d+([eE][+\-]?\d+)?', Number.Float), |
|
1767 # int_lit |
|
1768 # -- octal_lit |
|
1769 (r'0[0-7]+', Number.Oct), |
|
1770 # -- hex_lit |
|
1771 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
1772 # -- decimal_lit |
|
1773 (r'(0|[1-9][0-9]*)', Number.Integer), |
|
1774 # char_lit |
|
1775 (r"""'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" |
|
1776 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'""", |
|
1777 String.Char |
|
1778 ), |
|
1779 # StringLiteral |
|
1780 # -- raw_string_lit |
|
1781 (r'`[^`]*`', String), |
|
1782 # -- interpreted_string_lit |
|
1783 (r'"(\\\\|\\"|[^"])*"', String), |
|
1784 # Tokens |
|
1785 (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|' |
|
1786 r'|<-|\+\+|--|==|!=|:=|\.\.\.)|[+\-*/%&|^<>=!()\[\]{}.,;:]', |
|
1787 Punctuation |
|
1788 ), |
|
1789 # identifier |
|
1790 (r'[a-zA-Z_]\w*', Name), |
|
1791 ] |
|
1792 } |
|
1793 |
|
1794 |
|
1795 class FelixLexer(RegexLexer): |
|
1796 """ |
|
1797 For `Felix <http://www.felix-lang.org>`_ source code. |
|
1798 |
|
1799 *New in Pygments 1.2.* |
|
1800 """ |
|
1801 |
|
1802 name = 'Felix' |
|
1803 aliases = ['felix', 'flx'] |
|
1804 filenames = ['*.flx', '*.flxh'] |
|
1805 mimetypes = ['text/x-felix'] |
|
1806 |
|
1807 preproc = [ |
|
1808 'elif', 'else', 'endif', 'if', 'ifdef', 'ifndef', |
|
1809 ] |
|
1810 |
|
1811 keywords = [ |
|
1812 '_', '_deref', 'all', 'as', |
|
1813 'assert', 'attempt', 'call', 'callback', 'case', 'caseno', 'cclass', |
|
1814 'code', 'compound', 'ctypes', 'do', 'done', 'downto', 'elif', 'else', |
|
1815 'endattempt', 'endcase', 'endif', 'endmatch', 'enum', 'except', |
|
1816 'exceptions', 'expect', 'finally', 'for', 'forall', 'forget', 'fork', |
|
1817 'functor', 'goto', 'ident', 'if', 'incomplete', 'inherit', 'instance', |
|
1818 'interface', 'jump', 'lambda', 'loop', 'match', 'module', 'namespace', |
|
1819 'new', 'noexpand', 'nonterm', 'obj', 'of', 'open', 'parse', 'raise', |
|
1820 'regexp', 'reglex', 'regmatch', 'rename', 'return', 'the', 'then', |
|
1821 'to', 'type', 'typecase', 'typedef', 'typematch', 'typeof', 'upto', |
|
1822 'when', 'whilst', 'with', 'yield', |
|
1823 ] |
|
1824 |
|
1825 keyword_directives = [ |
|
1826 '_gc_pointer', '_gc_type', 'body', 'comment', 'const', 'export', |
|
1827 'header', 'inline', 'lval', 'macro', 'noinline', 'noreturn', |
|
1828 'package', 'private', 'pod', 'property', 'public', 'publish', |
|
1829 'requires', 'todo', 'virtual', 'use', |
|
1830 ] |
|
1831 |
|
1832 keyword_declarations = [ |
|
1833 'def', 'let', 'ref', 'val', 'var', |
|
1834 ] |
|
1835 |
|
1836 keyword_types = [ |
|
1837 'unit', 'void', 'any', 'bool', |
|
1838 'byte', 'offset', |
|
1839 'address', 'caddress', 'cvaddress', 'vaddress', |
|
1840 'tiny', 'short', 'int', 'long', 'vlong', |
|
1841 'utiny', 'ushort', 'vshort', 'uint', 'ulong', 'uvlong', |
|
1842 'int8', 'int16', 'int32', 'int64', |
|
1843 'uint8', 'uint16', 'uint32', 'uint64', |
|
1844 'float', 'double', 'ldouble', |
|
1845 'complex', 'dcomplex', 'lcomplex', |
|
1846 'imaginary', 'dimaginary', 'limaginary', |
|
1847 'char', 'wchar', 'uchar', |
|
1848 'charp', 'charcp', 'ucharp', 'ucharcp', |
|
1849 'string', 'wstring', 'ustring', |
|
1850 'cont', |
|
1851 'array', 'varray', 'list', |
|
1852 'lvalue', 'opt', 'slice', |
|
1853 ] |
|
1854 |
|
1855 keyword_constants = [ |
|
1856 'false', 'true', |
|
1857 ] |
|
1858 |
|
1859 operator_words = [ |
|
1860 'and', 'not', 'in', 'is', 'isin', 'or', 'xor', |
|
1861 ] |
|
1862 |
|
1863 name_builtins = [ |
|
1864 '_svc', 'while', |
|
1865 ] |
|
1866 |
|
1867 name_pseudo = [ |
|
1868 'root', 'self', 'this', |
|
1869 ] |
|
1870 |
|
1871 decimal_suffixes = '([tTsSiIlLvV]|ll|LL|([iIuU])(8|16|32|64))?' |
|
1872 |
|
1873 tokens = { |
|
1874 'root': [ |
|
1875 include('whitespace'), |
|
1876 |
|
1877 # Keywords |
|
1878 (r'(axiom|ctor|fun|gen|proc|reduce|union)\b', Keyword, |
|
1879 'funcname'), |
|
1880 (r'(class|cclass|cstruct|obj|struct)\b', Keyword, 'classname'), |
|
1881 (r'(instance|module|typeclass)\b', Keyword, 'modulename'), |
|
1882 |
|
1883 (r'(%s)\b' % '|'.join(keywords), Keyword), |
|
1884 (r'(%s)\b' % '|'.join(keyword_directives), Name.Decorator), |
|
1885 (r'(%s)\b' % '|'.join(keyword_declarations), Keyword.Declaration), |
|
1886 (r'(%s)\b' % '|'.join(keyword_types), Keyword.Type), |
|
1887 (r'(%s)\b' % '|'.join(keyword_constants), Keyword.Constant), |
|
1888 |
|
1889 # Operators |
|
1890 include('operators'), |
|
1891 |
|
1892 # Float Literal |
|
1893 # -- Hex Float |
|
1894 (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)' |
|
1895 r'[pP][+\-]?[0-9_]+[lLfFdD]?', Number.Float), |
|
1896 # -- DecimalFloat |
|
1897 (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|' |
|
1898 r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[lLfFdD]?', Number.Float), |
|
1899 (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[lLfFdD]?', |
|
1900 Number.Float), |
|
1901 |
|
1902 # IntegerLiteral |
|
1903 # -- Binary |
|
1904 (r'0[Bb][01_]+%s' % decimal_suffixes, Number), |
|
1905 # -- Octal |
|
1906 (r'0[0-7_]+%s' % decimal_suffixes, Number.Oct), |
|
1907 # -- Hexadecimal |
|
1908 (r'0[xX][0-9a-fA-F_]+%s' % decimal_suffixes, Number.Hex), |
|
1909 # -- Decimal |
|
1910 (r'(0|[1-9][0-9_]*)%s' % decimal_suffixes, Number.Integer), |
|
1911 |
|
1912 # Strings |
|
1913 ('([rR][cC]?|[cC][rR])"""', String, 'tdqs'), |
|
1914 ("([rR][cC]?|[cC][rR])'''", String, 'tsqs'), |
|
1915 ('([rR][cC]?|[cC][rR])"', String, 'dqs'), |
|
1916 ("([rR][cC]?|[cC][rR])'", String, 'sqs'), |
|
1917 ('[cCfFqQwWuU]?"""', String, combined('stringescape', 'tdqs')), |
|
1918 ("[cCfFqQwWuU]?'''", String, combined('stringescape', 'tsqs')), |
|
1919 ('[cCfFqQwWuU]?"', String, combined('stringescape', 'dqs')), |
|
1920 ("[cCfFqQwWuU]?'", String, combined('stringescape', 'sqs')), |
|
1921 |
|
1922 # Punctuation |
|
1923 (r'[\[\]{}:(),;?]', Punctuation), |
|
1924 |
|
1925 # Labels |
|
1926 (r'[a-zA-Z_]\w*:>', Name.Label), |
|
1927 |
|
1928 # Identifiers |
|
1929 (r'(%s)\b' % '|'.join(name_builtins), Name.Builtin), |
|
1930 (r'(%s)\b' % '|'.join(name_pseudo), Name.Builtin.Pseudo), |
|
1931 (r'[a-zA-Z_]\w*', Name), |
|
1932 ], |
|
1933 'whitespace': [ |
|
1934 (r'\n', Text), |
|
1935 (r'\s+', Text), |
|
1936 |
|
1937 include('comment'), |
|
1938 |
|
1939 # Preprocessor |
|
1940 (r'#\s*if\s+0', Comment.Preproc, 'if0'), |
|
1941 (r'#', Comment.Preproc, 'macro'), |
|
1942 ], |
|
1943 'operators': [ |
|
1944 (r'(%s)\b' % '|'.join(operator_words), Operator.Word), |
|
1945 (r'!=|==|<<|>>|\|\||&&|[-~+/*%=<>&^|.$]', Operator), |
|
1946 ], |
|
1947 'comment': [ |
|
1948 (r'//(.*?)\n', Comment.Single), |
|
1949 (r'/[*]', Comment.Multiline, 'comment2'), |
|
1950 ], |
|
1951 'comment2': [ |
|
1952 (r'[^\/*]', Comment.Multiline), |
|
1953 (r'/[*]', Comment.Multiline, '#push'), |
|
1954 (r'[*]/', Comment.Multiline, '#pop'), |
|
1955 (r'[\/*]', Comment.Multiline), |
|
1956 ], |
|
1957 'if0': [ |
|
1958 (r'^\s*#if.*?(?<!\\)\n', Comment, '#push'), |
|
1959 (r'^\s*#endif.*?(?<!\\)\n', Comment, '#pop'), |
|
1960 (r'.*?\n', Comment), |
|
1961 ], |
|
1962 'macro': [ |
|
1963 include('comment'), |
|
1964 (r'(import|include)(\s+)(<[^>]*?>)', |
|
1965 bygroups(Comment.Preproc, Text, String), '#pop'), |
|
1966 (r'(import|include)(\s+)("[^"]*?")', |
|
1967 bygroups(Comment.Preproc, Text, String), '#pop'), |
|
1968 (r"(import|include)(\s+)('[^']*?')", |
|
1969 bygroups(Comment.Preproc, Text, String), '#pop'), |
|
1970 (r'[^/\n]+', Comment.Preproc), |
|
1971 ##(r'/[*](.|\n)*?[*]/', Comment), |
|
1972 ##(r'//.*?\n', Comment, '#pop'), |
|
1973 (r'/', Comment.Preproc), |
|
1974 (r'(?<=\\)\n', Comment.Preproc), |
|
1975 (r'\n', Comment.Preproc, '#pop'), |
|
1976 ], |
|
1977 'funcname': [ |
|
1978 include('whitespace'), |
|
1979 (r'[a-zA-Z_]\w*', Name.Function, '#pop'), |
|
1980 # anonymous functions |
|
1981 (r'(?=\()', Text, '#pop'), |
|
1982 ], |
|
1983 'classname': [ |
|
1984 include('whitespace'), |
|
1985 (r'[a-zA-Z_]\w*', Name.Class, '#pop'), |
|
1986 # anonymous classes |
|
1987 (r'(?=\{)', Text, '#pop'), |
|
1988 ], |
|
1989 'modulename': [ |
|
1990 include('whitespace'), |
|
1991 (r'\[', Punctuation, ('modulename2', 'tvarlist')), |
|
1992 (r'', Error, 'modulename2'), |
|
1993 ], |
|
1994 'modulename2': [ |
|
1995 include('whitespace'), |
|
1996 (r'([a-zA-Z_]\w*)', Name.Namespace, '#pop:2'), |
|
1997 ], |
|
1998 'tvarlist': [ |
|
1999 include('whitespace'), |
|
2000 include('operators'), |
|
2001 (r'\[', Punctuation, '#push'), |
|
2002 (r'\]', Punctuation, '#pop'), |
|
2003 (r',', Punctuation), |
|
2004 (r'(with|where)\b', Keyword), |
|
2005 (r'[a-zA-Z_]\w*', Name), |
|
2006 ], |
|
2007 'stringescape': [ |
|
2008 (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|' |
|
2009 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) |
|
2010 ], |
|
2011 'strings': [ |
|
2012 (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' |
|
2013 '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol), |
|
2014 (r'[^\\\'"%\n]+', String), |
|
2015 # quotes, percents and backslashes must be parsed one at a time |
|
2016 (r'[\'"\\]', String), |
|
2017 # unhandled string formatting sign |
|
2018 (r'%', String) |
|
2019 # newlines are an error (use "nl" state) |
|
2020 ], |
|
2021 'nl': [ |
|
2022 (r'\n', String) |
|
2023 ], |
|
2024 'dqs': [ |
|
2025 (r'"', String, '#pop'), |
|
2026 # included here again for raw strings |
|
2027 (r'\\\\|\\"|\\\n', String.Escape), |
|
2028 include('strings') |
|
2029 ], |
|
2030 'sqs': [ |
|
2031 (r"'", String, '#pop'), |
|
2032 # included here again for raw strings |
|
2033 (r"\\\\|\\'|\\\n", String.Escape), |
|
2034 include('strings') |
|
2035 ], |
|
2036 'tdqs': [ |
|
2037 (r'"""', String, '#pop'), |
|
2038 include('strings'), |
|
2039 include('nl') |
|
2040 ], |
|
2041 'tsqs': [ |
|
2042 (r"'''", String, '#pop'), |
|
2043 include('strings'), |
|
2044 include('nl') |
|
2045 ], |
|
2046 } |
|
2047 |
|
2048 |
|
2049 class AdaLexer(RegexLexer): |
|
2050 """ |
|
2051 For Ada source code. |
|
2052 |
|
2053 *New in Pygments 1.3.* |
|
2054 """ |
|
2055 |
|
2056 name = 'Ada' |
|
2057 aliases = ['ada', 'ada95' 'ada2005'] |
|
2058 filenames = ['*.adb', '*.ads', '*.ada'] |
|
2059 mimetypes = ['text/x-ada'] |
|
2060 |
|
2061 flags = re.MULTILINE | re.I # Ignore case |
|
2062 |
|
2063 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' |
|
2064 |
|
2065 tokens = { |
|
2066 'root': [ |
|
2067 (r'[^\S\n]+', Text), |
|
2068 (r'--.*?\n', Comment.Single), |
|
2069 (r'[^\S\n]+', Text), |
|
2070 (r'function|procedure|entry', Keyword.Declaration, 'subprogram'), |
|
2071 (r'(subtype|type)(\s+)([a-z0-9_]+)', |
|
2072 bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), |
|
2073 (r'task|protected', Keyword.Declaration), |
|
2074 (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)), |
|
2075 (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'), |
|
2076 (r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text, |
|
2077 Comment.Preproc)), |
|
2078 (r'(true|false|null)\b', Keyword.Constant), |
|
2079 (r'(Byte|Character|Float|Integer|Long_Float|Long_Integer|' |
|
2080 r'Long_Long_Float|Long_Long_Integer|Natural|Positive|Short_Float|' |
|
2081 r'Short_Integer|Short_Short_Float|Short_Short_Integer|String|' |
|
2082 r'Wide_String|Duration)\b', Keyword.Type), |
|
2083 (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word), |
|
2084 (r'generic|private', Keyword.Declaration), |
|
2085 (r'package', Keyword.Declaration, 'package'), |
|
2086 (r'array\b', Keyword.Reserved, 'array_def'), |
|
2087 (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), |
|
2088 (r'([a-z0-9_]+)(\s*)(:)(\s*)(constant)', |
|
2089 bygroups(Name.Constant, Text, Punctuation, Text, |
|
2090 Keyword.Reserved)), |
|
2091 (r'<<[a-z0-9_]+>>', Name.Label), |
|
2092 (r'([a-z0-9_]+)(\s*)(:)(\s*)(declare|begin|loop|for|while)', |
|
2093 bygroups(Name.Label, Text, Punctuation, Text, Keyword.Reserved)), |
|
2094 (r'\b(abort|abs|abstract|accept|access|aliased|all|array|at|begin|' |
|
2095 r'body|case|constant|declare|delay|delta|digits|do|else|elsif|end|' |
|
2096 r'entry|exception|exit|interface|for|goto|if|is|limited|loop|new|' |
|
2097 r'null|of|or|others|out|overriding|pragma|protected|raise|range|' |
|
2098 r'record|renames|requeue|return|reverse|select|separate|subtype|' |
|
2099 r'synchronized|task|tagged|terminate|then|type|until|when|while|' |
|
2100 r'xor)\b', |
|
2101 Keyword.Reserved), |
|
2102 (r'"[^"]*"', String), |
|
2103 include('attribute'), |
|
2104 include('numbers'), |
|
2105 (r"'[^']'", String.Character), |
|
2106 (r'([a-z0-9_]+)(\s*|[(,])', bygroups(Name, using(this))), |
|
2107 (r"(<>|=>|:=|[\(\)\|:;,.'])", Punctuation), |
|
2108 (r'[*<>+=/&-]', Operator), |
|
2109 (r'\n+', Text), |
|
2110 ], |
|
2111 'numbers' : [ |
|
2112 (r'[0-9_]+#[0-9a-f]+#', Number.Hex), |
|
2113 (r'[0-9_]+\.[0-9_]*', Number.Float), |
|
2114 (r'[0-9_]+', Number.Integer), |
|
2115 ], |
|
2116 'attribute' : [ |
|
2117 (r"(')([a-zA-Z0-9_]+)", bygroups(Punctuation, Name.Attribute)), |
|
2118 ], |
|
2119 'subprogram' : [ |
|
2120 (r'\(', Punctuation, ('#pop', 'formal_part')), |
|
2121 (r';', Punctuation, '#pop'), |
|
2122 (r'is\b', Keyword.Reserved, '#pop'), |
|
2123 (r'"[^"]+"|[a-z0-9_]+', Name.Function), |
|
2124 include('root'), |
|
2125 ], |
|
2126 'end' : [ |
|
2127 ('(if|case|record|loop|select)', Keyword.Reserved), |
|
2128 ('"[^"]+"|[a-zA-Z0-9_]+', Name.Function), |
|
2129 ('[\n\s]+', Text), |
|
2130 (';', Punctuation, '#pop'), |
|
2131 ], |
|
2132 'type_def': [ |
|
2133 (r';', Punctuation, '#pop'), |
|
2134 (r'\(', Punctuation, 'formal_part'), |
|
2135 (r'with|and|use', Keyword.Reserved), |
|
2136 (r'array\b', Keyword.Reserved, ('#pop', 'array_def')), |
|
2137 (r'record\b', Keyword.Reserved, ('formal_part')), |
|
2138 include('root'), |
|
2139 ], |
|
2140 'array_def' : [ |
|
2141 (r';', Punctuation, '#pop'), |
|
2142 (r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text, |
|
2143 Keyword.Reserved)), |
|
2144 include('root'), |
|
2145 ], |
|
2146 'import': [ |
|
2147 (r'[a-z0-9_.]+', Name.Namespace, '#pop'), |
|
2148 ], |
|
2149 'formal_part' : [ |
|
2150 (r'\)', Punctuation, '#pop'), |
|
2151 (r'([a-z0-9_]+)(\s*)(,|:[^=])', bygroups(Name.Variable, |
|
2152 Text, Punctuation)), |
|
2153 (r'(in|not|null|out|access)\b', Keyword.Reserved), |
|
2154 include('root'), |
|
2155 ], |
|
2156 'package': [ |
|
2157 ('body', Keyword.Declaration), |
|
2158 ('is\s+new|renames', Keyword.Reserved), |
|
2159 ('is', Keyword.Reserved, '#pop'), |
|
2160 (';', Punctuation, '#pop'), |
|
2161 ('\(', Punctuation, 'package_instantiation'), |
|
2162 ('([a-zA-Z0-9_.]+)', Name.Class), |
|
2163 include('root'), |
|
2164 ], |
|
2165 'package_instantiation': [ |
|
2166 (r'("[^"]+"|[a-z0-9_]+)(\s+)(=>)', bygroups(Name.Variable, |
|
2167 Text, Punctuation)), |
|
2168 (r'[a-z0-9._\'"]', Text), |
|
2169 (r'\)', Punctuation, '#pop'), |
|
2170 include('root'), |
|
2171 ], |
|
2172 } |
|
2173 |
|
2174 |
|
2175 class Modula2Lexer(RegexLexer): |
|
2176 """ |
|
2177 For `Modula-2 <http://www.modula2.org/>`_ source code. |
|
2178 |
|
2179 Additional options that determine which keywords are highlighted: |
|
2180 |
|
2181 `pim` |
|
2182 Select PIM Modula-2 dialect (default: True). |
|
2183 `iso` |
|
2184 Select ISO Modula-2 dialect (default: False). |
|
2185 `objm2` |
|
2186 Select Objective Modula-2 dialect (default: False). |
|
2187 `gm2ext` |
|
2188 Also highlight GNU extensions (default: False). |
|
2189 |
|
2190 *New in Pygments 1.3.* |
|
2191 """ |
|
2192 name = 'Modula-2' |
|
2193 aliases = ['modula2', 'm2'] |
|
2194 filenames = ['*.def', '*.mod'] |
|
2195 mimetypes = ['text/x-modula2'] |
|
2196 |
|
2197 flags = re.MULTILINE | re.DOTALL |
|
2198 |
|
2199 tokens = { |
|
2200 'whitespace': [ |
|
2201 (r'\n+', Text), # blank lines |
|
2202 (r'\s+', Text), # whitespace |
|
2203 ], |
|
2204 'identifiers': [ |
|
2205 (r'([a-zA-Z_\$][a-zA-Z0-9_\$]*)', Name), |
|
2206 ], |
|
2207 'numliterals': [ |
|
2208 (r'[01]+B', Number.Binary), # binary number (ObjM2) |
|
2209 (r'[0-7]+B', Number.Oct), # octal number (PIM + ISO) |
|
2210 (r'[0-7]+C', Number.Oct), # char code (PIM + ISO) |
|
2211 (r'[0-9A-F]+C', Number.Hex), # char code (ObjM2) |
|
2212 (r'[0-9A-F]+H', Number.Hex), # hexadecimal number |
|
2213 (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number |
|
2214 (r'[0-9]+\.[0-9]+', Number.Float), # real number |
|
2215 (r'[0-9]+', Number.Integer), # decimal whole number |
|
2216 ], |
|
2217 'strings': [ |
|
2218 (r"'(\\\\|\\'|[^'])*'", String), # single quoted string |
|
2219 (r'"(\\\\|\\"|[^"])*"', String), # double quoted string |
|
2220 ], |
|
2221 'operators': [ |
|
2222 (r'[*/+=#~&<>\^-]', Operator), |
|
2223 (r':=', Operator), # assignment |
|
2224 (r'@', Operator), # pointer deref (ISO) |
|
2225 (r'\.\.', Operator), # ellipsis or range |
|
2226 (r'`', Operator), # Smalltalk message (ObjM2) |
|
2227 (r'::', Operator), # type conversion (ObjM2) |
|
2228 ], |
|
2229 'punctuation': [ |
|
2230 (r'[\(\)\[\]{},.:;|]', Punctuation), |
|
2231 ], |
|
2232 'comments': [ |
|
2233 (r'//.*?\n', Comment.Single), # ObjM2 |
|
2234 (r'/\*(.*?)\*/', Comment.Multiline), # ObjM2 |
|
2235 (r'\(\*([^\$].*?)\*\)', Comment.Multiline), |
|
2236 # TO DO: nesting of (* ... *) comments |
|
2237 ], |
|
2238 'pragmas': [ |
|
2239 (r'\(\*\$(.*?)\*\)', Comment.Preproc), # PIM |
|
2240 (r'<\*(.*?)\*>', Comment.Preproc), # ISO + ObjM2 |
|
2241 ], |
|
2242 'root': [ |
|
2243 include('whitespace'), |
|
2244 include('comments'), |
|
2245 include('pragmas'), |
|
2246 include('identifiers'), |
|
2247 include('numliterals'), |
|
2248 include('strings'), |
|
2249 include('operators'), |
|
2250 include('punctuation'), |
|
2251 ] |
|
2252 } |
|
2253 |
|
2254 pim_reserved_words = [ |
|
2255 # 40 reserved words |
|
2256 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', |
|
2257 'DIV', 'DO', 'ELSE', 'ELSIF', 'END', 'EXIT', 'EXPORT', 'FOR', |
|
2258 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN', 'LOOP', 'MOD', |
|
2259 'MODULE', 'NOT', 'OF', 'OR', 'POINTER', 'PROCEDURE', 'QUALIFIED', |
|
2260 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', |
|
2261 'UNTIL', 'VAR', 'WHILE', 'WITH', |
|
2262 ] |
|
2263 |
|
2264 pim_pervasives = [ |
|
2265 # 31 pervasives |
|
2266 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'DEC', |
|
2267 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH', 'INC', 'INCL', |
|
2268 'INTEGER', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW', 'NIL', 'ODD', |
|
2269 'ORD', 'PROC', 'REAL', 'SIZE', 'TRUE', 'TRUNC', 'VAL', |
|
2270 ] |
|
2271 |
|
2272 iso_reserved_words = [ |
|
2273 # 46 reserved words |
|
2274 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV', |
|
2275 'DO', 'ELSE', 'ELSIF', 'END', 'EXCEPT', 'EXIT', 'EXPORT', 'FINALLY', |
|
2276 'FOR', 'FORWARD', 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN', |
|
2277 'LOOP', 'MOD', 'MODULE', 'NOT', 'OF', 'OR', 'PACKEDSET', 'POINTER', |
|
2278 'PROCEDURE', 'QUALIFIED', 'RECORD', 'REPEAT', 'REM', 'RETRY', |
|
2279 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', 'UNTIL', 'VAR', 'WHILE', |
|
2280 'WITH', |
|
2281 ] |
|
2282 |
|
2283 iso_pervasives = [ |
|
2284 # 42 pervasives |
|
2285 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'CMPLX', |
|
2286 'COMPLEX', 'DEC', 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH', |
|
2287 'IM', 'INC', 'INCL', 'INT', 'INTEGER', 'INTERRUPTIBLE', 'LENGTH', |
|
2288 'LFLOAT', 'LONGCOMPLEX', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW', |
|
2289 'NIL', 'ODD', 'ORD', 'PROC', 'PROTECTION', 'RE', 'REAL', 'SIZE', |
|
2290 'TRUE', 'TRUNC', 'UNINTERRUBTIBLE', 'VAL', |
|
2291 ] |
|
2292 |
|
2293 objm2_reserved_words = [ |
|
2294 # base language, 42 reserved words |
|
2295 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV', |
|
2296 'DO', 'ELSE', 'ELSIF', 'END', 'ENUM', 'EXIT', 'FOR', 'FROM', 'IF', |
|
2297 'IMMUTABLE', 'IMPLEMENTATION', 'IMPORT', 'IN', 'IS', 'LOOP', 'MOD', |
|
2298 'MODULE', 'NOT', 'OF', 'OPAQUE', 'OR', 'POINTER', 'PROCEDURE', |
|
2299 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', |
|
2300 'UNTIL', 'VAR', 'VARIADIC', 'WHILE', |
|
2301 # OO extensions, 16 reserved words |
|
2302 'BYCOPY', 'BYREF', 'CLASS', 'CONTINUE', 'CRITICAL', 'INOUT', 'METHOD', |
|
2303 'ON', 'OPTIONAL', 'OUT', 'PRIVATE', 'PROTECTED', 'PROTOCOL', 'PUBLIC', |
|
2304 'SUPER', 'TRY', |
|
2305 ] |
|
2306 |
|
2307 objm2_pervasives = [ |
|
2308 # base language, 38 pervasives |
|
2309 'ABS', 'BITSET', 'BOOLEAN', 'CARDINAL', 'CHAR', 'CHR', 'DISPOSE', |
|
2310 'FALSE', 'HALT', 'HIGH', 'INTEGER', 'INRANGE', 'LENGTH', 'LONGCARD', |
|
2311 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEG', 'NEW', 'NEXTV', 'NIL', |
|
2312 'OCTET', 'ODD', 'ORD', 'PRED', 'PROC', 'READ', 'REAL', 'SUCC', 'TMAX', |
|
2313 'TMIN', 'TRUE', 'TSIZE', 'UNICHAR', 'VAL', 'WRITE', 'WRITEF', |
|
2314 # OO extensions, 3 pervasives |
|
2315 'OBJECT', 'NO', 'YES', |
|
2316 ] |
|
2317 |
|
2318 gnu_reserved_words = [ |
|
2319 # 10 additional reserved words |
|
2320 'ASM', '__ATTRIBUTE__', '__BUILTIN__', '__COLUMN__', '__DATE__', |
|
2321 '__FILE__', '__FUNCTION__', '__LINE__', '__MODULE__', 'VOLATILE', |
|
2322 ] |
|
2323 |
|
2324 gnu_pervasives = [ |
|
2325 # 21 identifiers, actually from pseudo-module SYSTEM |
|
2326 # but we will highlight them as if they were pervasives |
|
2327 'BITSET8', 'BITSET16', 'BITSET32', 'CARDINAL8', 'CARDINAL16', |
|
2328 'CARDINAL32', 'CARDINAL64', 'COMPLEX32', 'COMPLEX64', 'COMPLEX96', |
|
2329 'COMPLEX128', 'INTEGER8', 'INTEGER16', 'INTEGER32', 'INTEGER64', |
|
2330 'REAL8', 'REAL16', 'REAL32', 'REAL96', 'REAL128', 'THROW', |
|
2331 ] |
|
2332 |
|
2333 def __init__(self, **options): |
|
2334 self.reserved_words = set() |
|
2335 self.pervasives = set() |
|
2336 # ISO Modula-2 |
|
2337 if get_bool_opt(options, 'iso', False): |
|
2338 self.reserved_words.update(self.iso_reserved_words) |
|
2339 self.pervasives.update(self.iso_pervasives) |
|
2340 # Objective Modula-2 |
|
2341 elif get_bool_opt(options, 'objm2', False): |
|
2342 self.reserved_words.update(self.objm2_reserved_words) |
|
2343 self.pervasives.update(self.objm2_pervasives) |
|
2344 # PIM Modula-2 (DEFAULT) |
|
2345 else: |
|
2346 self.reserved_words.update(self.pim_reserved_words) |
|
2347 self.pervasives.update(self.pim_pervasives) |
|
2348 # GNU extensions |
|
2349 if get_bool_opt(options, 'gm2ext', False): |
|
2350 self.reserved_words.update(self.gnu_reserved_words) |
|
2351 self.pervasives.update(self.gnu_pervasives) |
|
2352 # initialise |
|
2353 RegexLexer.__init__(self, **options) |
|
2354 |
|
2355 def get_tokens_unprocessed(self, text): |
|
2356 for index, token, value in \ |
|
2357 RegexLexer.get_tokens_unprocessed(self, text): |
|
2358 # check for reserved words and pervasives |
|
2359 if token is Name: |
|
2360 if value in self.reserved_words: |
|
2361 token = Keyword.Reserved |
|
2362 elif value in self.pervasives: |
|
2363 token = Keyword.Pervasive |
|
2364 # return result |
|
2365 yield index, token, value |