Skip to content

Commit 781a1bb

Browse files
committed
align with new moonbit release
1 parent b2d7602 commit 781a1bb

File tree

31 files changed

+2869
-2772
lines changed

31 files changed

+2869
-2772
lines changed

boot/moonyacc.js

Lines changed: 2657 additions & 2554 deletions
Large diffs are not rendered by default.

moon.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "moonbitlang/yacc",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"deps": {
55
"moonbitlang/x": "0.4.23",
66
"Yoorkin/ArgParser": "0.1.9",

src/lib/codegen/gen_mbt/gen_mbt.mbt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,9 +1098,9 @@ fn codegen(
10981098
$| yy_parse(
10991099
$| tokens,
11001100
$| yy_state_\{start_state.num},
1101-
$| fn {
1102-
$| YYObj_\{derive_type_ident(nonterminal_meta(name).data_type)}(result) => result
1103-
$| _ => panic()
1101+
$| (it) => {
1102+
$| guard it is YYObj_\{derive_type_ident(nonterminal_meta(name).data_type)}(result)
1103+
$| result
11041104
$| },
11051105
$| initial_pos?,
11061106
$| )
@@ -1115,9 +1115,9 @@ fn codegen(
11151115
$| read_token,
11161116
$| start_pos,
11171117
$| yy_state_\{start_state.num},
1118-
$| fn {
1119-
$| YYObj_\{derive_type_ident(nonterminal_meta(name).data_type)}(result) => result
1120-
$| _ => panic()
1118+
$| (it) => {
1119+
$| guard it is YYObj_\{derive_type_ident(nonterminal_meta(name).data_type)}(result)
1120+
$| result
11211121
$| },
11221122
$| )
11231123
$|}
@@ -1159,9 +1159,9 @@ fn codegen(
11591159
output.write_string(
11601160
$|
11611161
$|fn args_to_json(args : ArrayView[(YYObj, \{meta.position_data_type}, \{meta.position_data_type})]) -> Json {
1162-
$| Json::array(args.iter().map(fn {
1163-
$| (YYObj_Json(json), _, _) => json
1164-
$| _ => panic()
1162+
$| Json::array(args.iter().map((it) => {
1163+
$| guard it.0 is YYObj_Json(json)
1164+
$| json
11651165
$| }).to_array())
11661166
$|}
11671167
$|

src/lib/desugar/eliminate_inline.mbt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ fn find_leaf_inline_rules(rules : Map[String, @elab.Rule]) -> Set[String] {
99
Set::from_iter(
1010
all_inline_rules
1111
.iter()
12-
.filter(fn {
13-
(_, rule) =>
14-
rule.clauses
12+
.filter(it => {
13+
let (_, rule) = it
14+
rule.clauses
15+
.iter()
16+
.all(fn(clause) {
17+
clause.items
1518
.iter()
16-
.all(fn(clause) {
17-
clause.items
18-
.iter()
19-
.all(fn(item) {
20-
match item.term {
21-
Token(_) => true
22-
RuleCall(rule_name, [], _type) =>
23-
not(all_inline_rules.contains(rule_name))
24-
Param(_) | RuleCall(_, _, _) => panic()
25-
}
26-
})
19+
.all(fn(item) {
20+
match item.term {
21+
Token(_) => true
22+
RuleCall(rule_name, [], _type) =>
23+
not(all_inline_rules.contains(rule_name))
24+
Param(_) | RuleCall(_, _, _) => panic()
25+
}
2726
})
27+
})
2828
})
29-
.map(fn { (rule_name, _) => rule_name }),
29+
.map(it => it.0),
3030
)
3131
}
3232

src/lib/elab/east.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub(all) struct Clause {
104104
}
105105

106106
// (code, (utf8_pos, utf8_len)?)
107+
107108
///|
108109
pub typealias (String, (Int, Int)?) as CodeChunk
109110

src/lib/elab/elaborate.mbt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ pub fn elaborate(
307307
let rule_param_map : Map[String, TypeExpr] = Map::from_array(rule.params)
308308
let ast_clause_iter = ast_rule.clauses
309309
.iter()
310-
.flat_map(fn {
311-
(clauses, action) => clauses.iter().map(fn(it) { (it, action) })
310+
.flat_map(it => {
311+
let (clauses, action) = it
312+
clauses.iter().map(fn(it) { (it, action) })
312313
})
313314
let mut clause_index = 0
314315
for ast_clause in ast_clause_iter {
@@ -369,7 +370,7 @@ pub fn elaborate(
369370
position_type = parse_and_elaborate_type_expr(type_)
370371
}
371372
Derive(traits~, type_~) => {
372-
let traits = traits.split(",").map(fn { t => t.trim(" ").to_string() })
373+
let traits = traits.split(",").map(t => t.trim(" ").to_string())
373374
for trait_ in traits {
374375
derive_map.add(type_, parse_and_elaborate_type_expr(trait_))
375376
}

src/lib/grm/builder.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn build(f : (BuilderContext) -> Unit) -> Grammar {
109109
productions.push(production)
110110
for symbol in production.rhs {
111111
match symbol {
112-
T(t) => last_prec = t.prec.map(fn { (level, _) => level })
112+
T(t) => last_prec = t.prec.map(it => it.0)
113113
NT(_) => ()
114114
}
115115
}

src/lib/lr1/automaton.mbt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub fn Automaton::build(grammar : @grm.Grammar, user_eoi~ : Bool) -> Automaton {
278278
starts.push((start_production, start_state))
279279
queue.push(start_state)
280280
}
281-
fn examine(candidate : LR1PreState) -> Unit {
281+
letrec examine = fn(candidate : LR1PreState) -> Unit {
282282
let family = families[candidate.items.core.num]
283283
for state in family {
284284
if candidate.items.subsume(state.items) {
@@ -287,8 +287,7 @@ pub fn Automaton::build(grammar : @grm.Grammar, user_eoi~ : Bool) -> Automaton {
287287
}
288288
fuse(family, candidate)
289289
}
290-
291-
fn fuse(family : Array[LR1PreState], candidate : LR1PreState) -> Unit {
290+
and fuse = fn(family : Array[LR1PreState], candidate : LR1PreState) -> Unit {
292291
for state in family {
293292
if state.items.weak_compat(candidate.items) &&
294293
(if user_eoi { state.items.eoi_compact(candidate.items) } else { true }) {

src/lib/lr1/closure.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// Copyright Inria. All rights reserved. This file is distributed under
2020
// the terms of the GNU General Public License version 2, as described in
2121
// the file LICENSE.
22+
2223
///|
2324
priv struct Node[LookaheadSet] {
2425
item : EncodedLR0Item
@@ -71,7 +72,7 @@ pub fn[LookaheadSet : AbstractLookaheadSet] build_closure_fn(
7172
fn(item_set) {
7273
let stamp = @stamp.new()
7374
let nodes = []
74-
fn visit(
75+
letrec visit = fn(
7576
node : Node[LookaheadSet],
7677
lookahead_set : EpsilonLookaheadSet[LookaheadSet],
7778
parent : Node[LookaheadSet]
@@ -86,8 +87,7 @@ pub fn[LookaheadSet : AbstractLookaheadSet] build_closure_fn(
8687
follow(node)
8788
}
8889
}
89-
90-
fn follow(node : Node[LookaheadSet]) -> Unit {
90+
and follow = fn(node : Node[LookaheadSet]) -> Unit {
9191
node.stamp = stamp
9292
nodes.push(node)
9393
for epsilon_transition in node.epsilon_transitions {

src/lib/lr1/encoded_lookahead_set.mbt

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,26 @@
1717
/// 1..<1024: Terminal number + 1
1818
priv type EncodedLookaheadSet @small_int_set.T derive(Eq, Compare, Hash)
1919

20-
///|
21-
fn EncodedLookaheadSet::is_empty(self : EncodedLookaheadSet) -> Bool {
22-
self._.is_empty()
23-
}
24-
2520
///|
2621
fn EncodedLookaheadSet::is_singleton(
2722
self : EncodedLookaheadSet,
2823
key : Lookahead
2924
) -> Bool {
30-
self._.is_singleton(
25+
self
26+
.inner()
27+
.is_singleton(
3128
match key {
3229
EndOfInput => 0
3330
Input(key) => key.num + 1
3431
},
3532
)
3633
}
3734

38-
///|
39-
fn EncodedLookaheadSet::contains(
40-
self : EncodedLookaheadSet,
41-
lookahead : Lookahead
42-
) -> Bool {
43-
match lookahead {
44-
Input(t) => self._.contains(t.num + 1)
45-
EndOfInput => self._.contains(0)
46-
}
47-
}
48-
4935
///|
5036
fn EncodedLookaheadSet::empty() -> EncodedLookaheadSet {
5137
@small_int_set.empty()
5238
}
5339

54-
///|
55-
fn EncodedLookaheadSet::default() -> EncodedLookaheadSet {
56-
EncodedLookaheadSet::empty()
57-
}
58-
59-
///|
60-
fn EncodedLookaheadSet::from_iter(
61-
iter : Iter[Lookahead]
62-
) -> EncodedLookaheadSet {
63-
@small_int_set.from_iter(
64-
iter.map(fn(lookahead) {
65-
match lookahead {
66-
Input(t) => t.num + 1
67-
EndOfInput => 0
68-
}
69-
}),
70-
)
71-
}
72-
7340
///|
7441
fn EncodedLookaheadSet::terminal(t : @grm.Terminal) -> EncodedLookaheadSet {
7542
@small_int_set.singleton(t.num + 1)
@@ -93,7 +60,8 @@ fn EncodedLookaheadSet::decode_iter(
9360
self : EncodedLookaheadSet,
9461
grammar : @grm.Grammar
9562
) -> Iter[Lookahead] {
96-
self._
63+
self
64+
.inner()
9765
.iter()
9866
.map(fn(t) {
9967
if t == 0 {
@@ -109,21 +77,21 @@ fn EncodedLookaheadSet::union(
10977
self : EncodedLookaheadSet,
11078
other : EncodedLookaheadSet
11179
) -> EncodedLookaheadSet {
112-
self._.union(other._)
80+
self.inner().union(other.inner())
11381
}
11482

11583
///|
11684
fn EncodedLookaheadSet::disjoint(
11785
self : EncodedLookaheadSet,
11886
other : EncodedLookaheadSet
11987
) -> Bool {
120-
self._.disjoint(other._)
88+
self.inner().disjoint(other.inner())
12189
}
12290

12391
///|
12492
fn EncodedLookaheadSet::subset(
12593
self : EncodedLookaheadSet,
12694
other : EncodedLookaheadSet
12795
) -> Bool {
128-
self._.subset(other._)
96+
self.inner().subset(other.inner())
12997
}

0 commit comments

Comments
 (0)