Since no distinction is to be done between both Int and Byte when
dealing with strings, there is no need to have both an 'ascii' and a
'code_point' service on both Int and Char.
Therefore, we remove the ascii method, as our Chars are first and
foremost Unicode-compliant.
Signed-off-by: Lucas Bajolet <lucas.bajolet@gmail.com>
13 files changed:
redef fun to_i32 is intern
redef fun to_u32 is intern
redef fun to_i32 is intern
redef fun to_u32 is intern
- # Returns `self` as a Char according to its ASCII value.
- fun ascii: Char `{ return (uint32_t)self; `}
-
redef fun distance(i) do return (self - i).to_i
redef fun <=>(other)
redef fun distance(i) do return (self - i).to_i
redef fun <=>(other)
redef fun *(i) is intern
redef fun /(i) is intern
redef fun *(i) is intern
redef fun /(i) is intern
- # Returns `self` as a Char according to its ASCII value.
- fun ascii: Char `{ return (uint32_t)self; `}
-
# Modulo of `self` with `i`.
#
# Returns the remainder of division of `self` by `i`.
# Modulo of `self` with `i`.
#
# Returns the remainder of division of `self` by `i`.
redef fun zero do return 0.to_u16
redef fun value_of(val) do return val.to_u16
redef fun zero do return 0.to_u16
redef fun value_of(val) do return val.to_u16
- # Returns `self` as a Char according to its ASCII value.
- fun ascii: Char `{ return (uint32_t)self; `}
-
# `i` bits shift to the left
#
# assert 5u16 << 1 == 10u16
# `i` bits shift to the left
#
# assert 5u16 << 1 == 10u16
redef fun *(i) is intern
redef fun /(i) is intern
redef fun *(i) is intern
redef fun /(i) is intern
- # Returns `self` as a Char according to its ASCII value.
- fun ascii: Char `{ return (uint32_t)self; `}
-
# Modulo of `self` with `i`.
#
# Returns the remainder of division of `self` by `i`.
# Modulo of `self` with `i`.
#
# Returns the remainder of division of `self` by `i`.
redef fun *(i) is intern
redef fun /(i) is intern
redef fun *(i) is intern
redef fun /(i) is intern
- # Returns `self` as a Char according to its ASCII value.
- fun ascii: Char `{ return (uint32_t)self; `}
-
# Modulo of `self` with `i`.
#
# Returns the remainder of division of `self` by `i`.
# Modulo of `self` with `i`.
#
# Returns the remainder of division of `self` by `i`.
# assert 0x220B.code_point == '∋'
fun code_point: Char is intern `{ return (uint32_t)self; `}
# assert 0x220B.code_point == '∋'
fun code_point: Char is intern `{ return (uint32_t)self; `}
- # Returns the character equivalent of `self`
- #
- # REQUIRE: `self <= 127`
- fun ascii: Char do return code_point
-
# Number of digits of an integer in base `b` (plus one if negative)
#
# assert 123.digit_count(10) == 3
# Number of digits of an integer in base `b` (plus one if negative)
#
# assert 123.digit_count(10) == 3
- # The ascii value of `self`
- #
- # assert 'a'.ascii == 97
- # assert '\n'.ascii == 10
- #
- # REQUIRE: `is_ascii`
- fun ascii: Int do return code_point
-
# The unicode code point value of `self`
#
# assert 'A'.code_point == 65
# The unicode code point value of `self`
#
# assert 'A'.code_point == 65
var mod = length % blocksize
if mod == 0 then return self
var pad = blocksize - mod
var mod = length % blocksize
if mod == 0 then return self
var pad = blocksize - mod
for i in [0..pad[ do add byte
return self
end
for i in [0..pad[ do add byte
return self
end
redef class ACharExpr
redef fun expr(v) do
redef class ACharExpr
redef fun expr(v) do
- if is_ascii then return v.int_instance(value.as(not null).ascii)
- if is_code_point then return v.int_instance(value.as(not null).code_point)
+ if is_code_point then
+ return v.int_instance(value.as(not null).code_point)
+ end
return v.char_instance(self.value.as(not null))
end
end
return v.char_instance(self.value.as(not null))
end
end
redef class ACharExpr
redef fun expr(v)
do
redef class ACharExpr
redef fun expr(v)
do
- if is_ascii then return v.int_instance(self.value.as(not null).ascii)
- if is_code_point then return v.int_instance(self.value.as(not null).code_point)
+ if is_code_point then
+ return v.int_instance(self.value.as(not null).code_point)
+ end
return v.char_instance(self.value.as(not null))
end
end
return v.char_instance(self.value.as(not null))
end
end
redef fun delimiter_end do return '\''
redef fun delimiter_end do return '\''
- # Is the expression returning an ASCII byte value ?
- fun is_ascii: Bool do return prefix == "b"
-
# Is the expression returning a Code Point ?
fun is_code_point: Bool do return prefix == "u"
# Is the expression returning a Code Point ?
fun is_code_point: Bool do return prefix == "u"
redef fun is_valid_augmentation do
if suffix != "" then return false
redef fun is_valid_augmentation do
if suffix != "" then return false
- if is_ascii then return true
if is_code_point then return true
if prefix != "" then return false
return true
if is_code_point then return true
if prefix != "" then return false
return true
return
end
self.value = txt.chars[1]
return
end
self.value = txt.chars[1]
- if is_ascii and txt.chars[1].code_point > 127 then v.toolcontext.error(self.hot_location, "Syntax Error: usage of byte prefix on multibyte character.")
if cla != null then mtype = cla.mclass_type
else if nexpr isa ACharExpr then
var cla: nullable MClass
if cla != null then mtype = cla.mclass_type
else if nexpr isa ACharExpr then
var cla: nullable MClass
- if nexpr.is_ascii then
- cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Byte")
- else if nexpr.is_code_point then
+ if nexpr.is_code_point then
cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Int")
else
cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Char")
cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Int")
else
cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Char")
redef class ACharExpr
redef fun accept_typing(v) do
var mclass: nullable MClass = null
redef class ACharExpr
redef fun accept_typing(v) do
var mclass: nullable MClass = null
- if is_ascii then
- mclass = v.get_mclass(self, "Byte")
- else if is_code_point then
mclass = v.get_mclass(self, "Int")
else
mclass = v.get_mclass(self, "Char")
mclass = v.get_mclass(self, "Int")
else
mclass = v.get_mclass(self, "Char")
-Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728)
+Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723)
-Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728)
+Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723)
-Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728)
+Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723)
Numeric -> Float [dir=back arrowtail=open style=dashed];
Byte [
Numeric -> Float [dir=back arrowtail=open style=dashed];
Byte [
- label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ ascii(): Char\l+ is_whitespace(): Bool\l}"
+ label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ is_whitespace(): Bool\l}"
]
Discrete -> Byte [dir=back arrowtail=open style=dashed];
Numeric -> Byte [dir=back arrowtail=open style=dashed];
Int [
]
Discrete -> Byte [dir=back arrowtail=open style=dashed];
Numeric -> Byte [dir=back arrowtail=open style=dashed];
Int [
- label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l}"
+ label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l+ is_whitespace(): Bool\l}"
]
Discrete -> Int [dir=back arrowtail=open style=dashed];
Numeric -> Int [dir=back arrowtail=open style=dashed];
Char [
]
Discrete -> Int [dir=back arrowtail=open style=dashed];
Numeric -> Int [dir=back arrowtail=open style=dashed];
Char [
- label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ ascii(): Byte\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}"
+ label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}"
]
Discrete -> Char [dir=back arrowtail=open style=dashed];
]
Discrete -> Char [dir=back arrowtail=open style=dashed];
Numeric -> Float [dir=back arrowtail=open style=dashed];
Byte [
Numeric -> Float [dir=back arrowtail=open style=dashed];
Byte [
- label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ ascii(): Char\l+ is_whitespace(): Bool\l}"
+ label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ is_whitespace(): Bool\l}"
]
Discrete -> Byte [dir=back arrowtail=open style=dashed];
Numeric -> Byte [dir=back arrowtail=open style=dashed];
Int [
]
Discrete -> Byte [dir=back arrowtail=open style=dashed];
Numeric -> Byte [dir=back arrowtail=open style=dashed];
Int [
- label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l}"
+ label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l+ is_whitespace(): Bool\l}"
]
Discrete -> Int [dir=back arrowtail=open style=dashed];
Numeric -> Int [dir=back arrowtail=open style=dashed];
Char [
]
Discrete -> Int [dir=back arrowtail=open style=dashed];
Numeric -> Int [dir=back arrowtail=open style=dashed];
Char [
- label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ ascii(): Byte\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}"
+ label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}"
]
Discrete -> Char [dir=back arrowtail=open style=dashed];
]
Discrete -> Char [dir=back arrowtail=open style=dashed];