#
# The generated tree will be something like this:
#
- # <ul>
- # <li>section 1</li>
- # <li>section 2
- # <ul>
- # <li>section 2.1</li>
- # <li>section 2.2</li>
- # </ul>
- # </li>
- # </ul>
+ # ~~~html
+ # <ul>
+ # <li>section 1</li>
+ # <li>section 2
+ # <ul>
+ # <li>section 2.1</li>
+ # <li>section 2.2</li>
+ # </ul>
+ # </li>
+ # </ul>
+ # ~~~
fun tpl_tree(limit: Int): Template do
return tpl_tree_intern(limit, 1)
end
# 2. Apply the method `run`, that will search and return a solution.
# 3. Retrieve information from the solution.
#
-# ~~~~
+# ~~~~nitish
# var p: BacktrackProblem = new MyProblem
# var solver = p.solve
# var res = solver.run
# The constraint is that two queens cannot be on the same row, column or diagonal.
#
# Eg. a solution to the 8-queens problem is
-# ~~~
+# ~~~raw
# +--------+
# |Q.......|
# |....Q...|
# 2. Apply the method `run`, that will search and return a solution.
# 3. Retrieve information from the solution.
#
-# ~~~~
+# ~~~~nitish
# var p: SearchProblem = new MyProblem
# var res = p.astar.run
# if res != null then print "Found plan with {res.depth} actions, that cost {res.cost}: {res.plan.join(", ")}"
# The general action to be performed
#
- # Example :
- # ~~~
+ # ~~~nitish
+ # # TODO better example
# intent.action = intent_action.view.to_s
# ~~~
fun action=(action: String)
# Add category to the intent
# Only activities providing all of the requested categories will be used
#
- # Example :
- # ~~~
+ # ~~~nitish
+ # # TODO better example
# intent.add_category(intent_category.home.to_s)
# ~~~
# Returns `self` allowing fluent programming
# Add a flag to be used by the intent
#
- # Example :
- # ~~~
+ # ~~~nitish
+ # # TODO better example
# intent.add_flags(intent_flag.activity_new_task)
# ~~~
# Returns `self` allowing fluent programming
# Services to show notification in the Android status bar
#
-# ~~~~
+# ~~~~nitish
# # Create and show a notification
# var notif = new Notification("My Title", "Some content")
# notif.ticker = "Ticker text"
# # Update the notification
# notif.text = "New content!"
# notif.ongoing = true # Make it un-dismissable
-# nofif.show
+# notif.show
#
# # Hide the notification
# notif.cancel
# The sensor support is implemented in android_app module, so the user can enable the type of sensor he wants to use.
# There is an example of how you can use the android sensors in nit/examples/mnit_ballz :
#
-# ~~~~
+# ~~~~nitish
+# #FIXME rewrite the example
# var app = new MyApp
# app.sensors_support_enabled = true
# app.accelerometer.enabled = true
#
# User has to manage local stack deallocation himself
#
- # Example :
- # ~~~
+ # ~~~nitish
# var foo = new HashMap[JavaString, JavaObject]
# # ...
# for key, value in foo do
# key.delete_local_ref
# value.delete_local_ref
# end
- # ~~~
+ # ~~~
# *You should use Nit getters instead and get each value one by one*
fun all: nullable HashMap[JavaString, JavaObject]
do
#
# User has to manage local stack deallocation himself
#
- # Example :
- # ~~~
- # var a_hash_set = shared_preferences.string_set("A key")
- # ...
+ # ~~~nitish
+ # var a_hash_set = app.shared_preferences.string_set("A key")
+ # # ...
# for element in a_hash_set do element.delete_local_ref
# ~~~
fun string_set(key: String): HashSet[JavaString]
#
# User has to manage local stack deallocation himself
#
- # Example :
- # ~~~
+ # ~~~nitish
# var foo = new HashSet[JavaString]
- # shared_preferences.add_string_set("A key", foo)
+ # app.shared_preferences.add_string_set("A key", foo)
# for element in foo do element.delete_local_ref
# ~~~
fun add_string_set(key: String, value: HashSet[JavaString]): SharedPreferences
# methods of the main thread to customize the response to a given event.
#
# This graph shows the path of a button click:
-# ~~~
+# ~~~raw
# UI Thread # Main thread
#
# User
# Utility to select options to create the VM using `create_jvm`
#
# Usage example:
-# ~~~~
+#
+# ~~~~nitish
# var builder = new JavaVMBuilder
# builder.options.add "-Djava.class.path=."
# var jvm = builder.create_jvm
# A Link Reference.
# Links that are specified somewhere in the mardown document to be reused as shortcuts.
#
-# Example:
-#
-# [1]: http://example.com/ "Optional title"
+# ~~~raw
+# [1]: http://example.com/ "Optional title"
+# ~~~
class LinkRef
# Link href
#
# The input event file is made of event descriptions, one event by line.
#
-# ~~~
+# ~~~raw
# 10 click 10.0 20.0
# 20 quit
# ~~~
# Draw image by specifying the positon of each image corners
# Corners are in counter-clockwise order stating top left
# a is top left, b is bottom left, c is bottom right and d is top right
- # ~~~
+ # ~~~raw
# a-d
# | |
# b-c
# Return a view of `e` in the poset.
# This allows to asks manipulate elements in thier relation with others elements.
#
- # var poset: POSet[Something] # ...
- # for x in poset do
- # for y in poset[x].direct_greaters do
- # print "{x} -> {y}"
- # end
+ # ~~~nitish
+ # var poset: POSet[Something] # ...
+ # for x in poset do
+ # for y in poset[x].direct_greaters do
+ # print "{x} -> {y}"
# end
+ # end
+ # ~~~
#
# REQUIRE: has(e)
fun [](e: E): POSetElement[E]
#
# For instance, one common usage is to add a specific attribute for each poset a class belong.
#
-# class Thing
-# var in_some_relation: POSetElement[Thing]
-# var in_other_relation: POSetElement[Thing]
-# end
-# var t: Thing # ...
-# t.in_some_relation.greaters
-#
+# ~~~nitish
+# class Thing
+# var in_some_relation: POSetElement[Thing]
+# var in_other_relation: POSetElement[Thing]
+# end
+# var t: Thing
+# # ...
+# t.in_some_relation.greaters
+# ~~~
class POSetElement[E: Object]
# The poset self belong to
var poset: POSet[E]
# document from a system identifier. It is the exact
# equivalent of the following:
#
- # var source = new InputSouce
- # source.system_id = system_id
- # parse(source)
+ # ~~~nitish
+ # var source = new InputSouce
+ # source.system_id = system_id
+ # parse(source)
+ # ~~~
#
# If the system identifier is a URL, it must be fully resolved
# by the application before it is passed to the parser.
# Subclasses often provide a more efficient implementation.
#
# Because of the `iterator` method, Collections instances can use
-# the `for` control structure:
+# the `for` control structure.
#
-# var x: Collection[U]
-# # ...
-# for u in x do
-# # u is a U
-# # ...
-# end
+# ~~~nitish
+# var x: Collection[U]
+# # ...
+# for u in x do
+# # u is a U
+# # ...
+# end
+# ~~~
#
-# that is equivalent with
+# that is equivalent with the following:
#
-# var x: Collection[U]
-# # ...
-# var i = x.iterator
-# while i.is_ok do
-# var u = i.item # u is a U
-# # ...
-# i.next
-# end
+# ~~~nitish
+# var x: Collection[U]
+# # ...
+# var i = x.iterator
+# while i.is_ok do
+# var u = i.item # u is a U
+# # ...
+# i.next
+# end
+# ~~~
interface Collection[E]
# Get a new iterator on the collection.
fun iterator: Iterator[E] is abstract
#
# In external file `example.tpl`:
#
-# <!DOCTYPE html>
-# <html lang="en">
-# <head>
-# <title>%TITLE%</title>
-# </head>
-# <body>
-# <h1>%TITLE%</h1>
-# <p>%ARTICLE%</p>
-# </body>
-# </html>
+# ~~~html
+# <!DOCTYPE html>
+# <html lang="en">
+# <head>
+# <title>%TITLE%</title>
+# </head>
+# <body>
+# <h1>%TITLE%</h1>
+# <p>%ARTICLE%</p>
+# </body>
+# </html>
+# ~~~
#
# Loading the template file using `TemplateString`:
#
# To create the new node `n`, we need to attach the child to it.
# But, to put `n` where `c` was in `p`, the place has to be remembered.
#
- # var p: AExpr
- # var c = p.c
- # var h = c.detach_with_placeholder
- # var n = astbuilder.make_XXX(c)
- # h.replace_with(n)
+ # ~~~nitish
+ # var p: AExpr
+ # var c = p.c
+ # var h = c.detach_with_placeholder
+ # var n = astbuilder.make_XXX(c)
+ # h.replace_with(n)
+ # ~~~
fun detach_with_placeholder: AExpr
do
var h = new APlaceholderExpr.make
# In Nit, for each super-class of a type, there is a equivalent super-type.
#
# Example:
+ #
+ # ~~~nitish
# class G[T, U] end
# class H[V] super G[V, Bool] end
+ #
# H[Int] supertype_to G #-> G[Int, Bool]
+ # ~~~
#
# REQUIRE: `super_mclass` is a super-class of `self`
# REQUIRE: `self.need_anchor implies anchor != null and self.can_resolve_for(anchor, null, mmodule)`
#
# ## Example 1
#
- # class G[E] end
- # class H[F] super G[F] end
- # class X[Z] end
+ # ~~~
+ # class G[E] end
+ # class H[F] super G[F] end
+ # class X[Z] end
+ # ~~~
#
# * Array[E].resolve_for(H[Int]) #-> Array[Int]
# * Array[E].resolve_for(G[Z], X[Int]) #-> Array[Z]
#
# ## Example 2
#
- # class A[E]
- # fun foo(e:E):E is abstract
- # end
- # class B super A[Int] end
+ # ~~~
+ # class A[E]
+ # fun foo(e:E):E is abstract
+ # end
+ # class B super A[Int] end
+ # ~~~
#
# The signature on foo is (e: E): E
# If we resolve the signature for B, we get (e:Int):Int
#
# ## Example 3
#
- # class A[E]
- # fun foo(e:E) is abstract
- # end
- # class B[F]
- # var a: A[Array[F]]
- # fun bar do a.foo(x) # <- x is here
- # end
+ # ~~~nitish
+ # class A[E]
+ # fun foo(e:E):E is abstract
+ # end
+ # class C[F]
+ # var a: A[Array[F]]
+ # fun bar do a.foo(x) # <- x is here
+ # end
+ # ~~~
#
# The first question is: is foo available on `a`?
#
# The static type of a is `A[Array[F]]`, that is an open type.
# in order to find a method `foo`, whe must look at a resolved type.
#
- # A[Array[F]].anchor_to(B[nullable Object]) #-> A[Array[nullable Object]]
+ # A[Array[F]].anchor_to(C[nullable Object]) #-> A[Array[nullable Object]]
#
# the method `foo` exists in `A[Array[nullable Object]]`, therefore `foo` exists for `a`.
#
#
# the signature of `foo` is `foo(e:E)`, thus we must resolve the type E
#
- # E.resolve_for(A[Array[F]],B[nullable Object]) #-> Array[F]
+ # E.resolve_for(A[Array[F]],C[nullable Object]) #-> Array[F]
#
# The resolution can be done because `E` make sense for the class A (see `can_resolve_for`)
#
#
# Comparison is made with the formula:
#
-# a.concern_rank + a.booster_rank <=> b.concern_rank + b.booster_ran
+# ~~~nitish
+# a.concern_rank + a.booster_rank <=> b.concern_rank + b.booster_ran
+# ~~~
#
# If both `a` and `b` have the same ranking,
# ordering is based on lexicographic comparison of `a.name` and `b.name`
#
# For example, if the source code contains:
#
+# ~~~nitish
# fun foo(a: A, b: B, c: C)
+# ~~~
#
# The `MSignature` node will contain a property
# `parameter_names = ["a", "b", "c"]` so the MSignature can be reconstructed
# `Licence comments` are attached to the top of the file
# no blank line before, one after.
#
-# # This is a licence comment
+# ~~~nitish
+# # This is a licence comment
#
-# # Documentation for module `foo`
-# module foo
+# # Documentation for module `foo`
+# module foo
+# ~~~
#
# `ADoc` are documentation comments attached to a `AModule`, `AClassdef`, `APropdef`.
#
# They are printed before the definition with a blank line before and no after
# at the same indentation level than the definition.
#
-# # Documentation for module `foo`
-# module foo
+# ~~~nitish
+# # Documentation for module `foo`
+# module foo
#
-# # Documentation for class `Bar`
-# class Bar
-# # Documentation for method `baz`
-# fun baz do end
-# end
+# # Documentation for class `Bar`
+# class Bar
+# # Documentation for method `baz`
+# fun baz do end
+# end
+# ~~~
#
# `Block comments` are comments composed of one or more line rattached to nothing.
# They are displayed with one blank line before and after at current indent level.
#
-# <blank>
-# # block
-# # comment
-# <blank>
+# ~~~nitish
+# <blank>
+# # block
+# # comment
+# <blank>
+# ~~~
#
# `Attached comments` are comments attached to a production.
# They are printed as this.
#
-# fun foo do # attached comment
-# end
+# ~~~nitish
+# fun foo do # attached comment
+# end
+# ~~~
#
# `nitpretty` automatically remove multiple blanks between comments:
#
-# # Licence
-# # ...
-# <blank>
-# # Block comment
+# ~~~nitish
+# # Licence
+# # ...
+# <blank>
+# # Block comment
+# ~~~
#
# ### Inlining
#
# * There is a blank between each class definition
# * There is no blank line at the end of the module
#
-# # Documentation for module `foo`
-# module foo
+# ~~~nitish
+# # Documentation for module `foo`
+# module foo
#
-# import a
-# # import b
-# import c
+# import a
+# # import b
+# import c
#
-# # Documentation for class `Bar`
-# class Bar end
+# # Documentation for class `Bar`
+# class Bar end
#
-# class Baz end # not a `ADoc` comment
+# class Baz end # not a `ADoc` comment
+# ~~~
#
#
# ### Classes
# * There is a blank between each block definition
# * There no blank line at the end of the class definition
#
-# # Documentation for class `Bar`
-# class Bar end
+# ~~~nitish
+# # Documentation for class `Bar`
+# class Bar end
#
-# class Baz
-# super Bar
+# class Baz
+# super Bar
#
-# fun a is abstract
-# private fun b do end
+# fun a is abstract
+# private fun b do end
#
-# fun c do
-# # ...
-# end
-# end
+# fun c do
+# # ...
+# end
+# end
+# ~~~
#
-# Generic types have no espace after or before brackets and are separated by a comma and a space:
+# Generic types have no space after or before brackets and are separated by a comma and a space:
#
-# class A[E: Type1, F: Type1] do end
+# ~~~nitish
+# class A[E: Type1, F: Type1] end
+# ~~~
#
# ### Blocks
#
# * Inlined productions have no blank lines between them
# * Block productions have a blank before and after
#
-# var a = 10
-# var b = 0
+# ~~~nitish
+# var a = 10
+# var b = 0
#
-# if a > b then
-# # is positive
-# print "positive"
-# end
+# if a > b then
+# # is positive
+# print "positive"
+# end
#
-# print "end"
+# print "end"
+# ~~~
#
# ### Calls and Binary Ops
#
# Arguments are always printed separated with a comma and a space:
#
-# foo(a, b, c)
+# ~~~nitish
+# foo(a, b, c)
+# ~~~
#
# Binary ops are always printed wrapped with spaces:
#
-# var c = 1 + 2
+# ~~~nitish
+# var c = 1 + 2
+# ~~~
#
# Calls and binary ops can be splitted to fit the `max-size` constraint.
# Breaking priority is given to arguments declaration after the comma.
#
-# return foo("aaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
-# "cccccccccccccccccccccccccc")
+# ~~~nitish
+# return foo("aaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
+# "cccccccccccccccccccccccccc")
+# ~~~
#
# Binary ops can also be broken to fit the `max-size` limit:
#
-# return "aaaaaaaaaaaaaaaaaaaaaaaaaa" + "bbbbbbbbbbbbbbbbbbbbbbbbbbb" +
-# "cccccccccccccccccccccccccc"
-#
+# ~~~nitish
+# return "aaaaaaaaaaaaaaaaaaaaaaaaaa" + "bbbbbbbbbbbbbbbbbbbbbbbbbbb" +
+# "cccccccccccccccccccccccccc"
+# ~~~
module nitpretty
import template
redef class AArrayExpr
# `[x,y]` is replaced with
#
- # var t = new Array[X].with_capacity(2)
- # t.add(x)
- # t.add(y)
- # t
+ # ~~~nitish
+ # var t = new Array[X].with_capacity(2)
+ # t.add(x)
+ # t.add(y)
+ # t
+ # ~~~
redef fun accept_transform_visitor(v)
do
var nblock = v.builder.make_block
redef class ASendReassignFormExpr
# `x.foo(y)+=z` is replaced with
#
- # x.foo(y) = x.foo(y) + z
+ # ~~~nitish
+ # x.foo(y) = x.foo(y) + z
+ # ~~~
#
# witch is, in reality:
#
- # x."foo="(y, x.foo(y)."+"(z))
+ # ~~~nitish
+ # x."foo="(y, x.foo(y)."+"(z))
+ # ~~~
redef fun accept_transform_visitor(v)
do
var nblock = v.builder.make_block