1
+ /*
2
+ * This file is a part of BSL Parser Core.
3
+ *
4
+ * Copyright (c) 2018-2025
5
+ * Alexey Sosnoviy <[email protected] >, Nikita Fedkin <[email protected] >, Valery Maximov <[email protected] >
6
+ *
7
+ * SPDX-License-Identifier: LGPL-3.0-or-later
8
+ *
9
+ * BSL Parser Core is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3.0 of the License, or (at your option) any later version.
13
+ *
14
+ * BSL Parser Core is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with BSL Parser Core.
21
+ */
22
+ /*
23
+ Originally released by BSD 3-clause license:
24
+
25
+ Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
26
+
27
+ Redistribution and use in source and binary forms, with or without
28
+ modification, are permitted provided that the following conditions
29
+ are met:
30
+
31
+ 1. Redistributions of source code must retain the above copyright
32
+ notice, this list of conditions and the following disclaimer.
33
+ 2. Redistributions in binary form must reproduce the above copyright
34
+ notice, this list of conditions and the following disclaimer in the
35
+ documentation and/or other materials provided with the distribution.
36
+ 3. Neither the name of the copyright holder nor the names of its contributors
37
+ may be used to endorse or promote products derived from this software
38
+ without specific prior written permission.
39
+
40
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
41
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
44
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
49
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50
+ */
51
+ package com .github ._1c_syntax .bsl .parser ;
52
+
53
+ import org .antlr .v4 .runtime .CharStream ;
54
+ import org .antlr .v4 .runtime .UnicodeCharStream ;
55
+ import org .antlr .v4 .runtime .misc .Interval ;
56
+
57
+ /**
58
+ * This class supports case-insensitive lexing by wrapping an existing
59
+ * {@link CharStream} and forcing the lexer to see either upper or
60
+ * lowercase characters. Grammar literals should then be either upper or
61
+ * lower case such as 'BEGIN' or 'begin'. The text of the character
62
+ * stream is unaffected. Example: input 'BeGiN' would match lexer rule
63
+ * 'BEGIN' if constructor parameter upper=true but getText() would return
64
+ * 'BeGiN'.
65
+ */
66
+ public class CaseChangingCharStream implements UnicodeCharStream {
67
+
68
+ private final UnicodeCharStream stream ;
69
+
70
+ /**
71
+ * Constructs a new CaseChangingCharStream wrapping the given {@link UnicodeCharStream} forcing
72
+ * all characters to upper case.
73
+ *
74
+ * @param stream The stream to wrap.
75
+ */
76
+ public CaseChangingCharStream (UnicodeCharStream stream ) {
77
+ this .stream = stream ;
78
+ }
79
+
80
+ @ Override
81
+ public String getText (Interval interval ) {
82
+ return stream .getText (interval );
83
+ }
84
+
85
+ @ Override
86
+ public void consume () {
87
+ stream .consume ();
88
+ }
89
+
90
+ @ Override
91
+ public int LA (int i ) {
92
+ int c = stream .LA (i );
93
+ if (c <= 0 ) {
94
+ return c ;
95
+ }
96
+ return Character .toUpperCase (c );
97
+ }
98
+
99
+ @ Override
100
+ public int mark () {
101
+ return stream .mark ();
102
+ }
103
+
104
+ @ Override
105
+ public void release (int marker ) {
106
+ stream .release (marker );
107
+ }
108
+
109
+ @ Override
110
+ public int index () {
111
+ return stream .index ();
112
+ }
113
+
114
+ @ Override
115
+ public void seek (int index ) {
116
+ stream .seek (index );
117
+ }
118
+
119
+ @ Override
120
+ public int size () {
121
+ return stream .size ();
122
+ }
123
+
124
+ @ Override
125
+ public String getSourceName () {
126
+ return stream .getSourceName ();
127
+ }
128
+
129
+ @ Override
130
+ public boolean supportsUnicodeCodePoints () {
131
+ return stream .supportsUnicodeCodePoints ();
132
+ }
133
+ }
0 commit comments