简体   繁体   中英

Java Lexer and Parser

I am writing a new editor for java using Xtext. I want parser to parse the main class and replace the method call by actual code.

eg

Class Test {                                                           
           public static void main(String[] args ){ 
                 System.out.println("Virag");                            
                 method();                                                        
           }                                                           
           public static method(){             
                System.out.println("Purnam");                                    
           }                                                                
}

After parsing I want to return a document like mentioned below.

Class Test {                                                           
           public static void main(String[] args ){ 
                 System.out.println("Virag");                            
                 System.out.println("Purnam");                                                        
           }                                                         

}

I achieved this in lexer and parser by return of method body instead of method. But later in editor, text region gets changed and any edit performed in editor goes wrong. Character positions in documents are going wrong. How to fix this problem?

您可能希望使用Xtext的代码生成概念将DSL的源代码转换为内联方法主体的新工件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM