1///|
2enum Prec {
3 Prec
NonAssoc
4 Prec
Left
5 Prec
Right
6 Prec
Dynamic
7} derive((Prec, Prec) -> Bool
Eq, (Prec, Hasher) -> Unit
Hash)
8
9///|
10impl trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Show for enum Prec {
NonAssoc
Left
Right
Dynamic
}
Prec with (self : Prec) -> String
to_string(Prec
self) {
11 match Prec
self {
12 Prec::Prec
NonAssoc => "PREC"
13 Prec::Prec
Left => "PREC_LEFT"
14 Prec::Prec
Right => "PREC_RIGHT"
15 Prec::Prec
Dynamic => "PREC_DYNAMIC"
16 }
17}
18
19///|
20impl trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Show for enum Prec {
NonAssoc
Left
Right
Dynamic
}
Prec with (self : Prec, logger : &Logger) -> Unit
output(Prec
self, &Logger
logger) {
21 &Logger
logger.(&Logger, String) -> Unit
write_string(Prec
self.(self : Prec) -> String
to_string())
22}
23
24///|
25impl trait ToJson {
to_json(Self) -> Json
}
ToJson for enum Prec {
NonAssoc
Left
Right
Dynamic
}
Prec with (self : Prec) -> Json
to_json(Prec
self) {
26 Prec
self.(self : Prec) -> String
to_string().(self : String) -> Json
to_json()
27}
28
29///|
30pub enum Rule {
31 (named~ : Bool, String, Rule) -> Rule
Alias(Bool
named~ : Bool
Bool, String
String, enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule)
32 Rule
Blank
33 (String) -> Rule
Symbol(String
String)
34 (String) -> Rule
String(String
String)
35 (Rule) -> Rule
Repeat(enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule)
36 (Rule) -> Rule
Repeat1(enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule)
37 (Array[Rule]) -> Rule
Choice(type Array[T]
Array[enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule])
38 (Array[Rule]) -> Rule
Seq(type Array[T]
Array[enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule])
39 (name~ : String, Rule) -> Rule
Field(String
name~ : String
String, enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule)
40 (immediate~ : Bool, Rule) -> Rule
Token(Bool
immediate~ : Bool
Bool, enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule)
41 (prec~ : Prec, value~ : Int, Rule) -> Rule
Prec(Prec
prec~ : enum Prec {
NonAssoc
Left
Right
Dynamic
}
Prec, Int
value~ : Int
Int, enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule)
42 (String) -> Rule
Pattern(String
String)
43} derive((Rule, &Logger) -> Unit
Show)
44
45///|
46pub impl trait Eq {
op_equal(Self, Self) -> Bool
}
Eq for enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule with (self : Rule, other : Rule) -> Bool
op_equal(Rule
self : enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule, Rule
other : enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule) -> Bool
Bool {
47 match (Rule
self, Rule
other) {
48 ((Bool, String, Rule) -> Rule
Alias(Bool
named=Bool
named1, String
alias1, Rule
rule1), (Bool, String, Rule) -> Rule
Alias(Bool
named=Bool
named2, String
alias2, Rule
rule2)) =>
49 Bool
named1 (self : Bool, other : Bool) -> Bool
Compares two boolean values for equality.
Parameters:
self : The first boolean value to compare.
other : The second boolean value to compare.
Returns true if both boolean values are equal (either both true or both
false), false otherwise.
Example:
test "Bool::op_equal" {
inspect!(true == true, content="true")
inspect!(false == true, content="false")
inspect!(true == false, content="false")
inspect!(false == false, content="true")
}
== Bool
named2 (Bool, Bool) -> Bool
&& String
alias1 (self : String, other : String) -> Bool
Tests whether two strings are equal by comparing their characters.
Parameters:
self : The first string to compare.
other : The second string to compare.
Returns true if both strings contain exactly the same sequence of
characters, false otherwise.
Example:
test "String::op_equal" {
let str1 = "hello"
let str2 = "hello"
let str3 = "world"
inspect!(str1 == str2, content="true")
inspect!(str1 == str3, content="false")
}
== String
alias2 (Bool, Bool) -> Bool
&& Rule
rule1 (self : Rule, other : Rule) -> Bool
== Rule
rule2
50 (Rule
Alias(_, ..), _) => false
51 (Rule
Blank, Rule
Blank) => true
52 (Rule
Blank, _) => false
53 ((String) -> Rule
Symbol(String
name1), (String) -> Rule
Symbol(String
name2)) => String
name1 (self : String, other : String) -> Bool
Tests whether two strings are equal by comparing their characters.
Parameters:
self : The first string to compare.
other : The second string to compare.
Returns true if both strings contain exactly the same sequence of
characters, false otherwise.
Example:
test "String::op_equal" {
let str1 = "hello"
let str2 = "hello"
let str3 = "world"
inspect!(str1 == str2, content="true")
inspect!(str1 == str3, content="false")
}
== String
name2
54 (Rule
Symbol(_), _) => false
55 ((String) -> Rule
String(String
value1), (String) -> Rule
String(String
value2)) => String
value1 (self : String, other : String) -> Bool
Tests whether two strings are equal by comparing their characters.
Parameters:
self : The first string to compare.
other : The second string to compare.
Returns true if both strings contain exactly the same sequence of
characters, false otherwise.
Example:
test "String::op_equal" {
let str1 = "hello"
let str2 = "hello"
let str3 = "world"
inspect!(str1 == str2, content="true")
inspect!(str1 == str3, content="false")
}
== String
value2
56 (Rule
String(_), _) => false
57 ((Rule) -> Rule
Repeat(Rule
rule1), (Rule) -> Rule
Repeat(Rule
rule2)) => Rule
rule1 (self : Rule, other : Rule) -> Bool
== Rule
rule2
58 (Rule
Repeat(_), _) => false
59 ((Rule) -> Rule
Repeat1(Rule
rule1), (Rule) -> Rule
Repeat1(Rule
rule2)) => Rule
rule1 (self : Rule, other : Rule) -> Bool
== Rule
rule2
60 (Rule
Repeat1(_), _) => false
61 ((Array[Rule]) -> Rule
Choice(Array[Rule]
rules1), (Array[Rule]) -> Rule
Choice(Array[Rule]
rules2)) => Array[Rule]
rules1 (self : Array[Rule], other : Array[Rule]) -> Bool
Compares two arrays for equality. Returns true if both arrays have the same
length and contain equal elements in the same order.
Parameters:
self : The first array to compare.
other : The second array to compare.
Returns true if the arrays are equal, false otherwise.
Example:
test "Array::op_equal" {
let arr1 = [1, 2, 3]
let arr2 = [1, 2, 3]
let arr3 = [1, 2, 4]
inspect!(arr1 == arr2, content="true")
inspect!(arr1 == arr3, content="false")
}
== Array[Rule]
rules2
62 (Rule
Choice(_, ..), _) => false
63 ((Array[Rule]) -> Rule
Seq(Array[Rule]
rules1), (Array[Rule]) -> Rule
Seq(Array[Rule]
rules2)) => Array[Rule]
rules1 (self : Array[Rule], other : Array[Rule]) -> Bool
Compares two arrays for equality. Returns true if both arrays have the same
length and contain equal elements in the same order.
Parameters:
self : The first array to compare.
other : The second array to compare.
Returns true if the arrays are equal, false otherwise.
Example:
test "Array::op_equal" {
let arr1 = [1, 2, 3]
let arr2 = [1, 2, 3]
let arr3 = [1, 2, 4]
inspect!(arr1 == arr2, content="true")
inspect!(arr1 == arr3, content="false")
}
== Array[Rule]
rules2
64 (Rule
Seq(_, ..), _) => false
65 ((String, Rule) -> Rule
Field(String
name=String
name1, Rule
rule1), (String, Rule) -> Rule
Field(String
name=String
name2, Rule
rule2)) =>
66 String
name1 (self : String, other : String) -> Bool
Tests whether two strings are equal by comparing their characters.
Parameters:
self : The first string to compare.
other : The second string to compare.
Returns true if both strings contain exactly the same sequence of
characters, false otherwise.
Example:
test "String::op_equal" {
let str1 = "hello"
let str2 = "hello"
let str3 = "world"
inspect!(str1 == str2, content="true")
inspect!(str1 == str3, content="false")
}
== String
name2 (Bool, Bool) -> Bool
&& Rule
rule1 (self : Rule, other : Rule) -> Bool
== Rule
rule2
67 (Rule
Field(_, ..), _) => false
68 ((Bool, Rule) -> Rule
Token(Bool
immediate=Bool
imm1, Rule
rule1), (Bool, Rule) -> Rule
Token(Bool
immediate=Bool
imm2, Rule
rule2)) =>
69 Bool
imm1 (self : Bool, other : Bool) -> Bool
Compares two boolean values for equality.
Parameters:
self : The first boolean value to compare.
other : The second boolean value to compare.
Returns true if both boolean values are equal (either both true or both
false), false otherwise.
Example:
test "Bool::op_equal" {
inspect!(true == true, content="true")
inspect!(false == true, content="false")
inspect!(true == false, content="false")
inspect!(false == false, content="true")
}
== Bool
imm2 (Bool, Bool) -> Bool
&& Rule
rule1 (self : Rule, other : Rule) -> Bool
== Rule
rule2
70 (Rule
Token(_, ..), _) => false
71 (
72 (Prec, Int, Rule) -> Rule
Prec(Prec
prec=Prec
prec1, Int
value=Int
value1, Rule
rule1),
73 (Prec, Int, Rule) -> Rule
Prec(Prec
prec=Prec
prec2, Int
value=Int
value2, Rule
rule2),
74 ) => Prec
prec1 (Prec, Prec) -> Bool
automatically derived
== Prec
prec2 (Bool, Bool) -> Bool
&& Int
value1 (self : Int, other : Int) -> Bool
Compares two integers for equality.
Parameters:
self : The first integer to compare.
other : The second integer to compare.
Returns true if both integers have the same value, false otherwise.
Example:
test "Int::op_equal" {
inspect!(42 == 42, content="true")
inspect!(42 == -42, content="false")
}
== Int
value2 (Bool, Bool) -> Bool
&& Rule
rule1 (self : Rule, other : Rule) -> Bool
== Rule
rule2
75 (Rule
Prec(_, ..), _) => false
76 ((String) -> Rule
Pattern(String
value1), (String) -> Rule
Pattern(String
value2)) => String
value1 (self : String, other : String) -> Bool
Tests whether two strings are equal by comparing their characters.
Parameters:
self : The first string to compare.
other : The second string to compare.
Returns true if both strings contain exactly the same sequence of
characters, false otherwise.
Example:
test "String::op_equal" {
let str1 = "hello"
let str2 = "hello"
let str3 = "world"
inspect!(str1 == str2, content="true")
inspect!(str1 == str3, content="false")
}
== String
value2
77 (Rule
Pattern(_, ..), _) => false
78 }
79}
80
81///|
82pub impl trait Hash {
hash_combine(Self, Hasher) -> Unit
hash(Self) -> Int
}
Hash for enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule with (self : Rule, hasher : Hasher) -> Unit
hash_combine(Rule
self, Hasher
hasher) {
83 match Rule
self {
84 (Bool, String, Rule) -> Rule
Alias(Bool
named~, String
value, Rule
rule) => {
85 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(0)
86 Hasher
hasher.(self : Hasher, value : Bool) -> Unit
Combines a boolean value into the current hash state. The boolean value is
converted to an integer (1 for true, 0 for false) before being combined with
the hash.
Parameters:
self : The hasher instance to update.
value : The boolean value to be combined into the hash state.
Example:
test "Hasher::combine_bool" {
let hasher = Hasher::new()
hasher.combine_bool(true)
inspect!(hasher.finalize(), content="-205818221")
}
combine_bool(Bool
named)
87 Hasher
hasher.(self : Hasher, value : String) -> Unit
Combines a string value into the current hash state by processing each
character in the string sequentially.
Parameters:
self : The hasher object whose state will be updated.
value : The string value to be combined into the hash state.
Example:
test "Hasher::combine_string" {
let hasher = Hasher::new()
hasher.combine_string("hello")
inspect!(hasher.finalize(), content="-655549713")
}
combine_string(String
value)
88 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
89 }
90 Rule
Blank => Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(1)
91 (String) -> Rule
Symbol(String
name) => {
92 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(2)
93 Hasher
hasher.(self : Hasher, value : String) -> Unit
Combines a string value into the current hash state by processing each
character in the string sequentially.
Parameters:
self : The hasher object whose state will be updated.
value : The string value to be combined into the hash state.
Example:
test "Hasher::combine_string" {
let hasher = Hasher::new()
hasher.combine_string("hello")
inspect!(hasher.finalize(), content="-655549713")
}
combine_string(String
name)
94 }
95 (String) -> Rule
String(String
value) => {
96 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(3)
97 Hasher
hasher.(self : Hasher, value : String) -> Unit
Combines a string value into the current hash state by processing each
character in the string sequentially.
Parameters:
self : The hasher object whose state will be updated.
value : The string value to be combined into the hash state.
Example:
test "Hasher::combine_string" {
let hasher = Hasher::new()
hasher.combine_string("hello")
inspect!(hasher.finalize(), content="-655549713")
}
combine_string(String
value)
98 }
99 (Rule) -> Rule
Repeat(Rule
rule) => {
100 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(4)
101 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
102 }
103 (Rule) -> Rule
Repeat1(Rule
rule) => {
104 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(5)
105 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
106 }
107 (Array[Rule]) -> Rule
Choice(Array[Rule]
rules) => {
108 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(6)
109 for Rule
rule in Array[Rule]
rules {
110 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
111 }
112 }
113 (Array[Rule]) -> Rule
Seq(Array[Rule]
rules) => {
114 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(7)
115 for Rule
rule in Array[Rule]
rules {
116 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
117 }
118 }
119 (String, Rule) -> Rule
Field(String
name~, Rule
rule) => {
120 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(8)
121 Hasher
hasher.(self : Hasher, value : String) -> Unit
Combines a string value into the current hash state by processing each
character in the string sequentially.
Parameters:
self : The hasher object whose state will be updated.
value : The string value to be combined into the hash state.
Example:
test "Hasher::combine_string" {
let hasher = Hasher::new()
hasher.combine_string("hello")
inspect!(hasher.finalize(), content="-655549713")
}
combine_string(String
name)
122 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
123 }
124 (Bool, Rule) -> Rule
Token(Bool
immediate~, Rule
rule) => {
125 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(9)
126 Hasher
hasher.(self : Hasher, value : Bool) -> Unit
Combines a boolean value into the current hash state. The boolean value is
converted to an integer (1 for true, 0 for false) before being combined with
the hash.
Parameters:
self : The hasher instance to update.
value : The boolean value to be combined into the hash state.
Example:
test "Hasher::combine_bool" {
let hasher = Hasher::new()
hasher.combine_bool(true)
inspect!(hasher.finalize(), content="-205818221")
}
combine_bool(Bool
immediate)
127 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
128 }
129 (Prec, Int, Rule) -> Rule
Prec(Prec
prec~, Int
value~, Rule
rule) => {
130 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(10)
131 Hasher
hasher.(self : Hasher, value : Prec) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Prec
prec)
132 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(Int
value)
133 Hasher
hasher.(self : Hasher, value : Rule) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(Rule
rule)
134 }
135 (String) -> Rule
Pattern(String
value) => {
136 Hasher
hasher.(self : Hasher, value : Int) -> Unit
Combines a 32-bit integer value into the hasher's internal state. The value
is processed
as a 4-byte sequence, and the internal accumulator is updated accordingly.
Parameters:
self : The hasher instance to update.
value : A 32-bit integer value to be incorporated into the hash.
Example:
test "Hasher::combine_int" {
let hasher = Hasher::new()
hasher.combine_int(42)
inspect!(hasher.finalize(), content="1161967057")
}
combine_int(11)
137 Hasher
hasher.(self : Hasher, value : String) -> Unit
Combines a hashable value with the current state of the hasher. This is
typically used to incrementally build a hash value from multiple components.
Parameters:
self : The hasher instance to update.
value : The value to be combined with the current hash state. Must
implement the Hash trait.
Example:
test "Hasher::combine" {
let hasher = Hasher::new()
hasher.combine(42)
hasher.combine("hello")
inspect!(hasher.finalize(), content="860601284")
}
combine(String
value)
138 }
139 }
140}
141
142///|
143fn enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(self : Rule, visitor : (Rule) -> Unit!E) -> Unit!E
visit_rule[E : Error](
144 Rule
self : enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule,
145 (Rule) -> Unit!E
visitor : (enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule) -> Unit
Unit!type parameter E
E
146) -> Unit
Unit!type parameter E
E {
147 (Rule) -> Unit!E
visitor!(Rule
self)
148 match Rule
self {
149 (String, Rule) -> Rule
Alias(_, Rule
rule, ..) => Rule
rule.(self : Rule, visitor : (Rule) -> Unit!E) -> Unit!E
visit_rule!((Rule) -> Unit!E
visitor)
150 (Rule) -> Rule
Prec(Rule
rule, ..) => Rule
rule.(self : Rule, visitor : (Rule) -> Unit!E) -> Unit!E
visit_rule!((Rule) -> Unit!E
visitor)
151 (Rule) -> Rule
Token(Rule
rule, ..) => Rule
rule.(self : Rule, visitor : (Rule) -> Unit!E) -> Unit!E
visit_rule!((Rule) -> Unit!E
visitor)
152 (Rule) -> Rule
Field(Rule
rule, ..) => Rule
rule.(self : Rule, visitor : (Rule) -> Unit!E) -> Unit!E
visit_rule!((Rule) -> Unit!E
visitor)
153 (Array[Rule]) -> Rule
Seq(Array[Rule]
rules) | (Array[Rule]) -> Rule
Choice(Array[Rule]
rules) =>
154 for Rule
rule in Array[Rule]
rules {
155 Rule
rule.(self : Rule, visitor : (Rule) -> Unit!E) -> Unit!E
visit_rule!((Rule) -> Unit!E
visitor)
156 }
157 (Rule) -> Rule
Repeat1(Rule
rule) | (Rule) -> Rule
Repeat(Rule
rule) => Rule
rule.(self : Rule, visitor : (Rule) -> Unit!E) -> Unit!E
visit_rule!((Rule) -> Unit!E
visitor)
158 Rule
String(_) => ()
159 Rule
Symbol(_) => ()
160 Rule
Blank => ()
161 Rule
Pattern(_) => ()
162 }
163}
164
165///|
166impl trait @json.FromJson {
from_json(Json, @json.JsonPath) -> Self!@json.JsonDecodeError
}
Trait for types that can be converted from Json
@json.FromJson for enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule with (json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json(
167 Json
json : enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json,
168 @json.JsonPath
json_path : type @json.JsonPath
@json.JsonPath
169) -> enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule!type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError {
170 match Json
json {
171 {
172 "type": "ALIAS",
173 "named": Json
True
174 | Json
False as named,
175 "value": (String) -> Json
String(String
value),
176 "content": Json
rule,
177 ..
178 } =>
179 Rule::(named~ : Bool, String, Rule) -> Rule
Alias(
180 Bool
named=(json : Json, path~ : @json.JsonPath = ..) -> Bool!@json.JsonDecodeError
@json.from_json!(Json
named),
181 String
value,
182 enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
rule, @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("content")),
183 )
184 { "type": "BLANK", .. } => Rule::Rule
Blank
185 { "type": "SYMBOL", "name": (String) -> Json
String(String
name), .. } => Rule::(String) -> Rule
Symbol(String
name)
186 { "type": "STRING", "value": (String) -> Json
String(String
value), .. } => Rule::(String) -> Rule
String(String
value)
187 { "type": "CHOICE", "members": (Array[Json]) -> Json
Array(Array[Json]
members_json), .. } => {
188 let @json.JsonPath
members_json_path = @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("members")
189 let Array[Rule]
rules = []
190 for Int
i, Json
member_json in Array[Json]
members_json {
191 Array[Rule]
rules.(self : Array[Rule], value : Rule) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(
192 enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
member_json, @json.JsonPath
members_json_path.(self : @json.JsonPath, index : Int) -> @json.JsonPath
add_index(Int
i)),
193 )
194 }
195 Rule::(Array[Rule]) -> Rule
Choice(Array[Rule]
rules)
196 }
197 { "type": "SEQ", "members": (Array[Json]) -> Json
Array(Array[Json]
members_json), .. } => {
198 let @json.JsonPath
members_json_path = @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("members")
199 let Array[Rule]
rules = []
200 for Int
i, Json
member_json in Array[Json]
members_json {
201 Array[Rule]
rules.(self : Array[Rule], value : Rule) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(
202 enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
member_json, @json.JsonPath
members_json_path.(self : @json.JsonPath, index : Int) -> @json.JsonPath
add_index(Int
i)),
203 )
204 }
205 Rule::(Array[Rule]) -> Rule
Seq(Array[Rule]
rules)
206 }
207 { "type": "REPEAT", "content": Json
rule, .. } =>
208 Rule::(Rule) -> Rule
Repeat(enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
rule, @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("content")))
209 { "type": "REPEAT1", "content": Json
rule, .. } =>
210 Rule::(Rule) -> Rule
Repeat1(enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
rule, @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("content")))
211 { "type": "TOKEN", "content": Json
rule, .. } =>
212 Rule::(immediate~ : Bool, Rule) -> Rule
Token(
213 Bool
immediate=false,
214 enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
rule, @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("content")),
215 )
216 { "type": "IMMEDIATE_TOKEN", "content": Json
rule, .. } =>
217 Rule::(immediate~ : Bool, Rule) -> Rule
Token(
218 Bool
immediate=true,
219 enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
rule, @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("content")),
220 )
221 { "type": "FIELD", "name": (String) -> Json
String(String
name), "content": Json
rule, .. } =>
222 Rule::(name~ : String, Rule) -> Rule
Field(String
name~, enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
rule, @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("content")))
223 {
224 "type": (String) -> Json
String(Char
[.. "PREC", .. suffix]),
225 "value": (Double) -> Json
Number(Double
value),
226 "content": Json
rule,
227 ..
228 } => {
229 let Prec
prec = match @string.StringView
suffix {
230 [.. ""] => Prec::Prec
NonAssoc
231 [.. "_LEFT"] => Prec::Prec
Left
232 [.. "_RIGHT"] => Prec::Prec
Right
233 [.. "_DYNAMIC"] => Prec::Prec
Dynamic
234 @string.StringView
suffix => {
235 let String
message = "Rule::from_json: invalid precedence type \"PREC\{@string.StringView
suffix}\""
236 raise @json.((@json.JsonPath, String)) -> @json.JsonDecodeError
JsonDecodeError((@json.JsonPath
json_path, String
message))
237 }
238 }
239 Rule::(prec~ : Prec, value~ : Int, Rule) -> Rule
Prec(
240 Prec
prec~,
241 Int
value=Double
value.(self : Double) -> Int
Converts a double-precision floating-point number to a 32-bit integer.
Handles special cases including NaN and numbers outside the valid Int range.
Parameters:
self : The double-precision floating-point number to be converted.
Returns an 32-bit integer value according to the following rules:
- Returns 0 if the input is NaN
- Returns
@int.max_value (2147483647) if the input is greater than or
equal to @int.max_value
- Returns
@int.min_value (-2147483648) if the input is less than or equal
to @int.min_value
- Otherwise returns the integer part of the input by truncating towards zero
Example:
test "Double::to_int/normal" {
inspect!(42.0.to_int(), content="42")
inspect!((-42.5).to_int(), content="-42")
inspect!((0.0 / 0.0).to_int(), content="0") // NaN
inspect!((1.0 / 0.0).to_int(), content="2147483647") // Infinity
inspect!((-1.0 / 0.0).to_int(), content="-2147483648") // -Infinity
}
to_int(),
242 enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule::(json : Json, json_path : @json.JsonPath) -> Rule!@json.JsonDecodeError
from_json!(Json
rule, @json.JsonPath
json_path.(self : @json.JsonPath, key : String) -> @json.JsonPath
add_key("content")),
243 )
244 }
245 { "type": "PATTERN", "value": (String) -> Json
String(String
value), .. } => Rule::(String) -> Rule
Pattern(String
value)
246 Json
json => {
247 let String
message = "Rule::from_json: expected object with \"type\" field, got \{Json
json}"
248 raise @json.((@json.JsonPath, String)) -> @json.JsonDecodeError
JsonDecodeError((@json.JsonPath
json_path, String
message))
249 }
250 }
251}
252
253///|
254impl trait ToJson {
to_json(Self) -> Json
}
ToJson for enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule with (self : Rule) -> Json
to_json(Rule
self : enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule) -> enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json {
255 match Rule
self {
256 (Bool, String, Rule) -> Rule
Alias(Bool
named~, String
value, Rule
rule) =>
257 {
258 "type": "ALIAS",
259 "value": String
value.(self : String) -> Json
to_json(),
260 "named": Bool
named.(self : Bool) -> Json
to_json(),
261 "content": Rule
rule.(self : Rule) -> Json
to_json(),
262 }
263 (Prec, Int, Rule) -> Rule
Prec(Prec
prec~, Int
value~, Rule
rule) =>
264 {
265 "type": Prec
prec.(self : Prec) -> Json
to_json(),
266 "value": Int
value.(self : Int) -> Json
to_json(),
267 "content": Rule
rule.(self : Rule) -> Json
to_json(),
268 }
269 (Bool, Rule) -> Rule
Token(Bool
immediate~, Rule
rule) => {
270 let String
token_type = if Bool
immediate { "IMMEDIATE_TOKEN" } else { "TOKEN" }
271 { "type": String
token_type.(self : String) -> Json
to_json(), "content": Rule
rule.(self : Rule) -> Json
to_json() }
272 }
273 (String, Rule) -> Rule
Field(String
name~, Rule
rule) =>
274 { "type": "FIELD", "name": enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json::(String) -> Json
Creates a JSON string value from a MoonBit string.
Parameters:
string : A MoonBit string to be converted to a JSON string value.
Returns a JSON value representing the given string.
Example:
test "string" {
inspect!(Json::string("hello"), content="String(\"hello\")")
}
string(String
name), "content": Rule
rule.(self : Rule) -> Json
to_json() }
275 (Array[Rule]) -> Rule
Seq(Array[Rule]
rules) => { "type": "SEQ", "members": Array[Rule]
rules.(self : Array[Rule]) -> Json
to_json() }
276 (Array[Rule]) -> Rule
Choice(Array[Rule]
rules) => { "type": "CHOICE", "members": Array[Rule]
rules.(self : Array[Rule]) -> Json
to_json() }
277 (Rule) -> Rule
Repeat1(Rule
rule) => { "type": "REPEAT1", "content": Rule
rule.(self : Rule) -> Json
to_json() }
278 (Rule) -> Rule
Repeat(Rule
rule) => { "type": "REPEAT", "content": Rule
rule.(self : Rule) -> Json
to_json() }
279 (String) -> Rule
String(String
value) => { "type": "STRING", "value": String
value.(self : String) -> Json
to_json() }
280 (String) -> Rule
Symbol(String
name) => { "type": "SYMBOL", "name": String
name.(self : String) -> Json
to_json() }
281 Rule
Blank => { "type": "BLANK" }
282 (String) -> Rule
Pattern(String
value) => { "type": "PATTERN", "value": String
value.(self : String) -> Json
to_json() }
283 }
284}
285
286///|
287struct RuleName {
288 String
name : String
String
289 mut Rule?
rule : enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule?
290} derive((RuleName, &Logger) -> Unit
Show)
291
292///|
293impl trait @json.FromJson {
from_json(Json, @json.JsonPath) -> Self!@json.JsonDecodeError
}
Trait for types that can be converted from Json
@json.FromJson for struct RuleName {
name: String
mut rule: Rule?
}
RuleName with (json : Json, json_path : @json.JsonPath) -> RuleName!@json.JsonDecodeError
from_json(
294 Json
json : enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json,
295 @json.JsonPath
json_path : type @json.JsonPath
@json.JsonPath
296) -> struct RuleName {
name: String
mut rule: Rule?
}
RuleName!type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError {
297 guard Json
json is (String) -> Json
String(String
name) else {
298 let String
message = "RuleName::from_json: expected string, got \{Json
json}"
299 raise @json.((@json.JsonPath, String)) -> @json.JsonDecodeError
JsonDecodeError((@json.JsonPath
json_path, String
message))
300 }
301 { String
name, Rule?
rule: Rule?
None }
302}
303
304///|
305impl trait ToJson {
to_json(Self) -> Json
}
ToJson for struct RuleName {
name: String
mut rule: Rule?
}
RuleName with (self : RuleName) -> Json
to_json(RuleName
self : struct RuleName {
name: String
mut rule: Rule?
}
RuleName) -> enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json {
306 RuleName
self.String
name.(self : String) -> Json
to_json()
307}
308
309///|
310pub struct Grammar {
311 String
name : String
String
312 Map[String, Rule]
rules : type Map[K, V]
Map[String
String, enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule]
313 Array[Rule]
extras : type Array[T]
Array[enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule]
314 Array[RuleName]
supertypes : type Array[T]
Array[struct RuleName {
name: String
mut rule: Rule?
}
RuleName]
315 Map[String, Rule]
reserved : type Map[K, V]
Map[String
String, enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule]
316 Array[Rule]
externals : type Array[T]
Array[enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule]
317 Array[RuleName]
inline : type Array[T]
Array[struct RuleName {
name: String
mut rule: Rule?
}
RuleName]
318 Array[Array[RuleName]]
conflicts : type Array[T]
Array[type Array[T]
Array[struct RuleName {
name: String
mut rule: Rule?
}
RuleName]]
319 RuleName?
word : struct RuleName {
name: String
mut rule: Rule?
}
RuleName?
320} derive((Json, @json.JsonPath) -> Grammar!@json.JsonDecodeError
Trait for types that can be converted from Json
@json.FromJson(fields(reserved(default={}))), (Grammar, &Logger) -> Unit
Show, (Grammar) -> Json
ToJson)
321
322///|
323type! GrammarParseError {
324 (@json.JsonDecodeError) -> GrammarParseError
JsonDecodeError(type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError)
325 (String) -> GrammarParseError
RuleNotFound(String
String)
326} derive((GrammarParseError, &Logger) -> Unit
Show)
327
328///|
329pub fn struct Grammar {
name: String
rules: Map[String, Rule]
extras: Array[Rule]
supertypes: Array[RuleName]
reserved: Map[String, Rule]
externals: Array[Rule]
inline: Array[RuleName]
conflicts: Array[Array[RuleName]]
word: RuleName?
}
Grammar::(json : Json) -> Grammar!GrammarParseError
from_json(Json
json : enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json) -> struct Grammar {
name: String
rules: Map[String, Rule]
extras: Array[Rule]
supertypes: Array[RuleName]
reserved: Map[String, Rule]
externals: Array[Rule]
inline: Array[RuleName]
conflicts: Array[Array[RuleName]]
word: RuleName?
}
Grammar!type! GrammarParseError {
JsonDecodeError(@json.JsonDecodeError)
RuleNotFound(String)
}
GrammarParseError {
330 let Grammar
grammar : struct Grammar {
name: String
rules: Map[String, Rule]
extras: Array[Rule]
supertypes: Array[RuleName]
reserved: Map[String, Rule]
externals: Array[Rule]
inline: Array[RuleName]
conflicts: Array[Array[RuleName]]
word: RuleName?
}
Grammar = try {
331 (json : Json, path~ : @json.JsonPath = ..) -> Grammar!@json.JsonDecodeError
@json.from_json!(Json
json)
332 } catch {
333 @json.JsonDecodeError
error => raise (@json.JsonDecodeError) -> GrammarParseError
JsonDecodeError(@json.JsonDecodeError
error)
334 }
335 for _, Rule
rule in Grammar
grammar.Map[String, Rule]
rules {
336 let (Rule) -> Unit!GrammarParseError
visitor = fn(Rule
rule : enum Rule {
Alias(named~ : Bool, String, Rule)
Blank
Symbol(String)
String(String)
Repeat(Rule)
Repeat1(Rule)
Choice(Array[Rule])
Seq(Array[Rule])
Field(name~ : String, Rule)
Token(immediate~ : Bool, Rule)
Prec(prec~ : Prec, value~ : Int, Rule)
Pattern(String)
}
Rule) -> Unit
Unit!type! GrammarParseError {
JsonDecodeError(@json.JsonDecodeError)
RuleNotFound(String)
}
GrammarParseError {
337 match Rule
rule {
338 (String) -> Rule
Symbol(String
name) =>
339 if Grammar
grammar.Map[String, Rule]
rules.(self : Map[String, Rule], key : String) -> Rule?
Get the value associated with a key.
get(String
name) is Rule?
None {
340 raise (String) -> GrammarParseError
RuleNotFound(String
name)
341 }
342 _ => return
343 }
344 }
345 Rule
rule.(self : Rule, visitor : (Rule) -> Unit!GrammarParseError) -> Unit!GrammarParseError
visit_rule!((Rule) -> Unit!GrammarParseError
visitor)
346 }
347 for RuleName
supertype in Grammar
grammar.Array[RuleName]
supertypes {
348 guard Grammar
grammar.Map[String, Rule]
rules.(self : Map[String, Rule], key : String) -> Rule?
Get the value associated with a key.
get(RuleName
supertype.String
name) is (Rule) -> Rule?
Some(Rule
rule) else {
349 raise (String) -> GrammarParseError
RuleNotFound(RuleName
supertype.String
name)
350 }
351 RuleName
supertype.Rule?
rule = (Rule) -> Rule?
Some(Rule
rule)
352 }
353 for RuleName
inline in Grammar
grammar.Array[RuleName]
inline {
354 guard Grammar
grammar.Map[String, Rule]
rules.(self : Map[String, Rule], key : String) -> Rule?
Get the value associated with a key.
get(RuleName
inline.String
name) is (Rule) -> Rule?
Some(Rule
rule) else {
355 raise (String) -> GrammarParseError
RuleNotFound(RuleName
inline.String
name)
356 }
357 RuleName
inline.Rule?
rule = (Rule) -> Rule?
Some(Rule
rule)
358 }
359 for Array[RuleName]
conflict in Grammar
grammar.Array[Array[RuleName]]
conflicts {
360 for RuleName
rule_name in Array[RuleName]
conflict {
361 guard Grammar
grammar.Map[String, Rule]
rules.(self : Map[String, Rule], key : String) -> Rule?
Get the value associated with a key.
get(RuleName
rule_name.String
name) is (Rule) -> Rule?
Some(Rule
rule) else {
362 raise (String) -> GrammarParseError
RuleNotFound(RuleName
rule_name.String
name)
363 }
364 RuleName
rule_name.Rule?
rule = (Rule) -> Rule?
Some(Rule
rule)
365 }
366 }
367 if Grammar
grammar.RuleName?
word is (RuleName) -> RuleName?
Some(RuleName
word) {
368 guard Grammar
grammar.Map[String, Rule]
rules.(self : Map[String, Rule], key : String) -> Rule?
Get the value associated with a key.
get(RuleName
word.String
name) is (Rule) -> Rule?
Some(Rule
rule) else {
369 raise (String) -> GrammarParseError
RuleNotFound(RuleName
word.String
name)
370 }
371 RuleName
word.Rule?
rule = (Rule) -> Rule?
Some(Rule
rule)
372 }
373 Grammar
grammar
374}
375