parser

package
v2.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedEOF = fmt.Errorf("unexpected end of file")
)

Functions

func TokenIsBlockStart

func TokenIsBlockStart(t token.Token) bool

TokenIsBlockStart returns true for a <(-token>, <{-token> or <[-token>.

func TokenIsDashndashdigitIdent

func TokenIsDashndashdigitIdent(t token.Token) bool

TokenIsDashndashdigitIdent returns true for a token that is a <dashndashdigit-ident>: an <ident-token> whose value is an ASCII case-insensitive match for "-n-*", where "*" is a series of one or more digits.

func TokenIsInteger

func TokenIsInteger(t token.Token) bool

TokenIsInteger returns true for a token that is an <integer>: a <number-token> with its type flag set to "integer".

func TokenIsNDimension

func TokenIsNDimension(t token.Token) bool

TokenIsNDimension returns true for a token that is a <n-dimension>: a <dimension-token> with its type flag set to "integer", and a unit that is an ASCII case-insensitive match for "n".

func TokenIsNdashdigitDimension

func TokenIsNdashdigitDimension(t token.Token) bool

TokenIsNdashdigitDimension returns true for a token that is a <ndashdigit-dimension>: a <dimension-token> with its type flag set to "integer", and a unit that is an ASCII case-insensitive match for "n-*", where "*" is a series of one or more digits.

func TokenIsNdashdigitIdent

func TokenIsNdashdigitIdent(t token.Token) bool

TokenIsNdashdigitIdent returns true for a token that is a <ndashdigit-ident>: an <ident-token> whose value is an ASCII case-insensitive match for "n-*", where "*" is a series of one or more digits.

func TokenIsSignedInteger

func TokenIsSignedInteger(t token.Token) bool

TokenIsSignedInteger returns true for a token that is a <signed-integer>: a <number-token> with its type flag set to "integer", and whose representation starts with "+" or "-".

func TokenIsSignlessInteger

func TokenIsSignlessInteger(t token.Token) bool

TokenIsSignlessInteger returns true for a token that is a <signless-integer>: a <number-token> with its type flag set to "integer", and whose representation starts with a digit.

Types

type Parser

type Parser struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"strings"

	"github.com/tawesoft/golib/v2/css/internal/parser"
	"github.com/tawesoft/golib/v2/css/tokenizer/token"
)

func main() {
	str := `rgb(128, 64, 64)`
	p := parser.New(strings.NewReader(str))
	k := p.Tokenizer()

	for {
		cv := p.ConsumeComponentValue(k)
		if cv.IsPreservedToken(token.EOF()) {
			break
		}
		fmt.Println(cv)
	}

	/*
	   if len(t.Errors()) > 0 {
	       fmt.Printf("%v\n", t.Errors())
	   }
	*/

}
Output:

<ComponentValue/Function{Name: "rgb", Value: [<ComponentValue:<number-token>{type: "integer", value: 128.000000, repr: "128"}> <ComponentValue:<comma-token>> <ComponentValue:<whitespace-token>> <ComponentValue:<number-token>{type: "integer", value: 64.000000, repr: "64"}> <ComponentValue:<comma-token>> <ComponentValue:<whitespace-token>> <ComponentValue:<number-token>{type: "integer", value: 64.000000, repr: "64"}>]}>

func New

func New(r io.Reader) *Parser

func (*Parser) ConsumeBlock

func (p *Parser) ConsumeBlock(k *tokenizer.Tokenizer, start token.Token) item.Block

ConsumeBlock consumes a simple block. Note that this algorithm assumes that the current input token has already been checked to be an <{-token>, <[-token>, or <(-token>.

func (*Parser) ConsumeComponentValue

func (p *Parser) ConsumeComponentValue(k *tokenizer.Tokenizer) item.ComponentValue

func (*Parser) ConsumeFunction

func (p *Parser) ConsumeFunction(k *tokenizer.Tokenizer, name token.Token) item.Function

ConsumeFunction consumes a function. Note: This algorithm assumes that the current input token has already been checked to be a <function-token>.

func (*Parser) Errors

func (p *Parser) Errors() []error

func (*Parser) Tokenizer

func (p *Parser) Tokenizer() *tokenizer.Tokenizer

Directories

Path Synopsis
Package item defines CSS items in the tree produced by a parser.
Package item defines CSS items in the tree produced by a parser.

Jump to

Keyboard shortcuts

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