source: trip-planner-front/node_modules/css-tree/lib/definition-syntax/tokenizer.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1var SyntaxError = require('./SyntaxError');
2
3var TAB = 9;
4var N = 10;
5var F = 12;
6var R = 13;
7var SPACE = 32;
8
9var Tokenizer = function(str) {
10 this.str = str;
11 this.pos = 0;
12};
13
14Tokenizer.prototype = {
15 charCodeAt: function(pos) {
16 return pos < this.str.length ? this.str.charCodeAt(pos) : 0;
17 },
18 charCode: function() {
19 return this.charCodeAt(this.pos);
20 },
21 nextCharCode: function() {
22 return this.charCodeAt(this.pos + 1);
23 },
24 nextNonWsCode: function(pos) {
25 return this.charCodeAt(this.findWsEnd(pos));
26 },
27 findWsEnd: function(pos) {
28 for (; pos < this.str.length; pos++) {
29 var code = this.str.charCodeAt(pos);
30 if (code !== R && code !== N && code !== F && code !== SPACE && code !== TAB) {
31 break;
32 }
33 }
34
35 return pos;
36 },
37 substringToPos: function(end) {
38 return this.str.substring(this.pos, this.pos = end);
39 },
40 eat: function(code) {
41 if (this.charCode() !== code) {
42 this.error('Expect `' + String.fromCharCode(code) + '`');
43 }
44
45 this.pos++;
46 },
47 peek: function() {
48 return this.pos < this.str.length ? this.str.charAt(this.pos++) : '';
49 },
50 error: function(message) {
51 throw new SyntaxError(message, this.str, this.pos);
52 }
53};
54
55module.exports = Tokenizer;
Note: See TracBrowser for help on using the repository browser.