[6a3a178] | 1 | var tokenizer = require('../../tokenizer');
|
---|
| 2 | var TYPE = tokenizer.TYPE;
|
---|
| 3 |
|
---|
| 4 | var WhiteSpace = TYPE.WhiteSpace;
|
---|
| 5 | var Semicolon = TYPE.Semicolon;
|
---|
| 6 | var LeftCurlyBracket = TYPE.LeftCurlyBracket;
|
---|
| 7 | var Delim = TYPE.Delim;
|
---|
| 8 | var EXCLAMATIONMARK = 0x0021; // U+0021 EXCLAMATION MARK (!)
|
---|
| 9 |
|
---|
| 10 | function getOffsetExcludeWS() {
|
---|
| 11 | if (this.scanner.tokenIndex > 0) {
|
---|
| 12 | if (this.scanner.lookupType(-1) === WhiteSpace) {
|
---|
| 13 | return this.scanner.tokenIndex > 1
|
---|
| 14 | ? this.scanner.getTokenStart(this.scanner.tokenIndex - 1)
|
---|
| 15 | : this.scanner.firstCharOffset;
|
---|
| 16 | }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | return this.scanner.tokenStart;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | // 0, 0, false
|
---|
| 23 | function balanceEnd() {
|
---|
| 24 | return 0;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | // LEFTCURLYBRACKET, 0, false
|
---|
| 28 | function leftCurlyBracket(tokenType) {
|
---|
| 29 | return tokenType === LeftCurlyBracket ? 1 : 0;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | // LEFTCURLYBRACKET, SEMICOLON, false
|
---|
| 33 | function leftCurlyBracketOrSemicolon(tokenType) {
|
---|
| 34 | return tokenType === LeftCurlyBracket || tokenType === Semicolon ? 1 : 0;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | // EXCLAMATIONMARK, SEMICOLON, false
|
---|
| 38 | function exclamationMarkOrSemicolon(tokenType, source, offset) {
|
---|
| 39 | if (tokenType === Delim && source.charCodeAt(offset) === EXCLAMATIONMARK) {
|
---|
| 40 | return 1;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | return tokenType === Semicolon ? 1 : 0;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | // 0, SEMICOLON, true
|
---|
| 47 | function semicolonIncluded(tokenType) {
|
---|
| 48 | return tokenType === Semicolon ? 2 : 0;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | module.exports = {
|
---|
| 52 | name: 'Raw',
|
---|
| 53 | structure: {
|
---|
| 54 | value: String
|
---|
| 55 | },
|
---|
| 56 | parse: function(startToken, mode, excludeWhiteSpace) {
|
---|
| 57 | var startOffset = this.scanner.getTokenStart(startToken);
|
---|
| 58 | var endOffset;
|
---|
| 59 |
|
---|
| 60 | this.scanner.skip(
|
---|
| 61 | this.scanner.getRawLength(startToken, mode || balanceEnd)
|
---|
| 62 | );
|
---|
| 63 |
|
---|
| 64 | if (excludeWhiteSpace && this.scanner.tokenStart > startOffset) {
|
---|
| 65 | endOffset = getOffsetExcludeWS.call(this);
|
---|
| 66 | } else {
|
---|
| 67 | endOffset = this.scanner.tokenStart;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | return {
|
---|
| 71 | type: 'Raw',
|
---|
| 72 | loc: this.getLocation(startOffset, endOffset),
|
---|
| 73 | value: this.scanner.source.substring(startOffset, endOffset)
|
---|
| 74 | };
|
---|
| 75 | },
|
---|
| 76 | generate: function(node) {
|
---|
| 77 | this.chunk(node.value);
|
---|
| 78 | },
|
---|
| 79 |
|
---|
| 80 | mode: {
|
---|
| 81 | default: balanceEnd,
|
---|
| 82 | leftCurlyBracket: leftCurlyBracket,
|
---|
| 83 | leftCurlyBracketOrSemicolon: leftCurlyBracketOrSemicolon,
|
---|
| 84 | exclamationMarkOrSemicolon: exclamationMarkOrSemicolon,
|
---|
| 85 | semicolonIncluded: semicolonIncluded
|
---|
| 86 | }
|
---|
| 87 | };
|
---|