phpdoc

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsTag added in v0.4.0

func ContainsTag(value []byte) bool

ContainsTag checks if /* */ comments contain annotations, which may mean that it is phpdoc, but there is a mistake when there is one asterisk instead of two at the beginning of a comment.

func IsPHPDoc

func IsPHPDoc(doc string) bool

IsPHPDoc checks if the string is a doc comment

func IsPHPDocToken added in v0.4.0

func IsPHPDocToken(t *token.Token) bool

IsPHPDocToken checks if the token is a doc comment

func IsSuspicious added in v0.4.0

func IsSuspicious(value []byte) bool

IsSuspicious checks that phpdoc starts with /* but has tags inside it.

Types

type Comment added in v0.4.0

type Comment struct {
	Raw     string
	Parsed  []CommentPart
	Inherit bool // Comment contains @inheritdoc marker.
}

func Parse

func Parse(parser *TypeParser, doc string) Comment

Parse returns parsed doc comment with interesting parts (ones that start "* @")

type CommentPart

type CommentPart interface {
	Line() int
	Name() string
}

type ExprKind added in v0.3.0

type ExprKind uint8
const (
	// ExprInvalid represents "failed to parse" type expression.
	ExprInvalid ExprKind = iota

	// ExprUnknown is a garbage-prefixed type expression.
	// Examples: `-int` `@@\Foo[]`
	// Args[0] - a valid expression that follows invalid prefix
	ExprUnknown

	// ExprName is a type that is identified by its name.
	// Examples: `int` `\Foo\Bar` `$this`
	ExprName

	// ExprSpecialName is a special name-like type node.
	// Examples: `*` `...`
	ExprSpecialName

	// ExprInt is a digit-only type expression.
	// Examples: `0` `10`
	ExprInt

	// ExprKeyVal is `key:val` type.
	// Examples: `name: string` `id:int`
	// Args[0] - key expression (left)
	// Args[1] - val expression (right)
	ExprKeyVal

	// ExprMemberType is access to member.
	// Examples: `\Foo::SOME_CONSTANT` `\Foo::$a`
	// Args[0] - class type expression (left)
	// Args[1] - member name expression (right)
	ExprMemberType

	// ExprArray is `elem[]` or `[]elem` type.
	// Examples: `int[]` `(int|float)[]` `int[`
	// Args[0] - array element type
	// ShapeArrayPrefix: `[]T`
	//
	// Note: may miss second `]`.
	ExprArray

	// ExprParen is `(expr)` type.
	// Examples: `(int)` `(\Foo\Bar[])` `(int`
	// Args[0] - enclosed type
	//
	// Note: may miss closing `)`.
	ExprParen

	// ExprNullable is `?expr` type.
	// Examples: `?int` `?\Foo`
	// Args[0] - nullable element type
	ExprNullable

	// ExprOptional is `expr?` type.
	// Examples: `k?: int`
	// Args[0] - optional element type
	ExprOptional

	// ExprNot is `!expr` type.
	// Examples: `!int` `!(int|float)`
	// Args[0] - negated element type
	//
	// Note: only valid for phpgrep type filters.
	ExprNot

	// ExprUnion is `x|y` type.
	// Examples: `T1|T2` `int|float[]|false`
	// Args - type variants
	ExprUnion

	// ExprInter is `x&y` type.
	// Examples: `T1&T2` `I1&I2&I3`
	ExprInter

	// ExprGeneric is a parametrized `expr<T,...>` type.
	// Examples: `\Collection<T>` `Either<int[], false>` `Bad<int`
	// Args[0] - parametrized type
	// Args[1:] - type parameters
	// ShapeGenericParen: `T(X,Y)`
	// ShapeGenericBrace: `T{X,Y}`
	//
	// Note: may miss closing `>`.
	ExprGeneric

	// ExprTypedCallable is a parametrized `callable(A,...):B` type.
	// Examples: `callable():void` `callable(int, int) : float`
	// Args[0] - return type
	// Args[1:] - argument types
	ExprTypedCallable

	// ExprLiteral is a single quoted string value.
	// Examples: `'a'` `'abc'` `'!'`
	ExprLiteral
)

func (ExprKind) String added in v0.3.0

func (i ExprKind) String() string

type ExprShape added in v0.3.0

type ExprShape uint8
const (
	ShapeDefault ExprShape = iota
	ShapeArrayPrefix
	ShapeGenericParen
	ShapeGenericBrace
)

type PackageCommentPart added in v0.5.3

type PackageCommentPart struct {
	PackageName string
	// contains filtered or unexported fields
}

func (*PackageCommentPart) Line added in v0.5.3

func (c *PackageCommentPart) Line() int

func (*PackageCommentPart) Name added in v0.5.3

func (c *PackageCommentPart) Name() string

type RawCommentPart added in v0.3.0

type RawCommentPart struct {
	Params     []string // {"something", "bla-bla-bla"} in example above
	ParamsText string   // "something bla-bla-bla" in example above
	// contains filtered or unexported fields
}

func (*RawCommentPart) Line added in v0.3.0

func (c *RawCommentPart) Line() int

func (*RawCommentPart) Name added in v0.3.0

func (c *RawCommentPart) Name() string

type Type added in v0.3.0

type Type struct {
	Source string
	Expr   TypeExpr
}

func (Type) Clone added in v0.3.0

func (typ Type) Clone() Type

func (Type) IsEmpty added in v0.3.0

func (typ Type) IsEmpty() bool

func (Type) String added in v0.3.0

func (typ Type) String() string

type TypeCommentPart added in v0.3.0

type TypeCommentPart struct {
	Type Type
	Rest string
	// contains filtered or unexported fields
}

func (*TypeCommentPart) Line added in v0.3.0

func (c *TypeCommentPart) Line() int

func (*TypeCommentPart) Name added in v0.3.0

func (c *TypeCommentPart) Name() string

type TypeExpr added in v0.2.0

type TypeExpr struct {
	Kind  ExprKind
	Shape ExprShape
	Begin uint16
	End   uint16
	Value string
	Args  []TypeExpr
}

func (TypeExpr) Clone added in v0.3.0

func (e TypeExpr) Clone() TypeExpr

type TypeParser added in v0.2.0

type TypeParser struct {
	// contains filtered or unexported fields
}

func NewTypeParser added in v0.3.0

func NewTypeParser() *TypeParser

func (*TypeParser) Parse added in v0.3.0

func (p *TypeParser) Parse(s string) Type

type TypeVarCommentPart added in v0.3.0

type TypeVarCommentPart struct {
	VarIsFirst bool
	Var        string
	Type       Type
	Rest       string
	// contains filtered or unexported fields
}

func (*TypeVarCommentPart) Line added in v0.3.0

func (c *TypeVarCommentPart) Line() int

func (*TypeVarCommentPart) Name added in v0.3.0

func (c *TypeVarCommentPart) Name() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL