• 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

84.85
/json5/lex_prop.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_property_name(ctx : ParseContext) -> Token!ParseError {
17
  lex_skip_whitespace!(ctx)
30✔
18
  match read_char(ctx) {
30✔
19
    Some('}') => RBrace
5✔
20
    Some('\'' | '"' as c) => {
2✔
21
      let s = lex_string!(ctx, c)
22
      String(s)
2✔
23
    }
24
    Some('$' | '_') => {
2✔
25
      let s = lex_ident!(ctx, ctx.offset - 1)
26
      String(s)
2✔
27
    }
28
    Some('\\') => {
4✔
29
      lex_assert_char!(ctx, 'u')
30
      let c = lex_hex_digits!(ctx, 4)
3✔
31
      let c = Char::from_int(c)
3✔
32
      if c == '$' ||
33
        c == '_' ||
34
        (c >= 'a' && c <= 'z') ||
35
        (c >= 'A' && c <= 'Z') ||
36
        (c > '\x7f' && non_ascii_id_start.contains(c)) {
37
        let buffer = StringBuilder::make()
3✔
38
        buffer.add_char(c)
39
        let s = lex_ident!(ctx, ctx.offset, buffer~)
40
        String(s)
3✔
41
      } else {
UNCOV
42
        parse_error!(
×
43
          InvalidIdentEscape(offset_to_position(ctx.input, ctx.offset - 6)),
UNCOV
44
        )
×
45
      }
46
    }
47
    Some(c) => {
16✔
48
      if (c >= 'a' && c <= 'z') ||
49
        (c >= 'A' && c <= 'Z') ||
50
        (c > '\x7f' && non_ascii_id_start.contains(c)) {
51
        let s = lex_ident!(ctx, ctx.offset - 1)
15✔
52
        return String(s)
13✔
53
      }
54
      invalid_char!(ctx, shift=-1)
55
    }
×
UNCOV
56
    None => parse_error!(InvalidEof)
×
57
  }
58
}
59

60
///|
61
fn lex_ident(
62
  ctx : ParseContext,
63
  start : Int,
64
  buffer~ : StringBuilder = StringBuilder::make()
65
) -> String!ParseError {
66
  let mut start = start
20✔
67
  fn flush(end : Int) {
68
    if start > 0 && end > start {
23✔
69
      buffer.add_substring(ctx.input, start, end)
17✔
70
    }
71
  }
72

73
  for {
74
    match read_char(ctx) {
36✔
75
      Some('\\') => {
5✔
76
        flush(ctx.offset - 1)
77
        lex_assert_char!(ctx, 'u')
78
        let c = lex_hex_digits!(ctx, 4)
4✔
79
        let c = Char::from_int(c)
4✔
80
        if c == '$' ||
81
          c == '_' ||
82
          (c >= 'a' && c <= 'z') ||
83
          (c >= 'A' && c <= 'Z') ||
84
          (c >= '0' && c <= '9') ||
85
          (c > '\x7f' && non_ascii_id_continue.contains(c)) {
86
          buffer.add_char(c)
3✔
87
          start = ctx.offset
88
          continue
89
        } else {
90
          parse_error!(
1✔
91
            InvalidIdentEscape(offset_to_position(ctx.input, ctx.offset - 6)),
UNCOV
92
          )
×
93
        }
94
      }
95
      Some('$' | '_') => continue
2✔
96
      Some(c) => {
28✔
97
        if (c >= 'a' && c <= 'z') ||
98
          (c >= 'A' && c <= 'Z') ||
99
          (c >= '0' && c <= '9') ||
100
          (c > '\x7f' && non_ascii_id_continue.contains(c)) {
101
          continue
11✔
102
        }
103
        ctx.offset -= 1
104
        break
105
      }
106
      None => break
1✔
107
    }
108
  }
109
  flush(ctx.offset)
110
  buffer.to_string()
111
}
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