--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import frontend
+import model_index
+import console
+
+redef class ToolContext
+ var opt_name_prefix = new OptionBool("", "--name-prefix")
+ var opt_full_name_prefix = new OptionBool("", "--full-name-prefix")
+ var opt_name_similarity = new OptionBool("", "--name-similarity")
+ var opt_full_name_similarity = new OptionBool("", "--full-name-similarity")
+ var opt_name = new OptionBool("", "--name")
+ var opt_full_name = new OptionBool("", "--full-name")
+
+ redef init do
+ option_context.add_option(opt_name_prefix, opt_full_name_prefix)
+ option_context.add_option(opt_name_similarity, opt_full_name_similarity)
+ option_context.add_option(opt_name, opt_full_name)
+ end
+end
+
+redef class MEntity
+ fun color: String do
+ if visibility == public_visibility then
+ return name.green
+ else if visibility == protected_visibility then
+ return name.yellow
+ else
+ return name.red
+ end
+ end
+end
+
+# build toolcontext
+var toolcontext = new ToolContext
+toolcontext.process_options(args)
+var args = toolcontext.option_context.rest
+
+if not args.length == 2 then
+ print "usage: test_model_index <nitfile> <search_query>"
+ exit 1
+end
+
+# build model
+var model = new Model
+var mbuilder = new ModelBuilder(model, toolcontext)
+var mmodules = mbuilder.parse_full([args.first])
+
+# process
+if mmodules.is_empty then return
+mbuilder.run_phases
+toolcontext.run_global_phases(mmodules)
+
+# Build index
+var index = new ModelIndex
+for mentity in model.private_view.mentities do
+ if mentity isa MClassDef or mentity isa MPropDef then continue
+ index.index(mentity)
+end
+
+var q = args[1]
+
+print "# {q}\n"
+
+var res
+if toolcontext.opt_name_prefix.value then
+ res = index.find_by_name_prefix(q)
+else if toolcontext.opt_full_name_prefix.value then
+ res = index.find_by_full_name_prefix(q)
+else if toolcontext.opt_name_similarity.value then
+ res = index.find_by_name_similarity(q)
+else if toolcontext.opt_full_name_similarity.value then
+ res = index.find_by_full_name_similarity(q)
+else if toolcontext.opt_name.value then
+ res = index.find_by_name(q)
+else if toolcontext.opt_full_name.value then
+ res = index.find_by_full_name(q)
+else
+ res = index.find(q)
+end
+
+res = res.sort(new ScoreComparator, new MEntityComparator).
+ uniq.
+ limit(10).
+ sort(new VisibilityComparator, new NameComparator)
+
+for e in res do
+ if toolcontext.opt_no_color.value then
+ print " * {e.score}: {e.mentity.name} ({e.mentity.full_name})"
+ else
+ print " * {e.score}: {e.mentity.color} ({e.mentity.full_name})"
+ end
+end
test_parser
test_highlight
test_model_visitor
+test_model_index
^nit
--- /dev/null
+Usage: [OPTION]... [ARG]...
+Use --help for help
--- /dev/null
+# Obj
+
+ * 1: Object (test_prog::Object)
--- /dev/null
+# elfves
+
+ * 4: Elf (test_prog::Elf)
+ * 5: Float (test_prog::Float)
+ * 5: Race (test_prog::Race)
+ * 5: careers (test_prog::careers)
+ * 5: excluded (excluded>)
+ * 5: excluded (excluded::excluded)
+ * 5: excluded (excluded)
+ * 5: game (test_prog>game>)
+ * 5: game (test_prog::game)
+ * 4: races (test_prog::races)
--- /dev/null
+# Dwarves
+
+ * 13: List (test_prog::List)
+ * 12: Sys (test_prog::Sys)
+ * 8: excluded (excluded>)
+ * 7: excluded (excluded)
+ * 13: game (test_prog>game>)
+ * 13: races (test_prog::races)
+ * 13: rpg (test_prog>rpg>)
+ * 13: rpg (test_prog::rpg)
+ * 9: test_prog (test_prog>)
+ * 9: test_prog (test_prog)
--- /dev/null
+# test_prof::Dwarves
+
+ * 5: Career (test_prog::Career)
+ * 4: Dwarf (test_prog::Dwarf)
+ * 6: Game (test_prog::Game)
+ * 6: Race (test_prog::Race)
+ * 5: Starter (test_prog::Starter)
+ * 5: careers (test_prog::careers)
+ * 7: character (test_prog::character)
+ * 6: game (test_prog::game)
+ * 5: races (test_prog::races)
+ * 7: rpg (test_prog::rpg)
--- /dev/null
+# Obj
+
+ * 3: * (test_prog::Float::*)
+ * 3: / (test_prog::Int::/)
+ * 3: == (test_prog::Object::==)
+ * 3: Elf (test_prog::Elf)
+ * 3: Int (test_prog::Int)
+ * 1: Object (test_prog::Object)
+ * 3: Sys (test_prog::Sys)
+ * 3: age (test_prog::Character::age)
+ * 3: rpg (test_prog>rpg>)
+ * 3: rpg (test_prog::rpg)
--- /dev/null
+# C
+
+ * 1: * (test_prog::Float::*)
+ * 1: * (test_prog::Int::*)
+ * 1: + (test_prog::Float::+)
+ * 1: - (test_prog::Int::-)
+ * 1: - (test_prog::Float::-)
+ * 1: / (test_prog::Float::/)
+ * 1: / (test_prog::Int::/)
+ * 1: > (test_prog::Int::>)
+ * 1: > (test_prog::Float::>)
+ * 1: Career (test_prog::Career)
--- /dev/null
+# to
+
+ * 2: * (test_prog::Float::*)
+ * 2: + (test_prog::Float::+)
+ * 2: - (test_prog::Float::-)
+ * 2: / (test_prog::Float::/)
+ * 2: / (test_prog::Int::/)
+ * 2: == (test_prog::Object::==)
+ * 2: > (test_prog::Int::>)
+ * 2: > (test_prog::Float::>)
+ * 1: to_f (test_prog::Int::to_f)
+ * 2: total_strengh (test_prog::Character::total_strengh)
--- /dev/null
+# Dwa
+
+ * 13: Dwarf (test_prog::Dwarf)
+ * 14: Game (test_prog::Game)
+ * 9: excluded (excluded>)
+ * 8: excluded (excluded)
+ * 14: game (test_prog>game>)
+ * 14: game (test_prog::game)
+ * 14: rpg (test_prog::rpg)
+ * 14: rpg (test_prog>rpg>)
+ * 10: test_prog (test_prog>)
+ * 9: test_prog (test_prog)
--- /dev/null
+# test_prog::C
+
+ * 1: Career (test_prog::Career)
+ * 2: Character (test_prog::Character)
+ * 3: Combatable (test_prog::Combatable)
+ * 3: Elf (test_prog::Elf)
+ * 3: Int (test_prog::Int)
+ * 3: Sys (test_prog::Sys)
+ * 4: game (test_prog::game)
+ * 3: rpg (test_prog::rpg)
+ * 3: test_prog (test_prog)
+ * 3: test_prog (test_prog>)
--- /dev/null
+# C
+
+ * 1: * (test_prog::Float::*)
+ * 1: * (test_prog::Int::*)
+ * 1: + (test_prog::Float::+)
+ * 1: - (test_prog::Int::-)
+ * 1: - (test_prog::Float::-)
+ * 1: / (test_prog::Float::/)
+ * 1: / (test_prog::Int::/)
+ * 1: > (test_prog::Int::>)
+ * 1: > (test_prog::Float::>)
+ * 1: Career (test_prog::Career)
--- /dev/null
+# to
+
+ * 2: * (test_prog::Int::*)
+ * 2: * (test_prog::Float::*)
+ * 2: + (test_prog::Float::+)
+ * 2: - (test_prog::Float::-)
+ * 2: / (test_prog::Float::/)
+ * 2: / (test_prog::Int::/)
+ * 2: > (test_prog::Float::>)
+ * 2: > (test_prog::Int::>)
+ * 1: to_f (test_prog::Int::to_f)
+ * 2: total_strengh (test_prog::Character::total_strengh)
--- /dev/null
+# C
+
+ * 1: Career (test_prog::Career)
+ * 2: Character (test_prog::Character)
+ * 3: Combatable (test_prog::Combatable)
--- /dev/null
+# Foo
+
+ * 3: != (test_prog::Object::!=)
+ * 3: + (test_prog::Int::+)
+ * 2: Bool (test_prog::Bool)
+ * 3: Elf (test_prog::Elf)
+ * 3: Float (test_prog::Float)
+ * 3: Int (test_prog::Int)
+ * 3: Sys (test_prog::Sys)
+ * 3: dps (test_prog::Weapon::dps)
+ * 3: rpg (test_prog::rpg)
+ * 3: rpg (test_prog>rpg>)
--- /dev/null
+# test_prog::C
+
+ * 1: Career (test_prog::Career)
+ * 2: Character (test_prog::Character)
+ * 3: Combatable (test_prog::Combatable)
+ * 3: Elf (test_prog::Elf)
+ * 3: Int (test_prog::Int)
+ * 3: Sys (test_prog::Sys)
+ * 3: rpg (test_prog::rpg)
+ * 3: test_prog (test_prog::test_prog)
+ * 3: test_prog (test_prog)
+ * 3: test_prog (test_prog>)
--- /dev/null
+# e
+
+ * 2: endurance_bonus (test_prog::Career::endurance_bonus)
+ * 1: excluded (excluded>)
+ * 1: excluded (excluded::excluded)
+ * 1: excluded (excluded)
+ * 3: endurance_bonus= (test_prog::Career::endurance_bonus=)
--- /dev/null
+# to
+
+ * 1: to_f (test_prog::Int::to_f)
+ * 3: total_endurance (test_prog::Character::total_endurance)
+ * 4: total_intelligence (test_prog::Character::total_intelligence)
+ * 2: total_strengh (test_prog::Character::total_strengh)
--- /dev/null
+# test_prog::
+
+ * 6: Bool (test_prog::Bool)
+ * 4: Elf (test_prog::Elf)
+ * 9: Game (test_prog::Game)
+ * 2: Int (test_prog::Int)
+ * 7: List (test_prog::List)
+ * 8: Race (test_prog::Race)
+ * 3: Sys (test_prog::Sys)
+ * 5: game (test_prog::game)
+ * 10: races (test_prog::races)
+ * 1: rpg (test_prog::rpg)
--- /dev/null
+# test_prog::C
+
+ * 1: Career (test_prog::Career)
+ * 2: Character (test_prog::Character)
+ * 3: Combatable (test_prog::Combatable)
+ * 4: age (test_prog::Character::age)
+ * 8: name (test_prog::Character::name)
+ * 7: quit (test_prog::Character::quit)
+ * 6: race (test_prog::Character::race)
+ * 5: sex (test_prog::Character::sex)
+ * 9: age= (test_prog::Character::age=)
+ * 10: sex= (test_prog::Character::sex=)
--- /dev/null
+# A
+
+ * 1: * (test_prog::Int::*)
+ * 1: * (test_prog::Float::*)
+ * 1: + (test_prog::Int::+)
+ * 1: + (test_prog::Float::+)
+ * 1: - (test_prog::Int::-)
+ * 1: - (test_prog::Float::-)
+ * 1: / (test_prog::Float::/)
+ * 1: / (test_prog::Int::/)
+ * 1: > (test_prog::Float::>)
+ * 1: > (test_prog::Int::>)
--- /dev/null
+# Foo
+
+ * 3: * (test_prog::Int::*)
+ * 3: / (test_prog::Int::/)
+ * 2: Bool (test_prog::Bool)
+ * 3: Elf (test_prog::Elf)
+ * 3: Float (test_prog::Float)
+ * 3: Int (test_prog::Int)
+ * 3: Sys (test_prog::Sys)
+ * 3: rpg (test_prog::rpg)
+ * 3: rpg (test_prog>rpg>)
+ * 3: sex (test_prog::Character::sex)
--- /dev/null
+test_prog Obj --name-prefix --no-color
+test_prog C --name-prefix --no-color
+test_prog e --name-prefix --no-color
+test_prog to --name-prefix --no-color
+test_prog C --full-name-prefix --no-color
+test_prog test_prog:: --full-name-prefix --no-color
+test_prog test_prog::C --full-name-prefix --no-color
+test_prog A --name-similarity --no-color
+test_prog Foo --name-similarity --no-color
+test_prog elfves --name-similarity --no-color
+test_prog Dwarves --full-name-similarity --no-color
+test_prog test_prof::Dwarves --full-name-similarity --no-color
+test_prog Obj --name --no-color
+test_prog C --name --no-color
+test_prog to --name --no-color
+test_prog Dwa --full-name --no-color
+test_prog test_prog::C --full-name --no-color
+test_prog C --no-color
+test_prog to --no-color
+test_prog Foo --no-color
+test_prog test_prog::C --no-color