2 * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
3 * Use is subject to license terms.
5 package com
.intellij
.lang
.pratt
;
7 import com
.intellij
.lang
.PsiBuilder
;
8 import com
.intellij
.psi
.tree
.IElementType
;
10 import java
.util
.LinkedList
;
15 public class MutableMarker
{
16 private final PsiBuilder
.Marker myStartMarker
;
17 private IElementType myResultType
;
18 private int myInitialPathLength
;
19 private LinkedList
<IElementType
> myPath
;
20 private boolean myFinished
;
22 public MutableMarker(final LinkedList
<IElementType
> path
, final PsiBuilder
.Marker startMarker
, final int initialPathLength
) {
24 myStartMarker
= startMarker
;
25 myInitialPathLength
= initialPathLength
;
28 public MutableMarker
setResultType(final IElementType resultType
) {
29 myResultType
= resultType
;
33 public IElementType
getResultType() {
37 public void finish() {
41 if (myResultType
== null) {
44 myStartMarker
.done(myResultType
);
46 myPath
.addLast(myResultType
);
50 private void restorePath() {
51 while (myPath
.size() > myInitialPathLength
) {
56 public MutableMarker
precede() {
57 return new MutableMarker(myPath
, myStartMarker
.precede(), myInitialPathLength
);
60 public void finish(final IElementType type
) {
71 public void rollback() {
75 myStartMarker
.rollbackTo();
78 public void error(final String message
) {
81 myStartMarker
.error(message
);