A production is a node without text but that usually has children.
nitc :: Prod :: _first_location
Location on the first token after the start of a productionnitc :: Prod :: _first_token
The first token of the production in the ASTnitc :: Prod :: _last_token
The last token of the production in the ASTnitc :: Prod :: _n_annotations
All the annotations attached directly to the nodenitc :: Prod :: collect_comments
Collect allTComment
contained in the production
nitc :: Prod :: defaultinit
nitc :: Prod :: first_location
Location on the first token after the start of a productionnitc :: Prod :: first_location=
Location on the first token after the start of a productionnitc :: Prod :: first_token
The first token of the production in the ASTnitc :: Prod :: first_token=
The first token of the production in the ASTnitc :: Prod :: get_annotations
Return all its annotations of a given name in the order of their declarationnitc :: Prod :: get_single_annotation
Try to get its single annotation with a given namenitc :: Prod :: last_token
The last token of the production in the ASTnitc :: Prod :: last_token=
The last token of the production in the ASTnitc :: Prod :: n_annotations
All the annotations attached directly to the nodenitc :: Prod :: n_annotations=
All the annotations attached directly to the nodenitc :: Prod :: start_token
The token where the production really start (skipping ADoc).nitc :: pretty $ Prod :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: pretty $ Prod :: collect_length
Collect the length (inChar
) of the node.
nitc $ Prod :: replace_with
Replace itself with an other node in the ASTnitc :: pretty $ Prod :: was_inline
Doesself
was written in one line before transformation?
nitc :: Prod :: _first_location
Location on the first token after the start of a productionnitc :: Prod :: _first_token
The first token of the production in the ASTnitc :: ANode :: _is_broken
The indication that the node did not pass some semantic verifications.nitc :: Prod :: _last_token
The last token of the production in the ASTnitc :: Prod :: _n_annotations
All the annotations attached directly to the nodenitc :: ANode :: accept_ast_validation
nitc :: ANode :: accept_auto_super_init
nitc :: ANode :: accept_flow_visitor
nitc :: ANode :: accept_forward_analysis
Apply the forward analysisv
to self
.
nitc :: ANode :: accept_literal
nitc :: ANode :: accept_post_typing
nitc :: ANode :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: ANode :: accept_reaching_defs
Apply a ReachingDefsAnalysis toself
.
nitc :: ANode :: accept_regex_visitor
nitc :: ANode :: accept_scope_visitor
nitc :: ANode :: accept_simple_misc
nitc :: ANode :: accept_string_finder
nitc :: ANode :: after_simple_misc
nitc :: ANode :: bad_expr_message
An additional information message to explain the role of a child expression.nitc :: ANode :: check_callsite
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: ANode :: collect_annotations_by_name
Do a deep search and return an array of node that are annotatednitc :: Prod :: collect_comments
Collect allTComment
contained in the production
nitc :: ANode :: collect_length
Collect the length (inChar
) of the node.
nitc :: ANode :: collect_tokens_by_text
Do a deep search and return an array of tokens that match a given textnitc :: ANode :: common_parent
The most specific common parent betweenself
and other
nitc :: ANode :: create_contracts
nitc :: ANode :: decorate_tag
Add aditionnal information on a child-token and return an additionnal HInfoBox on itcore :: Object :: defaultinit
core :: Cloneable :: defaultinit
nitc :: ANode :: defaultinit
nitc :: Prod :: defaultinit
nitc :: ANode :: do_cloneable
nitc :: Prod :: first_location
Location on the first token after the start of a productionnitc :: Prod :: first_location=
Location on the first token after the start of a productionnitc :: Prod :: first_token
The first token of the production in the ASTnitc :: Prod :: first_token=
The first token of the production in the ASTnitc :: ANode :: force_block=
Forceself
to be rendered as a block.
nitc :: ANode :: force_inline=
Forceself
to be rendered as a line.
nitc :: ANode :: full_transform_visitor
nitc :: Prod :: get_annotations
Return all its annotations of a given name in the order of their declarationnitc :: Prod :: get_single_annotation
Try to get its single annotation with a given namenitc :: ANode :: hot_location
The location of the important part of the node (identifier or whatever)nitc :: ANode :: is_broken=
The indication that the node did not pass some semantic verifications.nitc :: ANode :: is_noserialize
Is this node annotated to not be made serializable?core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: ANode :: is_serialize
Is this node annotated to be made serializable?nitc :: ANode :: is_structural
Isself
a token or a pure-structural production like AQId
?
nitc :: Prod :: last_token
The last token of the production in the ASTnitc :: Prod :: last_token=
The last token of the production in the ASTnitc :: ANode :: must_be_block
Doesself
have to be rendered as a block?
nitc :: ANode :: must_be_inline
Doesself
have be rendered as a line?
nitc :: Prod :: n_annotations
All the annotations attached directly to the nodenitc :: Prod :: n_annotations=
All the annotations attached directly to the nodecore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: ANode :: parentize_tokens
Visit the AST and computes advanced AST attributes on Tokens and Prodnitc :: ANode :: replace_child
Replace a child with an other node in the ASTnitc :: ANode :: replace_with
Replace itself with an other node in the ASTnitc :: Prod :: start_token
The token where the production really start (skipping ADoc).nitc :: ANode :: was_inline
Doesself
was written in one line before transformation?
nitc :: AClasskind
The modifier for the kind of class (abstract, interface, etc.)nitc :: AAsNotNullableExternCall
A single callback declaration on a cast to a non-nullable type= something
nitc :: ABinOpHelper
Used to factorize work on Or, And, Implies and Binop expressions.nitc :: ABraFormExpr
Whatever looks-like a call of the brackets[]
operator.
x[y,z]+=t
x.m(y)=z
. OR just a simple assignment.
x.m(y)+=z
. OR just a simple complex assignment.
nitc :: ACallrefExpr
A reference to a method with a captured receiver. eg.&x.foo
or just &foo
is self is captured.
class
)
nitc :: AIfexprExpr
Aif
expression (ternary conditional). eg. if true then 1 else 0
self
is implicit
nitc :: ALambdaExpr
nitc :: AModuledecl
The declaration of the module with the documentation, name, and annotations+= something
nitc :: AStdClassdef
A standard class definition with a name, superclasses and propertiesnitc :: AVarargExpr
An ellipsis notation used to pass an expression as it, in a vararg parameternitc :: AugmentedStringFormExpr
Any kind of string form with augmentations from prefixes or suffixes
# Ancestor of all productions
# A production is a node without text but that usually has children.
abstract class Prod
super ANode
# All the annotations attached directly to the node
var n_annotations: nullable AAnnotations = null is writable
# Return all its annotations of a given name in the order of their declaration
# Retun an empty array if no such an annotation.
fun get_annotations(name: String): Array[AAnnotation]
do
var res = new Array[AAnnotation]
var nas = n_annotations
if nas != null then for na in nas.n_items do
if na.name != name then continue
res.add(na)
end
if self isa AClassdef then for na in n_propdefs do
if na isa AAnnotPropdef then
if na.name != name then continue
res.add na
end
end
return res
end
redef fun replace_with(n: ANode)
do
super
assert n isa Prod
if not isset n._location and isset _location then n._location = _location
end
end
src/parser/parser_nodes.nit:424,1--458,3
redef class Prod
# Location on the first token after the start of a production
# So outside the production for epsilon production
var first_location: nullable Location
# Join the text of all visited tokens
fun collect_text: String
do
var v = new TextCollectorVisitor
v.enter_visit(self)
assert v.text != ""
return v.text
end
end
src/parser/parser_work.nit:161,1--174,3
redef class Prod
# The first token of the production in the AST
# Computed by `parentize_tokens`
var first_token: nullable Token = null
# The last token of the production in the AST
# Computed by `parentize_tokens`
var last_token: nullable Token = null
# Is the production contained in full block of line?
# Computed by `parentize_tokens`
fun is_block: Bool
do
if first_token == null or last_token == null then return false
#sys.stderr.write "{self}@{location}: start={first_token.is_starting_line} {first_token.inspect}@{first_token.location} ; end={last_token.is_ending_line} {last_token.inspect}@{last_token.location}\n"
return first_token.is_starting_line and last_token.is_ending_line
end
# Is the production a part of a single line (without being a block)
# Computed by `parentize_tokens`
fun is_span: Bool
do
if first_token == null or last_token == null then return false
return not is_block and location.line_start == location.line_end
end
# A XML representation of the AST
# Productions and token become elements
#
# detached tokens and whitespaces are preserved in the XML
#
# ~~~
# import parser_util
# var text = "y += foo"
# var ast = (new ToolContext).parse_something(text)
# assert ast isa AExpr
# ast.parentize_tokens
# assert ast.to_xml.write_to_string == """<ACallReassignExpr><AQid><TId>y</TId></AQid> <APlusAssignOp><TPluseq>+=</TPluseq></APlusAssignOp> <ACallExpr><AQid><TId>foo</TId></AQid></ACallExpr></ACallReassignExpr>"""
# ~~~
fun to_xml: HTMLTag
do
var res = new HTMLTag("AST")
var stack = new Array[HTMLTag]
var c = first_token
while c != null do
if c != first_token then res.append(c.blank_before)
var sp = c.starting_prods
if sp != null then for p in sp do
var tag = new HTMLTag(p.class_name)
res.add tag
stack.add res
res = tag
end
var tag = new HTMLTag(c.class_name)
res.add tag
tag.append c.text
var ep = c.ending_prods
if ep != null then for p in ep do
res = stack.pop
end
if c == last_token then
c = null
else
c = c.next_token
end
end
assert stack.is_empty
return res.children.first
end
end
src/astutil.nit:37,1--107,3
redef class Prod
super ANode
# Try to get its single annotation with a given name
# If there is no such an annotation, null is returned.
# If there is more than one annotation, a error message is printed and the first annotation is returned
fun get_single_annotation(name: String, modelbuilder: ModelBuilder): nullable AAnnotation
do
var res = get_annotations(name)
if res.is_empty then return null
if res.length > 1 then
modelbuilder.error(res[1], "Syntax Error: multiple `{name}`. A previous one is defined line {res[0].location.line_start}.")
end
return res.first
end
end
src/annotation.nit:22,1--37,3
redef class Prod
redef fun accept_pretty_printer(v) do v.visit first_token
# The token where the production really start (skipping ADoc).
private fun start_token: nullable Token do return first_token
# Collect all `TComment` contained in the production
# (between `start_token` and `end_token`).
private fun collect_comments: Array[TComment] do
var res = new Array[TComment]
if start_token == null or last_token == null then return res
var token = start_token
while token != last_token do
if token isa TComment then res.add token
token = token.next_token
end
return res
end
redef fun collect_length do
var res = 0
if start_token == null or last_token == null then return res
var token = start_token
while token != last_token do
res += token.text.length
token = token.next_token
end
res += token.text.length
return res
end
redef fun was_inline do
return start_token.location.line_start == last_token.location.line_end
end
end
src/pretty.nit:370,1--408,3