How to use character-parser - 10 common examples

To help you get started, we’ve selected a few character-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dortaldt / notyet / node_modules / pug-lexer / index.js View on Github external
attributeValue: function(str){
    var quoteRe = /['"]/;
    var val = '';
    var done, i, x;
    var escapeAttr = true;
    var state = characterParser.defaultState();
    var col = this.colno;
    var line = this.lineno;
    
    // consume all whitespace before the equals sign
    for(i = 0; i < str.length; i++){
      if(!this.whitespaceRe.test(str[i])) break;
      if(str[i] === '\n'){
        line++;
        col = 1;
      } else {
        col++;
      }
    }
    
    if(i === str.length){
      return { remainingSource: str };
github dortaldt / notyet / node_modules / pug-lexer / index.js View on Github external
col = this.colno;
    
    // start looping through the value
    for (; i < str.length; i++) {
      // if the character is in a string or in parentheses/brackets/braces
      if (!(state.isNesting() || state.isString())){
        
        if (this.whitespaceRe.test(str[i])) {
          done = false;
          
          // find the first non-whitespace character
          for (x = i; x < str.length; x++) {
            if (!this.whitespaceRe.test(str[x])) {
              // if it is a JavaScript punctuator, then assume that it is
              // a part of the value
              if((!characterParser.isPunctuator(str[x]) || quoteRe.test(str[x]) || str[x] === ':') && this.assertExpression(val, true)){
                done = true;
              }
              break;
            }
          }
          
          // if everything else is whitespace, return now so last attribute
          // does not include trailing whitespace
          if(done || x === str.length){
            break;
          }
        }
        
        // if there's no whitespace and the character is not ',', the
        // attribute did not end.
        if(str[i] === ',' && this.assertExpression(val, true)){
github ryangreenhall / insight / node_modules / jade / lib / compiler.js View on Github external
buffer: function (str, interpolate) {
    var self = this;
    if (interpolate) {
      var match = /(\\)?([#!]){((?:.|\n)*)$/.exec(str);
      if (match) {
        this.buffer(str.substr(0, match.index), false);
        if (match[1]) { // escape
          this.buffer(match[2] + '{', false);
          this.buffer(match[3], true);
          return;
        } else {
          try {
            var rest = match[3];
            var range = parseJSExpression(rest);
            var code = ('!' == match[2] ? '' : 'jade.escape') + "((jade.interp = " + range.src + ") == null ? '' : jade.interp)";
          } catch (ex) {
            throw ex;
            //didn't match, just as if escaped
            this.buffer(match[2] + '{', false);
            this.buffer(match[3], true);
            return;
          }
          this.bufferExpression(code);
          this.buffer(rest.substr(range.end + 1), true);
          return;
        }
      }
    }

    str = JSON.stringify(str);
github andrewshawcare / thoughtworks-email-signature-generator / node_modules / jade / lib / parser.js View on Github external
if (match) {
      if (match[1]) { // escape
        var text = new nodes.Text(str.substr(0, match.index) + '#[');
        text.line = line;
        var rest = this.parseInlineTagsInText(match[2]);
        if (rest[0].type === 'Text') {
          text.val += rest[0].val;
          rest.shift();
        }
        return [text].concat(rest);
      } else {
        var text = new nodes.Text(str.substr(0, match.index));
        text.line = line;
        var buffer = [text];
        var rest = match[2];
        var range = parseJSExpression(rest);
        var inner = new Parser(range.src, this.filename, this.options);
        buffer.push(inner.parse());
        return buffer.concat(this.parseInlineTagsInText(rest.substr(range.end + 1)));
      }
    } else {
      var text = new nodes.Text(str);
      text.line = line;
      return [text];
    }
  },
github clipperhouse / classicalrad.io / node_modules / jade / lib / compiler.js View on Github external
buffer: function (str, interpolate) {
    var self = this;
    if (interpolate) {
      var match = /(\\)?([#!]){((?:.|\n)*)$/.exec(str);
      if (match) {
        this.buffer(str.substr(0, match.index), false);
        if (match[1]) { // escape
          this.buffer(match[2] + '{', false);
          this.buffer(match[3], true);
          return;
        } else {
          try {
            var rest = match[3];
            var range = parseJSExpression(rest);
            var code = ('!' == match[2] ? '' : 'jade.escape') + "((jade.interp = " + range.src + ") == null ? '' : jade.interp)";
          } catch (ex) {
            throw ex;
            //didn't match, just as if escaped
            this.buffer(match[2] + '{', false);
            this.buffer(match[3], true);
            return;
          }
          this.bufferExpression(code);
          this.buffer(rest.substr(range.end + 1), true);
          return;
        }
      }
    }

    str = JSON.stringify(str);
github cwbuecheler / node-tutorial-for-frontend-devs / node_modules / jade / lib / compiler.js View on Github external
buffer: function (str, interpolate) {
    var self = this;
    if (interpolate) {
      var match = /(\\)?([#!]){((?:.|\n)*)$/.exec(str);
      if (match) {
        this.buffer(str.substr(0, match.index), false);
        if (match[1]) { // escape
          this.buffer(match[2] + '{', false);
          this.buffer(match[3], true);
          return;
        } else {
          try {
            var rest = match[3];
            var range = parseJSExpression(rest);
            var code = ('!' == match[2] ? '' : 'jade.escape') + "((jade.interp = " + range.src + ") == null ? '' : jade.interp)";
          } catch (ex) {
            throw ex;
            //didn't match, just as if escaped
            this.buffer(match[2] + '{', false);
            this.buffer(match[3], true);
            return;
          }
          this.bufferExpression(code);
          this.buffer(rest.substr(range.end + 1), true);
          return;
        }
      }
    }

    str = JSON.stringify(str);
github pugjs / pug / packages / pug-lexer / index.js View on Github external
// if everything else is whitespace, return now so last attribute
          // does not include trailing whitespace
          if(done || x === str.length){
            break;
          }
        }
        
        // if there's no whitespace and the character is not ',', the
        // attribute did not end.
        if(str[i] === ',' && this.assertExpression(val, true)){
          break;
        }
      }
      
      state = characterParser.parseChar(str[i], state);
      val += str[i];
      
      if (str[i] === '\n') {
        line++;
        col = 1;
      } else {
        col++;
      }
    }
    
    this.assertExpression(val);
    
    this.lineno = line;
    this.colno = col;
    
    return { val: val, mustEscape: escapeAttr, remainingSource: str.substr(i) };
github dortaldt / notyet / node_modules / pug-lexer / index.js View on Github external
// if everything else is whitespace, return now so last attribute
          // does not include trailing whitespace
          if(done || x === str.length){
            break;
          }
        }
        
        // if there's no whitespace and the character is not ',', the
        // attribute did not end.
        if(str[i] === ',' && this.assertExpression(val, true)){
          break;
        }
      }
      
      state = characterParser.parseChar(str[i], state);
      val += str[i];
      
      if (str[i] === '\n') {
        line++;
        col = 1;
      } else {
        col++;
      }
    }
    
    this.assertExpression(val);
    
    this.lineno = line;
    this.colno = col;
    
    return { val: val, mustEscape: escapeAttr, remainingSource: str.substr(i) };
github pugjs / pug / packages / pug-lexer / index.js View on Github external
bracketExpression: function(skip){
    skip = skip || 0;
    var start = this.input[skip];
    assert(start === '(' || start === '{' || start === '[',
           'The start character should be "(", "{" or "["');
    var end = characterParser.BRACKETS[start];
    var range;
    try {
      range = characterParser.parseUntil(this.input, end, {start: skip + 1});
    } catch (ex) {
      if (ex.index !== undefined) {
        var idx = ex.index;
        // starting from this.input[skip]
        var tmp = this.input.substr(skip).indexOf('\n');
        // starting from this.input[0]
        var nextNewline = tmp + skip;
        var ptr = 0;
        while (idx > nextNewline && tmp !== -1) {
          this.incrementLine(1);
          idx -= nextNewline + 1;
          ptr += nextNewline + 1;
          tmp = nextNewline = this.input.substr(ptr).indexOf('\n');
        };

        this.incrementColumn(idx);
github pugjs / pug-lexer / index.js View on Github external
bracketExpression: function(skip){
    skip = skip || 0;
    var start = this.input[skip];
    assert(start === '(' || start === '{' || start === '[',
           'The start character should be "(", "{" or "["');
    var end = characterParser.BRACKETS[start];
    var range;
    try {
      range = characterParser.parseUntil(this.input, end, {start: skip + 1});
    } catch (ex) {
      if (ex.index !== undefined) {
        var idx = ex.index;
        // starting from this.input[skip]
        var tmp = this.input.substr(skip).indexOf('\n');
        // starting from this.input[0]
        var nextNewline = tmp + skip;
        var ptr = 0;
        while (idx > nextNewline && tmp !== -1) {
          this.incrementLine(1);
          idx -= nextNewline + 1;
          ptr += nextNewline + 1;
          tmp = nextNewline = this.input.substr(ptr).indexOf('\n');
        };

        this.incrementColumn(idx);

character-parser

Parse JavaScript one character at a time to look for snippets in Templates. This is not a validator, it's just designed to allow you to have sections of JavaScript delimited by brackets robustly.

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis