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

moonbitlang / x / 301

10 Dec 2024 06:19AM UTC coverage: 85.204% (-2.6%) from 87.841%
301

Pull #78

github

web-flow
Merge b830031f4 into 91f0fdf48
Pull Request #78: feat: new package encoding

105 of 161 new or added lines in 3 files covered. (65.22%)

124 existing lines in 29 files now uncovered.

1169 of 1372 relevant lines covered (85.2%)

434.92 hits per line

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

86.21
/json5/lex_main.mbt
1
// Copyright 2024 International Digital Economy Academy
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
///|
16
fn lex_value(
17
  ctx : ParseContext,
18
  allow_rbracket~ : Bool = false
19
) -> Token!ParseError {
20
  for {
133✔
21
    match read_char(ctx) {
134✔
UNCOV
22
      Some('\t' | '\u000B' | '\u000C' | ' ' | '\n' | '\r') => continue
×
23
      Some('/') => {
4✔
24
        lex_comment!(ctx)
25
        continue
1✔
26
      }
27
      Some('{') => return LBrace
25✔
28
      Some('[') => return LBracket
17✔
29
      Some(']') =>
30
        if allow_rbracket {
1✔
31
          return RBracket
1✔
32
        } else {
UNCOV
33
          invalid_char!(ctx, shift=-1)
×
34
        }
35
      Some('n') => {
1✔
36
        lex_assert_char!(ctx, 'u')
37
        lex_assert_char!(ctx, 'l')
1✔
38
        lex_assert_char!(ctx, 'l')
1✔
39
        return Null
1✔
40
      }
41
      Some('t') => {
2✔
42
        lex_assert_char!(ctx, 'r')
43
        lex_assert_char!(ctx, 'u')
2✔
44
        lex_assert_char!(ctx, 'e')
2✔
45
        return True
1✔
46
      }
47
      Some('f') => {
1✔
48
        lex_assert_char!(ctx, 'a')
49
        lex_assert_char!(ctx, 'l')
1✔
50
        lex_assert_char!(ctx, 's')
1✔
51
        lex_assert_char!(ctx, 'e')
1✔
52
        return False
1✔
53
      }
54
      Some('-' | '+' as c) =>
55
        match read_char(ctx) {
9✔
56
          Some('I') => {
1✔
57
            lex_infinity!(ctx)
58
            return Number(
1✔
59
              if c == '-' {
60
                @double.neg_infinity
1✔
61
              } else {
UNCOV
62
                @double.infinity
×
63
              },
64
            )
65
          }
66
          Some('N') => {
1✔
67
            lex_assert_char!(ctx, 'a')
68
            lex_assert_char!(ctx, 'N')
1✔
69
            return Number(@double.not_a_number)
1✔
70
          }
71
          Some('0') => {
2✔
72
            let n = lex_zero!(ctx, neg=c == '-', start=ctx.offset - 2)
73
            return Number(n)
2✔
74
          }
75
          Some('.') => {
1✔
76
            let n = lex_decimal_point_leading!(ctx, start=ctx.offset - 2)
77
            return Number(n)
1✔
78
          }
79
          Some(c2) => {
4✔
80
            if c2 >= '1' && c2 <= '9' {
81
              let n = lex_decimal_integer!(ctx, start=ctx.offset - 2)
3✔
82
              return Number(n)
3✔
83
            }
84
            invalid_char!(ctx, shift=-1)
85
          }
×
UNCOV
86
          None => parse_error!(InvalidEof)
×
87
        }
88
      Some('.') => {
3✔
89
        let n = lex_decimal_point_leading!(ctx, start=ctx.offset - 1)
90
        return Number(n)
2✔
91
      }
92
      Some('0') => {
9✔
93
        let n = lex_zero!(ctx, neg=false, start=ctx.offset - 1)
94
        return Number(n)
8✔
95
      }
96
      Some('1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9') => {
41✔
97
        let n = lex_decimal_integer!(ctx, start=ctx.offset - 1)
98
        return Number(n)
39✔
99
      }
100
      Some('I') => {
1✔
101
        lex_infinity!(ctx)
102
        return Number(@double.infinity)
1✔
103
      }
104
      Some('N') => {
1✔
105
        lex_assert_char!(ctx, 'a')
106
        lex_assert_char!(ctx, 'N')
1✔
107
        return Number(@double.not_a_number)
1✔
108
      }
109
      Some('"') => {
11✔
110
        let n = lex_string!(ctx, '"')
111
        return String(n)
3✔
112
      }
113
      Some('\'') => return String(lex_string!(ctx, '\''))
2✔
114
      Some(c) => {
2✔
115
        if c > '\x7f' && non_ascii_whitespace.contains(c) {
UNCOV
116
          continue
×
117
        }
118
        invalid_char!(ctx, shift=-1)
119
      }
×
UNCOV
120
      None => parse_error!(InvalidEof)
×
121
    }
122
  }
123
}
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

© 2025 Coveralls, Inc