File: errors.py

package info (click to toggle)
mozjs128 128.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,132,528 kB
  • sloc: javascript: 2,181,430; cpp: 1,371,420; python: 776,651; ansic: 641,398; xml: 117,736; sh: 17,537; asm: 13,468; makefile: 11,191; yacc: 4,504; perl: 2,221; lex: 1,414; ruby: 1,032; exp: 756; java: 185; sql: 66; sed: 18
file content (70 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from typing import Tuple, Union


class ParseError(Exception):
    def __init__(self, code: str, *args: Union[str, None]):
        self.code = code
        self.args = args
        self.message = get_error_message(code, args)


def get_error_message(code: str, args: Tuple[Union[str, None], ...]) -> str:
    if code == 'E00001':
        return 'Generic error'
    if code == 'E0002':
        return 'Expected an entry start'
    if code == 'E0003':
        return 'Expected token: "{}"'.format(args[0])
    if code == 'E0004':
        return 'Expected a character from range: "{}"'.format(args[0])
    if code == 'E0005':
        msg = 'Expected message "{}" to have a value or attributes'
        return msg.format(args[0])
    if code == 'E0006':
        msg = 'Expected term "-{}" to have a value'
        return msg.format(args[0])
    if code == 'E0007':
        return 'Keyword cannot end with a whitespace'
    if code == 'E0008':
        return 'The callee has to be an upper-case identifier or a term'
    if code == 'E0009':
        return 'The argument name has to be a simple identifier'
    if code == 'E0010':
        return 'Expected one of the variants to be marked as default (*)'
    if code == 'E0011':
        return 'Expected at least one variant after "->"'
    if code == 'E0012':
        return 'Expected value'
    if code == 'E0013':
        return 'Expected variant key'
    if code == 'E0014':
        return 'Expected literal'
    if code == 'E0015':
        return 'Only one variant can be marked as default (*)'
    if code == 'E0016':
        return 'Message references cannot be used as selectors'
    if code == 'E0017':
        return 'Terms cannot be used as selectors'
    if code == 'E0018':
        return 'Attributes of messages cannot be used as selectors'
    if code == 'E0019':
        return 'Attributes of terms cannot be used as placeables'
    if code == 'E0020':
        return 'Unterminated string expression'
    if code == 'E0021':
        return 'Positional arguments must not follow named arguments'
    if code == 'E0022':
        return 'Named arguments must be unique'
    if code == 'E0024':
        return 'Cannot access variants of a message.'
    if code == 'E0025':
        return 'Unknown escape sequence: \\{}.'.format(args[0])
    if code == 'E0026':
        return 'Invalid Unicode escape sequence: {}.'.format(args[0])
    if code == 'E0027':
        return 'Unbalanced closing brace in TextElement.'
    if code == 'E0028':
        return 'Expected an inline expression'
    if code == 'E0029':
        return 'Expected simple expression as selector'
    return code