1 19 20 package org.netbeans.modules.lexer.gen.javacc; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.netbeans.modules.lexer.gen.DescriptionReader; 25 import org.netbeans.modules.lexer.gen.LanguageGenerator; 26 import org.netbeans.modules.lexer.gen.LanguageData; 27 import org.netbeans.modules.lexer.gen.util.LexerGenUtilities; 28 import org.xml.sax.SAXException ; 29 30 36 37 public class JavaCCLanguageGenerator extends LanguageGenerator { 38 39 protected void appendClassStart(StringBuffer sb, LanguageData data) { 40 LexerGenUtilities.appendSpaces(sb, 4); 41 sb.append("/** Maximum lexer state determined from xxxConstants class. */\n"); 42 LexerGenUtilities.appendSpaces(sb, 4); 43 sb.append("static final int MAX_STATE = "); 44 JavaCCTokenTypes jcctt = (JavaCCTokenTypes)data.getTokenTypes(); 45 sb.append(jcctt.getMaxState()); 46 sb.append(";\n\n"); 47 48 super.appendClassStart(sb, data); 49 } 50 51 public String generate(String langClassName, String lexerClassName, 52 String tokenTypesClassName, File xmlLangDescFile) 53 throws ClassNotFoundException , SAXException , IOException { 54 55 LanguageData data = new LanguageData(); 56 data.setLanguageClassName(langClassName); 57 data.setLexerClassName(lexerClassName); 58 59 if (tokenTypesClassName != null) { 61 Class tokenTypesClass = Class.forName(tokenTypesClassName); 62 JavaCCTokenTypes tokenTypes = new JavaCCTokenTypes(tokenTypesClass); 63 data.registerTokenTypes(tokenTypes); 64 } 65 66 if (xmlLangDescFile != null) { 68 DescriptionReader xmlLangDesc = new DescriptionReader( 69 xmlLangDescFile.getAbsolutePath()); 70 71 xmlLangDesc.applyTo(data); 72 73 } 74 75 data.updateUnassignedIntIds(); 77 78 return createSource(data); 79 } 80 81 } 82 83 | Popular Tags |