on master help sign in
Check for reserved words when parsing qualified lowercase names
2d24732Evan Czaplicki
src/Parse/Primitives/Variable.hs+19−22
@@ -126,8 +126,14 @@ foreignUpper =
126 eerr (expect row newCol ctx E.CapVar)
126 eerr (expect row newCol ctx E.CapVar)
127 else
127 else
128 let
128 let
129− !foreign = toForeign fp offset start end
130 !newState = State fp end terminal indent row newCol ctx
129 !newState = State fp end terminal indent row newCol ctx
130+ !variable = Text.decodeUtf8 (B.PS fp start (end - start))
131+ !foreign =
132+ if start == offset then
133+ (Nothing, variable)
134+ else
135+ let !home = Text.decodeUtf8 (B.PS fp offset ((start - 1) - offset)) in
136+ (Just home, variable)
131 in
137 in
132 cok foreign newState noError
138 cok foreign newState noError
133
139
@@ -158,7 +164,18 @@ foreignAlpha =
158 if start == end then
164 if start == end then
159 eerr (E.ParseError row newCol (E.Theories ctx [E.LowVar, E.CapVar]))
165 eerr (E.ParseError row newCol (E.Theories ctx [E.LowVar, E.CapVar]))
160 else
166 else
167+ let
161− cok (toForeign fp offset start end) (State fp end terminal indent row newCol ctx) noError
168+ !newState = State fp end terminal indent row newCol ctx
169+ !variable = Text.decodeUtf8 (B.PS fp start (end - start))
170+ in
171+ if start == offset then
172+ if Set.member variable reservedWords then
173+ eerr noError
174+ else
175+ cok (Nothing, variable) newState noError
176+ else
177+ let !home = Text.decodeUtf8 (B.PS fp offset ((start - 1) - offset)) in
178+ cok (Just home, variable) newState noError
162
179
163
180
164foreignAlphaHelp :: ForeignPtr Word8 -> Int -> Int -> Int -> (# Int, Int, Int #)
181foreignAlphaHelp :: ForeignPtr Word8 -> Int -> Int -> Int -> (# Int, Int, Int #)
@@ -184,26 +201,6 @@ foreignAlphaHelp fp offset terminal col =
184
201
185
202
186
203
187−-- TO FOREIGN NAME
188−
189−
190−toForeign :: ForeignPtr Word8 -> Int -> Int -> Int -> ( Maybe Text, Text )
191−toForeign fp offset start end =
192− let
193− !qualifier =
194− if start == offset then
195− Nothing
196− else
197− Just (Text.decodeUtf8 (B.PS fp offset ((start - 1) - offset)))
198−
199− !variable =
200− Text.decodeUtf8 (B.PS fp start (end - start))
201− in
202− ( qualifier, variable )
203−
204−
205−
206−
207---- CHAR CHOMPERS ----
204---- CHAR CHOMPERS ----
208
205
209
206