1
0
forked from GitHub/gf-core

Prelude.CAPIT is now a built-in primitive. It still generates &| in the Haskell runtime but will be intepreted in the C runtime

This commit is contained in:
kr.angelov
2014-10-09 19:34:12 +00:00
parent 57f7b61c6b
commit 4efb2d5a22
19 changed files with 48 additions and 4 deletions

View File

@@ -204,6 +204,7 @@ typedef enum {
PGF_SYMBOL_KP,
PGF_SYMBOL_BIND,
PGF_SYMBOL_SOFT_BIND,
PGF_SYMBOL_CAPIT,
PGF_SYMBOL_NE
} PgfSymbolTag;
@@ -238,6 +239,9 @@ typedef struct {
typedef struct {
} PgfSymbolBIND;
typedef struct {
} PgfSymbolCAPIT;
typedef GuBuf PgfProductionIdx;
typedef struct {

View File

@@ -904,6 +904,8 @@ pgf_lzr_linearize_symbols(PgfLzr* lzr, PgfCncTreeApp* fapp,
}
break;
}
case PGF_SYMBOL_CAPIT:
break;
default:
gu_impossible();
}

View File

@@ -137,6 +137,8 @@ pgf_prev_extern_sym(PgfSymbol sym)
case PGF_SYMBOL_BIND:
case PGF_SYMBOL_SOFT_BIND:
return *((PgfSymbol*) (((PgfSymbolBIND*) i.data)+1));
case PGF_SYMBOL_CAPIT:
return *((PgfSymbol*) (((PgfSymbolCAPIT*) i.data)+1));
case PGF_SYMBOL_NE:
return *((PgfSymbol*) (((PgfSymbolNE*) i.data)+1));
default:
@@ -1147,6 +1149,9 @@ pgf_symbols_cmp(GuString* psent, size_t sent_len, BIND_TYPE* pbind, PgfSymbols*
*pbind = BIND_SOFT;
break;
}
case PGF_SYMBOL_CAPIT: {
break;
}
case PGF_SYMBOL_NE: {
return -2;
}
@@ -1719,6 +1724,9 @@ pgf_parsing_symbol(PgfParsing* ps, PgfItem* item, PgfSymbol sym)
}
break;
}
case PGF_SYMBOL_CAPIT: {
break;
}
default:
gu_impossible();
}

View File

@@ -276,6 +276,10 @@ pgf_print_symbol(PgfSymbol sym, GuOut *out, GuExn *err)
gu_puts("SOFT_BIND", out, err);
break;
}
case PGF_SYMBOL_CAPIT: {
gu_puts("CAPIT", out, err);
break;
}
default:
gu_impossible();
}

View File

@@ -709,6 +709,13 @@ pgf_read_symbol(PgfReader* rdr)
gu_return_on_exn(rdr->err, gu_null_variant);
break;
}
case PGF_SYMBOL_CAPIT: {
gu_new_variant(PGF_SYMBOL_CAPIT,
PgfSymbolCAPIT,
&sym, rdr->opool);
gu_return_on_exn(rdr->err, gu_null_variant);
break;
}
default:
pgf_read_tag_error(rdr);
}

View File

@@ -201,7 +201,8 @@ instance Binary Symbol where
put (SymKP d vs) = putWord8 4 >> put (d,vs)
put SymBIND = putWord8 5
put SymSOFT_BIND = putWord8 6
put SymNE = putWord8 7
put SymCAPIT = putWord8 7
put SymNE = putWord8 8
get = do tag <- getWord8
case tag of
0 -> liftM2 SymCat get get
@@ -211,7 +212,8 @@ instance Binary Symbol where
4 -> liftM2 (\d vs -> SymKP d vs) get get
5 -> return SymBIND
6 -> return SymSOFT_BIND
7 -> return SymNE
7 -> return SymCAPIT
8 -> return SymNE
_ -> decodingError
instance Binary PArg where

View File

@@ -62,6 +62,7 @@ data Symbol
| SymKP [Symbol] [([Symbol],[String])]
| SymBIND -- the special BIND token
| SymSOFT_BIND -- the special SOFT_BIND token
| SymCAPIT -- the special CAPIT token
| SymNE -- non exist (this should be last constructor to simplify the binary search in the runtime)
deriving (Eq,Ord,Show)
data Production

View File

@@ -156,6 +156,7 @@ data BracketedTokn
| LeafNE
| LeafBIND
| LeafSOFT_BIND
| LeafCAPIT
| LeafKP [BracketedTokn] [([BracketedTokn],[String])]
deriving Eq
@@ -219,6 +220,7 @@ computeSeq filter seq args = concatMap compute seq
compute SymNE = [LeafNE]
compute SymBIND = [LeafKS "&+"]
compute SymSOFT_BIND = []
compute SymCAPIT = [LeafKS "&|"]
compute (SymKP syms alts) = [LeafKP (concatMap compute syms) [(concatMap compute syms,cs) | (syms,cs) <- alts]]
getArg d r

View File

@@ -240,6 +240,7 @@ splitLexicalRules cnc p_prods =
seq2prefix (SymNE :syms) = TrieMap.empty
seq2prefix (SymBIND :syms) = TrieMap.fromList [wf ["&+"]]
seq2prefix (SymSOFT_BIND :syms) = TrieMap.fromList [wf []]
seq2prefix (SymCAPIT :syms) = TrieMap.fromList [wf ["&|"]]
updateConcrete abs cnc =
let p_prods0 = filterProductions IntMap.empty IntSet.empty (productions cnc)

View File

@@ -311,10 +311,13 @@ process flit ftok cnc (item@(Active j ppos funid seqid args key0):items) acc cha
SymBIND -> let !acc' = ftok_ ["&+"] (Active j (ppos+1) funid seqid args key0) acc
in process flit ftok cnc items acc' chart
SymSOFT_BIND->process flit ftok cnc ((Active j (ppos+1) funid seqid args key0):items) acc chart
SymCAPIT -> let !acc' = ftok_ ["&|"] (Active j (ppos+1) funid seqid args key0) acc
in process flit ftok cnc items acc' chart
SymKP syms vars
-> let to_tok (SymKS t) = [t]
to_tok SymBIND = ["&+"]
to_tok SymSOFT_BIND = []
to_tok SymCAPIT = ["&|"]
to_tok _ = []
!acc' = foldl (\acc syms -> ftok_ (concatMap to_tok syms) (Active j (ppos+1) funid seqid args key0) acc) acc

View File

@@ -94,6 +94,7 @@ ppSymbol (SymKS t) = doubleQuotes (text t)
ppSymbol SymNE = text "nonExist"
ppSymbol SymBIND = text "BIND"
ppSymbol SymSOFT_BIND = text "SOFT_BIND"
ppSymbol SymCAPIT = text "CAPIT"
ppSymbol (SymKP syms alts) = text "pre" <+> braces (hsep (punctuate semi (hsep (map ppSymbol syms) : map ppAlt alts)))
ppAlt (syms,ps) = hsep (map ppSymbol syms) <+> char '/' <+> hsep (map (doubleQuotes . text) ps)