![일반적인 Linux 명령줄 도구를 사용하여 자바스크립트 파일에서 모든 주석을 제거하는 방법은 무엇입니까? [폐쇄]](https://linux55.com/image/143208/%EC%9D%BC%EB%B0%98%EC%A0%81%EC%9D%B8%20Linux%20%EB%AA%85%EB%A0%B9%EC%A4%84%20%EB%8F%84%EA%B5%AC%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%20%ED%8C%8C%EC%9D%BC%EC%97%90%EC%84%9C%20%EB%AA%A8%EB%93%A0%20%EC%A3%BC%EC%84%9D%EC%9D%84%20%EC%A0%9C%EA%B1%B0%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%ED%8F%90%EC%87%84%5D.png)
꼭 필요한 주석이 포함된 자바스크립트 파일이 있습니다. Javascript는 C 스타일 주석을 사용합니다.
//this is a single line comment
그리고
/* this is
a multi-line
comment */
그러나 실제 코드는 다음과 유사합니다.
/* blah blah
// [NOTE] blah blah
// blah
// blah blah blah
// blah
// blah blah
function("string", false);
// 1: blah blah blah blah blah blah
// [1] https://example.com
function("string", true);
/* blah blah
* blah blah //* /
function("string", false);
// * * * /
// 18: blah blah blah blah blah blah
// [-] (part1) https://example.org/43
function("string", 0);
// * * * /
// 20: blah blah blah blah blah blah
// [NOTE] blah blah blah blah blah blah blah blah blah blah blah blah
// [-] https://example.org/62015
function("some_string", "string"); // (comment)
// 0301: blah blah blah blah blah blah
// [-] https://example.org/205
// function("string", false);
// 040: blah blah blah blah blah blah
// What is this?
// [-] https://example.org/58917
function("string", true);
// 050: blah blah blah blah blah blah
// [-] https://example.org/57226
function("string", false);
// 103: blah blah blah blah blah blah
// [-] https://example.org/53751
// function("string", false);
// 203: blah blah blah blah blah blah
// [WARNING] This may break
// [-] https://example.org/70082
function("string", false);
// 27: blah blah blah blah blah blah
// [-] https://example.org/57170
// function("string", 90); // default: 90
// 55: blah blah blah blah blah blah
// [-] https://example.org/73595
// function("string", true);
// * * * /
// ***/
function("string", 99); //comment comment
내가 찾은 답변(이와 같은)은 더 간단한 사례를 다룹니다.
쉘 스크립트 - 파일의 모든 주석을 제거하는 방법은 무엇입니까? - Unix 및 Linux 스택 교환파일에서 모든 주석을 제거하는 방법은 무엇입니까?
내가 겪고 있는 가장 큰 문제는 내 다양한 정규 표현식이 너무 욕심이 많다는 것입니다. 예를 들어 /*
처음부터 마지막까지 모든 것을 선택합니다 */
. 나는 Perl에 익숙하지 않기 때문에 Perl을 사용해 보지 않았습니다. 그리고 불행하게도 내가 시도한 도구는 내가 시도하고 싶었던 정규식 구문을 모두 지원하지 못했습니다. 이 작업에 어떤 간단한 도구가 가장 적합한지 잘 모르겠습니다.
답변1
cpp -undef -P your_file.js
이것을 달성하기 위해 또는 를 사용합니다 cc -undef -E -P -xc your_file.js
.
cpp
도구가 cc
충분히 "일반적"이지 않다고 생각한다면 운이 좋지 않을 것입니다. 정말 그래야 합니다.