MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

Parser

MMO\doc\js · 1 symbole · générée le 27 Oct 2026

class

Parser

Parser.php:35

Extracts documentation from javascript sources, the way reflection extracts it from php.

class MMO\doc\js\Parser
Espace de noms
MMO\doc\js
There is no reflection for a `.js` file -- the code never runs here -- so this walks [`Lexer`](https://mmoframework.fr/fr/documentation/mmo.doc/php/js/Lexer.md#lexer)'s tokens and recognises the handful of declaration shapes this codebase actually uses, then reads the jsdoc comment sitting above each one with the very same [`DocComment`](https://mmoframework.fr/fr/documentation/mmo.doc/php/helpers/DocComment.md#doccomment) parser the php side uses (so `@param`, `@return`, `@throws`, `@example`, `@see`, `{@link }` all behave identically in both languages): | source | documented as | |---|---| | `goog.provide('MMO.core.Map')` | the file's declared namespaces | | `MMO.core.Map = class extends X {...}` | a class, with every member of its body | | `class Foo extends Bar {...}` | a class | | `MMO.elements.CustomElement = Base => class extends Base {...}` | a mixin, with every member of its body | | `MMO.core.strings.bytesize = function (a, b = 2) {...}` | a function | | `MMO.core.dom.$ = MMO.core.dom.query` | an alias constant | | `MMO.core.strings = {A: 1, b() {}}` | a namespace, with its keys as members | | `MMO.core.MAP_CHANGED = Symbol('...')` | a constant | Inside a class body it recognises methods, `static`/`async`/generator methods, `get`/`set` accessors, `#private` names and class fields -- and is careful about the one case a naive scanner always gets wrong: `get` and `set` are also perfectly ordinary *method names* (`MMO.core.Map` has both), told apart by whether a `(` follows immediately.
$symbols = (new \MMO\doc\js\Parser())->parseFile('/path/to/Map.js'); foreach ($symbols as $symbol) {echo $symbol['name'], ': ', $symbol['summary'], "\n";}

Index

comments
count
filename
language
provides
source
symbols
tokens
accessorSignature($name, $getter, $setter, $modifiers)
comment($doc)
continuesExpression($i)
endsOpen($i)
examplesOf($comment)
fieldSignature($name, $value, $modifiers)
getProvides()
isArrowHeader($i)
isOpening($i)
lineCommentsDoc($texts, $first, $i, $line, $doc)Turn a kept run of // lines into a doc-comment-shaped token, or give the pending one back when there is nothing worth keeping.
looksLikeConstant($name)
matchBracket($i)
mergeAccessors($members)Fold each get x()/set x() pair into the single property it really is, the way a reader thinks of it -- with the getter's own doc comment and @return {T} type (a setter's jsdoc is discarde…
methodSignature($name, $params, $modifiers)
newMember($kind, $name, $comment, $line, $modifiers, $owner)
newSymbol($kind, $name, $doc, $line)
paramTag($comment, $name)
parse($source, $filename)
parseAssignment($start, $name, $i, $doc)Parse <name> = <value> once the left-hand side is known, and turn the right-hand side into the matching kind of symbol.
parseClass($i, $name, $doc)
parseFile($filename)
parseFunction($i, $name, $doc, $async)
parseMembers($i, $end, $owner)Parse a class body or an object literal into members.
parseParam($from, $to, $comment)
parseParams($i, $end, $comment)Split a parameter list into DocParam, merging in whatever the jsdoc @param tags say about each one.
parseStatement($i, $doc)Parse one top-level statement, registering whatever symbol it declares.
readLineComments($i, $doc)Collect a run of consecutive // lines as a doc comment, so constants documented that way are not lost.
readPath($i)Read a dotted path (MMO.core.Map) starting at $i.
reference($name)
register($symbol)Register a symbol, merging it into a same-named one already found (a class re-opened, a namespace extended).
returnOf($comment)
skipArrowHeader($i)
skipSemicolon($i)
skipStatement($i)
split($name)A symbol declared under an already-known namespace object becomes one of its members instead of a page of its own -- that is what makes MMO.core.strings.bytesize show up on the MMO.core.strings…
statementEnd($i, $limit)Find where a statement (or an object-literal entry) ends: the first ; or , at depth 0, the first token on a new line when nothing is left open (javascript's automatic semicolon insertion), or $…
stringAt($i)
StripBanner($text) staticDrop the section banners this codebase draws with comments, which would otherwise be read as the documentation of whatever follows them -- and, worse, turn into setext <h1>s once rendered as mark…
tagsOf($comment)Every doc tag that is not already rendered as a first-class part of the model, kept in source order so the page can show @see, @deprecated, @todo, @since, @author...
tagType($tag)
text($from, $to)
throwsOf($comment)
type($text)Build a DocType from a jsdoc type expression ({number|string}, {Array<MMO.core.Map>}).
typeAt($i)
value($i)

Propriétés8

comments

protected array $comments = []
Type
array

count

protected int $count = 0
Type
int

filename

protected string $filename = ''
Type
string

language

protected string $language = 'js'
Type
string

provides

protected array $provides = []
Type
array

source

protected string $source = ''
Type
string

symbols

protected array $symbols = []
Type
array

tokens

protected array $tokens = []
Type
array

Méthodes45

accessorSignature($name, $getter, $setter, $modifiers)

Parser.php:438
protected function accessorSignature(string $name, bool $getter, bool $setter, array $modifiers): string
$namestring
$getterbool
$setterbool
$modifiersarray
retournestring

comment($doc)

Parser.php:564
protected function comment(?array $doc): MMO\doc\helpers\DocComment
$docnull | array
retourneDocCommentthe parsed doc comment (empty when there is none), banner rules stripped.

continuesExpression($i)

Parser.php:916
protected function continuesExpression(int $i): bool
$iint
retournebooltrue when the token at $i can only be the continuation of the expression on the line above.

endsOpen($i)

Parser.php:922
protected function endsOpen(int $i): bool
$iint
retournebooltrue when the token at $i leaves the expression obviously unfinished (a trailing operator).

examplesOf($comment)

Parser.php:652
protected function examplesOf(MMO\doc\helpers\DocComment $comment): array
$commentDocComment
retournearraythe @example blocks of a doc comment, as {code, language} entries.

getProvides()

Parser.php:97
function getProvides(): array
retournearraythe namespaces declared by the last parsed file.

lineCommentsDoc($texts, $first, $i, $line, $doc)

Parser.php:542

Turn a kept run of // lines into a doc-comment-shaped token, or give the pending one back when there is nothing worth keeping.

protected function lineCommentsDoc(array $texts, int $first, int $i, int $line, ?array $doc): array
$textsarray
$firstintthe index of the run's first token
$iintthe index just past the run
$lineintthe line the run starts on
$docnull | array
retournearray?array, 1: int}

looksLikeConstant($name)

Parser.php:794
protected function looksLikeConstant(string $name): bool
$namestring
retournebooltrue when $name reads like a constant (SCREAMING_CASE) rather than a variable.

matchBracket($i)

Parser.php:844
protected function matchBracket(int $i): int
$iintthe index of an opening bracket
retourneintthe index of its matching closing bracket (the last token, when it is unbalanced)

mergeAccessors($members)

Parser.php:392

Fold each get x()/set x() pair into the single property it really is, the way a reader thinks of it -- with the getter's own doc comment and @return {T} type (a setter's jsdoc is discarded, matching what JHSCompiler's own documentation() extractor does), and marked readonly when no setter exists. Without this, every accessor pair would show up twice, under the same anchor.

protected function mergeAccessors(array $members): array
$membersarray
retournearray

methodSignature($name, $params, $modifiers)

Parser.php:799
protected function methodSignature(string $name, array $params, array $modifiers): string
$namestring
$paramsarray
$modifiersarray
retournestring

newMember($kind, $name, $comment, $line, $modifiers, $owner)

Parser.php:711
protected function newMember( string $kind, string $name, MMO\doc\helpers\DocComment $comment, int $line, array $modifiers, string $owner ): MMO\doc\models\DocMember
$kindstring
$namestring
$commentDocComment
$lineint
$modifiersarray
$ownerstring
retourneDocMember

newSymbol($kind, $name, $doc, $line)

Parser.php:670
protected function newSymbol(string $kind, string $name, ?array $doc, int $line): MMO\doc\models\DocSymbol
$kindstring
$namestringthe fully qualified name
$docnull | array
$lineint
retourneDocSymbola symbol with its doc text, location and tags already filled in

paramTag($comment, $name)

Parser.php:599
protected function paramTag(MMO\doc\helpers\DocComment $comment, string $name): ?MMO\doc\helpers\DocTag
$commentDocComment
$namestring
retournenull | DocTagthe @param tag documenting $name, matched with or without brackets.

parse($source, $filename)

Parser.php:65
function parse(string $source, string $filename = ''): array
$sourcestringthe javascript source
$filename = ''stringthe name it is reported under (source links)
retournearray

parseAssignment($start, $name, $i, $doc)

Parser.php:156

Parse <name> = <value> once the left-hand side is known, and turn the right-hand side into the matching kind of symbol.

protected function parseAssignment(int $start, string $name, int $i, ?array $doc): int
$startintthe index of the left-hand side (used only for the statement's line)
$namestringthe assigned, fully qualified name
$iintthe index of the first token of the value
$docnull | array
retourneintthe index just past the statement

parseClass($i, $name, $doc)

Parser.php:213
protected function parseClass(int $i, string $name, ?array $doc): array
$iintthe index of the class keyword
$namestringthe name the class is known under
$docnull | array
retournearrayDocSymbol, 1: int} the symbol, and the index just past the class body

parseFile($filename)

Parser.php:56
function parseFile(string $filename): array
$filenamestring
retournearraythe symbols the file declares, in source order

parseFunction($i, $name, $doc, $async)

Parser.php:254
protected function parseFunction(int $i, string $name, ?array $doc, bool $async = false): array
$iintthe index of the function keyword, or of an arrow function's first token
$namestring
$docnull | array
$async = falsebool
retournearrayDocSymbol, 1: int}

