public void advanceLexer_remapTokens(){ final String tokenText = getTokenText(); final String[] namesThroughWhichThisTokenWasRedefined = getNamesThroughWhichThisTokenWasRedefined(); for (String name : namesThroughWhichThisTokenWasRedefined) { if (name != null && name.equals(tokenText)) { // Happens for #define name .*name.* // We must not replace it with itself, as it would lead to much tears (and probably is't up to spec anyway) return; } } final List<ForeignLeafType> definition = definitions.get(tokenText); if (definition != null) { Marker macro = mark(); remapCurrentTokenAdvanceLexer_remapTokens = false; remapCurrentToken(definition, tokenText); //This will advance the lexer which will eat the (real or substituted) token and replace it with redefinition remapCurrentTokenAdvanceLexer_remapTokens = true; macro.done(new RedefinedTokenElementType(definitionTexts.get(tokenText))); advanceLexer_remapTokens(); } }
public void remapCurrentToken(List<ForeignLeafType> remapToTypes, String remappedThrough) { remapCurrentTokenAdvanceLexer(); final ArrayList<IElementType> tagged = new ArrayList<IElementType>(remapToTypes.size()); for (final ForeignLeafType type : remapToTypes) { final IElementType taggedType; if (type instanceof RedefinedTokenType) { taggedType = ((RedefinedTokenType) type).redefineAlsoThrough(remappedThrough); } else { taggedType = new RedefinedTokenType(type, remappedThrough); } tagged.add(taggedType); } waitingTokens.addAll(0, tagged); }
public ForeignLeafPsiElement(@NotNull ForeignLeafType type, CharSequence text) { super(dereferenceElementType(type.getDelegate()), text); myForeignType = type; }
@NotNull public ForeignLeafType getForeignType() { return myForeignType; }
public RedefinedTokenType(@NotNull ForeignLeafType delegate, String redefinedThrough) { super(delegate.getDelegate(), delegate.getValue()); this.redefinedThrough = new String[]{redefinedThrough}; }
public ForeignLeafPsiElement(ForeignLeafType type, CharSequence text) { super(dereferenceElementType(type.getDelegate()), text); myForeignType = type; }
public ForeignLeafType getForeignType() { return myForeignType; }