Incremental parsing with gf 3.1

3 views
Skip to first unread message

Muhammad Humayoun

unread,
Jan 5, 2010, 2:39:41 PM1/5/10
to gf-...@googlegroups.com
Dear all,

I upgraded to gf 3.1 today and have some problems with incremental parser.
I was using incremental parsing with gf 3.0 in a way that it may
report the exact token which fails to parse (using initState,
finalState and extractExps functions) as shown below:

loop :: PGF -> Language -> Type -> String -> Abs.ErrM.Err [Tree]
loop pgf lang cat [] = fail $ "error: no text to parse"
loop pgf lang cat text = do
let state0 = initState pgf lang cat
finalState <- mkStates state0 (words text)
return $ extractExps finalState cat

mkStates :: ParseState -> [String] -> Abs.ErrM.Err ParseState
mkStates state0 [] = return state0
mkStates state0 (w:ws) = do
let state1 = Parse.nextState state0 w
case state1 of
Nothing -> fail $ "error: no Parse at token: " ++ w
Just state2 -> mkStates state2 ws

I think these state functions are very useful and may benefit a lot to
the users.
So my question is: how can I restore the above mentioned functionality
in gf 3.1 ?

Thanks in advance


/Humayoun

Krasimir Angelov

unread,
Jan 5, 2010, 5:12:37 PM1/5/10
to gf-...@googlegroups.com
The API in 3.1 is almost the same. There are only minor changes:

- nextState now returns:

Either ErrorState ParseState

instead of

Maybe ParseState

You have to replace Nothing with 'Left es' and 'Just ps' with 'Right
ps'. The error state is new experimental feature which makes it
possible to do some kind of robust parsing.

- extractExps is called extractTrees now.

Muhammad Humayoun

unread,
Jan 6, 2010, 2:34:21 AM1/6/10
to gf-...@googlegroups.com
thanks you very much. It is indeed very helpful.

--
Muhammad Humayoun
PhD student
University of Savoie
Laboratory of Mathematics
Batiment Le Chablais, office 020
73376 Le Bourget-du-Lac Cedex, France

Tel: (+33/0) 4.79.75.85.85 extension 70.95
Fax: (+33/0) 4.79.75.81.42
Web: http://www.lama.univ-savoie.fr/~humayoun/

Reply all
Reply to author
Forward
0 new messages