• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SPF-OST / trnsys-dck-parser / 8924936794

02 May 2024 01:45PM UTC coverage: 0.0%. First build
8924936794

Pull #1

github

web-flow
Merge 16fd89c64 into add13752b
Pull Request #1: Expressions

0 of 401 new or added lines in 9 files covered. (0.0%)

0 of 401 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/trnsys_dck_parser/parse/equations.py
NEW
1
import typing as _tp
×
NEW
2
import re as _re
×
3

NEW
4
import trnsys_dck_parser.model.equations as _meqs
×
NEW
5
import trnsys_dck_parser.model.expression as _mexp
×
NEW
6
import trnsys_dck_parser.parse.common as _pcom
×
NEW
7
import trnsys_dck_parser.parse.tokens as _ptok
×
NEW
8
import trnsys_dck_parser.parse.expression.parse as _pexp
×
9

10

NEW
11
class Tokens:
×
NEW
12
    EQUATIONS = _pcom.TokenDefinition("EQUATIONS", r"EQUATIONS", _re.RegexFlag.IGNORECASE)
×
NEW
13
    POSITIVE_INTEGER = _pcom.TokenDefinition("positive integer", _ptok.Regexes.POSITIVE_INTEGER)
×
NEW
14
    EQUALS = _pcom.TokenDefinition("=", r"=")
×
15

16

NEW
17
class Parser(_pcom.ParserBase[_meqs.Equations]):
×
NEW
18
    def __init__(self, input_string: str) -> None:
×
NEW
19
        lexer = _pcom.Lexer(
×
20
            input_string, [Tokens.EQUATIONS, Tokens.POSITIVE_INTEGER, Tokens.EQUALS, _ptok.Tokens.IDENTIFIER]
21
        )
NEW
22
        super().__init__(lexer)
×
23

NEW
24
    def parse(self) -> _pcom.ParseResult[_meqs.Equations]:
×
NEW
25
        try:
×
NEW
26
            equations = self._equations()
×
NEW
27
            return _pcom.ParseSuccess(equations, self._remaining_input_string_start_index)
×
NEW
28
        except _pcom.ParseErrorException as exception:
×
NEW
29
            return exception.parse_error
×
30

NEW
31
    def _equations(self) -> _meqs.Equations:
×
NEW
32
        self._expect(Tokens.EQUATIONS)
×
33

NEW
34
        n_equations_value = self._expect(Tokens.POSITIVE_INTEGER)
×
NEW
35
        n_equations = None if n_equations_value is None else int(n_equations_value)
×
36

NEW
37
        equations = [self._equation()]
×
NEW
38
        while True:
×
NEW
39
            try:
×
NEW
40
                equations.append(self._equation())
×
NEW
41
            except _pcom.ParseErrorException:
×
NEW
42
                break
×
43

NEW
44
        return _meqs.Equations(n_equations, equations)
×
45

NEW
46
    def _equation(self) -> _meqs.Equation:
×
NEW
47
        variable_name = self._expect(_ptok.Tokens.IDENTIFIER)
×
NEW
48
        self._expect(Tokens.EQUALS)
×
NEW
49
        expression = self._expression()
×
NEW
50
        equation = _meqs.Equation(variable_name, expression)
×
NEW
51
        return equation
×
52

NEW
53
    def _expression(self) -> _mexp.Expression:
×
NEW
54
        parser = _pexp.Parser(self._remaining_input_string)
×
NEW
55
        return self._expect_sub_parser(parser)
×
56

57

NEW
58
def parse_equations(input_string: str) -> _pcom.ParseResult[_meqs.Equations]:
×
NEW
59
    parser = Parser(input_string)
×
NEW
60
    return parser.parse()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc