diff options
| author | krasimir <krasimir@chalmers.se> | 2010-10-18 16:51:25 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2010-10-18 16:51:25 +0000 |
| commit | 775e59dabeb6d1e15a3c1c80d7578a865121b9cf (patch) | |
| tree | b46e85b17fa124b9508058f6069bb8c268424174 /src/runtime/haskell/PGF/Parse.hs | |
| parent | 205ac48ac3f96c938e6650c2a610e3e637af5570 (diff) | |
added explicit depth parameter to the parsing API and the corresponding command in the shell
Diffstat (limited to 'src/runtime/haskell/PGF/Parse.hs')
| -rw-r--r-- | src/runtime/haskell/PGF/Parse.hs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/runtime/haskell/PGF/Parse.hs b/src/runtime/haskell/PGF/Parse.hs index 3ed3d7a72..7c5b1a22f 100644 --- a/src/runtime/haskell/PGF/Parse.hs +++ b/src/runtime/haskell/PGF/Parse.hs @@ -52,25 +52,25 @@ data ParseOutput -- The list should be non-empty.
| ParseIncomplete -- ^ The sentence is not complete. Only partial output is produced
-parse :: PGF -> Language -> Type -> [Token] -> (ParseOutput,BracketedString)
-parse pgf lang typ toks = loop (initState pgf lang typ) toks
+parse :: PGF -> Language -> Type -> Maybe Int -> [Token] -> (ParseOutput,BracketedString)
+parse pgf lang typ dp toks = loop (initState pgf lang typ) toks
where
- loop ps [] = getParseOutput ps typ
+ loop ps [] = getParseOutput ps typ dp
loop ps (t:ts) = case nextState ps (simpleParseInput t) of
Left es -> case es of
- EState _ _ chart -> (ParseFailed (offset chart),snd (getParseOutput ps typ))
+ EState _ _ chart -> (ParseFailed (offset chart),snd (getParseOutput ps typ dp))
Right ps -> loop ps ts
-parseWithRecovery :: PGF -> Language -> Type -> [Type] -> [String] -> (ParseOutput,BracketedString)
-parseWithRecovery pgf lang typ open_typs toks = accept (initState pgf lang typ) toks
+parseWithRecovery :: PGF -> Language -> Type -> [Type] -> Maybe Int -> [String] -> (ParseOutput,BracketedString)
+parseWithRecovery pgf lang typ open_typs dp toks = accept (initState pgf lang typ) toks
where
- accept ps [] = getParseOutput ps typ
+ accept ps [] = getParseOutput ps typ dp
accept ps (t:ts) =
case nextState ps (simpleParseInput t) of
Right ps -> accept ps ts
Left es -> skip (recoveryStates open_typs es) ts
- skip ps_map [] = getParseOutput (fst ps_map) typ
+ skip ps_map [] = getParseOutput (fst ps_map) typ dp
skip ps_map (t:ts) =
case Map.lookup t (snd ps_map) of
Just ps -> accept ps ts
@@ -210,19 +210,19 @@ recoveryStates open_types (EState pgf cnc chart) = -- that spans the whole input consumed so far. The trees are also
-- limited by the category specified, which is usually
-- the same as the startup category.
-getParseOutput :: ParseState -> Type -> (ParseOutput,BracketedString)
-getParseOutput (PState pgf cnc chart items) ty@(DTyp _ start _) =
+getParseOutput :: ParseState -> Type -> Maybe Int -> (ParseOutput,BracketedString)
+getParseOutput (PState pgf cnc chart items) ty@(DTyp _ start _) dp =
let froots | null roots = getPartialSeq (sequences cnc) (reverse (active chart1 : actives chart1)) seq
| otherwise = [([SymCat 0 lbl],[PArg [] fid]) | AK fid lbl <- roots]
f = Forest (abstract pgf) cnc (forest chart1) froots
- bs = linearizeWithBrackets f
+ bs = linearizeWithBrackets dp f
res | not (null es) = ParseOk es
| not (null errs) = TypeError errs
| otherwise = ParseIncomplete
- where xs = [getAbsTrees f (PArg [] fid) (Just ty) | (AK fid lbl) <- roots]
+ where xs = [getAbsTrees f (PArg [] fid) (Just ty) dp | (AK fid lbl) <- roots]
es = concat [es | Right es <- xs]
errs = concat [errs | Left errs <- xs]
|
