|
@ -14,6 +14,7 @@ import Frontend.Syntax |
|
|
import Text.Show.Pretty |
|
|
import Text.Show.Pretty |
|
|
import Frontend.Parser.Posn |
|
|
import Frontend.Parser.Posn |
|
|
import Data.Char (isAlpha) |
|
|
import Data.Char (isAlpha) |
|
|
|
|
|
import Errors |
|
|
|
|
|
|
|
|
parseForeignItem :: Token -> Alex FfiImpEnt |
|
|
parseForeignItem :: Token -> Alex FfiImpEnt |
|
|
parseForeignItem token@(Token (TokString impent) line col) = go 0 impent emptyItem |
|
|
parseForeignItem token@(Token (TokString impent) line col) = go 0 impent emptyItem |
|
@ -54,45 +55,45 @@ parseForeignItem _ = undefined |
|
|
tooManyHeaders :: Posn -> Int -> Int -> Alex a |
|
|
tooManyHeaders :: Posn -> Int -> Int -> Alex a |
|
|
tooManyHeaders (Posn l c) off len = |
|
|
tooManyHeaders (Posn l c) off len = |
|
|
alexThrow $ \fname -> |
|
|
alexThrow $ \fname -> |
|
|
ParseError |
|
|
|
|
|
{ parseErrorMessage = "this foreign entity has too many header names; only one is allowed." |
|
|
|
|
|
, parseErrorFilename = fname |
|
|
|
|
|
, parseErrorInlineDesc = Just "repeated header name" |
|
|
|
|
|
, parseErrorBegin = Posn l (c + off) |
|
|
|
|
|
, parseErrorEnd = Posn l (c + off + len) |
|
|
|
|
|
|
|
|
emptyError |
|
|
|
|
|
{ errorMessage = "this foreign entity has too many header names; only one is allowed." |
|
|
|
|
|
, errorFilename = fname |
|
|
|
|
|
, errorInlineDesc = Just "repeated header name" |
|
|
|
|
|
, errorBegin = Posn l (c + off) |
|
|
|
|
|
, errorEnd = Posn l (c + off + len) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
tooManyItemNames :: Posn -> Int -> Int -> Alex a |
|
|
tooManyItemNames :: Posn -> Int -> Int -> Alex a |
|
|
tooManyItemNames (Posn l c) off len = |
|
|
tooManyItemNames (Posn l c) off len = |
|
|
alexThrow $ \fname -> |
|
|
alexThrow $ \fname -> |
|
|
ParseError |
|
|
|
|
|
{ parseErrorMessage = "this foreign entity has too many names; only one is allowed." |
|
|
|
|
|
, parseErrorFilename = fname |
|
|
|
|
|
, parseErrorInlineDesc = Just "repeated name" |
|
|
|
|
|
, parseErrorBegin = Posn l (c + off) |
|
|
|
|
|
, parseErrorEnd = Posn l (c + off + len) |
|
|
|
|
|
|
|
|
emptyError |
|
|
|
|
|
{ errorMessage = "this foreign entity has too many names; only one is allowed." |
|
|
|
|
|
, errorFilename = fname |
|
|
|
|
|
, errorInlineDesc = Just "repeated name" |
|
|
|
|
|
, errorBegin = Posn l (c + off) |
|
|
|
|
|
, errorEnd = Posn l (c + off + len) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
tooManyReferences :: Posn -> Int -> Alex a |
|
|
tooManyReferences :: Posn -> Int -> Alex a |
|
|
tooManyReferences (Posn l c) off = |
|
|
tooManyReferences (Posn l c) off = |
|
|
alexThrow $ \fname -> |
|
|
alexThrow $ \fname -> |
|
|
ParseError |
|
|
|
|
|
{ parseErrorMessage = "this foreign entity has too many '&'s; only one is allowed." |
|
|
|
|
|
, parseErrorFilename = fname |
|
|
|
|
|
, parseErrorInlineDesc = Just "repeated '&'" |
|
|
|
|
|
, parseErrorBegin = Posn l (c + off) |
|
|
|
|
|
, parseErrorEnd = Posn l (c + off + 1) |
|
|
|
|
|
|
|
|
emptyError |
|
|
|
|
|
{ errorMessage = "this foreign entity has too many '&'s; only one is allowed." |
|
|
|
|
|
, errorFilename = fname |
|
|
|
|
|
, errorInlineDesc = Just "repeated '&'" |
|
|
|
|
|
, errorBegin = Posn l (c + off) |
|
|
|
|
|
, errorEnd = Posn l (c + off + 1) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
tooManyStatics :: Posn -> Int -> Alex a |
|
|
tooManyStatics :: Posn -> Int -> Alex a |
|
|
tooManyStatics (Posn l c) off = |
|
|
tooManyStatics (Posn l c) off = |
|
|
alexThrow $ \fname -> |
|
|
alexThrow $ \fname -> |
|
|
ParseError |
|
|
|
|
|
{ parseErrorMessage = "this foreign entity has too many 'static's; only one is allowed." |
|
|
|
|
|
, parseErrorFilename = fname |
|
|
|
|
|
, parseErrorInlineDesc = Just "repeated 'static'" |
|
|
|
|
|
, parseErrorBegin = Posn l (c + off) |
|
|
|
|
|
, parseErrorEnd = Posn l (c + off + length "static") |
|
|
|
|
|
|
|
|
emptyError |
|
|
|
|
|
{ errorMessage = "this foreign entity has too many 'static's; only one is allowed." |
|
|
|
|
|
, errorFilename = fname |
|
|
|
|
|
, errorInlineDesc = Just "repeated 'static'" |
|
|
|
|
|
, errorBegin = Posn l (c + off) |
|
|
|
|
|
, errorEnd = Posn l (c + off + length "static") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
parseCid :: Posn -> Int -> T.Text -> Alex (Maybe T.Text) |
|
|
parseCid :: Posn -> Int -> T.Text -> Alex (Maybe T.Text) |
|
@ -101,12 +102,12 @@ parseCid (Posn l c) off id |
|
|
| isValidCIdent id = pure $ Just id |
|
|
| isValidCIdent id = pure $ Just id |
|
|
| otherwise = |
|
|
| otherwise = |
|
|
alexThrow $ \fname -> |
|
|
alexThrow $ \fname -> |
|
|
ParseError |
|
|
|
|
|
{ parseErrorMessage = "names for foreign entities must be valid C identifiers." |
|
|
|
|
|
, parseErrorFilename = fname |
|
|
|
|
|
, parseErrorInlineDesc = Just "this is not a C identifier" |
|
|
|
|
|
, parseErrorBegin = Posn l (c + off) |
|
|
|
|
|
, parseErrorEnd = Posn l (c + off + T.length id) |
|
|
|
|
|
|
|
|
emptyError |
|
|
|
|
|
{ errorMessage = "names for foreign entities must be valid C identifiers." |
|
|
|
|
|
, errorFilename = fname |
|
|
|
|
|
, errorInlineDesc = Just "this is not a C identifier" |
|
|
|
|
|
, errorBegin = Posn l (c + off) |
|
|
|
|
|
, errorEnd = Posn l (c + off + T.length id) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
isValidCIdent :: T.Text -> Bool |
|
|
isValidCIdent :: T.Text -> Bool |
|
|