Commits

pyos committed 60c705b

Update the dg lexer.

  • Participants
  • Parent commits 7304e47

Comments (0)

Files changed (2)

File pygments/lexers/agile.py

 
     tokens = {
         'root': [
-            # Whitespace:
             (r'\s+', Text),
             (r'#.*?$', Comment.Single),
-            # Lexemes:
-            #  Numbers
-            (r'0[bB][01]+', Number.Bin),
-            (r'0[oO][0-7]+', Number.Oct),
-            (r'0[xX][\da-fA-F]+', Number.Hex),
-            (r'[+-]?\d+\.\d+([eE][+-]?\d+)?[jJ]?', Number.Float),
-            (r'[+-]?\d+[eE][+-]?\d+[jJ]?', Number.Float),
-            (r'[+-]?\d+[jJ]?', Number.Integer),
-            #  Character/String Literals
-            (r"[br]*'''", String, combined('stringescape', 'tsqs', 'string')),
-            (r'[br]*"""', String, combined('stringescape', 'tdqs', 'string')),
-            (r"[br]*'", String, combined('stringescape', 'sqs', 'string')),
-            (r'[br]*"', String, combined('stringescape', 'dqs', 'string')),
-            #  Operators
-            (r"`\w+'*`", Operator), # Infix links
-            #   Reserved infix links
-            (r'\b(or|and|if|else|where|is|in)\b', Operator.Word),
+
+            (r'(?i)0b[01]+', Number.Bin),
+            (r'(?i)0o[0-7]+', Number.Oct),
+            (r'(?i)0x[0-9a-f]+', Number.Hex),
+            (r'(?i)[+-]?[0-9]+\.[0-9]+(e[+-]?[0-9]+)?j?', Number.Float),
+            (r'(?i)[+-]?[0-9]+e[+-]?\d+j?', Number.Float),
+            (r'(?i)[+-]?[0-9]+j?', Number.Integer),
+
+            (r"(?i)(br|r?b?)'''", String, combined('stringescape', 'tsqs', 'string')),
+            (r'(?i)(br|r?b?)*"""', String, combined('stringescape', 'tdqs', 'string')),
+            (r"(?i)(br|r?b?)*'", String, combined('stringescape', 'sqs', 'string')),
+            (r'(?i)(br|r?b?)*"', String, combined('stringescape', 'dqs', 'string')),
+
+            (r"`\w+'*`", Operator),
+            (r'\b(and|in|is|or|where)\b', Operator.Word),
             (r'[!$%&*+\-./:<-@\\^|~;,]+', Operator),
-            #  Identifiers
-            #   Python 3 types
+
             (r"(?<!\.)(bool|bytearray|bytes|classmethod|complex|dict'?|"
              r"float|frozenset|int|list'?|memoryview|object|property|range|"
              r"set'?|slice|staticmethod|str|super|tuple'?|type)"
              r"(?!['\w])", Name.Builtin),
-            #   Python 3 builtins + some more
             (r'(?<!\.)(__import__|abs|all|any|bin|bind|chr|cmp|compile|complex|'
-             r'delattr|dir|divmod|drop|dropwhile|enumerate|eval|filter|flip|'
-             r'foldl1?|format|fst|getattr|globals|hasattr|hash|head|hex|id|'
-             r'init|input|isinstance|issubclass|iter|iterate|last|len|locals|'
-             r'map|max|min|next|oct|open|ord|pow|print|repr|reversed|round|'
-             r'setattr|scanl1?|snd|sorted|sum|tail|take|takewhile|vars|zip)'
-             r"(?!['\w])", Name.Builtin),
+             r'delattr|dir|divmod|drop|dropwhile|enumerate|eval|exhaust|'
+             r'filter|flip|foldl1?|format|fst|getattr|globals|hasattr|hash|'
+             r'head|hex|id|init|input|isinstance|issubclass|iter|iterate|last|'
+             r'len|locals|map|max|min|next|oct|open|ord|pow|print|repr|'
+             r'reversed|round|setattr|scanl1?|snd|sorted|sum|tail|take|'
+             r"takewhile|vars|zip)(?!['\w])", Name.Builtin),
             (r"(?<!\.)(self|Ellipsis|NotImplemented|None|True|False)(?!['\w])",
              Name.Builtin.Pseudo),
+
             (r"(?<!\.)[A-Z]\w*(Error|Exception|Warning)'*(?!['\w])",
              Name.Exception),
-            (r"(?<!\.)(KeyboardInterrupt|SystemExit|StopIteration|"
-             r"GeneratorExit)(?!['\w])", Name.Exception),
-            #   Compiler-defined identifiers
-            (r"(?<![\.\w])(import|inherit|for|while|switch|not|raise|unsafe|"
-             r"yield|with)(?!['\w])", Keyword.Reserved),
-            #   Other links
-            (r"[A-Z_']+\b", Name),
-            (r"[A-Z][\w']*\b", Keyword.Type),
+            (r"(?<!\.)(Exception|GeneratorExit|KeyboardInterrupt|StopIteration|"
+             r"SystemExit)(?!['\w])", Name.Exception),
+
+            (r"(?<![\.\w])(except|finally|for|if|import|not|otherwise|raise|"
+             r"subclass|while|with|yield)(?!['\w])", Keyword.Reserved),
+
+            (r"[A-Z_]+'*\b", Name),
+            (r"[A-Z]\w+'*\b", Keyword.Type),
             (r"\w+'*", Name),
-            #  Blocks
+
             (r'[()]', Punctuation),
+            (r'.', Error),
         ],
         'stringescape': [
             (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'

File tests/examplefiles/inet_pton6.dg

-re  = import!
-sys = import!
+import '/re'
+import '/sys'
 
 
 # IPv6address    =  hexpart [ ":" IPv4address ]
 #
 # :return: a decimal integer
 #
-base_n = (q digits) -> foldl (x y) -> (x * q + y) 0 digits
+base_n = q digits -> foldl (x y -> x * q + y) 0 digits
 
 
 # Parse a sequence of hexadecimal numbers
 #
 # :return: an iterable of Python ints
 #
-unhex = q -> q and map p -> (int p 16) (q.split ':')
+unhex = q -> q and map (p -> int p 16) (q.split ':')
 
 
 # Parse an IPv6 address as specified in RFC 4291.
 # :return: an integer which, written in binary form, points to the same node.
 #
 inet_pton6 = address ->
-  raise $ ValueError 'not a valid IPv6 address' if not (match = addrv6.match address)
+  not (match = addrv6.match address) => raise $ ValueError 'not a valid IPv6 address'
   start, end, *ipv4 = match.groups!
 
   is_ipv4 = not $ None in ipv4
   shift   = (7 - start.count ':' - 2 * is_ipv4) * 16
 
-  raise $ ValueError 'not a valid IPv6 address' if (end is None and shift) or shift < 0
+  (end is None and shift) or shift < 0 => raise $ ValueError 'not a valid IPv6 address'
   hexaddr = (base_n 0x10000 (unhex start) << shift) + base_n 0x10000 (unhex $ end or '')
-  (hexaddr << 32) + base_n 0x100 (map int ipv4) if is_ipv4 else hexaddr
+  if (is_ipv4 => (hexaddr << 32) + base_n 0x100 (map int ipv4)) (otherwise => hexaddr)
 
 
-inet6_type = q -> switch
-  not q = 'unspecified'
-  q == 1 = 'loopback'
-  (q >>  32)              == 0x000000000000ffff = 'IPv4-mapped'
-  (q >>  64)              == 0xfe80000000000000 = 'link-local'
-  (q >> 120)              != 0x00000000000000ff = 'general unicast'
-  (q >> 112) % (1 << 4)   == 0x0000000000000000 = 'multicast w/ reserved scope value'
-  (q >> 112) % (1 << 4)   == 0x000000000000000f = 'multicast w/ reserved scope value'
-  (q >> 112) % (1 << 4)   == 0x0000000000000001 = 'interface-local multicast'
-  (q >> 112) % (1 << 4)   == 0x0000000000000004 = 'admin-local multicast'
-  (q >> 112) % (1 << 4)   == 0x0000000000000005 = 'site-local multicast'
-  (q >> 112) % (1 << 4)   == 0x0000000000000008 = 'organization-local multicast'
-  (q >> 112) % (1 << 4)   == 0x000000000000000e = 'global multicast'
-  (q >> 112) % (1 << 4)   != 0x0000000000000002 = 'multicast w/ unknown scope value'
-  (q >>  24) % (1 << 112) == 0x00000000000001ff = 'solicited-node multicast'
-  True = 'link-local multicast'
+inet6_type = q -> if
+  q == 0 => 'unspecified'
+  q == 1 => 'loopback'
+  (q >>  32)              == 0x000000000000ffff => 'IPv4-mapped'
+  (q >>  64)              == 0xfe80000000000000 => 'link-local'
+  (q >> 120)              != 0x00000000000000ff => 'general unicast'
+  (q >> 112) % (1 << 4)   == 0x0000000000000000 => 'multicast w/ reserved scope value'
+  (q >> 112) % (1 << 4)   == 0x000000000000000f => 'multicast w/ reserved scope value'
+  (q >> 112) % (1 << 4)   == 0x0000000000000001 => 'interface-local multicast'
+  (q >> 112) % (1 << 4)   == 0x0000000000000004 => 'admin-local multicast'
+  (q >> 112) % (1 << 4)   == 0x0000000000000005 => 'site-local multicast'
+  (q >> 112) % (1 << 4)   == 0x0000000000000008 => 'organization-local multicast'
+  (q >> 112) % (1 << 4)   == 0x000000000000000e => 'global multicast'
+  (q >> 112) % (1 << 4)   != 0x0000000000000002 => 'multicast w/ unknown scope value'
+  (q >>  24) % (1 << 112) == 0x00000000000001ff => 'solicited-node multicast'
+  otherwise => 'link-local multicast'
 
 
-print $ (x -> (inet6_type x, hex x)) $ inet_pton6 $ sys.stdin.read!.strip!
+print $ (x -> inet6_type x, hex x) $ inet_pton6 $ sys.stdin.read!.strip!