Debian Codegraph @

third_party/python/fluent.syntax/fluent/syntax/errors.py

raw
1 from typing import Tuple, Union
2
3
4 class ParseError(Exception):
5 def __init__(self, code: str, *args: Union[str, None]):
6 self.code = code
7 self.args = args
8 self.message = get_error_message(code, args)
9
10
11 def get_error_message(code: str, args: Tuple[Union[str, None], ...]) -> str:
12 if code == 'E00001':
13 return 'Generic error'
14 if code == 'E0002':
15 return 'Expected an entry start'
16 if code == 'E0003':
17 return 'Expected token: "{}"'.format(args[0])
18 if code == 'E0004':
19 return 'Expected a character from range: "{}"'.format(args[0])
20 if code == 'E0005':
21 msg = 'Expected message "{}" to have a value or attributes'
22 return msg.format(args[0])
23 if code == 'E0006':
24 msg = 'Expected term "-{}" to have a value'
25 return msg.format(args[0])
26 if code == 'E0007':
27 return 'Keyword cannot end with a whitespace'
28 if code == 'E0008':
29 return 'The callee has to be an upper-case identifier or a term'
30 if code == 'E0009':
31 return 'The argument name has to be a simple identifier'
32 if code == 'E0010':
33 return 'Expected one of the variants to be marked as default (*)'
34 if code == 'E0011':
35 return 'Expected at least one variant after "->"'
36 if code == 'E0012':
37 return 'Expected value'
38 if code == 'E0013':
39 return 'Expected variant key'
40 if code == 'E0014':
41 return 'Expected literal'
42 if code == 'E0015':
43 return 'Only one variant can be marked as default (*)'
44 if code == 'E0016':
45 return 'Message references cannot be used as selectors'
46 if code == 'E0017':
47 return 'Terms cannot be used as selectors'
48 if code == 'E0018':
49 return 'Attributes of messages cannot be used as selectors'
50 if code == 'E0019':
51 return 'Attributes of terms cannot be used as placeables'
52 if code == 'E0020':
53 return 'Unterminated string expression'
54 if code == 'E0021':
55 return 'Positional arguments must not follow named arguments'
56 if code == 'E0022':
57 return 'Named arguments must be unique'
58 if code == 'E0024':
59 return 'Cannot access variants of a message.'
60 if code == 'E0025':
61 return 'Unknown escape sequence: \\{}.'.format(args[0])
62 if code == 'E0026':
63 return 'Invalid Unicode escape sequence: {}.'.format(args[0])
64 if code == 'E0027':
65 return 'Unbalanced closing brace in TextElement.'
66 if code == 'E0028':
67 return 'Expected an inline expression'
68 if code == 'E0029':
69 return 'Expected simple expression as selector'
70 return code