c6: github.com/c9s/c6/parser Index | Files

package parser

import "github.com/c9s/c6/parser"

Index

Package Files

ast_map.go config_release.go encoding.go errors.go parser.go rules.go

Constants

const (
    UnknownFileType uint = iota
    ScssFileType
    SassFileType
    EcssFileType
)
const DEBUG_EMIT = false

Variables

var AbsoluteUrlPattern = regexp.MustCompile("^[a-zA-Z]+?://")
var HttpUrlPattern = regexp.MustCompile("^https?://")

type ASTFileMap Uses

type ASTFileMap map[string]interface{}

* We will cache the compiled ast.Block in the map,

var ASTCache ASTFileMap = ASTFileMap{}

type Parser Uses

type Parser struct {
    GlobalContext *runtime.Context
    ContextStack  []runtime.Context

    File *ast.File

    // file content
    Content string

    // The token input channel, feeded by github.com/c9s/c6/lexer
    Input chan *ast.Token

    // Integer for counting token
    Pos int

    // Position saved for rollbacking back.
    RollbackPos int

    // A token slice that contains all lexed tokens
    Tokens []*ast.Token

    TopScope *ast.Scope // The top-most scope
}

func NewParser Uses

func NewParser(context *runtime.Context) *Parser

func (*Parser) ParseAssignStmt Uses

func (parser *Parser) ParseAssignStmt() ast.Stmt

func (*Parser) ParseBlock Uses

func (parser *Parser) ParseBlock() *ast.Block

ParseBlock method allows root level statements, which does not allow css properties.

func (*Parser) ParseBoolean Uses

func (parser *Parser) ParseBoolean() ast.Expr

func (*Parser) ParseCharsetStmt Uses

func (parser *Parser) ParseCharsetStmt() ast.Stmt

func (*Parser) ParseCommaSepList Uses

func (parser *Parser) ParseCommaSepList() ast.Expr

func (*Parser) ParseComparisonExpr Uses

func (parser *Parser) ParseComparisonExpr() ast.Expr

func (*Parser) ParseComplexSelector Uses

func (parser *Parser) ParseComplexSelector(parentRuleSet *ast.RuleSet) *ast.ComplexSelector

func (*Parser) ParseCompoundSelector Uses

func (parser *Parser) ParseCompoundSelector(parentRuleSet *ast.RuleSet) *ast.CompoundSelector

func (*Parser) ParseCondition Uses

func (parser *Parser) ParseCondition() ast.Expr

The operator precedence is described here

@see http://introcs.cs.princeton.edu/java/11precedence/

func (*Parser) ParseContentStmt Uses

func (parser *Parser) ParseContentStmt() ast.Stmt

@content directive is only allowed in mixin block

func (*Parser) ParseDeclBlock Uses

func (parser *Parser) ParseDeclBlock() *ast.DeclBlock

func (*Parser) ParseDeclaration Uses

func (parser *Parser) ParseDeclaration() ast.Stmt

func (*Parser) ParseExpr Uses

func (parser *Parser) ParseExpr(inParenthesis bool) ast.Expr

*

We here treat the property values as expressions:

padding: {expression} {expression} {expression};
margin: {expression};

func (*Parser) ParseExtendStmt Uses

func (parser *Parser) ParseExtendStmt() ast.Stmt

func (*Parser) ParseFactor Uses

func (parser *Parser) ParseFactor() ast.Expr

* The ParseFactor must return an Expr interface compatible object

func (*Parser) ParseFile Uses

func (parser *Parser) ParseFile(path string) error

func (*Parser) ParseFlags Uses

func (parser *Parser) ParseFlags(stm *ast.AssignStmt)

ParseFlags requires a variable assignment.

func (*Parser) ParseFontFaceStmt Uses

func (parser *Parser) ParseFontFaceStmt() ast.Stmt

func (*Parser) ParseForStmt Uses

func (parser *Parser) ParseForStmt() ast.Stmt

Parse the SASS @for statement.

@for $var from <start> to <end> {  }

@for $var from <start> through <end> {  }

@see http://sass-lang.com/documentation/file.SASS_REFERENCE.html#_10

func (*Parser) ParseFunctionCall Uses

func (parser *Parser) ParseFunctionCall() *ast.FunctionCall

func (*Parser) ParseFunctionCallArgument Uses

func (parser *Parser) ParseFunctionCallArgument() *ast.Argument

func (*Parser) ParseFunctionCallArguments Uses

func (parser *Parser) ParseFunctionCallArguments() *ast.ArgumentList

func (*Parser) ParseFunctionDeclaration Uses

func (parser *Parser) ParseFunctionDeclaration() ast.Stmt

func (*Parser) ParseFunctionPrototype Uses

func (parser *Parser) ParseFunctionPrototype() *ast.ArgumentList

func (*Parser) ParseFunctionPrototypeArgument Uses

func (parser *Parser) ParseFunctionPrototypeArgument() *ast.Argument

func (*Parser) ParseIdent Uses

func (parser *Parser) ParseIdent() *ast.Ident

func (*Parser) ParseIfStmt Uses

func (parser *Parser) ParseIfStmt() ast.Stmt

func (*Parser) ParseImportStmt Uses

func (parser *Parser) ParseImportStmt() ast.Stmt

The @import syntax is described here:

@see CSS2.1 http://www.w3.org/TR/CSS2/cascade.html#at-import

@see https://developer.mozilla.org/en-US/docs/Web/CSS/@import

func (*Parser) ParseIncludeStmt Uses

func (parser *Parser) ParseIncludeStmt() ast.Stmt

func (*Parser) ParseInterp Uses

func (parser *Parser) ParseInterp() ast.Expr

func (*Parser) ParseInterpolation Uses

