summaryrefslogtreecommitdiff
path: root/src/runtime/c/pgf/pgf.c
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2013-05-01 06:09:55 +0000
committerkr.angelov <kr.angelov@gmail.com>2013-05-01 06:09:55 +0000
commit22f44ef61f99acdec5d19f336bb80f6bb3a4e8b7 (patch)
tree4ee1496edc1c5df1b11464ce8425071c3ef11994 /src/runtime/c/pgf/pgf.c
parent41bccf5737544a6981dc6a17bb4bb8116ace7937 (diff)
word completion in the C runtime. The runtime/python/test.py example is now using readline with word completion
Diffstat (limited to 'src/runtime/c/pgf/pgf.c')
-rw-r--r--src/runtime/c/pgf/pgf.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/runtime/c/pgf/pgf.c b/src/runtime/c/pgf/pgf.c
index 39d3fcfbf..24d330981 100644
--- a/src/runtime/c/pgf/pgf.c
+++ b/src/runtime/c/pgf/pgf.c
@@ -236,6 +236,37 @@ pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool)
return pgf_parse_result(state, pool);
}
+GuEnum*
+pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
+ GuString prefix, GuPool* pool)
+{
+ // Begin parsing a sentence of the specified category
+ PgfParseState* state =
+ pgf_parser_init_state(concr, cat, 0, pool);
+ if (state == NULL) {
+ return NULL;
+ }
+
+ // Tokenization
+ GuExn* lex_err = gu_new_exn(NULL, gu_kind(type), pool);
+ PgfToken tok = pgf_lexer_read_token(lexer, lex_err);
+ while (!gu_exn_is_raised(lex_err)) {
+ // feed the token to get a new parse state
+ state = pgf_parser_next_state(state, tok);
+ if (state == NULL) {
+ return NULL;
+ }
+
+ tok = pgf_lexer_read_token(lexer, lex_err);
+ }
+
+ if (gu_exn_caught(lex_err) != gu_type(GuEOF))
+ return NULL;
+
+ // Now begin enumerating the resulting syntax trees
+ return pgf_parser_completions(state, prefix, pool);
+}
+
void
pgf_print_chunks(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool)
{