1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Parsing of commands understood by documentation tools.
17 # This can be through:
18 # * `nitx` commands like `code: MEntity::name`
19 # * `nitdoc` wikilinks like `[[doc: MEntity::name]]`
24 # A command aimed at a documentation tool like `nitdoc` or `nitx`.
26 # `DocCommand` are generally of the form `command: args`.
29 # Original command string.
30 fun string
: String is abstract
33 fun name
: String is abstract
37 # FIXME: define a syntax
38 fun args
: Array[String] is abstract
42 # Returns a concrete instance of `DocCommand` depending on the string.
43 new(command_string
: String) do
44 if command_string
.has_prefix
("doc:") then
45 return new ArticleCommand(command_string
)
46 else if command_string
.has_prefix
("comment:") then
47 return new CommentCommand(command_string
)
48 else if command_string
.has_prefix
("list:") then
49 return new ListCommand(command_string
)
50 else if command_string
.has_prefix
("param:") then
51 return new ParamCommand(command_string
)
52 else if command_string
.has_prefix
("return:") then
53 return new ReturnCommand(command_string
)
54 else if command_string
.has_prefix
("new:") then
55 return new NewCommand(command_string
)
56 else if command_string
.has_prefix
("call:") then
57 return new CallCommand(command_string
)
58 else if command_string
.has_prefix
("code:") then
59 return new CodeCommand(command_string
)
61 return new UnknownCommand(command_string
)
64 redef fun to_s
do return string
67 # Used to factorize initialization of DocCommands.
68 abstract class AbstractDocCommand
72 redef var name
is noinit
73 redef var args
= new Array[String]
77 var str
= new FlatBuffer
79 while i
< string
.length
do
82 if c
== ':' then break
85 name
= str
.write_to_string
87 args
.add string
.substring_from
(i
).trim
91 # A `DocCommand` not recognized by documentation tools.
93 # Used to provide warnings or any other behavior for unexisting commands.
95 super AbstractDocCommand
98 # A `DocCommand` that includes the documentation article of a `MEntity`.
100 # Syntax: `doc: MEntity::name`.
102 super AbstractDocCommand
105 # A `DocCommand` that includes the MDoc of a `MEntity`.
107 # Syntax: `comment: MEntity::name`.
109 super AbstractDocCommand
112 # A `DocCommand` that includes a list of something.
114 # Syntax: `list:kind: <arg>`.
116 super AbstractDocCommand
119 # A `DocCommand` that includes the list of methods tanking a `MType` as parameter.
121 # Syntax: `param: MType`.
123 super AbstractDocCommand
126 # A `DocCommand` that includes the list of methods returning a `MType` as parameter.
128 # Syntax: `param: MType`.
130 super AbstractDocCommand
133 # A `DocCommand` that includes the list of methods creating new instances of a specific `MType`
135 # Syntax: `new: MType`.
137 super AbstractDocCommand
140 # A `DocCommand` that includes the list of methods calling a specific `MProperty`.
142 # Syntax: `call: MEntity::name`.
144 super AbstractDocCommand
147 # A `DocCommand` that includes the source code of a `MEntity`.
150 # * `code: MEntity::name`
151 # * `./src/file.nit` to include source code from a file.
152 # * `./src/file.nit:1,2--3,4` to select code between positions.
154 super AbstractDocCommand