Documentation ¶
Index ¶
- Constants
- Variables
- func Parse(filename string, b []byte, opts ...Option) (any, error)
- func ParseFile(filename string, opts ...Option) (i any, err error)
- func ParseReader(filename string, r io.Reader, opts ...Option) (any, error)
- func StringPointer(s string) *string
- type Annotation
- type Annotations
- type BadDefinition
- func (d *BadDefinition) Children() []Node
- func (d *BadDefinition) ChildrenBadNode() bool
- func (d *BadDefinition) Equals(node Node) bool
- func (d *BadDefinition) IsBadNode() bool
- func (d *BadDefinition) SetAnnotations(annos *Annotations)
- func (d *BadDefinition) SetComments([]*Comment, []*Comment)
- func (d *BadDefinition) SetLocation(loc Location)
- func (d *BadDefinition) Type() string
- type BadHeader
- type CPPInclude
- func (i *CPPInclude) Children() []Node
- func (i *CPPInclude) ChildrenBadNode() bool
- func (i *CPPInclude) Equals(node Node) bool
- func (i *CPPInclude) IsBadNode() bool
- func (i *CPPInclude) SetComments(comments []*Comment, endLineComments []*Comment)
- func (i *CPPInclude) SetLocation(loc Location)
- func (i *CPPInclude) Type() string
- type CPPIncludeKeyword
- type Cloner
- type ColonKeyword
- type CommaKeyword
- type Comment
- type CommentStyle
- type Const
- func (c *Const) Children() []Node
- func (c *Const) ChildrenBadNode() bool
- func (c *Const) Equals(node Node) bool
- func (c *Const) IsBadNode() bool
- func (c *Const) SetAnnotations(annos *Annotations)
- func (c *Const) SetComments(comments []*Comment, endLineComments []*Comment)
- func (c *Const) SetLocation(loc Location)
- func (c *Const) Type() string
- type ConstKeyword
- type ConstValue
- type CppType
- type CppTypeKeyword
- type Definition
- type Document
- type Enum
- func (e *Enum) Children() []Node
- func (e *Enum) ChildrenBadNode() bool
- func (e *Enum) Equals(node Node) bool
- func (e *Enum) IsBadNode() bool
- func (e *Enum) SetAnnotations(annos *Annotations)
- func (e *Enum) SetComments(comments []*Comment, endlineComments []*Comment)
- func (e *Enum) SetLocation(loc Location)
- func (e *Enum) Type() string
- type EnumKeyword
- type EnumValue
- type EqualKeyword
- type ErrorLister
- type Exception
- func (e *Exception) Children() []Node
- func (e *Exception) ChildrenBadNode() bool
- func (e *Exception) Equals(node Node) bool
- func (e *Exception) IsBadNode() bool
- func (e *Exception) SetAnnotations(annos *Annotations)
- func (e *Exception) SetComments(comments []*Comment, endLineComments []*Comment)
- func (e *Exception) SetLocation(loc Location)
- func (e *Exception) Type() string
- type ExceptionKeyword
- type ExtendsKeyword
- type Field
- type FieldIndex
- type FieldType
- type Function
- type Header
- type Identifier
- type IdentifierName
- type Include
- func (i *Include) Children() []Node
- func (i *Include) ChildrenBadNode() bool
- func (i *Include) Equals(node Node) bool
- func (i *Include) IsBadNode() bool
- func (i *Include) Name() string
- func (i *Include) SetComments(comments []*Comment, endLineComments []*Comment)
- func (i *Include) SetLocation(loc Location)
- func (i *Include) Type() string
- type IncludeCall
- type IncludeKeyword
- type Keyword
- type KeywordLiteral
- type LBrkKeyword
- type LCurKeyword
- type LParKeyword
- type LPointKeyword
- type ListSeparatorKeyword
- type Literal
- type LiteralValue
- type Location
- type Namespace
- func (n *Namespace) Children() []Node
- func (n *Namespace) ChildrenBadNode() bool
- func (n *Namespace) Equals(node Node) bool
- func (n *Namespace) IsBadNode() bool
- func (n *Namespace) SetComments(comments []*Comment, endLineComments []*Comment)
- func (n *Namespace) SetLocation(loc Location)
- func (n *Namespace) Type() string
- type NamespaceKeyword
- type NamespaceScope
- type Node
- type OnewayKeyword
- type Option
- func AllowInvalidUTF8(b bool) Option
- func Debug(b bool) Option
- func Entrypoint(ruleName string) Option
- func GlobalStore(key string, value any) Option
- func InitState(key string, value any) Option
- func MaxExpressions(maxExprCnt uint64) Option
- func Memoize(b bool) Option
- func Recover(b bool) Option
- func Statistics(stats *Stats, choiceNoMatch string) Option
- type PEGParser
- type ParseResult
- type Parser
- type ParserError
- type Position
- type RBrkKeyword
- type RCurKeyword
- type RParKeyword
- type RPointKeyword
- type RequiredKeyword
- type Service
- func (s *Service) Children() []Node
- func (s *Service) ChildrenBadNode() bool
- func (s *Service) Equals(node Node) bool
- func (s *Service) IsBadNode() bool
- func (s *Service) SetAnnotations(annos *Annotations)
- func (s *Service) SetComments(comments []*Comment, endLineComments []*Comment)
- func (s *Service) SetLocation(loc Location)
- func (s *Service) Type() string
- type ServiceKeyword
- type Stats
- type Struct
- func (s *Struct) Children() []Node
- func (s *Struct) ChildrenBadNode() bool
- func (s *Struct) Equals(node Node) bool
- func (s *Struct) IsBadNode() bool
- func (s *Struct) SetAnnotations(annos *Annotations)
- func (s *Struct) SetComments(comments []*Comment, endLineComments []*Comment)
- func (s *Struct) SetLocation(loc Location)
- func (s *Struct) Type() string
- type StructKeyword
- type Throws
- type ThrowsKeyword
- type TypeName
- type Typedef
- func (t *Typedef) Children() []Node
- func (t *Typedef) ChildrenBadNode() bool
- func (t *Typedef) Equals(node Node) bool
- func (t *Typedef) IsBadNode() bool
- func (t *Typedef) SetAnnotations(annos *Annotations)
- func (t *Typedef) SetComments(comments []*Comment, endLineComments []*Comment)
- func (t *Typedef) SetLocation(loc Location)
- func (t *Typedef) Type() string
- type TypedefKeyword
- type Union
- func (u *Union) Children() []Node
- func (u *Union) ChildrenBadNode() bool
- func (u *Union) Equals(node Node) bool
- func (u *Union) IsBadNode() bool
- func (u *Union) SetAnnotations(annos *Annotations)
- func (u *Union) SetComments(comments []*Comment, endLineComments []*Comment)
- func (u *Union) SetLocation(loc Location)
- func (u *Union) Type() string
- type UnionKeyword
- type VoidKeyword
Constants ¶
const ( LCUR = "{" RCUR = "}" )
Variables ¶
var ( RequiredError error = errors.New("expecting 'required' or 'optional'") InvalidFieldTypeError error = errors.New("expecting a valid field type") InvalidFieldIndexError error = errors.New("expecting a valid int16 field index") InvalidStructError error = errors.New("expecting a valid struct definition") InvalidStructIdentifierError error = errors.New("expecting a valid struct identifier") InvalidStructBlockLCURError error = errors.New("expecting a starting '{' of struct block") InvalidStructBlockRCURError error = errors.New("expecting an ending '}' of struct block") InvalidStructFieldError error = errors.New("expecting a valid struct field") InvalidUnionError error = errors.New("expecting a valid union definition") InvalidUnionIdentifierError error = errors.New("expecting a valid union identifier") InvalidUnionBlockLCURError error = errors.New("expecting a starting '{' of union block") InvalidUnionBlockRCURError error = errors.New("expecting a ending '}' of union block") InvalidUnionFieldError error = errors.New("expecting a valid union field") InvalidExceptionError error = errors.New("expecting a valid exception definition") InvalidExceptionIdentifierError error = errors.New("expecting a valid exception identifier") InvalidExceptionBlockLCURError error = errors.New("expecting a starting '{' of exception block") InvalidExceptionBlockRCURError error = errors.New("expecting a ending '}' of exception block") InvalidExceptionFieldError error = errors.New("expecting a valid exception field") InvalidEnumError error = errors.New("expecting a valid enum definition") InvalidEnumIdentifierError error = errors.New("expecting a valid enum identifier") InvalidEnumBlockLCURError error = errors.New("expecting a starting '{' of enum block") InvalidEnumBlockRCURError error = errors.New("expecting a ending '}' of enum block") InvalidEnumValueError error = errors.New("expecting a valid enum field") InvalidEnumValueIntConstantError error = errors.New("expecting a valid int contant") InvalidTypedefError error = errors.New("expecting a valid typedef definition") InvalidTypedefIdentifierError error = errors.New("expecting a valid typedef identifier") InvalidConstError error = errors.New("expecting a valid const definition") InvalidConstConstValueError error = errors.New("expecting a valid const value") InvalidConstMissingValueError error = errors.New("expecting a const value") InvalidConstIdentifierError error = errors.New("expecting a valid const identifier") InvalidServiceIdentifierError error = errors.New("expecting a valid service identifier") InvalidServiceBlockRCURError error = errors.New("expecting a ending '}' of service block") InvalidServiceFunctionError error = errors.New("expecting a valid service function") InvalidFunctionIdentifierError error = errors.New("expecting a valid function identifier") InvalidFunctionArgumentError error = errors.New("expecting a valid function argument") InvalidIdentifierError error = errors.New("expecting a valid identifier") InvalidLiteral1MissingRightError error = errors.New("expecting a right \" ") InvalidLiteral1Error error = errors.New("expecting a valid literal") InvalidLiteral2MissingRightError error = errors.New("expecting a right ' ") InvalidLiteral2Error error = errors.New("expecting a valid literal") InvalidHeaderError error = errors.New("expecting a valid header") InvalidIncludeError error = errors.New("expecting a valid include header") InvalidCppIncludeError error = errors.New("expecting a valid cpp include header") InvalidNamespaceError error = errors.New("expecting a valid namespace header") InvalidDefinitionError error = errors.New("expecting a valid definition") InvalidServiceError error = errors.New("expecting a valid service definition") )
var InvalidPosition = Position{
Line: -1,
Col: -1,
Offset: -1,
}
Functions ¶
func ParseReader ¶
ParseReader parses the data from r using filename as information in the error messages.
func StringPointer ¶
Types ¶
type Annotation ¶
type Annotation struct { EqualKeyword *EqualKeyword ListSeparatorKeyword *ListSeparatorKeyword Identifier *Identifier Value *Literal BadNode bool Location }
func NewAnnotation ¶
func NewAnnotation(equalKeyword *EqualKeyword, listSeparatorKeyword *ListSeparatorKeyword, id *Identifier, value *Literal, loc Location) *Annotation
func NewBadAnnotation ¶
func NewBadAnnotation(loc Location) *Annotation
func (*Annotation) Children ¶
func (a *Annotation) Children() []Node
func (*Annotation) ChildrenBadNode ¶
func (a *Annotation) ChildrenBadNode() bool
func (*Annotation) Equals ¶ added in v0.1.4
func (a *Annotation) Equals(node Node) bool
func (*Annotation) IsBadNode ¶
func (a *Annotation) IsBadNode() bool
func (*Annotation) Type ¶
func (a *Annotation) Type() string
type Annotations ¶
type Annotations struct { Annotations []*Annotation LParKeyword *LParKeyword RParKeyword *RParKeyword BadNode bool Location }
func NewAnnotations ¶
func NewAnnotations(lpar *LParKeyword, rpar *RParKeyword, annos []*Annotation, loc Location) *Annotations
func (*Annotations) Children ¶
func (a *Annotations) Children() []Node
func (*Annotations) ChildrenBadNode ¶
func (a *Annotations) ChildrenBadNode() bool
func (*Annotations) Equals ¶ added in v0.1.4
func (a *Annotations) Equals(node Node) bool
func (*Annotations) IsBadNode ¶
func (a *Annotations) IsBadNode() bool
func (*Annotations) Type ¶
func (a *Annotations) Type() string
type BadDefinition ¶
func NewBadDefinition ¶
func NewBadDefinition(loc Location) *BadDefinition
func (*BadDefinition) Children ¶
func (d *BadDefinition) Children() []Node
func (*BadDefinition) ChildrenBadNode ¶
func (d *BadDefinition) ChildrenBadNode() bool
func (*BadDefinition) Equals ¶ added in v0.1.4
func (d *BadDefinition) Equals(node Node) bool
func (*BadDefinition) IsBadNode ¶
func (d *BadDefinition) IsBadNode() bool
func (*BadDefinition) SetAnnotations ¶
func (d *BadDefinition) SetAnnotations(annos *Annotations)
func (*BadDefinition) SetComments ¶
func (d *BadDefinition) SetComments([]*Comment, []*Comment)
func (*BadDefinition) SetLocation ¶
func (d *BadDefinition) SetLocation(loc Location)
func (*BadDefinition) Type ¶
func (d *BadDefinition) Type() string
type BadHeader ¶
func NewBadHeader ¶
func (*BadHeader) ChildrenBadNode ¶
func (*BadHeader) SetComments ¶
func (*BadHeader) SetLocation ¶
type CPPInclude ¶
type CPPInclude struct { CPPIncludeKeyword *CPPIncludeKeyword Path *Literal Comments []*Comment EndLineComments []*Comment BadNode bool Location }
func NewBadCPPInclude ¶
func NewBadCPPInclude(loc Location) *CPPInclude
func NewCPPInclude ¶
func NewCPPInclude(keyword *CPPIncludeKeyword, path *Literal, loc Location) *CPPInclude
func (*CPPInclude) Children ¶
func (i *CPPInclude) Children() []Node
func (*CPPInclude) ChildrenBadNode ¶
func (i *CPPInclude) ChildrenBadNode() bool
func (*CPPInclude) Equals ¶ added in v0.1.4
func (i *CPPInclude) Equals(node Node) bool
func (*CPPInclude) IsBadNode ¶
func (i *CPPInclude) IsBadNode() bool
func (*CPPInclude) SetComments ¶
func (i *CPPInclude) SetComments(comments []*Comment, endLineComments []*Comment)
func (*CPPInclude) SetLocation ¶
func (i *CPPInclude) SetLocation(loc Location)
func (*CPPInclude) Type ¶
func (i *CPPInclude) Type() string
type CPPIncludeKeyword ¶
type CPPIncludeKeyword struct {
Keyword
}
func (*CPPIncludeKeyword) Equals ¶ added in v0.1.4
func (c *CPPIncludeKeyword) Equals(node Node) bool
func (*CPPIncludeKeyword) Type ¶
func (c *CPPIncludeKeyword) Type() string
type Cloner ¶
type Cloner interface {
Clone() any
}
Cloner is implemented by any value that has a Clone method, which returns a copy of the value. This is mainly used for types which are not passed by value (e.g map, slice, chan) or structs that contain such types.
This is used in conjunction with the global state feature to create proper copies of the state to allow the parser to properly restore the state in the case of backtracking.
type ColonKeyword ¶
type ColonKeyword struct {
Keyword
}
func (*ColonKeyword) Equals ¶ added in v0.1.4
func (c *ColonKeyword) Equals(node Node) bool
func (*ColonKeyword) Type ¶
func (c *ColonKeyword) Type() string
type CommaKeyword ¶
type CommaKeyword struct {
Keyword
}
func (*CommaKeyword) Equals ¶ added in v0.1.4
func (r *CommaKeyword) Equals(node Node) bool
func (*CommaKeyword) Type ¶
func (r *CommaKeyword) Type() string
type Comment ¶
type Comment struct { Text string Style CommentStyle // shell: #xxx, multiline: /* *** */, singleline: // xxxxx BadNode bool Location }
func NewBadComment ¶
func NewComment ¶
func NewComment(text string, style CommentStyle, loc Location) *Comment
func (*Comment) ChildrenBadNode ¶
type CommentStyle ¶
type CommentStyle string
const ( CommentStyleShell CommentStyle = "shell" CommentStyleMultiLine CommentStyle = "multiline" CommentStyleSingleLine CommentStyle = "singleline" )
type Const ¶
type Const struct { ConstKeyword *ConstKeyword EqualKeyword *EqualKeyword ListSeparatorKeyword *ListSeparatorKeyword // can be nil Name *Identifier ConstType *FieldType Value *ConstValue Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadConst ¶
func NewConst ¶
func NewConst(constKeyword *ConstKeyword, equalKeyword *EqualKeyword, listSeparatorKeyword *ListSeparatorKeyword, name *Identifier, t *FieldType, v *ConstValue, loc Location) *Const
func (*Const) ChildrenBadNode ¶
func (*Const) SetAnnotations ¶
func (c *Const) SetAnnotations(annos *Annotations)
func (*Const) SetComments ¶
func (*Const) SetLocation ¶
type ConstKeyword ¶
type ConstKeyword struct {
Keyword
}
func (*ConstKeyword) Equals ¶ added in v0.1.4
func (c *ConstKeyword) Equals(node Node) bool
func (*ConstKeyword) Type ¶
func (c *ConstKeyword) Type() string
type ConstValue ¶
type ConstValue struct { // TypeName can be: list, map, pair, string, identifier, i64, double TypeName string // Value is the actual value or identifier name Value any // ValueInText is the user input value // it is used for i64 and double type value ValueInText string // only exist when TypeName is map Key any // exist in list LBrkKeyword *LBrkKeyword RBrkKeyword *RBrkKeyword // exist in map LCurKeyword *LCurKeyword RCurKeyword *RCurKeyword // exist in list, map item ListSeparatorKeyword *ListSeparatorKeyword // exist in map item ColonKeyword *ColonKeyword Comments []*Comment BadNode bool Location }
func NewBadConstValue ¶
func NewBadConstValue(loc Location) *ConstValue
func NewBadIntConstValue ¶
func NewBadIntConstValue(loc Location) *ConstValue
func NewConstValue ¶
func NewConstValue(typeName string, value any, loc Location) *ConstValue
func NewMapConstValue ¶
func NewMapConstValue(key, value *ConstValue, loc Location) *ConstValue
func (*ConstValue) ChildrenBadNode ¶
func (c *ConstValue) ChildrenBadNode() bool
func (*ConstValue) Equals ¶ added in v0.1.4
func (c *ConstValue) Equals(node Node) bool
func (*ConstValue) IsBadNode ¶
func (c *ConstValue) IsBadNode() bool
func (*ConstValue) SetComments ¶
func (c *ConstValue) SetComments(comments []*Comment)
func (*ConstValue) Type ¶
func (c *ConstValue) Type() string
type CppType ¶
type CppType struct { CppTypeKeyword *CppTypeKeyword Literal *Literal BadNode bool Location }
func NewCppType ¶
func NewCppType(cppTypeKeyword *CppTypeKeyword, literal *Literal, loc Location) *CppType
func (*CppType) ChildrenBadNode ¶
type CppTypeKeyword ¶
type CppTypeKeyword struct {
Keyword
}
func (*CppTypeKeyword) Equals ¶ added in v0.1.4
func (r *CppTypeKeyword) Equals(node Node) bool
func (*CppTypeKeyword) Type ¶
func (r *CppTypeKeyword) Type() string
type Definition ¶
type Document ¶
type Document struct { Filename string BadHeaders []*BadHeader Includes []*Include CPPIncludes []*CPPInclude Namespaces []*Namespace Consts []*Const Typedefs []*Typedef Enums []*Enum Services []*Service Structs []*Struct Unions []*Union Exceptions []*Exception BadDefinitions []*BadDefinition Comments []*Comment // Comments at end of doc Nodes []Node Location }
func NewDocument ¶
func NewDocument(headers []Header, defs []Definition, comments []*Comment, loc Location) *Document
func (*Document) ChildrenBadNode ¶
type Enum ¶
type Enum struct { EnumKeyword *EnumKeyword LCurKeyword *LCurKeyword RCurKeyword *RCurKeyword Name *Identifier Values []*EnumValue Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadEnum ¶
func NewEnum ¶
func NewEnum(enumKeyword *EnumKeyword, lCurKeyword *LCurKeyword, rCurKeyword *RCurKeyword, name *Identifier, values []*EnumValue, loc Location) *Enum
func (*Enum) ChildrenBadNode ¶
func (*Enum) SetAnnotations ¶
func (e *Enum) SetAnnotations(annos *Annotations)
func (*Enum) SetComments ¶
func (*Enum) SetLocation ¶
type EnumKeyword ¶
type EnumKeyword struct {
Keyword
}
func (*EnumKeyword) Equals ¶ added in v0.1.4
func (e *EnumKeyword) Equals(node Node) bool
func (*EnumKeyword) Type ¶
func (e *EnumKeyword) Type() string
type EnumValue ¶
type EnumValue struct { ListSeparatorKeyword *ListSeparatorKeyword // can be nil EqualKeyword *EqualKeyword // can be nil Name *Identifier ValueNode *ConstValue Value int64 // Value only record enum value. it is not a ast node Annotations *Annotations Comments []*Comment EndLineComments []*Comment BadNode bool Location }
func NewBadEnumValue ¶
func NewEnumValue ¶
func NewEnumValue(listSeparatorKeyword *ListSeparatorKeyword, equalKeyword *EqualKeyword, name *Identifier, valueNode *ConstValue, value int64, annotations *Annotations, loc Location) *EnumValue
func (*EnumValue) ChildrenBadNode ¶
func (*EnumValue) SetComments ¶
type EqualKeyword ¶
type EqualKeyword struct {
Keyword
}
func NewBadEqualKeyword ¶
func NewBadEqualKeyword() *EqualKeyword
func (*EqualKeyword) Equals ¶ added in v0.1.4
func (e *EqualKeyword) Equals(node Node) bool
func (*EqualKeyword) Type ¶
func (e *EqualKeyword) Type() string
type ErrorLister ¶
type ErrorLister interface {
Errors() []error
}
ErrorLister is the public interface to access the inner errors included in a errList
type Exception ¶
type Exception struct { ExceptionKeyword *ExceptionKeyword LCurKeyword *LCurKeyword RCurKeyword *RCurKeyword Name *Identifier Fields []*Field Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadException ¶
func NewException ¶
func NewException(exceptionKeyword *ExceptionKeyword, lCurKeyword *LCurKeyword, rCurKeyword *RCurKeyword, name *Identifier, fields []*Field, loc Location) *Exception
func (*Exception) ChildrenBadNode ¶
func (*Exception) SetAnnotations ¶
func (e *Exception) SetAnnotations(annos *Annotations)
func (*Exception) SetComments ¶
func (*Exception) SetLocation ¶
type ExceptionKeyword ¶
type ExceptionKeyword struct {
Keyword
}
func (*ExceptionKeyword) Equals ¶ added in v0.1.4
func (e *ExceptionKeyword) Equals(node Node) bool
func (*ExceptionKeyword) Type ¶
func (e *ExceptionKeyword) Type() string
type ExtendsKeyword ¶
type ExtendsKeyword struct {
Keyword
}
func (*ExtendsKeyword) Equals ¶ added in v0.1.4
func (s *ExtendsKeyword) Equals(node Node) bool
func (*ExtendsKeyword) Type ¶
func (s *ExtendsKeyword) Type() string
type Field ¶
type Field struct { Index *FieldIndex RequiredKeyword *RequiredKeyword FieldType *FieldType Identifier *Identifier ConstValue *ConstValue EqualKeyword *EqualKeyword // can be nil ListSeparatorKeyword *ListSeparatorKeyword // can be nil Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadField ¶
func NewField ¶
func NewField(equalKeyword *EqualKeyword, listSeparatorKeyword *ListSeparatorKeyword, comments []*Comment, endLineComments []*Comment, annotations *Annotations, index *FieldIndex, required *RequiredKeyword, fieldType *FieldType, identifier *Identifier, constValue *ConstValue, loc Location) *Field
func (*Field) ChildrenBadNode ¶
type FieldIndex ¶
type FieldIndex struct { ColonKeyword *ColonKeyword Value int Comments []*Comment BadNode bool Location }
func NewBadFieldIndex ¶
func NewBadFieldIndex(loc Location) *FieldIndex
func NewFieldIndex ¶
func NewFieldIndex(ColonKeyword *ColonKeyword, v int, comments []*Comment, loc Location) *FieldIndex
func (*FieldIndex) Children ¶
func (f *FieldIndex) Children() []Node
func (*FieldIndex) ChildrenBadNode ¶
func (f *FieldIndex) ChildrenBadNode() bool
func (*FieldIndex) Equals ¶ added in v0.1.4
func (f *FieldIndex) Equals(node Node) bool
func (*FieldIndex) IsBadNode ¶
func (f *FieldIndex) IsBadNode() bool
func (*FieldIndex) Type ¶
func (f *FieldIndex) Type() string
type FieldType ¶
type FieldType struct { TypeName *TypeName // only exist when TypeName is map or set or list KeyType *FieldType // only exist when TypeName is map ValueType *FieldType // only exist in map, set, list. can be nil CppType *CppType // only exist in map, set, list LPointKeyword *LPointKeyword // only exist in map, set, list RPointKeyword *RPointKeyword // only exist in map CommaKeyword *CommaKeyword Annotations *Annotations BadNode bool Location }
func NewFieldType ¶
func NewFieldType(lpointKeyword *LPointKeyword, rpointKeyword *RPointKeyword, commaKeyword *CommaKeyword, cppType *CppType, typeName *TypeName, keyType *FieldType, valueType *FieldType, loc Location) *FieldType
func (*FieldType) ChildrenBadNode ¶
type Function ¶
type Function struct { LParKeyword *LParKeyword RParKeyword *RParKeyword ListSeparatorKeyword *ListSeparatorKeyword // can be nil Name *Identifier Oneway *OnewayKeyword // can be nil Void *VoidKeyword // can be nil FunctionType *FieldType Arguments []*Field Throws *Throws Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadFunction ¶
func NewFunction ¶
func NewFunction(lParKeyword *LParKeyword, rParKeyword *RParKeyword, listSeparatorKeyword *ListSeparatorKeyword, name *Identifier, oneway *OnewayKeyword, void *VoidKeyword, ft *FieldType, args []*Field, throws *Throws, comments []*Comment, endlineComments []*Comment, annotations *Annotations, loc Location) *Function
func (*Function) ChildrenBadNode ¶
type Identifier ¶
type Identifier struct { Name *IdentifierName Comments []*Comment BadNode bool Location }
func NewBadIdentifier ¶
func NewBadIdentifier(loc Location) *Identifier
func NewIdentifier ¶
func NewIdentifier(name *IdentifierName, comments []*Comment, loc Location) *Identifier
func (*Identifier) Children ¶
func (i *Identifier) Children() []Node
func (*Identifier) ChildrenBadNode ¶
func (i *Identifier) ChildrenBadNode() bool
func (*Identifier) Equals ¶ added in v0.1.4
func (i *Identifier) Equals(node Node) bool
func (*Identifier) IsBadNode ¶
func (i *Identifier) IsBadNode() bool
func (*Identifier) ToFieldType ¶
func (i *Identifier) ToFieldType() *FieldType
func (*Identifier) Type ¶
func (i *Identifier) Type() string
type IdentifierName ¶
func NewIdentifierName ¶
func NewIdentifierName(name string, loc Location) *IdentifierName
func (*IdentifierName) Children ¶
func (i *IdentifierName) Children() []Node
func (*IdentifierName) ChildrenBadNode ¶
func (i *IdentifierName) ChildrenBadNode() bool
func (*IdentifierName) Equals ¶ added in v0.1.4
func (i *IdentifierName) Equals(node Node) bool
func (*IdentifierName) IsBadNode ¶
func (i *IdentifierName) IsBadNode() bool
func (*IdentifierName) Type ¶
func (i *IdentifierName) Type() string
type Include ¶
type Include struct { IncludeKeyword *IncludeKeyword Path *Literal Comments []*Comment EndLineComments []*Comment BadNode bool Location }
func NewBadInclude ¶
func NewInclude ¶
func NewInclude(keyword *IncludeKeyword, path *Literal, loc Location) *Include
func (*Include) ChildrenBadNode ¶
func (*Include) SetComments ¶
func (*Include) SetLocation ¶
type IncludeCall ¶
type IncludeKeyword ¶
type IncludeKeyword struct {
Keyword
}
func (*IncludeKeyword) Equals ¶ added in v0.1.4
func (i *IncludeKeyword) Equals(node Node) bool
func (*IncludeKeyword) Type ¶
func (i *IncludeKeyword) Type() string
type Keyword ¶
type Keyword struct { Comments []*Comment Literal *KeywordLiteral BadNode bool Location }
func NewKeyword ¶
func NewKeyword(comments []*Comment, literal *KeywordLiteral, loc Location) Keyword
func (*Keyword) ChildrenBadNode ¶
type KeywordLiteral ¶
func NewBadKeywordLiteral ¶
func NewBadKeywordLiteral(c *current) *KeywordLiteral
func NewKeywordLiteral ¶
func NewKeywordLiteral(c *current) *KeywordLiteral
func (*KeywordLiteral) Children ¶
func (k *KeywordLiteral) Children() []Node
func (*KeywordLiteral) ChildrenBadNode ¶
func (k *KeywordLiteral) ChildrenBadNode() bool
func (*KeywordLiteral) Equals ¶ added in v0.1.4
func (k *KeywordLiteral) Equals(node Node) bool
func (*KeywordLiteral) IsBadNode ¶
func (k *KeywordLiteral) IsBadNode() bool
func (*KeywordLiteral) Type ¶
func (k *KeywordLiteral) Type() string
type LBrkKeyword ¶
type LBrkKeyword struct {
Keyword
}
func (*LBrkKeyword) Equals ¶ added in v0.1.4
func (l *LBrkKeyword) Equals(node Node) bool
func (*LBrkKeyword) Type ¶
func (l *LBrkKeyword) Type() string
type LCurKeyword ¶
type LCurKeyword struct {
Keyword
}
func (*LCurKeyword) Equals ¶ added in v0.1.4
func (s *LCurKeyword) Equals(node Node) bool
func (*LCurKeyword) Type ¶
func (s *LCurKeyword) Type() string
type LParKeyword ¶
type LParKeyword struct {
Keyword
}
func (*LParKeyword) Equals ¶ added in v0.1.4
func (l *LParKeyword) Equals(node Node) bool
func (*LParKeyword) Type ¶
func (l *LParKeyword) Type() string
type LPointKeyword ¶
type LPointKeyword struct {
Keyword
}
func (*LPointKeyword) Equals ¶ added in v0.1.4
func (l *LPointKeyword) Equals(node Node) bool
func (*LPointKeyword) Type ¶
func (l *LPointKeyword) Type() string
type ListSeparatorKeyword ¶
func (*ListSeparatorKeyword) Equals ¶ added in v0.1.4
func (e *ListSeparatorKeyword) Equals(node Node) bool
func (*ListSeparatorKeyword) Type ¶
func (e *ListSeparatorKeyword) Type() string
type Literal ¶
type Literal struct { Value *LiteralValue Quote string // single for ', double for " Comments []*Comment BadNode bool Location }
func NewBadLiteral ¶
func NewLiteral ¶
func NewLiteral(comments []*Comment, v *LiteralValue, quote string, loc Location) *Literal
TODO: 区分单引号还是双引号?
func (*Literal) ChildrenBadNode ¶
type LiteralValue ¶
func NewBadLiteralValue ¶
func NewBadLiteralValue(loc Location) *LiteralValue
func NewLiteralValue ¶
func NewLiteralValue(text string, loc Location) *LiteralValue
func (*LiteralValue) Children ¶
func (l *LiteralValue) Children() []Node
func (*LiteralValue) ChildrenBadNode ¶
func (l *LiteralValue) ChildrenBadNode() bool
func (*LiteralValue) Equals ¶ added in v0.1.4
func (l *LiteralValue) Equals(node Node) bool
func (*LiteralValue) IsBadNode ¶
func (l *LiteralValue) IsBadNode() bool
func (*LiteralValue) Type ¶
func (l *LiteralValue) Type() string
type Location ¶
func NewLocation ¶
func NewLocationFromCurrent ¶
func NewLocationFromCurrent(c *current) Location
func NewLocationFromPos ¶
func (Location) MoveStartInLine ¶
type Namespace ¶
type Namespace struct { NamespaceKeyword *NamespaceKeyword Language *NamespaceScope Name *Identifier Annotations *Annotations Comments []*Comment EndLineComments []*Comment BadNode bool Location }
func NewBadNamespace ¶
func NewNamespace ¶
func NewNamespace(keyword *NamespaceKeyword, language *NamespaceScope, name *Identifier, annotations *Annotations, loc Location) *Namespace
func (*Namespace) ChildrenBadNode ¶
func (*Namespace) SetComments ¶
func (*Namespace) SetLocation ¶
type NamespaceKeyword ¶
type NamespaceKeyword struct {
Keyword
}
func (*NamespaceKeyword) Equals ¶ added in v0.1.4
func (n *NamespaceKeyword) Equals(node Node) bool
func (*NamespaceKeyword) Type ¶
func (n *NamespaceKeyword) Type() string
type NamespaceScope ¶
type NamespaceScope struct {
Identifier
}
func (*NamespaceScope) Equals ¶ added in v0.1.4
func (ns *NamespaceScope) Equals(node Node) bool
type Node ¶
type Node interface { // position of first charactor of this node Pos() Position // position of first charactor immediately after this node End() Position Contains(pos Position) bool Children() []Node Type() string IsBadNode() bool ChildrenBadNode() bool // Equals checks ast equals between two node Equals(node Node) bool }
func SearchNodePathByPosition ¶ added in v0.0.9
type OnewayKeyword ¶
type OnewayKeyword struct {
Keyword
}
func (*OnewayKeyword) Equals ¶ added in v0.1.4
func (o *OnewayKeyword) Equals(node Node) bool
func (*OnewayKeyword) Type ¶
func (o *OnewayKeyword) Type() string
type Option ¶
type Option func(*parser) Option
Option is a function that can set an option on the parser. It returns the previous setting as an Option.
func AllowInvalidUTF8 ¶
AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) by character class matchers and is matched by the any matcher. The returned matched value, c.text and c.offset are NOT affected.
The default is false.
func Debug ¶
Debug creates an Option to set the debug flag to b. When set to true, debugging information is printed to stdout while parsing.
The default is false.
func Entrypoint ¶
Entrypoint creates an Option to set the rule name to use as entrypoint. The rule name must have been specified in the -alternate-entrypoints if generating the parser with the -optimize-grammar flag, otherwise it may have been optimized out. Passing an empty string sets the entrypoint to the first rule in the grammar.
The default is to start parsing at the first rule in the grammar.
func GlobalStore ¶
GlobalStore creates an Option to set a key to a certain value in the globalStore.
func InitState ¶
InitState creates an Option to set a key to a certain value in the global "state" store.
func MaxExpressions ¶
MaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).
The default for maxExprCnt is 0.
func Memoize ¶
Memoize creates an Option to set the memoize flag to b. When set to true, the parser will cache all results so each expression is evaluated only once. This guarantees linear parsing time even for pathological cases, at the expense of more memory and slower times for typical cases.
The default is false.
func Recover ¶
Recover creates an Option to set the recover flag to b. When set to true, this causes the parser to recover from panics and convert it to an error. Setting it to false can be useful while debugging to access the full stack trace.
The default is true.
func Statistics ¶
Statistics adds a user provided Stats struct to the parser to allow the user to process the results after the parsing has finished. Also the key for the "no match" counter is set.
Example usage:
input := "input" stats := Stats{} _, err := Parse("input-file", []byte(input), Statistics(&stats, "no match")) if err != nil { log.Panicln(err) } b, err := json.MarshalIndent(stats.ChoiceAltCnt, "", " ") if err != nil { log.Panicln(err) } fmt.Println(string(b))
type PEGParser ¶
type PEGParser struct {
// contains filtered or unexported fields
}
PEGParser use PEG as a parser implementation
func (*PEGParser) ParseRecursively ¶
func (p *PEGParser) ParseRecursively(filename string, content []byte, maxDepth int, call IncludeCall) []*ParseResult
type ParseResult ¶
type Parser ¶
type Parser interface { Parse(filename string, content []byte) *ParseResult ParseRecursively(filename string, content []byte, maxDepth int, call IncludeCall) []*ParseResult }
type ParserError ¶
type ParserError interface { Error() string InnerError() error Pos() (int, int, int) Expected() []string }
ParserError is the public interface to errors of type parserError
type Position ¶
type Position struct { Line int // 1-based line number Col int // 1-based rune count from start of line. Offset int // 0-based byte offset }
func ConvertPosition ¶
func ConvertPosition(pos position) Position
type RBrkKeyword ¶
type RBrkKeyword struct {
Keyword
}
func (*RBrkKeyword) Equals ¶ added in v0.1.4
func (l *RBrkKeyword) Equals(node Node) bool
func (*RBrkKeyword) Type ¶
func (l *RBrkKeyword) Type() string
type RCurKeyword ¶
type RCurKeyword struct {
Keyword
}
func (*RCurKeyword) Equals ¶ added in v0.1.4
func (s *RCurKeyword) Equals(node Node) bool
func (*RCurKeyword) Type ¶
func (s *RCurKeyword) Type() string
type RParKeyword ¶
type RParKeyword struct {
Keyword
}
func (*RParKeyword) Equals ¶ added in v0.1.4
func (r *RParKeyword) Equals(node Node) bool
func (*RParKeyword) Type ¶
func (r *RParKeyword) Type() string
type RPointKeyword ¶
type RPointKeyword struct {
Keyword
}
func (*RPointKeyword) Equals ¶ added in v0.1.4
func (r *RPointKeyword) Equals(node Node) bool
func (*RPointKeyword) Type ¶
func (r *RPointKeyword) Type() string
type RequiredKeyword ¶
type RequiredKeyword struct {
Keyword
}
func (*RequiredKeyword) Equals ¶ added in v0.1.4
func (r *RequiredKeyword) Equals(node Node) bool
func (*RequiredKeyword) Type ¶
func (r *RequiredKeyword) Type() string
type Service ¶
type Service struct { ServiceKeyword *ServiceKeyword ExtendsKeyword *ExtendsKeyword // can be nil LCurKeyword *LCurKeyword RCurKeyword *RCurKeyword Name *Identifier Extends *Identifier Functions []*Function Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadService ¶
func NewService ¶
func NewService(serviceKeyword *ServiceKeyword, extendsKeyword *ExtendsKeyword, lCurKeyword *LCurKeyword, rCurKeyword *RCurKeyword, name *Identifier, extends *Identifier, fns []*Function, loc Location) *Service
func (*Service) ChildrenBadNode ¶
func (*Service) SetAnnotations ¶
func (s *Service) SetAnnotations(annos *Annotations)
func (*Service) SetComments ¶
func (*Service) SetLocation ¶
type ServiceKeyword ¶
type ServiceKeyword struct {
Keyword
}
func (*ServiceKeyword) Equals ¶ added in v0.1.4
func (s *ServiceKeyword) Equals(node Node) bool
func (*ServiceKeyword) Type ¶
func (s *ServiceKeyword) Type() string
type Stats ¶
type Stats struct { // ExprCnt counts the number of expressions processed during parsing // This value is compared to the maximum number of expressions allowed // (set by the MaxExpressions option). ExprCnt uint64 // ChoiceAltCnt is used to count for each ordered choice expression, // which alternative is used how may times. // These numbers allow to optimize the order of the ordered choice expression // to increase the performance of the parser // // The outer key of ChoiceAltCnt is composed of the name of the rule as well // as the line and the column of the ordered choice. // The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative. // For each alternative the number of matches are counted. If an ordered choice does not // match, a special counter is incremented. The name of this counter is set with // the parser option Statistics. // For an alternative to be included in ChoiceAltCnt, it has to match at least once. ChoiceAltCnt map[string]map[string]int }
Stats stores some statistics, gathered during parsing
type Struct ¶
type Struct struct { StructKeyword *StructKeyword LCurKeyword *LCurKeyword RCurKeyword *RCurKeyword Identifier *Identifier Fields []*Field Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadStruct ¶
func NewStruct ¶
func NewStruct(structKeyword *StructKeyword, lCurKeyword *LCurKeyword, rCurKeyword *RCurKeyword, identifier *Identifier, fields []*Field, loc Location) *Struct
func (*Struct) ChildrenBadNode ¶
func (*Struct) SetAnnotations ¶
func (s *Struct) SetAnnotations(annos *Annotations)
func (*Struct) SetComments ¶
func (*Struct) SetLocation ¶
type StructKeyword ¶
type StructKeyword struct {
Keyword
}
func (*StructKeyword) Equals ¶ added in v0.1.4
func (s *StructKeyword) Equals(node Node) bool
func (*StructKeyword) Type ¶
func (s *StructKeyword) Type() string
type Throws ¶
type Throws struct { ThrowsKeyword *ThrowsKeyword LParKeyword *LParKeyword RParKeyword *RParKeyword Fields []*Field BadNode bool Location }
func NewThrows ¶
func NewThrows(throwsKeyword *ThrowsKeyword, lparKeyword *LParKeyword, rparKeyword *RParKeyword, fields []*Field, loc Location) *Throws
func (*Throws) ChildrenBadNode ¶
type ThrowsKeyword ¶
type ThrowsKeyword struct {
Keyword
}
func (*ThrowsKeyword) Equals ¶ added in v0.1.4
func (t *ThrowsKeyword) Equals(node Node) bool
func (*ThrowsKeyword) Type ¶
func (t *ThrowsKeyword) Type() string
type TypeName ¶
type TypeName struct { // TypeName can be: // container type: map, set, list // base type: bool, byte, i8, i16, i32, i64, double, string, binary // struct, enum, union, exception, identifier Name string Comments []*Comment BadNode bool Location }
func NewTypeName ¶
func (*TypeName) ChildrenBadNode ¶
type Typedef ¶
type Typedef struct { TypedefKeyword *TypedefKeyword T *FieldType Alias *Identifier Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadTypedef ¶
func NewTypedef ¶
func NewTypedef(keyword *TypedefKeyword, t *FieldType, alias *Identifier, loc Location) *Typedef
func (*Typedef) ChildrenBadNode ¶
func (*Typedef) SetAnnotations ¶
func (t *Typedef) SetAnnotations(annos *Annotations)
func (*Typedef) SetComments ¶
func (*Typedef) SetLocation ¶
type TypedefKeyword ¶
type TypedefKeyword struct {
Keyword
}
func (*TypedefKeyword) Equals ¶ added in v0.1.4
func (t *TypedefKeyword) Equals(node Node) bool
func (*TypedefKeyword) Type ¶
func (t *TypedefKeyword) Type() string
type Union ¶
type Union struct { UnionKeyword *UnionKeyword LCurKeyword *LCurKeyword RCurKeyword *RCurKeyword Name *Identifier Fields []*Field Comments []*Comment EndLineComments []*Comment Annotations *Annotations BadNode bool Location }
func NewBadUnion ¶
func NewUnion ¶
func NewUnion(unionKeyword *UnionKeyword, lCurKeyword *LCurKeyword, rCurKeyword *RCurKeyword, name *Identifier, fields []*Field, loc Location) *Union
func (*Union) ChildrenBadNode ¶
func (*Union) SetAnnotations ¶
func (u *Union) SetAnnotations(annos *Annotations)
func (*Union) SetComments ¶
func (*Union) SetLocation ¶
type UnionKeyword ¶
type UnionKeyword struct {
Keyword
}
func (*UnionKeyword) Equals ¶ added in v0.1.4
func (u *UnionKeyword) Equals(node Node) bool
func (*UnionKeyword) Type ¶
func (u *UnionKeyword) Type() string
type VoidKeyword ¶
type VoidKeyword struct {
Keyword
}
func (*VoidKeyword) Equals ¶ added in v0.1.4
func (v *VoidKeyword) Equals(node Node) bool
func (*VoidKeyword) Type ¶
func (v *VoidKeyword) Type() string