packages/java-parser/scripts/unicode.js
function generateFile() {
  let data = `
  /*File generated with ../scripts/unicode.js using ../resources/Unicode/UnicodeData.txt.
  * As Java Identifiers may contains unicodes letters, this file defines two sets of unicode
  * characters, firstIdentChar used to help to determine if a character can be the first letter
  * of a JavaIdentifier and the other one (restIdentChar) to determine if it can be part of a
  * JavaIdentifier other than the first character.
  * Java uses the same file UnicodeData.txt as the unicode.js script to define the unicodes.
  * For more:
  *   https://github.com/jhipster/prettier-java/issues/116
  *   https://github.com/jhipster/prettier-java/pull/155
  */
  "use strict"
  const addRanges = (set, rangesArr) => {
    for (let i = 0; i < rangesArr.length; i++) {
      const range = rangesArr[i];
      const start =  range[0];
      const end = range[1];
      for (let codePoint = start; codePoint <= end; codePoint++) {
        set.add(codePoint)
      }
    }
  };
  const fic = new Set([`;
  firstIdentCharCategories.forEach(el => {
    unicode[el].unicode.forEach(value => {
      data += `${value},`;
    });
  });
  data += `]);
  `;

  data += `const fic_a = [`;
  firstIdentCharCategories.forEach(el => {
    unicode[el].ranges.forEach(array => {
      data += `[${array}],`;
    });
  });
  data += `];
  addRanges(fic, fic_a);
  `;

  data += `const ricd = new Set([`;
  restIdentCharCategories.forEach(el => {
    unicode[el].unicode.forEach(value => {
      data += `${value},`;
    });
  });
  manuallyAddedCharacters.unicode.forEach(v => (data += `${v},`));

  data += `]);
  `;

  data += `const ricd_a = [`;
  restIdentCharCategories.forEach(el => {
    unicode[el].ranges.forEach(array => {
      data += `[${array}],`;
    });
  });
  data += `];
  addRanges(ricd, ricd_a);
  `;

  data += `const mac_a = [`;
  manuallyAddedCharacters.ranges.forEach(array => {
    data += `[${array}],`;
  });
  data += `];
  addRanges(ricd, mac_a);
  `;

  data += `const ric = new Set(function*() { yield* fic; yield* ricd; }());`;

  data += `module.exports = {
    firstIdentChar: fic,
    restIdentChar: ric
  }`;
  fs.writeFileSync(
    path.resolve(__dirname, "../src/unicodesets.js"),
    data,
    err => {
      if (err) {
        throw err;
      }
    }
  );
}
function generateFile() {
  let data = `
  /*File generated with ../scripts/unicode.js using ../resources/Unicode/UnicodeData.txt.
  * As Java Identifiers may contains unicodes letters, this file defines two sets of unicode
  * characters, firstIdentChar used to help to determine if a character can be the first letter
  * of a JavaIdentifier and the other one (restIdentChar) to determine if it can be part of a
  * JavaIdentifier other than the first character.
  * Java uses the same file UnicodeData.txt as the unicode.js script to define the unicodes.
  * For more:
  *   https://github.com/jhipster/prettier-java/issues/116
  *   https://github.com/jhipster/prettier-java/pull/155
  */
  "use strict"
  const addRanges = (set, rangesArr) => {
    for (let i = 0; i < rangesArr.length; i++) {
      const range = rangesArr[i];
      const start =  range[0];
      const end = range[1];
      for (let codePoint = start; codePoint <= end; codePoint++) {
        set.add(codePoint)
      }
    }
  };
  const fic = new Set([`;
  firstIdentCharCategories.forEach(el => {
    unicode[el].unicode.forEach(value => {
      data += `${value},`;
    });
  });
  data += `]);
  `;

  data += `const fic_a = [`;
  firstIdentCharCategories.forEach(el => {
    unicode[el].ranges.forEach(array => {
      data += `[${array}],`;
    });
  });
  data += `];
  addRanges(fic, fic_a);
  `;

  data += `const ricd = new Set([`;
  restIdentCharCategories.forEach(el => {
    unicode[el].unicode.forEach(value => {
      data += `${value},`;
    });
  });
  manuallyAddedCharacters.unicode.forEach(v => (data += `${v},`));

  data += `]);
  `;

  data += `const ricd_a = [`;
  restIdentCharCategories.forEach(el => {
    unicode[el].ranges.forEach(array => {
      data += `[${array}],`;
    });
  });
  data += `];
  addRanges(ricd, ricd_a);
  `;

  data += `const mac_a = [`;
  manuallyAddedCharacters.ranges.forEach(array => {
    data += `[${array}],`;
  });
  data += `];
  addRanges(ricd, mac_a);
  `;

  data += `const ric = new Set(function*() { yield* fic; yield* ricd; }());`;

  data += `module.exports = {
    firstIdentChar: fic,
    restIdentChar: ric
  }`;
  fs.writeFileSync(
    path.resolve(__dirname, "../src/unicodesets.js"),
    data,
    err => {
      if (err) {
        throw err;
      }
    }
  );
}
function generateFile ( ) { let data = ` ` ; firstIdentCharCategories . forEach ( el => { unicode [ el ] . unicode . forEach ( value => { data += ` ${ value } ` ; } ) ; } ) ; data += ` ` ; data += ` ` ; firstIdentCharCategories . forEach ( el => { unicode [ el ] . ranges . forEach ( array => { data += ` ${ array } ` ; } ) ; } ) ; data += ` ` ; data += ` ` ; restIdentCharCategories . forEach ( el => { unicode [ el ] . unicode . forEach ( value => { data += ` ${ value } ` ; } ) ; } ) ; manuallyAddedCharacters . unicode . forEach ( v => ( data += ` ${ v } ` ) ) ; data += ` ` ; data += ` ` ; restIdentCharCategories . forEach ( el => { unicode [ el ] . ranges . forEach ( array => { data += ` ${ array } ` ; } ) ; } ) ; data += ` ` ; data += ` ` ; manuallyAddedCharacters . ranges . forEach ( array => { data += ` ${ array } ` ; } ) ; data += ` ` ; data += ` ` ; data += ` ` ; fs . writeFileSync ( path . resolve ( __dirname , "../src/unicodesets.js" ) , data , err => { if ( err ) { throw err ; } } ) ; }
Generating a unicodesets.js file so that we don't have to reparse the file each time the parser is called.
Generating a unicodesets . js file so that we don t have to reparse the file each time the parser is called .