parseMembers($i, $end, $owner)

Parser.php:299

Parse a class body or an object literal into members.

protected function parseMembers(int $i, int $end, string $owner): array
$iintthe index just past the opening {
$endintthe index of the matching }
$ownerstringthe name members are documented as belonging to
retournearray

parseParam($from, $to, $comment)

Parser.php:469
protected function parseParam(int $from, int $to, MMO\doc\helpers\DocComment $comment): MMO\doc\models\DocParam
$fromint
$toint
$commentDocComment
retourneDocParamone parameter, from the tokens in [$from, $to].

parseParams($i, $end, $comment)

Parser.php:453

Split a parameter list into DocParam, merging in whatever the jsdoc @param tags say about each one.

protected function parseParams(int $i, int $end, MMO\doc\helpers\DocComment $comment): array
$iintthe index just past the opening (
$endintthe index of the matching )
$commentDocComment
retournearray

parseStatement($i, $doc)

Parser.php:110

Parse one top-level statement, registering whatever symbol it declares.

protected function parseStatement(int $i, ?array $doc): int
$iintthe index of its first token
$docnull | arraythe doc comment sitting above it, if any
retourneintthe index just past the statement

readLineComments($i, $doc)

Parser.php:510

Collect a run of consecutive // lines as a doc comment, so constants documented that way are not lost.

protected function readLineComments(int $i, ?array $doc): arrayA run is only kept when nothing but comment lines separate it from what it documents.
$iint
$docnull | arraythe pending doc comment, kept when the // run turns out to be a separator banner
retournearray?array, 1: int}

readPath($i)

Parser.php:933

Read a dotted path (MMO.core.Map) starting at $i.

protected function readPath(int $i): array
$iint
retournearray?string, 1: int} the path (null when there is none) and the index just past it

reference($name)

Parser.php:788
protected function reference(string $name): array
$namestring
retournearraystring, short: string, url: null} a reference to another symbol, left unlinked.

register($symbol)

Parser.php:741

Register a symbol, merging it into a same-named one already found (a class re-opened, a namespace extended).

protected function register(MMO\doc\models\DocSymbol $symbol): void
$symbolDocSymbol
retournevoid

returnOf($comment)

Parser.php:611
protected function returnOf(MMO\doc\helpers\DocComment $comment): ?array
$commentDocComment
retournenull | arraythe {type, description} the @return/@returns tag declares.

skipArrowHeader($i)

Parser.php:866
protected function skipArrowHeader(int $i): ?int
$iintthe index of an =/(/name that may start an arrow function's parameter list
retournenull | intthe index just past the =>, or null when this is not an arrow function

skipSemicolon($i)

Parser.php:947
protected function skipSemicolon(int $i): int
$iint
retourneintthe index just past an optional ; -- what follows a block that already ended a statement.

skipStatement($i)

Parser.php:952
protected function skipStatement(int $i): int
$iint
retourneintthe index just past the statement starting at $i, whatever it is.

split($name)

Parser.php:764

A symbol declared under an already-known namespace object becomes one of its members instead of a page of its own -- that is what makes MMO.core.strings.bytesize show up on the MMO.core.strings page.

protected function split(string $name): array
$namestring
retournearraystring, 1: string} the namespace and the short name

