UNPKG

@ciao-lang/ts-ciao-interface

Version:

Simple Ciao interface for node.

60 lines 17.2 kB
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#273f79"/><link rel="stylesheet" href="lpdoc.css" type="text/css"/><script type="text/javascript" src="lpdoc.js"></script><title>Term input &mdash; The Ciao System v1.22</title></head><body><div class="lpdoc-page fixleftbar"><a href="#" id="sidebar-toggle-button" class="lpdoc-navbutton"><span id="sidebar-button-arrow">&#9776;</span></a><div id="sidebar" class="lpdoc-sidebar"><div style="height: 40px; margin-left: auto; margin-right: auto"><img src="ciao-logo_autofig.png" width=auto height=100%></div><div class="lpdoc-nav"><span class="lpdoc-on-right"><a class="lpdoc-navbutton" href="StdLibs.html">&#x2191;</a><a class="lpdoc-navbutton" href="tokenize.html">&#x2190;</a><a class="lpdoc-navbutton" href="read_from_string.html">&#x2192;</a><a class="lpdoc-navbutton" href="ciaosearch.html">&#x1F50D;</a></span><span><a href="ciaofulltoc.html">TOC</a></span></div><hr></hr><ul class="lpdoc-itemize-sectpath"><li><a href="ciao.html">The Ciao System</a> &raquo;<br/> </li><li><a href="StdLibs.html">PART VII - Standard libraries</a> &raquo;<br/> </li><li><a href=""><strong>Term input</strong></a></li></ul><hr></hr><em>ON THIS PAGE</em><ul><li><a href="#Usage and interface">Usage and interface</a></li><li><a href="#Documentation on exports">Documentation on exports</a></li><li><a href="#Documentation on multifiles">Documentation on multifiles</a></li><li><a href="#Documentation on imports">Documentation on imports</a></li></ul></div><div class="lpdoc-main"><div id=""><h1>Term input</h1><a class="lpdoc-idx-anchor" href="ciaosearch.html#read"></a> <strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="Daniel Cabeza" href="ciaosearch.html#Daniel Cabeza">Daniel Cabeza (modifications and documentation, adapted from SICStus 0.6 code)</a>, <a class="lpdoc-idx-anchor" id="Manuel Carro" href="ciaosearch.html#Manuel Carro">Manuel Carro (modifications and documentation)</a>, <a class="lpdoc-idx-anchor" id="Jose F. Morales" href="ciaosearch.html#Jose F. Morales">Jose F. Morales (modifications for curly blocks,postfix blocks, infix dot, string constants, and doccomments)</a>, <a class="lpdoc-idx-anchor" id="Manuel Hermenegildo" href="ciaosearch.html#Manuel Hermenegildo">Manuel Hermenegildo (minor in documentation)</a>.<p> This module provides facilities for reading terms in Prolog syntax. This is very convenient in many cases (and not only if you are writing a Prolog compiler) because Prolog terms are easy to write and can encode a large amount of information in a human-readable fashion. Note that, in addition, the use of <a class="lpdoc-idx-anchor" id="0" href="ciaosearch.html#operator definitions">operator definitions</a> makes it possible to enhance the readibility of such terms, or, for example, data files composed of Prolog terms.<p>The behavior of these reading predicates can be modified in two ways:<p><ul> <p><li>The operators that are active at run time when the reading predicate is called (see <a href="operators.html">Defining operators</a>).<p><li>A number of flags (see below) which control how some special terms are read in or activate some syntax extensions.<p></ul> <br/><div id="Usage and interface"><h2>Usage and interface</h2><div class="lpdoc-cartouche"><ul><li><strong>Library usage:</strong><br/><tt>:- use_module(library(read)).</tt><li><strong>Exports:</strong><br/><ul class="lpdoc-itemize-minus"><li><em>Predicates:</em><br/><a class="lpdoc-idx-anchor" id="1" href="#read/1"><tt>read/1</tt></a>, <a class="lpdoc-idx-anchor" id="2" href="iso_incomplete.html#read/2"><tt>read/2</tt></a>, <a class="lpdoc-idx-anchor" id="3" href="#read_term/2"><tt>read_term/2</tt></a>, <a class="lpdoc-idx-anchor" id="4" href="iso_incomplete.html#read_term/3"><tt>read_term/3</tt></a>, <a class="lpdoc-idx-anchor" id="5" href="#read_top_level/3"><tt>read_top_level/3</tt></a>, <a class="lpdoc-idx-anchor" id="6" href="#second_prompt/2"><tt>second_prompt/2</tt></a>. <li><em>Regular Types:</em><br/><a class="lpdoc-idx-anchor" id="7" href="#read_option/1"><tt>read_option/1</tt></a>. <li><em>Multifiles:</em><br/><a class="lpdoc-idx-anchor" id="8" href="tokenize.html#define_flag/3"><tt>define_flag/3</tt></a>. </ul></ul></div></div><div id="Documentation on exports"><h2>Documentation on exports</h2><div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="read/1" href="ciaosearch.html#read/1">read/1</a></div><div class="lpdoc-deftext"><span class="lpdoc-usage-decl"><tt>read(Term)</tt> </span><p>Like <tt>read(Stream,Term)</tt> with <span class="lpdoc-var">Stream</span> associated to the current input stream.<p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><span class="lpdoc-on-right"><span class="lpdoc-iso">ISO</span></span><span></span> </span><p></p><ul class="lpdoc-itemize-minus"><li><em>Call and exit should be compatible with:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="9" href="basic_props.html#term/1"><tt>basic_props:term/1</tt></a>)</span><span><span class="lpdoc-var">Term</span> is any term. </span> <li><em>The following properties should hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="10" href="basic_props.html#term/1"><tt>basic_props:term/1</tt></a>)</span><span><span class="lpdoc-var">Term</span> is any term. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="read/2" href="ciaosearch.html#read/2">read/2</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><span class="lpdoc-on-right"><span class="lpdoc-iso">ISO</span></span><span><tt>read(Stream,Term)</tt></span> </span><p>The next term, delimited by a full-stop (i.e., a <tt>.</tt> followed by either a space or a control character), is read from <span class="lpdoc-var">Stream</span> and is unified with <span class="lpdoc-var">Term</span>. The syntax of the term must agree with current operator declarations. If the end of <span class="lpdoc-var">Stream</span> has been reached, <span class="lpdoc-var">Term</span> is unified with the term <tt>end_of_file</tt>. Further calls to <tt>read/2</tt> for the same stream will then cause an error, unless the stream is connected to the terminal (in which case a prompt is opened on the terminal).</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="11" href="term_typing.html#nonvar/1"><tt>term_typing:nonvar/1</tt></a>)</span><span><span class="lpdoc-var">Stream</span> is currently a term which is not a free variable. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="12" href="stream_basic.html#stream/1"><tt>stream_basic:stream/1</tt></a>)</span><span><span class="lpdoc-var">Stream</span> is an open stream. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="13" href="basic_props.html#term/1"><tt>basic_props:term/1</tt></a>)</span><span><span class="lpdoc-var">Term</span> is any term. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="read_term/2" href="ciaosearch.html#read_term/2">read_term/2</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><span class="lpdoc-on-right"><span class="lpdoc-iso">ISO</span></span><span><tt>read_term(Term,Options)</tt></span> </span><p>Like <a class="lpdoc-idx-anchor" id="14" href="iso_incomplete.html#read_term/3"><tt>read_term/3</tt></a>, but reading from the <a class="lpdoc-idx-anchor" id="15" href="ciaosearch.html#current input">current input</a></p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="16" href="term_typing.html#nonvar/1"><tt>term_typing:nonvar/1</tt></a>)</span><span><span class="lpdoc-var">Options</span> is currently a term which is not a free variable. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="17" href="basic_props.html#term/1"><tt>basic_props:term/1</tt></a>)</span><span><span class="lpdoc-var">Term</span> is any term. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="18" href="basic_props.html#list/2"><tt>basic_props:list/2</tt></a>)</span><span><span class="lpdoc-var">Options</span> is a list of <span class="lpdoc-var">read_option</span>s. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="read_term/3" href="ciaosearch.html#read_term/3">read_term/3</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><span class="lpdoc-on-right"><span class="lpdoc-iso">ISO</span></span><span><tt>read_term(Stream,Term,Options)</tt></span> </span><p>Reads a <span class="lpdoc-var">Term</span> from <span class="lpdoc-var">Stream</span> with the ISO-Prolog <span class="lpdoc-var">Options</span>. These options can control the behavior of read term (see <a class="lpdoc-idx-anchor" id="19" href="#read_option/1"><tt>read_option/1</tt></a>).</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="20" href="term_typing.html#nonvar/1"><tt>term_typing:nonvar/1</tt></a>)</span><span><span class="lpdoc-var">Stream</span> is currently a term which is not a free variable. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="21" href="term_typing.html#nonvar/1"><tt>term_typing:nonvar/1</tt></a>)</span><span><span class="lpdoc-var">Options</span> is currently a term which is not a free variable. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="22" href="stream_basic.html#stream/1"><tt>stream_basic:stream/1</tt></a>)</span><span><span class="lpdoc-var">Stream</span> is an open stream. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="23" href="basic_props.html#term/1"><tt>basic_props:term/1</tt></a>)</span><span><span class="lpdoc-var">Term</span> is any term. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="24" href="basic_props.html#list/2"><tt>basic_props:list/2</tt></a>)</span><span><span class="lpdoc-var">Options</span> is a list of <span class="lpdoc-var">read_option</span>s. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="read_top_level/3" href="ciaosearch.html#read_top_level/3">read_top_level/3</a></div><div class="lpdoc-deftext"><span class="lpdoc-usage-decl"><tt>read_top_level(Stream,Data,Variables)</tt> </span><p>Predicate used to read in the Top Level.</div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="second_prompt/2" href="ciaosearch.html#second_prompt/2">second_prompt/2</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>second_prompt(Old,New)</tt> </span><p>Changes the prompt (the <em>second prompt</em>, as opposed to the first one, used by the toplevel) used by <a class="lpdoc-idx-anchor" id="25" href="iso_incomplete.html#read/2"><tt>read/2</tt></a> and friends to <span class="lpdoc-var">New</span>, and returns the current one in <span class="lpdoc-var">Old</span>.</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="26" href="term_typing.html#atom/1"><tt>term_typing:atom/1</tt></a>)</span><span><span class="lpdoc-var">Old</span> is currently instantiated to an atom. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="27" href="term_typing.html#atom/1"><tt>term_typing:atom/1</tt></a>)</span><span><span class="lpdoc-var">New</span> is currently instantiated to an atom. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">REGTYPE</span><a class="lpdoc-idx-anchor" id="read_option/1" href="ciaosearch.html#read_option/1">read_option/1</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>read_option(Option)</tt> </span><p><span class="lpdoc-var">Option</span> is an allowed <a class="lpdoc-idx-anchor" id="28" href="ciaosearch.html#read_term/[2,3]"><tt>read_term/[2,3]</tt></a> option. These options are: <pre class="lpdoc-codeblock">read_option(variables(_V)). read_option(variable_names(_N)). read_option(singletons(_S)). read_option(lines(_StartLine,_EndLine)). read_option(dictionary(_Dict)). </pre> They can be used to return the singleton variables in the term, a list of variables, etc.</p><ul class="lpdoc-itemize-minus"></ul></div></div><p> </div><div id="Documentation on multifiles"><h2>Documentation on multifiles</h2><div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="define_flag/3" href="ciaosearch.html#define_flag/3">define_flag/3</a></div><div class="lpdoc-deftext">The folowing flags are defined: <pre class="lpdoc-codeblock">define_flag(read_hiord,[on,off],off). define_flag(read_curly_blocks,[on,off],off). define_flag(read_postfix_blocks,[on,off],off). define_flag(read_string_data_type,[on,off],off). define_flag(read_infix_dot,[on,off],off). </pre> (See <a href="runtime_control.html">Runtime system control and flags</a>).<p><dl> <p><dt><tt>read_hiord</tt><dd> <p>If flag is <tt>on</tt> (it is <tt>off</tt> by default), a variable followed by a parenthesized list of arguments is read as a <a class="lpdoc-idx-anchor" id="29" href="ciaosearch.html#call/N"><tt>call/N</tt></a> term, except if the variable is anonymous, in which case it is read as an anonymous predicate abstraction head. For example, <tt>P(X)</tt> is read as <tt>call(P,X)</tt> and <tt>_(X,Y)</tt> as <tt>&apos;&apos;(X,Y)</tt>.<p><dt><tt>read_curly_blocks</tt><dd> When enabled, read terms of the form &apos;<tt>{</tt> <em>&lt;list of sentences&gt;</em> <tt>}</tt>&apos;.<p><dt><tt>read_postfix_blocks</tt><dd> When enabled, allow &apos;<em>&lt;term&gt; &lt;term&gt;</em>&apos; as valid terms.<p><dt><tt>read_string_data_type</tt><dd> When enabled, strings are read as &apos;<tt>\6\string</tt>&apos; terms (not as lists).<p><dt><tt>read_infix_dot</tt><dd> When enabled, infix dot &apos;<tt>.</tt>&apos; is read as &apos;<tt>\6\dot</tt>&apos; terms (not as a list).<p></dl> <p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>define_flag(Flag,FlagValues,Default)</tt> </span><p></p><ul class="lpdoc-itemize-minus"><li><em>The following properties hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="30" href="basic_props.html#atm/1"><tt>basic_props:atm/1</tt></a>)</span><span><span class="lpdoc-var">Flag</span> is an atom. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="31" href="basic_props.html#flag_values/1"><tt>basic_props:flag_values/1</tt></a>)</span><span>Define the valid flag values </span> </ul> The predicate is <em>multifile</em>.<br/></div></div><p> </div><div id="Documentation on imports"><h2>Documentation on imports</h2>This module has the following direct dependencies:<ul class="lpdoc-itemize-minus"><li><em>System library modules:</em><br/><a class="lpdoc-idx-anchor" id="32" href="datafacts_rt.html"><tt>datafacts_rt</tt></a>, <a class="lpdoc-idx-anchor" id="33" href="tokenize.html"><tt>tokenize</tt></a>, <a class="lpdoc-idx-anchor" id="34" href="dict.html"><tt>dict</tt></a>, <a class="lpdoc-idx-anchor" id="35" href="operators.html"><tt>operators</tt></a>, <a class="lpdoc-idx-anchor" id="36" href="lists.html"><tt>lists</tt></a>. <li><em>Packages:</em><br/><a class="lpdoc-idx-anchor" id="37" href="ciaosearch.html#prelude"><tt>prelude</tt></a>, <a class="lpdoc-idx-anchor" id="38" href="ciaosearch.html#initial"><tt>initial</tt></a>, <a class="lpdoc-idx-anchor" id="39" href="condcomp_doc.html"><tt>condcomp</tt></a>, <a class="lpdoc-idx-anchor" id="40" href="assertions_doc.html"><tt>assertions</tt></a>, <a class="lpdoc-idx-anchor" id="41" href="ciaosearch.html#assertions/assertions_basic"><tt>assertions/assertions_basic</tt></a>, <a class="lpdoc-idx-anchor" id="42" href="ciaosearch.html#nortchecks"><tt>nortchecks</tt></a>, <a class="lpdoc-idx-anchor" id="43" href="isomodes_doc.html"><tt>isomodes</tt></a>, <a class="lpdoc-idx-anchor" id="44" href="ciaosearch.html#define_flag"><tt>define_flag</tt></a>, <a class="lpdoc-idx-anchor" id="45" href="datafacts_doc.html"><tt>datafacts</tt></a>. </ul></div></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>