@grammar/css
Version:
CSS3 grammar.
221 lines • 6.93 kB
TypeScript
import $ from './spellu-engine';
/**
* CSS
* 3.0 - https://www.w3.org/TR/css-syntax-3/
* 2.2 - 2016/4/12 https://www.w3.org/TR/CSS22/
* 1.0 - 2008/4/11 https://www.w3.org/TR/CSS1/
*/
declare namespace grammar$css {
const enum Syntax {
StyleSheet = "css.StyleSheet",
Statement = "css.Statement",
Import = "css.Import",
AtRule = "css.AtRule",
Ruleset = "css.Ruleset",
Selector = "css.Selector",
Declaration = "css.Declaration",
Identifier = "css.Identifier",
Tag = "css.Tag",
Id = "css.Id",
Class = "css.Class",
Attribute = "css.Attribute",
Pseudo = "css.Pseudo",
Combinator = "css.Combinator",
ValueList = "css.ValueList",
Value = "css.Value",
Function = "css.Function"
}
const enum Syntax {
OpenCommentToken = "css.token.open-comment",
CloseCommentToken = "css.token.close-comment",
CommentToken = "css.token.comment",
AsteriskToken = "css.token.*",
IdToken = "css.token.id",
ClassToken = "css.token.class",
IdentToken = "css.token.ident",
NumberToken = "css.token.number",
DimensionToken = "css.token.dimension",
PercentageToken = "css.token.percentage",
HashToken = "css.token.hash",
StringToken = "css.token.string",
ImportantToken = "css.token.important",
CommaToken = "css.token.,",
SlashToken = "css.token.slash",
ColonToken = "css.token.:",
SemiColonToken = "css.token.;",
SingleQuoteToken = "css.token.'",
DoublequoteToken = "css.token.\"",
PlusToken = "css.token.+",
GreaterToken = "css.token.>",
TildaToken = "css.token.~",
AtmarkToken = "css.token.@",
EqualToken = "css.token.=",
HatEqualToken = "css.token.^=",
DollerEqualToken = "css.token.$=",
AsteriskEqualToken = "css.token.*=",
TildaEqualToken = "css.token.~=",
VerticalBarEqualToken = "css.token.|=",
OpenParenToken = "css.token.(",
CloseParenToken = "css.token.)",
OpenBraceToken = "css.token.{",
CloseBraceToken = "css.token.}",
OpenBracketToken = "css.token.[",
CloseBracketToken = "css.token.]",
LooseSlashToken = "css.token.loose-slash"
}
enum ElementCombinator {
Descendant = " ",
Child = ">",
NextSibling = "+",
SubsequentSibling = "~"
}
enum MatchOperator {
WholeMatch = "=",
PrefixMatch = "^=",
SuffixMatch = "$=",
SubstringMatch = "*=",
Includes = "~=",
DashMatch = "|="
}
type Node = Token | StyleSheet | Statement | Selector | SelectorItem | Declaration | Identifier | Expression | Value;
interface Token extends $.Token {
}
interface StyleSheet extends $.Node {
syntax: Syntax.StyleSheet;
statements: Statement[];
}
type Statement = Statement.Import | Statement.Ruleset;
namespace Statement {
interface Import extends $.Node {
syntax: Syntax.Import;
}
interface Ruleset extends $.Node {
syntax: Syntax.Ruleset;
selectors: Selector[];
declarations: Declaration[];
}
}
interface Selector extends $.Node {
syntax: Syntax.Selector;
items: SelectorItem[];
}
type SelectorItem = SelectorItem.Tag | SelectorItem.Id | SelectorItem.Class | SelectorItem.Attribute | SelectorItem.Pseudo | SelectorItem.Combinator;
namespace SelectorItem {
interface Tag extends $.Node {
syntax: Syntax.Tag;
name: string;
}
interface Id extends $.Node {
syntax: Syntax.Id;
name: string;
}
interface Class extends $.Node {
syntax: Syntax.Class;
name: string;
}
interface Attribute extends $.Node {
syntax: Syntax.Attribute;
name: Token;
operator?: MatchOperator;
value?: Value;
}
interface Pseudo extends $.Node {
syntax: Syntax.Pseudo;
name: Token;
parameter?: SelectorItem;
}
interface Combinator extends $.Node {
syntax: Syntax.Combinator;
combinator: ElementCombinator;
}
}
interface Declaration extends $.Node {
syntax: Syntax.Declaration;
property: Identifier;
value: Expression;
important?: boolean;
}
interface Identifier extends $.Node {
syntax: Syntax.Identifier;
name: Token;
}
type Expression = ValueList | Function | Value;
interface ValueList extends $.Node {
syntax: Syntax.ValueList;
items: Expression[];
separator: string;
}
interface Function extends $.Node {
syntax: Syntax.Function;
name: Token;
parameters: Value[];
}
interface Value extends $.Node {
syntax: Syntax.Value;
value: string;
token: Token;
}
}
declare namespace grammar$css {
function selectProcessorSuite(suite: ProcessorSuite): $.Processor[];
function scan<V>(source: string | $.SourceDescriptor, suite?: ProcessorSuite, rule?: string, options?: Partial<$.ScanOptions>): V;
function tokens(source: string | $.SourceDescriptor, options?: Partial<$.ScanOptions>): Token[];
}
declare namespace grammar$css {
const enum PrintFormat {
Minify = 0,
Pretty = 1
}
type PrintOptions = {
format?: PrintFormat;
};
function print(value: StyleSheet, options?: PrintOptions): string;
}
/**
* CSS 3
*
* stylesheet = statement-list
* statement-list = ( ruleset )*
* ruleset = selectorGroup '{' propertyList '}'
* selectorGroup = selector ( ',' selector )*
* selector = selectorItem ( combinator )? selectorItem
* selectorItem = id | class | attribute | pseudo | negation
* id = '#' [a-zA-Z][a-zA-Z0-9]*
* class = '.' [a-zA-Z][a-zA-Z0-9]*
* combinator = '+' | '>' | '~'
* declarationList = ( declaration? ( ';' declaration? )* )?
* declaration = property ':' value
* property = ident
* value = ...
* comment = '/' '*' ... '*' '/'
*/
declare namespace grammar$css.recipes {
const css: $.Recipe;
}
declare namespace grammar$css.recipes {
const selectors: $.Recipe;
}
declare namespace grammar$css.recipes {
const values: $.Recipe;
}
declare namespace grammar$css {
enum ProcessorSuite {
CST = "cst",
AST = "ast"
}
const processors: {
[name: string]: {
[name: string]: $.Processor;
};
};
}
declare namespace grammar$css {
}
declare namespace grammar$css {
}
declare namespace grammar$css {
}
declare namespace grammar$css {
}
export default grammar$css;
//# sourceMappingURL=grammar-css.d.ts.map