Top Description Fields Constructors Methods
org.python.indexer.demos

pack-priv Class DocStringParser

extends Object
Class Inheritance
Imports
org.python.indexer.Indexer, .NBinding, .Ref, .Scope, .StyleRun, org.python.indexer.ast.NStr, java.util.ArrayList, .HashSet, .List, .Set, java.util.regex.Matcher, .Pattern

Scans doc strings looking for interesting stuff to highlight or hyperlink.

Field Summary

Modifier and TypeField and Description
private NStr
private int
private String
private String
private static final String
IDENT

Matches an unqualified Python identifier.

private Linker
private static final int
MIN_TYPE_NAME_LENGTH

Only try to resolve possible qnames of at least this length.

private Set<Integer>
private boolean
private Scope
private List<StyleRun>
private static final Pattern
TYPE_NAME

Matches probable type names.

Constructor Summary

AccessConstructor and Description
public
DocStringParser(String
the doc string or doc-comment text
comment
,
NStr
the AST node for the doc string
node
,
Linker linker)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private void
addStyle(int beg, int len, NBinding nb)

private void
addStyle(int beg, int len, StyleRun.Type type)

private void
checkForReference(int offset, String qname)

Look for the name in the current scope.

public List<StyleRun>

Returns:

the non-null but possibly empty list of additional styles for the doc string.
highlight
()

Main entry point.

public boolean
private void
scanCommentForTypeNames()

Try to match potential type names against the code graph.

public void
setResolveReferences(boolean
true to do name resolution, false to guess purely based on syntax in the doc string. Pass false if you're using the highlighter to syntax-highlight a file (i.e. no code graph or indexing.)
resolve
)

Configures whether to highlight syntactically or semantically.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

docNodeback to summary
private NStr docNode
docOffsetback to summary
private int docOffset
docStringback to summary
private String docString
fileback to summary
private String file
IDENTback to summary
private static final String IDENT

Matches an unqualified Python identifier.

linkerback to summary
private Linker linker
MIN_TYPE_NAME_LENGTHback to summary
private static final int MIN_TYPE_NAME_LENGTH

Only try to resolve possible qnames of at least this length. Helps cut down on noise.

offsetsback to summary
private Set<Integer> offsets
resolveReferencesback to summary
private boolean resolveReferences
scopeback to summary
private Scope scope
stylesback to summary
private List<StyleRun> styles
TYPE_NAMEback to summary
private static final Pattern TYPE_NAME

Matches probable type names. Does loose matching; caller must do more checks.

Constructor Detail

DocStringParserback to summary
public DocStringParser(String comment, NStr node, Linker linker)

Constructor.

Parameters
comment:String

the doc string or doc-comment text

node:NStr

the AST node for the doc string

Method Detail

addStyleback to summary
private void addStyle(int beg, int len, NBinding nb)
addStyleback to summary
private void addStyle(int beg, int len, StyleRun.Type type)
checkForReferenceback to summary
private void checkForReference(int offset, String qname)

Look for the name in the current scope. If found, and its qname is a valid binding in the graph, record a reference.

highlightback to summary
public List<StyleRun> highlight()

Main entry point.

Returns:List<StyleRun>

the non-null but possibly empty list of additional styles for the doc string.

isResolvingReferencesback to summary
public boolean isResolvingReferences()
scanCommentForTypeNamesback to summary
private void scanCommentForTypeNames()

Try to match potential type names against the code graph. If any match, graph references and styles are added for them.

setResolveReferencesback to summary
public void setResolveReferences(boolean resolve)

Configures whether to highlight syntactically or semantically.

Parameters
resolve:boolean

true to do name resolution, false to guess purely based on syntax in the doc string. Pass false if you're using the highlighter to syntax-highlight a file (i.e. no code graph or indexing.)