ANTLR provides a header tool which allows you to include package and imports. You include this in your *.g grammar file:
@header {
package org.xmlcml.cml.converters.antlr;
import java.util.HashMap;
}
And you may need it in the Lexer as well:
@lexer::header {package org.xmlcml.cml.converters.antlr;}
and in case you need to add some members and code:
@members {
HashMap<String, Object> objectMap = new HashMap<String, Object>();
//...
private void addArrayValue(String content) {
//... code required by snippets in the grammar
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…