mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Pratt cleanup: inline extra class
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,31 +15,30 @@
|
||||
*/
|
||||
package com.intellij.lang.pratt;
|
||||
|
||||
import com.intellij.lang.ITokenTypeRemapper;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.lang.ITokenTypeRemapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class PrattBuilder {
|
||||
|
||||
public abstract Lexer getLexer();
|
||||
|
||||
public abstract void setTokenTypeRemapper(@Nullable ITokenTypeRemapper remapper);
|
||||
|
||||
public abstract MutableMarker mark();
|
||||
|
||||
public PrattBuilderFacade createChildBuilder(int priority, @Nullable String expectedMessage) {
|
||||
public PrattBuilder createChildBuilder(int priority, @Nullable String expectedMessage) {
|
||||
return createChildBuilder(priority).expecting(expectedMessage);
|
||||
}
|
||||
|
||||
public PrattBuilderFacade createChildBuilder(int priority) {
|
||||
public PrattBuilder createChildBuilder(int priority) {
|
||||
return createChildBuilder().withLowestPriority(priority);
|
||||
}
|
||||
|
||||
@@ -48,7 +47,7 @@ public abstract class PrattBuilder {
|
||||
return createChildBuilder(priority, expectedMessage).parse();
|
||||
}
|
||||
|
||||
protected abstract PrattBuilderFacade createChildBuilder();
|
||||
protected abstract PrattBuilder createChildBuilder();
|
||||
|
||||
public boolean assertToken(final PrattTokenType type) {
|
||||
if (checkToken(type)) {
|
||||
@@ -95,15 +94,22 @@ public abstract class PrattBuilder {
|
||||
public abstract void reduce(@NotNull IElementType type);
|
||||
|
||||
public ListIterator<IElementType> getBackResultIterator() {
|
||||
final LinkedList<IElementType> resultTypes = getResultTypes();
|
||||
final List<IElementType> resultTypes = getResultTypes();
|
||||
return resultTypes.listIterator(resultTypes.size());
|
||||
}
|
||||
|
||||
public abstract LinkedList<IElementType> getResultTypes();
|
||||
public abstract List<IElementType> getResultTypes();
|
||||
|
||||
public abstract PrattBuilder getParent();
|
||||
|
||||
public abstract int getPriority();
|
||||
|
||||
public abstract int getCurrentOffset();
|
||||
|
||||
public abstract PrattBuilder expecting(@Nullable String expectedMessage);
|
||||
|
||||
public abstract PrattBuilder withLowestPriority(int priority);
|
||||
|
||||
@Nullable
|
||||
public abstract IElementType parse();
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.lang.pratt;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public interface PrattBuilderFacade {
|
||||
PrattBuilderFacade expecting(@Nullable String expectedMessage);
|
||||
|
||||
PrattBuilderFacade withLowestPriority(int priority);
|
||||
|
||||
@Nullable
|
||||
IElementType parse();
|
||||
|
||||
@NotNull
|
||||
LinkedList<IElementType> getResultTypes();
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.intellij.lang.pratt;
|
||||
|
||||
import com.intellij.lang.ITokenTypeRemapper;
|
||||
import com.intellij.lang.LangBundle;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.ITokenTypeRemapper;
|
||||
import com.intellij.lang.impl.PsiBuilderImpl;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.openapi.util.Trinity;
|
||||
@@ -26,11 +26,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class PrattBuilderImpl extends PrattBuilder implements PrattBuilderFacade {
|
||||
public class PrattBuilderImpl extends PrattBuilder {
|
||||
private final PrattBuilder myParentBuilder;
|
||||
private final PsiBuilder myBuilder;
|
||||
private final LinkedList<IElementType> myLeftSiblings = new LinkedList<IElementType>();
|
||||
@@ -44,16 +45,16 @@ public class PrattBuilderImpl extends PrattBuilder implements PrattBuilderFacade
|
||||
myParentBuilder = parent;
|
||||
}
|
||||
|
||||
public static PrattBuilderImpl createBuilder(final PsiBuilder builder) {
|
||||
public static PrattBuilder createBuilder(final PsiBuilder builder) {
|
||||
return new PrattBuilderImpl(builder, null);
|
||||
}
|
||||
|
||||
public PrattBuilderFacade expecting(final String expectedMessage) {
|
||||
public PrattBuilder expecting(final String expectedMessage) {
|
||||
myExpectedMessage = expectedMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PrattBuilderFacade withLowestPriority(final int priority) {
|
||||
public PrattBuilder withLowestPriority(final int priority) {
|
||||
myPriority = priority;
|
||||
return this;
|
||||
}
|
||||
@@ -76,7 +77,7 @@ public class PrattBuilderImpl extends PrattBuilder implements PrattBuilderFacade
|
||||
return myLeftSiblings.size() != 1 ? null : myLeftSiblings.getLast();
|
||||
}
|
||||
|
||||
protected PrattBuilderFacade createChildBuilder() {
|
||||
protected PrattBuilder createChildBuilder() {
|
||||
assert myParsingStarted;
|
||||
return new PrattBuilderImpl(myBuilder, this) {
|
||||
protected void doParse() {
|
||||
@@ -150,7 +151,7 @@ public class PrattBuilderImpl extends PrattBuilder implements PrattBuilderFacade
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LinkedList<IElementType> getResultTypes() {
|
||||
public List<IElementType> getResultTypes() {
|
||||
checkParsed();
|
||||
return myLeftSiblings;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,16 +27,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
public abstract class PrattParser implements PsiParser {
|
||||
@NotNull
|
||||
public final ASTNode parse(final IElementType root, final PsiBuilder builder) {
|
||||
//builder.setDebugMode(true);
|
||||
|
||||
final PrattBuilderImpl prattBuilder = PrattBuilderImpl.createBuilder(builder);
|
||||
final PrattBuilder prattBuilder = PrattBuilderImpl.createBuilder(builder);
|
||||
final MutableMarker marker = prattBuilder.mark();
|
||||
parse(prattBuilder);
|
||||
marker.finish(root);
|
||||
return builder.getTreeBuilt();
|
||||
}
|
||||
|
||||
protected void parse(final PrattBuilderImpl builder) {
|
||||
protected void parse(final PrattBuilder builder) {
|
||||
builder.parse();
|
||||
while (!builder.isEof()) builder.advance();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,10 @@ package com.intellij.lang.pratt;
|
||||
import com.intellij.openapi.util.Trinity;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -28,17 +29,16 @@ import java.util.Collections;
|
||||
public class PrattRegistry {
|
||||
private static final MultiMap<IElementType, Trinity<Integer, PathPattern, TokenParser>> ourMap = new MultiMap<IElementType, Trinity<Integer, PathPattern, TokenParser>>();
|
||||
|
||||
public static void registerParser(IElementType type, int priority, TokenParser parser) {
|
||||
public static void registerParser(@NotNull final IElementType type, final int priority, final TokenParser parser) {
|
||||
registerParser(type, priority, PathPattern.path(), parser);
|
||||
}
|
||||
|
||||
public static void registerParser(final IElementType type, final int priority, final PathPattern pattern, final TokenParser parser) {
|
||||
public static void registerParser(@NotNull final IElementType type, final int priority, final PathPattern pattern, final TokenParser parser) {
|
||||
ourMap.putValue(type, new Trinity<Integer, PathPattern, TokenParser>(priority, pattern, parser));
|
||||
}
|
||||
|
||||
public static Collection<Trinity<Integer, PathPattern, TokenParser>> getParsers(IElementType type) {
|
||||
final Collection<Trinity<Integer,PathPattern,TokenParser>> trinities = ourMap.get(type);
|
||||
return trinities == null ? Collections.<Trinity<Integer, PathPattern, TokenParser>>emptyList() : trinities;
|
||||
@NotNull
|
||||
public static Collection<Trinity<Integer, PathPattern, TokenParser>> getParsers(@Nullable final IElementType type) {
|
||||
return ourMap.get(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user