Mostly, this mean using `chars`.
Signed-off-by: Jean Privat <jean@pryen.org>
class Lexer_nitcc
var text: String
- var iter: Iterator[Char] = "".iterator
+ var iter: Iterator[Char] = "".chars.iterator
var pos = 0
var tokens = new Array[NToken]
fun lex: Array[NToken]
do
- iter = text.iterator
+ iter = text.chars.iterator
while iter.is_ok do
trim
if not iter.is_ok then break
var text = self.text
if text != null then
var nfa = new Automaton.epsilon
- for c in text.as(not null) do
+ for c in text.chars do
nfa.concat(new Automaton.atom(c.ascii))
end
return nfa
do
var a = new Automaton.epsilon
var val
- for c in self.value do
+ for c in self.value.chars do
var b = new Automaton.atom(c.ascii)
a.concat(b)
end
redef fun value: String do return text.substring_from(1).to_i.ascii.to_s
redef fun make_rfa: Automaton
do
- var a = new Automaton.atom(self.value.first.ascii)
+ var a = new Automaton.atom(self.value.chars.first.ascii)
return a
end
end
exit(1)
abort
end
- var a = new Automaton.cla(c1.first.ascii, c2.first.ascii)
+ var a = new Automaton.cla(c1.chars.first.ascii, c2.chars.first.ascii)
return a
end
end
var s = context.result.to_precision_native(6)
var index : nullable Int = null
for i in s.length.times do
- var chiffre = s[i]
+ var chiffre = s.chars[i]
if chiffre == '0' and index == null then
index = i
else if chiffre != '0' then
end
if index != null then
s = s.substring(0, index)
- if s[s.length-1] == ',' then s = s.substring(0, s.length-1)
+ if s.chars[s.length-1] == ',' then s = s.substring(0, s.length-1)
end
lbl_disp.text = s
end
if val.length != 1 then print "Error: expected a single char when deserializing '{val}'."
- return val.first
+ return val.chars.first
end
print "Malformed Json string: unexpected Json Object kind '{kind}'"
var words = l.split_with(" ")
if words.length > 1 then
var key = words[0].to_lower
- var first_space = l.index_of(' ')
+ var first_space = l.chars.index_of(' ')
var rest = l.substring_from(first_space+1)
if key == "volume:" then
volume = rest.to_i
var words = l.split_with(" ")
if words.length > 1 then
var key = words[0].to_lower
- var first_space = l.index_of(' ')
+ var first_space = l.chars.index_of(' ')
var rest = l.substring_from(first_space+1)
if key == "album:" then
album = rest
c = '\0'
next = null
else
- c = text[pos]
+ c = text.chars[pos]
next = state.trans(c)
end
if next == null then
class NLexerError
super NError
- redef fun unexpected do return "character '{text.first}'"
+ redef fun unexpected do return "character '{text.chars.first}'"
end
# A parser error linked to a unexpected token
parseargs = false
else
# We're looking for packed short options
- if str.last_index_of('-') == 0 and str.length > 2 then
+ if str.chars.last_index_of('-') == 0 and str.length > 2 then
var next_called = false
for i in [1..str.length] do
var short_opt = "-" + str.chars[i].to_s
redef fun to_nit_object
do
var text = n_number.text
- if text.has('.') or text.has('e') or text.has('E') then return text.to_f
+ if text.chars.has('.') or text.chars.has('e') or text.chars.has('E') then return text.to_f
return text.to_i
end
end
var l = length - 1 # Index of the last char
while l > 0 and self.chars[l] == '/' do l -= 1 # remove all trailing `/`
if l == 0 then return "/"
- var pos = last_index_of_from('/', l)
+ var pos = chars.last_index_of_from('/', l)
var n = self
if pos >= 0 then
n = substring(pos+1, l-pos)
do
var l = length - 1 # Index of the last char
while l > 0 and self.chars[l] == '/' do l -= 1 # remove all trailing `/`
- var pos = last_index_of_from('/', l)
+ var pos = chars.last_index_of_from('/', l)
if pos > 0 then
return substring(0, pos)
else if pos == 0 then
# assert ".file".file_extension == null
fun file_extension: nullable String
do
- var last_slash = last_index_of('.')
+ var last_slash = chars.last_index_of('.')
if last_slash > 0 then
return substring( last_slash+1, length )
else
fun has_substring(str: String, pos: Int): Bool
do
var myiter = self.chars.iterator_from(pos)
- var itsiter = str.iterator
+ var itsiter = str.chars.iterator
while myiter.is_ok and itsiter.is_ok do
if myiter.item != itsiter.item then return false
myiter.next
fun escape_more_to_c(chars: String): String
do
var b = new FlatBuffer
- for c in escape_to_c do
+ for c in escape_to_c.chars do
if chars.chars.has(c) then
b.add('\\')
end
# assert s.length == 2
# var u = s.unescape_nit
# assert u.length == 1
- # assert u[0].ascii == 10 # (the ASCII value of the "new line" character)
+ # assert u.chars[0].ascii == 10 # (the ASCII value of the "new line" character)
fun unescape_nit: String
do
var res = new FlatBuffer.with_capacity(self.length)
var was_slash = false
- for c in self do
+ for c in chars do
if not was_slash then
if c == '\\' then
was_slash = true
# Processes an array print command
fun process_array_command(parts_of_command: Array[String])
do
- var index_of_first_brace = parts_of_command[1].index_of('[')
+ var index_of_first_brace = parts_of_command[1].chars.index_of('[')
var variable_name = get_real_variable_name(parts_of_command[1].substring(0,index_of_first_brace))
var braces = parts_of_command[1].substring_from(index_of_first_brace)
# Returns an array containing all the indexes demanded
fun process_index(index_string: String): nullable Array[Int]
do
- var from_end_index = index_string.index_of('.')
- var to_start_index = index_string.last_index_of('.')
+ var from_end_index = index_string.chars.index_of('.')
+ var to_start_index = index_string.chars.last_index_of('.')
if from_end_index != -1 and to_start_index != -1 then
var index_from_string = index_string.substring(0,from_end_index)
error(nfd, "Error: A formal parameter type `{ptname}' already exists")
return
end
- for c in ptname do if c >= 'a' and c<= 'z' then
+ for c in ptname.chars do if c >= 'a' and c<= 'z' then
warning(nfd, "Warning: lowercase in the formal parameter type {ptname}")
break
end
if mprop == null then
var mvisibility = new_property_visibility(modelbuilder, nclassdef, self.n_visibility)
mprop = new MVirtualTypeProp(mclassdef, name, mvisibility)
- for c in name do if c >= 'a' and c<= 'z' then
+ for c in name.chars do if c >= 'a' and c<= 'z' then
modelbuilder.warning(n_id, "Warning: lowercase in the virtual type {name}")
break
end
for t in n_comment do
var text = t.text
text = text.substring_from(1)
- if text.first == ' ' then text = text.substring_from(1)
+ if text.chars.first == ' ' then text = text.substring_from(1)
res.append(text.html_escape)
end
var str = res.to_s
if nit_name == ">>" then return "_right"
if nit_name == "<=>" then return "_starship"
- if nit_name.last == '=' then return "{nit_name.substring(0, nit_name.length-1)}__assign"
+ if nit_name.chars.last == '=' then return "{nit_name.substring(0, nit_name.length-1)}__assign"
return nit_name
end
end
for nclassdef in nclassdefs do
var name = nclassdef.n_id.text
- if not name.has('[') then # FIXME this is a temporary hack
+ if not name.chars.has('[') then # FIXME this is a temporary hack
code.add " if name == \"{name}\" then return new {name}.from_deserializer(self)"
end
end
# ok
var map = new MapIterable
-map.map["Riri"] = "Riri".to_a
-map.map["Fifi"] = "Fifi".to_a
-map.map["Loulou"] = "Loulou".to_a
+map.map["Riri"] = "Riri".chars.to_a
+map.map["Fifi"] = "Fifi".chars.to_a
+map.map["Loulou"] = "Loulou".chars.to_a
for k, v in map do print "{k}: {v.join(",")}"