• 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

85.0
/json5/parse.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
pub fn parse(input : String) -> @json.JsonValue!ParseError {
17
  let ctx = ParseContext::make(input)
74✔
18
  let val = parse_value!(ctx)
19
  lex_skip_whitespace!(ctx)
40✔
20
  if ctx.offset >= ctx.end_offset {
40✔
21
    val
39✔
22
  } else {
UNCOV
23
    invalid_char!(ctx)
×
24
  }
25
}
26

27
///|
28
fn parse_value(ctx : ParseContext) -> @json.JsonValue!ParseError {
29
  let tok = lex_value!(ctx)
92✔
30
  parse_value2!(ctx, tok)
57✔
31
}
32

33
///|
34
fn parse_value2(ctx : ParseContext, tok : Token) -> @json.JsonValue!ParseError {
35
  match tok {
109✔
36
    Null => Null
1✔
37
    True => True
1✔
38
    False => False
1✔
39
    Number(n) => Number(n)
59✔
40
    String(s) => String(s)
5✔
41
    LBrace => parse_object!(ctx)
15✔
42
    LBracket => parse_array!(ctx)
14✔
UNCOV
43
    _ => abort("unreachable")
×
44
  }
45
}
46

47
///|
48
fn parse_object(ctx : ParseContext) -> @json.JsonValue!ParseError {
49
  let map = Map::new()
25✔
50
  for {
51
    let tok = lex_property_name!(ctx)
30✔
52
    match tok {
25✔
53
      RBrace => break
5✔
54
      String(name) => {
20✔
55
        let tok2 = lex_after_property_name!(ctx)
56
        match tok2 {
18✔
57
          Colon => {
18✔
58
            let val = parse_value!(ctx)
59
            map.set(name, val)
17✔
60
            let tok3 = lex_after_object_value!(ctx)
61
            match tok3 {
15✔
62
              Comma => continue
5✔
63
              RBrace => break
10✔
UNCOV
64
              _ => abort("unreachable")
×
65
            }
66
          }
UNCOV
67
          _ => abort("unreachable")
×
68
        }
69
      }
UNCOV
70
      _ => abort("unreachable")
×
71
    }
72
  }
73
  Object(map)
74
}
75

76
///|
77
fn parse_array(ctx : ParseContext) -> @json.JsonValue!ParseError {
78
  let vec = []
17✔
79
  for {
80
    let tok = lex_value!(ctx, allow_rbracket=true)
41✔
81
    match tok {
40✔
82
      RBracket => break
1✔
83
      _ => {
39✔
84
        vec.push(parse_value2!(ctx, tok))
39✔
85
        let tok2 = lex_after_array_value!(ctx)
86
        match tok2 {
37✔
87
          Comma => continue
24✔
88
          RBracket => break
13✔
UNCOV
89
          _ => abort("unreachable")
×
90
        }
91
      }
92
    }
93
  }
94
  Array(vec)
95
}
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