func (parser *Parser) ParseInterpolation() ast.Expr

func (*Parser) ParseKeywordArguments Uses

func (parser *Parser) ParseKeywordArguments(fcall *ast.FunctionCall) *ast.FunctionCallArguments

This parse method looks up the argument in the function declaration and convert the keyword arguments into the argument list. this way, we can handle the function call in a simple way - push/pop the stack.

@param fcall ast.FunctionCall The current parsing function call ast node @return arguments []Expr

func (*Parser) ParseList Uses

func (parser *Parser) ParseList() ast.Expr

func (*Parser) ParseLiteralExpr Uses

func (parser *Parser) ParseLiteralExpr() ast.Expr

Parse string literal expression (literal concat with interpolation)

func (*Parser) ParseLogStmt Uses

func (parser *Parser) ParseLogStmt() ast.Stmt

func (*Parser) ParseLogicANDExpr Uses

func (parser *Parser) ParseLogicANDExpr() ast.Expr

func (*Parser) ParseLogicExpr Uses

func (parser *Parser) ParseLogicExpr() ast.Expr

func (*Parser) ParseMap Uses

func (parser *Parser) ParseMap() ast.Expr

func (*Parser) ParseMediaQuery Uses

func (parser *Parser) ParseMediaQuery() *ast.MediaQuery

This method parses media type first, then expecting more that on media expressions.

media_query: [[only | not]? <media_type> [ and <expression> ]*]

| <expression> [ and <expression> ]*

expression: ( <media_feature> [: <value>]? )

Specification: http://dev.w3.org/csswg/mediaqueries-3

func (*Parser) ParseMediaQueryExpr Uses

func (parser *Parser) ParseMediaQueryExpr() ast.Expr

An media query expression must start with a '(' and ends with ')'

func (*Parser) ParseMediaQueryList Uses

func (parser *Parser) ParseMediaQueryList() *ast.MediaQueryList

func (*Parser) ParseMediaQueryStmt Uses

func (parser *Parser) ParseMediaQueryStmt() ast.Stmt

Media Query Syntax: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

func (*Parser) ParseMediaType Uses

func (parser *Parser) ParseMediaType() *ast.MediaType

ParseMediaType returns Ident Node or UnaryExpr as ast.Expr

func (*Parser) ParseMixinStmt Uses

func (parser *Parser) ParseMixinStmt() ast.Stmt

func (*Parser) ParseNumber Uses

func (parser *Parser) ParseNumber() ast.Expr

func (*Parser) ParsePropertyName Uses

func (parser *Parser) ParsePropertyName() ast.Expr

func (*Parser) ParsePropertyNameToken Uses

func (parser *Parser) ParsePropertyNameToken() ast.Expr

func (*Parser) ParsePropertyValue Uses

func (parser *Parser) ParsePropertyValue(parentRuleSet *ast.RuleSet, property *ast.Property) *ast.List

* We treat the property value section as a list value, which is separated by ',' or ' '

func (*Parser) ParseReturnStmt Uses

func (parser *Parser) ParseReturnStmt() ast.Stmt

func (*Parser) ParseRuleSet Uses

func (parser *Parser) ParseRuleSet() ast.Stmt

func (*Parser) ParseScss Uses

func (parser *Parser) ParseScss(code string) *ast.StmtList

func (*Parser) ParseScssFile Uses

func (parser *Parser) ParseScssFile(file string) (*ast.StmtList, error)

func (*Parser) ParseSelectorList Uses

func (parser *Parser) ParseSelectorList() *ast.ComplexSelectorList

func (*Parser) ParseSimpleSelector Uses

func (parser *Parser) ParseSimpleSelector(parentRuleSet *ast.RuleSet) ast.Selector

func (*Parser) ParseSpaceSepList Uses

func (parser *Parser) ParseSpaceSepList() ast.Expr

func (*Parser) ParseStmt Uses

func (parser *Parser) ParseStmt() ast.Stmt

func (*Parser) ParseStmts Uses

func (parser *Parser) ParseStmts() *ast.StmtList

func (*Parser) ParseString Uses

func (parser *Parser) ParseString() ast.Expr

func (*Parser) ParseTerm Uses

func (parser *Parser) ParseTerm() ast.Expr

func (*Parser) ParseValue Uses

func (parser *Parser) ParseValue(stopTokType ast.TokenType) ast.Expr

* Parse Value loosely

This parse method allows space/comma separated tokens of list.

To parse mixin argument or function argument, we only allow comma-separated list inside the parenthesis.

@param stopTokType ast.TokenType

The stop token is used from variable assignment expression, We expect ';' semicolon at the end of expression to avoid the ambiguity of list, map and expression.

func (*Parser) ParseValueStrict Uses

func (parser *Parser) ParseValueStrict() ast.Expr

func (*Parser) ParseVariable Uses

func (parser *Parser) ParseVariable() *ast.Variable

func (*Parser) ParseWhileStmt Uses

func (parser *Parser) ParseWhileStmt() ast.Stmt

func (*Parser) ReadFile Uses

func (parser *Parser) ReadFile(file string) error

type ParserError Uses

type ParserError struct {
    ExpectingToken string
    ActualToken    string
}

Parser's fault

func (ParserError) Error Uses

func (e ParserError) Error() string

type SyntaxError Uses

type SyntaxError struct {
    Reason      string
    ActualToken *ast.Token
    Guide       string
    GuideUrl    string
    File        *ast.File
}

User's fault, probably.

Struct for common syntax error.

Examples:

panic(SyntaxError{

Reason: ...,
ActualToken: tok,

})

func (SyntaxError) Error Uses

func (err SyntaxError) Error() (out string)

Package parser imports 9 packages (graph). Updated 2017-10-13. Refresh now. Tools for package owners.