Pygments lexer for Aspectj.
-
12-12-2019 - |
문제
방금 gitHub (* .aj) 파일이 구문 강조 표시되지 않는 이유를 GitHub에 대해 지원했습니다.대답은 피그먼트를 사용하고 있지만 AspectJ 용 기존의 렉서를 알지 못합니다.나는 빠른 웹 검색을했고 어느 쪽도 찾지 못했습니다.여기에 아무도 쓰여지거나 기존 하나의 링크를 가리킬 수 있습니까?
오래 전 KConfig (Linux 커널 구성) 파일에 대한 렉서를 작성했지만 파이썬을 말하지 않기 때문에 오히려 어려웠습니다.그래서 나는 다시 내 뇌를 다시 고문하기 시작하기 전에, 나는 휠을 다시 발명하는 대신 먼저 묻는 것이 좋습니다.
해결책
Python을 말하지 않으므로 Python을 말하지 않기 때문에 "복사, 붙여 넣기 및 수정"솔루션을 생성 한 후에는 Tublasses JavaLexer
를 하위 클래스하고 대부분 대부분 대리인을 대표하는 또 다른 Quick'n'Dirty 솔루션을 해킹 할 수있었습니다.예외는 입니다
- aspectj- 특정 키워드,
- Java 라벨이 아닌 공간이없는 공간이없는 콜론이 뒤 따르는 콜론을 처리하지만 AspectJ 키워드 플러스 ":"연산자 및
- 종류 간 주석 선언을 AspectJ 키워드로 처리하였고 Java Name Decorators는 아닙니다.
나는 내 작은 휴리스틱 솔루션이 약간의 세부 사항을 놓치지 만, Andrew Eisenberg가 말했듯이, 불완전하지만, 작동 솔루션은 존재하지 않는 완벽한 것보다 낫다 :
.class AspectJLexer(JavaLexer): """ For `AspectJ <http://www.eclipse.org/aspectj/>`_ source code. """ name = 'AspectJ' aliases = ['aspectj'] filenames = ['*.aj'] mimetypes = ['text/x-aspectj'] aj_keywords = [ 'aspect', 'pointcut', 'privileged', 'call', 'execution', 'initialization', 'preinitialization', 'handler', 'get', 'set', 'staticinitialization', 'target', 'args', 'within', 'withincode', 'cflow', 'cflowbelow', 'annotation', 'before', 'after', 'around', 'proceed', 'throwing', 'returning', 'adviceexecution', 'declare', 'parents', 'warning', 'error', 'soft', 'precedence', 'thisJoinPoint', 'thisJoinPointStaticPart', 'thisEnclosingJoinPointStaticPart', 'issingleton', 'perthis', 'pertarget', 'percflow', 'percflowbelow', 'pertypewithin', 'lock', 'unlock', 'thisAspectInstance' ] aj_inter_type = ['parents:', 'warning:', 'error:', 'soft:', 'precedence:'] aj_inter_type_annotation = ['@type', '@method', '@constructor', '@field'] def get_tokens_unprocessed(self, text): for index, token, value in JavaLexer.get_tokens_unprocessed(self, text): if token is Name and value in self.aj_keywords: yield index, Keyword, value elif token is Name.Label and value in self.aj_inter_type: yield index, Keyword, value[:-1] yield index, Operator, value[-1] elif token is Name.Decorator and value in self.aj_inter_type_annotation: yield index, Keyword, value else: yield index, token, value
다른 팁
구문은 Java Lexer로 시작하면 AspectJ에 대한 aspectj를 강조 표시해야합니다.렉서는 Java와 동일한 키워드와 동일합니다.
AspectJ 특정 키워드 목록은 여기를 참조하십시오. http://git.eclipse.org/c/ajdt/org.eclipse.ajdt.git/tree/org.eclipse.ajdt.core/src/org/eclipse/ajdt/core/aspectjplugin..java
및 여기에서 Java 키워드를 위해 : http://git.eclipse.org/c/ajdt/org.eclipse.ajdt.git/tree/org.eclipse.ajdt.ui/src/org/eclipse/ajdt./ internal/ui/editor/aspectjcodescanner.java