1 | /**
|
2 | * @license
|
3 | * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
4 | * This code may only be used under the BSD style license found at
|
5 | * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
|
6 | * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
|
7 | * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
|
8 | * Google as part of the polymer project is also subject to an additional IP
|
9 | * rights grant found at http://polymer.github.io/PATENTS.txt
|
10 | */
|
11 | import { Range } from './common';
|
12 | import { Token } from './token';
|
13 | /**
|
14 | * Class that implements tokenization of significant lexical features of the
|
15 | * CSS syntax.
|
16 | */
|
17 | declare class Tokenizer {
|
18 | cssText: string;
|
19 | /**
|
20 | * Tracks the position of the tokenizer in the source string.
|
21 | * Also the default head of the Token linked list.
|
22 | */
|
23 | private cursorToken_;
|
24 | /**
|
25 | * Holds a reference to a Token that is "next" in the source string, often
|
26 | * due to having been peeked at.
|
27 | */
|
28 | private currentToken_;
|
29 | /**
|
30 | * Create a Tokenizer instance.
|
31 | * @param cssText The raw CSS string to be tokenized.
|
32 | *
|
33 | */
|
34 | constructor(cssText: string);
|
35 | readonly offset: number;
|
36 | /**
|
37 | * The current token that will be returned by a call to `advance`. This
|
38 | * reference is useful for "peeking" at the next token ahead in the sequence.
|
39 | * If the entire CSS text has been tokenized, the `currentToken` will be null.
|
40 | */
|
41 | readonly currentToken: Token | null;
|
42 | /**
|
43 | * Advance the Tokenizer to the next token in the sequence.
|
44 | * @return The current token prior to the call to `advance`, or null
|
45 | * if the entire CSS text has been tokenized.
|
46 | */
|
47 | advance(): Token | null;
|
48 | /**
|
49 | * Extract a slice from the CSS text, using two tokens to represent the range
|
50 | * of text to be extracted. The extracted text will include all text between
|
51 | * the start index of the first token and the offset index of the second token
|
52 | * (or the offset index of the first token if the second is not provided).
|
53 | * @param startToken The token that represents the beginning of the
|
54 | * text range to be extracted.
|
55 | * @param endToken The token that represents the end of the text range
|
56 | * to be extracted. Defaults to the startToken if no endToken is provided.
|
57 | * @return The substring of the CSS text corresponding to the
|
58 | * startToken and endToken.
|
59 | */
|
60 | slice(startToken: Token, endToken?: Token | undefined | null): string;
|
61 | /**
|
62 | * Like `slice`, but returns the offsets into the source, rather than the
|
63 | * substring itself.
|
64 | */
|
65 | getRange(startToken: Token, endToken?: Token | undefined | null): {
|
66 | start: number;
|
67 | end: number;
|
68 | };
|
69 | trimRange({start, end}: Range): Range;
|
70 | /**
|
71 | * Flush all tokens from the Tokenizer.
|
72 | * @return An array of all tokens corresponding to the CSS text.
|
73 | */
|
74 | flush(): (Token | null)[];
|
75 | /**
|
76 | * Extract the next token from the CSS text and advance the Tokenizer.
|
77 | * @return A Token instance, or null if the entire CSS text has beeen
|
78 | * tokenized.
|
79 | */
|
80 | private getNextToken_();
|
81 | /**
|
82 | * Tokenize a string starting at a given offset in the CSS text. A string is
|
83 | * any span of text that is wrapped by eclusively paired, non-escaped matching
|
84 | * quotation marks.
|
85 | * @param offset An offset in the CSS text.
|
86 | * @return A string Token instance.
|
87 | */
|
88 | tokenizeString(offset: number): Token;
|
89 | /**
|
90 | * Tokenize a word starting at a given offset in the CSS text. A word is any
|
91 | * span of text that is not whitespace, is not a string, is not a comment and
|
92 | * is not a structural delimiter (such as braces and semicolon).
|
93 | * @param number An offset in the CSS text.
|
94 | * @return A word Token instance.
|
95 | */
|
96 | tokenizeWord(offset: number): Token;
|
97 | /**
|
98 | * Tokenize whitespace starting at a given offset in the CSS text. Whitespace
|
99 | * is any span of text made up of consecutive spaces, tabs, newlines and other
|
100 | * single whitespace characters.
|
101 | * @param number An offset in the CSS text.
|
102 | * @return A whitespace Token instance.
|
103 | */
|
104 | tokenizeWhitespace(offset: number): Token;
|
105 | /**
|
106 | * Tokenize a comment starting at a given offset in the CSS text. A comment is
|
107 | * any span of text beginning with the two characters / and *, and ending with
|
108 | * a matching counterpart pair of consecurtive characters (* and /).
|
109 | * @param number An offset in the CSS text.
|
110 | * @return A comment Token instance.
|
111 | */
|
112 | tokenizeComment(offset: number): Token;
|
113 | /**
|
114 | * Tokenize a boundary at a given offset in the CSS text. A boundary is any
|
115 | * single structurally significant character. These characters include braces,
|
116 | * semicolons, the "at" symbol and others.
|
117 | * @param number An offset in the CSS text.
|
118 | * @return A boundary Token instance.
|
119 | */
|
120 | tokenizeBoundary(offset: number): Token;
|
121 | }
|
122 | export { Tokenizer };
|