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
("param:") then
49 return new ParamCommand(command_string
)
50 else if command_string
.has_prefix
("return:") then
51 return new ReturnCommand(command_string
)
52 else if command_string
.has_prefix
("new:") then
53 return new NewCommand(command_string
)
54 else if command_string
.has_prefix
("call:") then
55 return new CallCommand(command_string
)
56 else if command_string
.has_prefix
("code:") then
57 return new CodeCommand(command_string
)
59 return new UnknownCommand(command_string
)
62 redef fun to_s
do return string
65 # Used to factorize initialization of DocCommands.
66 abstract class AbstractDocCommand
70 redef var name
is noinit
71 redef var args
= new Array[String]
75 var str
= new FlatBuffer
77 while i
< string
.length
do
80 if c
== ':' then break
83 name
= str
.write_to_string
85 args
.add string
.substring_from
(i
).trim
89 # A `DocCommand` not recognized by documentation tools.
91 # Used to provide warnings or any other behavior for unexisting commands.
93 super AbstractDocCommand
96 # A `DocCommand` that includes the documentation article of a `MEntity`.
98 # Syntax: `doc: MEntity::name`.
100 super AbstractDocCommand
103 # A `DocCommand` that includes the MDoc of a `MEntity`.
105 # Syntax: `comment: MEntity::name`.
107 super AbstractDocCommand
110 # A `DocCommand` that includes the list of methods tanking a `MType` as parameter.
112 # Syntax: `param: MType`.
114 super AbstractDocCommand
117 # A `DocCommand` that includes the list of methods returning a `MType` as parameter.
119 # Syntax: `param: MType`.
121 super AbstractDocCommand
124 # A `DocCommand` that includes the list of methods creating new instances of a specific `MType`
126 # Syntax: `new: MType`.
128 super AbstractDocCommand
131 # A `DocCommand` that includes the list of methods calling a specific `MProperty`.
133 # Syntax: `call: MEntity::name`.
135 super AbstractDocCommand
138 # A `DocCommand` that includes the source code of a `MEntity`.
141 # * `code: MEntity::name`
142 # * `./src/file.nit` to include source code from a file.
143 # * `./src/file.nit:1,2--3,4` to select code between positions.
145 super AbstractDocCommand