• 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

75.0
/json5/lex_misc.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 read_char(ctx : ParseContext) -> Char? {
17
  if ctx.offset < ctx.end_offset {
780✔
18
    let c = ctx.input[ctx.offset]
715✔
19
    ctx.offset += 1
20
    let c1 = c.to_int()
21
    if c1 >= 0xD800 && c1 <= 0xDBFF {
22
      if ctx.offset < ctx.end_offset {
×
UNCOV
23
        let c2 = ctx.input[ctx.offset].to_int()
×
24
        if c2 >= 0xDC00 && c2 <= 0xDFFF {
UNCOV
25
          ctx.offset += 1
×
26
          let c3 = (c1 << 10) + c2 - 0x35fdc00
27
          return Some(Char::from_int(c3))
28
        }
29
      }
30
    }
31
    Some(c)
32
  } else {
33
    None
65✔
34
  }
35
}
36

37
///|
38
fn lex_skip_whitespace(ctx : ParseContext) -> Unit!ParseError {
39
  for {
146✔
40
    match read_char(ctx) {
162✔
41
      Some('\t' | '\u000B' | '\u000C' | ' ' | '\n' | '\r') => continue
8✔
42
      Some('/') => {
3✔
43
        lex_comment!(ctx)
44
        continue
3✔
45
      }
46
      Some(c) => {
108✔
47
        if c > '\x7f' && non_ascii_whitespace.contains(c) {
48
          continue
5✔
49
        }
50
        ctx.offset -= 1
51
        return ()
52
      }
53
      None => return ()
43✔
54
    }
55
  }
56
}
57

58
///|
59
fn lex_after_array_value(ctx : ParseContext) -> Token!ParseError {
60
  lex_skip_whitespace!(ctx)
39✔
61
  match read_char(ctx) {
39✔
62
    Some(']') => Token::RBracket
13✔
63
    Some(',') => Token::Comma
24✔
UNCOV
64
    Some(_) => invalid_char!(ctx, shift=-1)
×
UNCOV
65
    None => parse_error!(InvalidEof)
×
66
  }
67
}
68

69
///|
70
fn lex_after_property_name(ctx : ParseContext) -> Token!ParseError {
71
  lex_skip_whitespace!(ctx)
20✔
72
  match read_char(ctx) {
20✔
73
    Some(':') => Token::Colon
18✔
UNCOV
74
    Some(_) => invalid_char!(ctx, shift=-1)
×
UNCOV
75
    None => parse_error!(InvalidEof)
×
76
  }
77
}
78

79
///|
80
fn lex_after_object_value(ctx : ParseContext) -> Token!ParseError {
81
  lex_skip_whitespace!(ctx)
17✔
82
  match read_char(ctx) {
17✔
83
    Some('}') => Token::RBrace
10✔
84
    Some(',') => Token::Comma
5✔
UNCOV
85
    Some(_) => invalid_char!(ctx, shift=-1)
×
UNCOV
86
    None => parse_error!(InvalidEof)
×
87
  }
88
}
89

90
///|
91
fn lex_assert_char(ctx : ParseContext, c : Char) -> Unit!ParseError {
92
  match read_char(ctx) {
40✔
UNCOV
93
    Some(c2) => if c == c2 { () } else { invalid_char!(ctx, shift=-1) }
×
UNCOV
94
    None => parse_error!(InvalidEof)
×
95
  }
96
}
97

98
///|
99
fn lex_infinity(ctx : ParseContext) -> Unit!ParseError {
100
  lex_assert_char!(ctx, 'n')
2✔
101
  lex_assert_char!(ctx, 'f')
2✔
102
  lex_assert_char!(ctx, 'i')
2✔
103
  lex_assert_char!(ctx, 'n')
2✔
104
  lex_assert_char!(ctx, 'i')
2✔
105
  lex_assert_char!(ctx, 't')
2✔
106
  lex_assert_char!(ctx, 'y')
2✔
107
}
108

109
///|
110
fn lex_comment(ctx : ParseContext) -> Unit!ParseError {
111
  match read_char(ctx) {
7✔
112
    Some('/') =>
113
      for {
3✔
114
        match read_char(ctx) {
18✔
115
          Some('\n' | '\r' | '\u2028' | '\u2029') => {
1✔
116
            ctx.offset -= 1
117
            return ()
118
          }
119
          None => return ()
2✔
120
          _ => ()
15✔
121
        }
122
      }
123
    Some('*') =>
124
      for {
3✔
125
        match read_char(ctx) {
14✔
126
          Some('*') =>
127
            match read_char(ctx) {
3✔
128
              Some('/') => return ()
1✔
129
              _ => ()
2✔
130
            }
UNCOV
131
          None => parse_error!(InvalidEof)
×
132
          _ => ()
9✔
133
        }
134
      }
UNCOV
135
    Some(_) => invalid_char!(ctx, shift=-1)
×
UNCOV
136
    None => parse_error!(InvalidEof)
×
137
  }
138
}
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