Quasiquotations and EDCG

In

“Implementing GraphQL as a Query Language for Deductive Databases in SWI–Prolog Using DCGs, Quasi Quotations, and Dicts” by Falco Nogatz (@fnogatz) and Dietmar Seipel (pdf)

it notes

we intend to adopt EDCG rules for writing more powerful grammars in a simpler way in the future.

Is there more that has/can be shared regarding the use of EDCG with Quasiquotations?

Currently looking at existing and other ways to create Cytoscape visual graphs (nodes and edges) from Prolog and this is an avenue worth exploring.


EDIT

For those looking for related source code (not identical) to the paper see: Pack - graphql

Install instructions
  1. First, optionally check to see if it is already installed.
?- pack_list_installed.
Installed packages (18):

i callgraph@0.4.1           - Predicate call graph visualisation
i clitable@1.0.8            - Pretty unicode tables for the CLI with Prolog
i dcgutils@1.1.3            - DCG related utilities
i dictoo@1.4.111            - Dict-like OO Syntax
i edcg@0.9.1.2              - Extended DCG
i fileutils@0.3.5           - Utilities for reading, writing and finding files
i fnotation@0.0.3           - Function notation for Prolog
i func@0.4.2                - Function application and composition
i function_expansion@0.1.2  - Help for writing function-like macros
i genutils@0.3.8            - General miscellaneous utilities
i gvar_syntax@1.5.666       - Global Variable Syntax
i list_util@0.13.0          - Predicates for working with lists
i logicmoo_utils@1.5.666    - Common predicates that are used throughout LogicMOO Software
i pfc@1.4.111               - Pfc -- a package for forward chaining in Prolog
i predicate_streams@1.5.666 - Implement your own Abstract Predicate Streams
i quickcheck@0.3.0          - QuickCheck randomized testing
i sldnfdraw@1.61            - SLDNF Draw is a Prolog program that draws SLDNF Trees in LaTeX
i swipe@0.2.6               - Shell pipeline construction with type checking
true.

If not installed then install it.

NB There are two identical versions of the pack. I would suggest using graphql as it does not have the - in the name which can cause problems when the name graphql-swipl is not single quoted.

?- pack_search(graphql).
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
p graphql@0.0.1             - GraphQL Prolog Library
p graphql-swipl@0.0.1       - GraphQL Prolog Library
true.
?- pack_install(graphql).
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
Install graphql@0.0.1 from GIT at https://github.com/NaohiroTamura/graphql.git Y/n? 
% Cloning into 'c:/users/eric/appdata/local/swi-prolog/pack/graphql'...
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
% "graphql.git" was downloaded 17 times
Package:                graphql
Title:                  GraphQL Prolog Library
Installed version:      0.0.1
Author:                 Naohiro Tamura <naohirot@jp.fujitsu.com>
Home page:              https://github.com/NaohiroTamura
Activate pack "graphql" Y/n? 
true.

For more working examples of Quasiquotations with SWI-Prolog see Anne’s Creating Web Applications in SWI-Prolog

Uh, long time ago :wink:
We moved away from the name EDCG and library(edcgs), in order to avoid confusion with Peter Van Roy’s EDCG package. The latest version of our work is library(dcg4pt), which extends DCGs for Prolog by an additional argument to automatically store the corresponding parse tree. One practical application is library(plammar), which implements a Prolog parser and serialiser in Prolog. We also used dcg4pt for processing natural language.

Quasi-quotations just provide a way to put an external DSL right next to native Prolog code. In this regard, they are just syntactic sugar if you want to avoid external files that store the DSL. Regarding the parsing process, it does not matter whether you put the things into external files or between quasi-quotations. And our dcg4pt is just one way to ease the writing for parsers and serialisers. You could also stick to plain old DCG, or use Peter van Roy’s EDCG instead.

3 Likes

If you want to hold the parse tree as an additional argument, you might be interested in DCTGs.
Here’s an example and a short explanation (you’ll have to read the book for a fuller explanation and more complete examples): http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/prolog/code/syntax/dctg/0.html

1 Like