/
ISyntaxErrorMessageProvider.java
130 lines (112 loc) · 4.29 KB
/
ISyntaxErrorMessageProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
* Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.parser.antlr;
import java.util.List;
import org.antlr.runtime.FailedPredicateException;
import org.antlr.runtime.RecognitionException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.AbstractElement;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage;
import com.google.inject.ImplementedBy;
/**
* A {@link ISyntaxErrorMessageProvider} can be used to customize the error messages
* that the parser attaches to syntax errors.
*
* Implementors should extends the {@link SyntaxErrorMessageProvider} rather than implementing
* the interface directly.
*
* @author Sebastian Zarnekow - Initial contribution and API
* @noimplement This interface is not intended to be implemented by clients.
*/
@ImplementedBy(SyntaxErrorMessageProvider.class)
public interface ISyntaxErrorMessageProvider {
/**
* Provide the error message for a syntax error.
* @see IParserErrorContext
* @see IUnorderedGroupErrorContext
* @return a {@link SyntaxErrorMessage}.
*/
SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context);
/**
* Provide the error message for a value conversion error.
* @see IValueConverterErrorContext
* @return a {@link SyntaxErrorMessage}.
*/
SyntaxErrorMessage getSyntaxErrorMessage(IValueConverterErrorContext context);
/**
* The error context provides some information about the internal state
* of the parser when a syntax error occurred.
* @noimplement This interface is not intended to be implemented by clients.
*/
interface IErrorContext {
/**
* Provides the default error message as it is produced by the parser.
* @return the default message.
*/
String getDefaultMessage();
/**
* Returns the last produced instance or <code>null</code> if the parser did not yet create something.
* @return the current context object or <code>null</code>.
*/
EObject getCurrentContext();
/**
* Returns the recently produced node or <code>null</code> if the parser did not yet create something.
* @return the current node or <code>null</code>.
*/
INode getCurrentNode();
}
/**
* The error context for parser and lexer errors.
* @noimplement This interface is not intended to be implemented by clients.
*/
interface IParserErrorContext extends IErrorContext {
/**
* Returns the recognition exception or <code>null</code> in case of lexer errors.
* @return the recognition exception in the parser. May be <code>null</code> in
* case of lexer errors.
*/
RecognitionException getRecognitionException();
/**
* Returns the names of the tokens in as they are used by the parser.
* @return the token names.
*/
String[] getTokenNames();
}
/**
* In case of failed unordered group constraints, an {@link IUnorderedGroupErrorContext} is
* used.
* @noimplement This interface is not intended to be implemented by clients.
*/
interface IUnorderedGroupErrorContext extends IParserErrorContext {
/**
* Returns the list of mandatory elements that have not been recognized.
* @return the list of missing mandatory elements.
*/
List<AbstractElement> getMissingMandatoryElements();
/**
* Returns the failed predicate exception caused by a specific unordered group.
* @return the failed predicate exception caused by a specific unordered group. Never <code>null</code>.
*/
@Override
FailedPredicateException getRecognitionException();
}
/**
* The error context for a particular value conversion issue.
* @noimplement This interface is not intended to be implemented by clients.
*/
interface IValueConverterErrorContext extends IErrorContext {
/**
* Returns the thrown {@link ValueConverterException}.
* @return the {@link ValueConverterException}.
*/
ValueConverterException getValueConverterException();
}
}