forked from GitHub/gf-core
Added missing BNFC-generated alex and happy files, and alex-generated lexer for GFCCRaw.
This commit is contained in:
340
src/GF/GFCC/Raw/LexGFCCRaw.hs
Normal file
340
src/GF/GFCC/Raw/LexGFCCRaw.hs
Normal file
File diff suppressed because one or more lines are too long
135
src/GF/GFCC/Raw/LexGFCCRaw.x
Normal file
135
src/GF/GFCC/Raw/LexGFCCRaw.x
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
-- -*- haskell -*-
|
||||||
|
-- This Alex file was machine-generated by the BNF converter
|
||||||
|
{
|
||||||
|
{-# OPTIONS -fno-warn-incomplete-patterns #-}
|
||||||
|
module GF.GFCC.Raw.LexGFCCRaw where
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$l = [a-zA-Z\192 - \255] # [\215 \247] -- isolatin1 letter FIXME
|
||||||
|
$c = [A-Z\192-\221] # [\215] -- capital isolatin1 letter FIXME
|
||||||
|
$s = [a-z\222-\255] # [\247] -- small isolatin1 letter FIXME
|
||||||
|
$d = [0-9] -- digit
|
||||||
|
$i = [$l $d _ '] -- identifier character
|
||||||
|
$u = [\0-\255] -- universal: any character
|
||||||
|
|
||||||
|
@rsyms = -- symbols and non-identifier-like reserved words
|
||||||
|
\( | \) | \?
|
||||||
|
|
||||||
|
:-
|
||||||
|
|
||||||
|
$white+ ;
|
||||||
|
@rsyms { tok (\p s -> PT p (TS $ share s)) }
|
||||||
|
(\_ | $l)($l | $d | \' | \_)* { tok (\p s -> PT p (eitherResIdent (T_CId . share) s)) }
|
||||||
|
|
||||||
|
$l $i* { tok (\p s -> PT p (eitherResIdent (TV . share) s)) }
|
||||||
|
\" ([$u # [\" \\ \n]] | (\\ (\" | \\ | \' | n | t)))* \"{ tok (\p s -> PT p (TL $ share $ unescapeInitTail s)) }
|
||||||
|
|
||||||
|
$d+ { tok (\p s -> PT p (TI $ share s)) }
|
||||||
|
$d+ \. $d+ (e (\-)? $d+)? { tok (\p s -> PT p (TD $ share s)) }
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
tok f p s = f p s
|
||||||
|
|
||||||
|
share :: String -> String
|
||||||
|
share = id
|
||||||
|
|
||||||
|
data Tok =
|
||||||
|
TS !String -- reserved words and symbols
|
||||||
|
| TL !String -- string literals
|
||||||
|
| TI !String -- integer literals
|
||||||
|
| TV !String -- identifiers
|
||||||
|
| TD !String -- double precision float literals
|
||||||
|
| TC !String -- character literals
|
||||||
|
| T_CId !String
|
||||||
|
|
||||||
|
deriving (Eq,Show,Ord)
|
||||||
|
|
||||||
|
data Token =
|
||||||
|
PT Posn Tok
|
||||||
|
| Err Posn
|
||||||
|
deriving (Eq,Show,Ord)
|
||||||
|
|
||||||
|
tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
|
||||||
|
tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
|
||||||
|
tokenPos _ = "end of file"
|
||||||
|
|
||||||
|
posLineCol (Pn _ l c) = (l,c)
|
||||||
|
mkPosToken t@(PT p _) = (posLineCol p, prToken t)
|
||||||
|
|
||||||
|
prToken t = case t of
|
||||||
|
PT _ (TS s) -> s
|
||||||
|
PT _ (TI s) -> s
|
||||||
|
PT _ (TV s) -> s
|
||||||
|
PT _ (TD s) -> s
|
||||||
|
PT _ (TC s) -> s
|
||||||
|
PT _ (T_CId s) -> s
|
||||||
|
|
||||||
|
_ -> show t
|
||||||
|
|
||||||
|
data BTree = N | B String Tok BTree BTree deriving (Show)
|
||||||
|
|
||||||
|
eitherResIdent :: (String -> Tok) -> String -> Tok
|
||||||
|
eitherResIdent tv s = treeFind resWords
|
||||||
|
where
|
||||||
|
treeFind N = tv s
|
||||||
|
treeFind (B a t left right) | s < a = treeFind left
|
||||||
|
| s > a = treeFind right
|
||||||
|
| s == a = t
|
||||||
|
|
||||||
|
resWords = N
|
||||||
|
where b s = B s (TS s)
|
||||||
|
|
||||||
|
unescapeInitTail :: String -> String
|
||||||
|
unescapeInitTail = unesc . tail where
|
||||||
|
unesc s = case s of
|
||||||
|
'\\':c:cs | elem c ['\"', '\\', '\''] -> c : unesc cs
|
||||||
|
'\\':'n':cs -> '\n' : unesc cs
|
||||||
|
'\\':'t':cs -> '\t' : unesc cs
|
||||||
|
'"':[] -> []
|
||||||
|
c:cs -> c : unesc cs
|
||||||
|
_ -> []
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
-- Alex wrapper code.
|
||||||
|
-- A modified "posn" wrapper.
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
|
data Posn = Pn !Int !Int !Int
|
||||||
|
deriving (Eq, Show,Ord)
|
||||||
|
|
||||||
|
alexStartPos :: Posn
|
||||||
|
alexStartPos = Pn 0 1 1
|
||||||
|
|
||||||
|
alexMove :: Posn -> Char -> Posn
|
||||||
|
alexMove (Pn a l c) '\t' = Pn (a+1) l (((c+7) `div` 8)*8+1)
|
||||||
|
alexMove (Pn a l c) '\n' = Pn (a+1) (l+1) 1
|
||||||
|
alexMove (Pn a l c) _ = Pn (a+1) l (c+1)
|
||||||
|
|
||||||
|
type AlexInput = (Posn, -- current position,
|
||||||
|
Char, -- previous char
|
||||||
|
String) -- current input string
|
||||||
|
|
||||||
|
tokens :: String -> [Token]
|
||||||
|
tokens str = go (alexStartPos, '\n', str)
|
||||||
|
where
|
||||||
|
go :: (Posn, Char, String) -> [Token]
|
||||||
|
go inp@(pos, _, str) =
|
||||||
|
case alexScan inp 0 of
|
||||||
|
AlexEOF -> []
|
||||||
|
AlexError (pos, _, _) -> [Err pos]
|
||||||
|
AlexSkip inp' len -> go inp'
|
||||||
|
AlexToken inp' len act -> act pos (take len str) : (go inp')
|
||||||
|
|
||||||
|
alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
|
||||||
|
alexGetChar (p, c, []) = Nothing
|
||||||
|
alexGetChar (p, _, (c:s)) =
|
||||||
|
let p' = alexMove p c
|
||||||
|
in p' `seq` Just (c, (p', c, s))
|
||||||
|
|
||||||
|
alexInputPrevChar :: AlexInput -> Char
|
||||||
|
alexInputPrevChar (p, c, s) = c
|
||||||
|
}
|
||||||
@@ -15,14 +15,14 @@ import GHC.Exts
|
|||||||
import GlaExts
|
import GlaExts
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
parseGrammar :: String -> IO Grammar
|
-- parser produced by Happy Version 1.17
|
||||||
parseGrammar f = case pGrammar (myLexer f) of
|
|
||||||
Ok g -> return g
|
|
||||||
Bad s -> error s
|
|
||||||
|
|
||||||
-- parser produced by Happy Version 1.16
|
newtype HappyAbsSyn = HappyAbsSyn HappyAny
|
||||||
|
#if __GLASGOW_HASKELL__ >= 607
|
||||||
newtype HappyAbsSyn = HappyAbsSyn (() -> ())
|
type HappyAny = GHC.Exts.Any
|
||||||
|
#else
|
||||||
|
type HappyAny = forall a . a
|
||||||
|
#endif
|
||||||
happyIn6 :: (Integer) -> (HappyAbsSyn )
|
happyIn6 :: (Integer) -> (HappyAbsSyn )
|
||||||
happyIn6 x = unsafeCoerce# x
|
happyIn6 x = unsafeCoerce# x
|
||||||
{-# INLINE happyIn6 #-}
|
{-# INLINE happyIn6 #-}
|
||||||
@@ -72,6 +72,7 @@ happyOutTok :: (HappyAbsSyn ) -> Token
|
|||||||
happyOutTok x = unsafeCoerce# x
|
happyOutTok x = unsafeCoerce# x
|
||||||
{-# INLINE happyOutTok #-}
|
{-# INLINE happyOutTok #-}
|
||||||
|
|
||||||
|
|
||||||
happyActOffsets :: HappyAddr
|
happyActOffsets :: HappyAddr
|
||||||
happyActOffsets = HappyA# "\x00\x00\x11\x00\x00\x00\x23\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x11\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00"#
|
happyActOffsets = HappyA# "\x00\x00\x11\x00\x00\x00\x23\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x11\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00"#
|
||||||
|
|
||||||
@@ -242,6 +243,11 @@ pListRExp tks = happySomeParser where
|
|||||||
happySeq = happyDontSeq
|
happySeq = happyDontSeq
|
||||||
|
|
||||||
|
|
||||||
|
parseGrammar :: String -> IO Grammar
|
||||||
|
parseGrammar f = case pGrammar (myLexer f) of
|
||||||
|
Ok g -> return g
|
||||||
|
Bad s -> error s
|
||||||
|
|
||||||
returnM :: a -> Err a
|
returnM :: a -> Err a
|
||||||
returnM = return
|
returnM = return
|
||||||
|
|
||||||
@@ -257,13 +263,14 @@ happyError ts =
|
|||||||
_ -> " before " ++ unwords (map prToken (take 4 ts))
|
_ -> " before " ++ unwords (map prToken (take 4 ts))
|
||||||
|
|
||||||
myLexer = tokens
|
myLexer = tokens
|
||||||
{-# LINE 1 "GenericTemplate.hs" #-}
|
{-# LINE 1 "templates/GenericTemplate.hs" #-}
|
||||||
|
{-# LINE 1 "templates/GenericTemplate.hs" #-}
|
||||||
{-# LINE 1 "<built-in>" #-}
|
{-# LINE 1 "<built-in>" #-}
|
||||||
{-# LINE 1 "<command line>" #-}
|
{-# LINE 1 "<command line>" #-}
|
||||||
{-# LINE 1 "GenericTemplate.hs" #-}
|
{-# LINE 1 "templates/GenericTemplate.hs" #-}
|
||||||
-- Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp
|
-- Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp
|
||||||
|
|
||||||
{-# LINE 28 "GenericTemplate.hs" #-}
|
{-# LINE 28 "templates/GenericTemplate.hs" #-}
|
||||||
|
|
||||||
|
|
||||||
data Happy_IntList = HappyCons Int# Happy_IntList
|
data Happy_IntList = HappyCons Int# Happy_IntList
|
||||||
@@ -272,11 +279,11 @@ data Happy_IntList = HappyCons Int# Happy_IntList
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
{-# LINE 49 "GenericTemplate.hs" #-}
|
{-# LINE 49 "templates/GenericTemplate.hs" #-}
|
||||||
|
|
||||||
{-# LINE 59 "GenericTemplate.hs" #-}
|
{-# LINE 59 "templates/GenericTemplate.hs" #-}
|
||||||
|
|
||||||
{-# LINE 68 "GenericTemplate.hs" #-}
|
{-# LINE 68 "templates/GenericTemplate.hs" #-}
|
||||||
|
|
||||||
infixr 9 `HappyStk`
|
infixr 9 `HappyStk`
|
||||||
data HappyStk a = HappyStk a (HappyStk a)
|
data HappyStk a = HappyStk a (HappyStk a)
|
||||||
@@ -328,7 +335,7 @@ happyDoAction i tk st
|
|||||||
action | check = indexShortOffAddr happyTable off_i
|
action | check = indexShortOffAddr happyTable off_i
|
||||||
| otherwise = indexShortOffAddr happyDefActions st
|
| otherwise = indexShortOffAddr happyDefActions st
|
||||||
|
|
||||||
{-# LINE 127 "GenericTemplate.hs" #-}
|
{-# LINE 127 "templates/GenericTemplate.hs" #-}
|
||||||
|
|
||||||
|
|
||||||
indexShortOffAddr (HappyA# arr) off =
|
indexShortOffAddr (HappyA# arr) off =
|
||||||
@@ -361,7 +368,7 @@ data HappyAddr = HappyA# Addr#
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- HappyState data type (not arrays)
|
-- HappyState data type (not arrays)
|
||||||
|
|
||||||
{-# LINE 170 "GenericTemplate.hs" #-}
|
{-# LINE 170 "templates/GenericTemplate.hs" #-}
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- Shifting a token
|
-- Shifting a token
|
||||||
|
|||||||
79
src/GF/GFCC/Raw/ParGFCCRaw.y
Normal file
79
src/GF/GFCC/Raw/ParGFCCRaw.y
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
-- This Happy file was machine-generated by the BNF converter
|
||||||
|
{
|
||||||
|
{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
|
||||||
|
module GF.GFCC.Raw.ParGFCCRaw (parseGrammar) where
|
||||||
|
import GF.GFCC.Raw.AbsGFCCRaw
|
||||||
|
import GF.GFCC.Raw.LexGFCCRaw
|
||||||
|
import GF.GFCC.Raw.ErrM
|
||||||
|
}
|
||||||
|
|
||||||
|
%name pGrammar Grammar
|
||||||
|
%name pRExp RExp
|
||||||
|
%name pListRExp ListRExp
|
||||||
|
|
||||||
|
-- no lexer declaration
|
||||||
|
%monad { Err } { thenM } { returnM }
|
||||||
|
%tokentype { Token }
|
||||||
|
|
||||||
|
%token
|
||||||
|
'(' { PT _ (TS "(") }
|
||||||
|
')' { PT _ (TS ")") }
|
||||||
|
'?' { PT _ (TS "?") }
|
||||||
|
|
||||||
|
L_integ { PT _ (TI $$) }
|
||||||
|
L_quoted { PT _ (TL $$) }
|
||||||
|
L_doubl { PT _ (TD $$) }
|
||||||
|
L_CId { PT _ (T_CId $$) }
|
||||||
|
L_err { _ }
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
Integer :: { Integer } : L_integ { (read $1) :: Integer }
|
||||||
|
String :: { String } : L_quoted { $1 }
|
||||||
|
Double :: { Double } : L_doubl { (read $1) :: Double }
|
||||||
|
CId :: { CId} : L_CId { CId ($1)}
|
||||||
|
|
||||||
|
Grammar :: { Grammar }
|
||||||
|
Grammar : ListRExp { Grm (reverse $1) }
|
||||||
|
|
||||||
|
|
||||||
|
RExp :: { RExp }
|
||||||
|
RExp : '(' CId ListRExp ')' { App $2 (reverse $3) }
|
||||||
|
| CId { AId $1 }
|
||||||
|
| Integer { AInt $1 }
|
||||||
|
| String { AStr $1 }
|
||||||
|
| Double { AFlt $1 }
|
||||||
|
| '?' { AMet }
|
||||||
|
|
||||||
|
|
||||||
|
ListRExp :: { [RExp] }
|
||||||
|
ListRExp : {- empty -} { [] }
|
||||||
|
| ListRExp RExp { flip (:) $1 $2 }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
parseGrammar :: String -> IO Grammar
|
||||||
|
parseGrammar f = case pGrammar (myLexer f) of
|
||||||
|
Ok g -> return g
|
||||||
|
Bad s -> error s
|
||||||
|
|
||||||
|
returnM :: a -> Err a
|
||||||
|
returnM = return
|
||||||
|
|
||||||
|
thenM :: Err a -> (a -> Err b) -> Err b
|
||||||
|
thenM = (>>=)
|
||||||
|
|
||||||
|
happyError :: [Token] -> Err a
|
||||||
|
happyError ts =
|
||||||
|
Bad $ "syntax error at " ++ tokenPos ts ++
|
||||||
|
case ts of
|
||||||
|
[] -> []
|
||||||
|
[Err _] -> " due to lexer error"
|
||||||
|
_ -> " before " ++ unwords (map prToken (take 4 ts))
|
||||||
|
|
||||||
|
myLexer = tokens
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user