1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE BangPatterns, UnboxedTuples, OverloadedStrings #-}
3module Parse.Primitives.Kernel
10import Prelude hiding (length)
11import qualified Data.ByteString.Internal as B
12import Data.Text (Text)
13import Data.Word (Word8)
14import Foreign.ForeignPtr (ForeignPtr)
16import qualified Elm.Name as N
17import Parse.Primitives.Internals (Parser(..), State(..), noError)
18import qualified Parse.Primitives.Internals as I
19import qualified Parse.Primitives.Variable as Var
39chunk :: Parser (B.ByteString, Maybe Special)
41 Parser $ \(State fp offset terminal indent row col ctx) cok _ _ _ ->
43 (# maybeSpecial, jsOffset, newOffset, newRow, newCol #) =
44 chompChunk fp offset terminal row col
46 !javascript = B.PS fp offset (jsOffset - offset)
47 !newState = State fp newOffset terminal indent newRow newCol ctx
49 cok (javascript, maybeSpecial) newState noError
56chompChunk :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> (# Maybe Special, Int, Int, Int, Int #)
57chompChunk fp offset terminal row col =
58 if offset >= terminal then
59 (# Nothing, offset, offset, row, col #)
62 let !word = I.unsafeIndex fp offset in
63 if word == 0x5F {- _ -} then
69 if offset3 <= terminal && I.unsafeIndex fp offset1 == 0x5F {- _ -} then
70 chompSpecial fp offset3 terminal row (col + 3) offset
72 chompChunk fp offset1 terminal row (col + 1)
74 else if word == 0x0A {- \n -} then
75 chompChunk fp (offset + 1) terminal (row + 1) 1
78 let !newOffset = offset + I.getCharWidth fp offset terminal word in
79 chompChunk fp newOffset terminal row (col + 1)
86-- relies on external checks in chompChunk
87chompSpecial :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> Int -> (# Maybe Special, Int, Int, Int, Int #)
88chompSpecial fp offset terminal row col jsOffset =
90 (# newOffset, newCol #) =
91 Var.chompInnerChars fp offset terminal col
93 !tagOffset = offset - 1
94 !word = I.unsafeIndex fp tagOffset
97 if word == 0x24 {- $ -} then
98 ElmField (N.fromForeignPtr fp offset (newOffset - offset))
101 let !name = N.fromForeignPtr fp tagOffset (newOffset - tagOffset) in
102 if 0x30 <= word && word <= 0x39 then
103 Enum (fromIntegral (word - 0x30)) name
105 else if 0x61 {- a -} <= word && word <= 0x7A {- z -} then
108 else if name == "DEBUG" then
111 else if name == "PROD" then
117 (# Just special, jsOffset, newOffset, row, newCol #)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list