statementEnd($i, $limit)

Parser.php:885

Find where a statement (or an object-literal entry) ends: the first ; or , at depth 0, the first token on a new line when nothing is left open (javascript's automatic semicolon insertion), or $limit.

protected function statementEnd(int $i, ?int $limit = null): int
$iint
$limit = nullnull | intan upper bound (the enclosing } when scanning a class body)
retourneintthe index just past the statement

StripBanner($text)

staticParser.php:579

Drop the section banners this codebase draws with comments, which would otherwise be read as the documentation of whatever follows them -- and, worse, turn into setext <h1>s once rendered as markdown (a line of = right under a line of text *is* a heading).

protected static function StripBanner(string $text): stringA rule line is dropped wherever it appears; a comment that is nothing but a title over a rule (`Change events` + `================`) is a banner in full and yields no documentation at all.
$textstringthe raw comment, delimiters included
retournestringthe comment body, without its delimiters or leading asterisks
\MMO\doc\js\Parser::StripBanner("*\n * Change events\n * ======== *" . "/"); // ''

tagsOf($comment)

Parser.php:633

Every doc tag that is not already rendered as a first-class part of the model, kept in source order so the page can show @see, @deprecated, @todo, @since, @author... without this parser having to know what each of them means.

protected function tagsOf(MMO\doc\helpers\DocComment $comment): array
$commentDocComment
retournearraystring, text: string}>

tagType($tag)

Parser.php:556
protected function tagType(?MMO\doc\helpers\DocTag $tag): string
$tagnull | DocTag
retournestringthe {type} a tag declares -- read from the tag's parsed type when DocTag knew how to split it off, and from the raw text otherwise (@type {T}, @css {color}, ...)

text($from, $to)

Parser.php:831
protected function text(int $from, int $to): string
$fromint
$toint
retournestringthe source text covering the tokens [$from, $to].

throwsOf($comment)

Parser.php:618
protected function throwsOf(MMO\doc\helpers\DocComment $comment): array
$commentDocComment
retournearraythe {type, description} of every @throws tag.

type($text)

Parser.php:776

Build a DocType from a jsdoc type expression ({number|string}, {Array<MMO.core.Map>}). Nothing is resolved here -- linking is the documentor's job, since only it knows which symbols exist across the whole package (JSDocumentor::link).

protected function type(string $text): ?array
$textstring
retournenull | array