parser

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

This is a *generic* implementation of a lexer. gengen should be used to create a specific version of this lexer. If this file does not contain the gengen package, then it has already been generated by gengen. TODO: remove this hack if/when golang ever supports proper generics.

parser package defines the parser and lexer for translating a *supported subset* of WebIDL (http://www.w3.org/TR/WebIDL/) into an AST.

This is a *generic* implementation of a parser. gengen should be used to create a specific version of this parser. If this file does not contain the gengen package, then it has already been generated by gengen. TODO: remove this hack if/when golang ever supports proper generics.

Copyright 2015 The Serulian Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2015 The Serulian Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	//
	// All nodes
	//
	// The source of this node.
	NodePredicateSource = "input-source"

	// The rune position in the input string at which this node begins.
	NodePredicateStartRune = "start-rune"

	// The rune position in the input string at which this node ends.
	NodePredicateEndRune = "end-rune"

	// A direct child of this node. Implementations should handle the ordering
	// automatically for this predicate.
	NodePredicateChild = "child-node"

	// The message for the parsing error.
	NodePredicateErrorMessage = "error-message"

	// The value of the comment, including its delimeter(s)
	NodePredicateCommentValue = "comment-value"

	// Decorates with the name of the annotation.
	NodePredicateAnnotationName = "annotation-name"

	// Connects an annotation to a parameter.
	NodePredicateAnnotationParameter = "annotation-parameter"

	// Decorates an annotation with its defined value. For example [Foo=Value], "Bar" is
	// the defined value.
	NodePredicateAnnotationDefinedValue = "annotation-defined-value"

	// Decorates a parameter with its name.
	NodePredicateParameterName = "parameter-name"

	// Decorates a parameter as being optional.
	NodePredicateParameterOptional = "parameter-optional"

	// Decorates a parameter with its type.
	NodePredicateParameterType = "parameter-type"

	// Decorates a declaration with its kind (interface, etc)
	NodePredicateDeclarationKind = "declaration-kind"

	// Decorates a declaration with its parent type.
	NodePredicateDeclarationParentType = "declaration-parent-type"

	// Decorates a declaration with its name.
	NodePredicateDeclarationName = "declaration-name"

	// Connects a declaration to an annotation.
	NodePredicateDeclarationAnnotation = "declaration-annotation"

	// Connects a declaration to one of its member definitions.
	NodePredicateDeclarationMember = "declaration-member"

	// Connects a declaration with a custom operation (serializer, jsonifier, etc).
	NodePredicateDeclarationCustomOperation = "declaration-custom-operation"

	//
	// NodeTypeCustomOp
	//
	NodePredicateCustomOpName = "custom-op-name"

	// Decorates a member with its name.
	NodePredicateMemberName = "member-name"

	// Decorates a member as being an attribute (instead of an operation).
	NodePredicateMemberAttribute = "member-attribute"

	// Decorates a member as being static.
	NodePredicateMemberStatic = "member-static"

	// Decorates a member as being readonly.
	NodePredicateMemberReadonly = "member-readonly"

	// Decorates a member with its type.
	NodePredicateMemberType = "member-type"

	// Connects a member to a parameter.
	NodePredicateMemberParameter = "member-parameter"

	// Connects a member to an annotation.
	NodePredicateMemberAnnotation = "member-annotation"

	// Decorates an anonymous member with its specialized type.
	NodePredicateMemberSpecialization = "member-specialization"

	// Decorates an implementation with its name.
	NodePredicateImplementationName = "implementation-name"

	// Decorates an implementation with the name of its source interface.
	NodePredicateImplementationSource = "implementation-source"
)
View Source
const EOFRUNE = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type AstNode

type AstNode interface {
	// Connect connects this AstNode to another AstNode with the given predicate,
	// and returns the same AstNode.
	Connect(predicate string, other AstNode) AstNode

	// Decorate decorates this AstNode with the given property and string value,
	// and returns the same AstNode.
	Decorate(property string, value string) AstNode

	// Decorate decorates this AstNode with the given property and int value,
	// and returns the same AstNode.
	DecorateWithInt(property string, value int) AstNode
}

AstNode defines an interface for working with nodes created by this parser.

func Parse

func Parse(moduleNode AstNode, builder NodeBuilder, source compilercommon.InputSource, input string) AstNode

Parse parses the given WebIDL source into a parse tree.

type NodeBuilder

type NodeBuilder func(source compilercommon.InputSource, kind NodeType) AstNode

NodeBuilder is a function for building AST nodes.

type NodeType

type NodeType int

NodeType identifies the type of AST node.

const (
	// Top-level
	NodeTypeError             NodeType = iota // error occurred; value is text of error
	NodeTypeGlobalModule                      // Virtual node created to hold all files.
	NodeTypeGlobalDeclaration                 // Virtual node created to hold all declarations.

	NodeTypeFile    // The file root node
	NodeTypeComment // A single or multiline comment

	NodeTypeCustomOp    // A custom operation (serializer, etc)
	NodeTypeAnnotation  // [Constructor]
	NodeTypeParameter   // optional any SomeArg
	NodeTypeDeclaration // interface Foo { ... }
	NodeTypeMember      // readonly attribute something

	NodeTypeImplementation // Window implements ECMA262Globals

	NodeTypeTagged
)

func (NodeType) Build

func (t NodeType) Build(value string) interface{}

func (NodeType) Name

func (t NodeType) Name() string

func (NodeType) String

func (i NodeType) String() string

func (NodeType) Value

func (t NodeType) Value() string

Jump to

Keyboard shortcuts

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