fixed actions in lexer
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6893]
This commit is contained in:
parent
f32056f978
commit
38ef035c06
|
@ -300,7 +300,7 @@ import org.antlr.runtime.*;
|
|||
<lexer>
|
||||
>>
|
||||
|
||||
Lexer(lexerName, modes, pdas, tokens, actions, sempreds) ::= <<
|
||||
Lexer(lexerName, modes, pdas, tokens, actions, sempreds, namedActions) ::= <<
|
||||
public class <lexerName> extends Lexer {
|
||||
<tokens.keys:{k | public static final int <k>=<tokens.(k)>;}; separator="\n">
|
||||
<modes:{m| public static final int <m> = <i0>;}; separator="\n">
|
||||
|
@ -310,27 +310,27 @@ public class <lexerName> extends Lexer {
|
|||
}
|
||||
public <lexerName>(CharStream input, LexerSharedState state) {
|
||||
super(input,state);
|
||||
modeToPDA = new PDA[] { <modes:{m | new <m>_PDA()}; separator=", "> };
|
||||
}
|
||||
public String getGrammarFileName() { return "<fileName>"; }
|
||||
|
||||
<namedActions.members>
|
||||
|
||||
<actions>
|
||||
<sempreds>
|
||||
<pdas>
|
||||
|
||||
static {
|
||||
modeToPDA = new PDA[] { <modes:{m | new <m>_PDA()}; separator=", "> };
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
PDA(name, model, actions, sempreds) ::= <<
|
||||
public static final class <name>_PDA extends PDA {
|
||||
public static final byte[] code = {
|
||||
<model.code; separator=", ">
|
||||
};
|
||||
public static final int[] tokenTypeToAddr = {
|
||||
<model.tokenTypeToAddr; separator=", ">
|
||||
};
|
||||
public static final byte[] <name>_code = {
|
||||
<model.code; separator=", ">
|
||||
};
|
||||
public static final int[] <name>_tokenTypeToAddr = {
|
||||
<model.tokenTypeToAddr; separator=", ">
|
||||
};
|
||||
|
||||
public final class <name>_PDA extends PDA {
|
||||
<if(actions)>
|
||||
public void action(int r, int a) {
|
||||
<actions:{a |
|
||||
|
@ -350,9 +350,9 @@ public static final class <name>_PDA extends PDA {
|
|||
}
|
||||
<endif>
|
||||
public <name>_PDA() {
|
||||
super(code, tokenTypeToAddr, <model.nLabels>);
|
||||
super(<name>_code, <name>_tokenTypeToAddr, <model.nLabels>);
|
||||
}
|
||||
}
|
||||
}<\n>
|
||||
>>
|
||||
|
||||
actionMethod(name, actions) ::= <<
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.antlr.runtime.Token;
|
|||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.misc.Misc;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
|
@ -31,7 +32,7 @@ public class LexerFactory {
|
|||
ST actionST = gen.templates.getInstanceOf("actionMethod");
|
||||
actionST.add("name", r.name);
|
||||
for (Token t : actionTokens) {
|
||||
actionST.add("actions", t.getText());
|
||||
actionST.add("actions", Misc.strip(t.getText(),1));
|
||||
}
|
||||
pdaST.add("actions", actionST);
|
||||
lexerST.add("actions", actionST);
|
||||
|
@ -49,13 +50,16 @@ public class LexerFactory {
|
|||
pdaST.add("name", modeName);
|
||||
pdaST.add("model", pda);
|
||||
lexerST.add("pdas", pdaST);
|
||||
LinkedHashMap<String,Integer> tokens = new LinkedHashMap<String,Integer>();
|
||||
for (String t : gen.g.tokenNameToTypeMap.keySet()) {
|
||||
Integer ttype = gen.g.tokenNameToTypeMap.get(t);
|
||||
if ( ttype>0 ) tokens.put(t, ttype);
|
||||
}
|
||||
lexerST.add("tokens", tokens);
|
||||
}
|
||||
|
||||
LinkedHashMap<String,Integer> tokens = new LinkedHashMap<String,Integer>();
|
||||
for (String t : gen.g.tokenNameToTypeMap.keySet()) {
|
||||
Integer ttype = gen.g.tokenNameToTypeMap.get(t);
|
||||
if ( ttype>0 ) tokens.put(t, ttype);
|
||||
}
|
||||
lexerST.add("tokens", tokens);
|
||||
lexerST.add("namedActions", gen.g.namedActions);
|
||||
|
||||
return fileST;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue