From eb9cc69bfb39bcfe4c33f015adce0bfaeab168ee Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 27 Jan 2018 11:40:40 +0000 Subject: [PATCH 1/3] :module --- packages/python/yap_kernel/yap_ipython/core/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/python/yap_kernel/yap_ipython/core/__init__.py b/packages/python/yap_kernel/yap_ipython/core/__init__.py index e69de29bb..0517ffe82 100644 --- a/packages/python/yap_kernel/yap_ipython/core/__init__.py +++ b/packages/python/yap_kernel/yap_ipython/core/__init__.py @@ -0,0 +1 @@ +#nothing here From aaadd513092a2e452fe0c418d785eed99ae97eeb Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 29 Jan 2018 15:24:32 +0000 Subject: [PATCH 2/3] sync --- os/charsio.c | 24 +- os/iopreds.c | 5 +- packages/python/swig/prolog/yapi.yap | 15 +- packages/python/swig/setup.py.in | 2 +- packages/python/yap_kernel/CMakeLists.txt | 456 +++++++++++++++--- packages/python/yap_kernel/setup.py | 38 +- .../python/yap_kernel/yap_ipython/yapi.py | 6 +- pl/boot.yap | 7 +- pl/directives.yap | 3 +- pl/meta.yap | 24 +- pl/modules.yap | 15 +- 11 files changed, 471 insertions(+), 124 deletions(-) diff --git a/os/charsio.c b/os/charsio.c index b3925d69e..34ba3e880 100644 --- a/os/charsio.c +++ b/os/charsio.c @@ -96,7 +96,7 @@ INLINE_ONLY inline EXTERN Int CharOfAtom(Atom at) { int Yap_peekWideWithGetwc(int sno) { StreamDesc *s; s = GLOBAL_Stream + sno; - int ch = getwc(s->file); + int ch = fgetwc(s->file); ungetwc(ch, s->file); return ch; } @@ -104,7 +104,7 @@ int Yap_peekWideWithGetwc(int sno) { int Yap_peekWithGetc(int sno) { StreamDesc *s; s = GLOBAL_Stream + sno; - int ch = getc(s->file); + int ch = fgetc(s->file); ungetc(ch, s->file); return ch; } @@ -167,6 +167,7 @@ int Yap_peekWide(int sno) { Int line = s->linecount; Int lpos = s->linepos; int ch = s->stream_wgetc(sno); + fprintf(stderr, "%d=%c\n", fileno(s->file), ch); if (ch == EOF) { if (s->file) clearerr(s->file); @@ -181,9 +182,13 @@ int Yap_peekWide(int sno) { s->charcount = pos; s->linecount = line; s->linepos = lpos; + s->stream_wgetc = Yap_popChar; + s->stream_getc = NU; + s->stream_peek= NULL; + s->stream_wpeek= NULL; s->stream_getc = Yap_popChar; s->stream_wgetc = Yap_popChar; - Yap_SetCurInpPos(sno, pos); + // Yap_SetCurInpPos(sno, pos); } return ch; } @@ -209,15 +214,17 @@ int Yap_peekChar(int sno) { s->linecount = line; s->linepos = lpos; s->stream_getc = Yap_popChar; - s->stream_wgetc = Yap_popChar; - Yap_SetCurInpPos(sno, pos); + s->stream_wgetc = NU; + s->stream_peek= NULL; + s->stream_wpeek= NULL; + //Yap_SetCurInpPos(sno, pos); } return ch; } int Yap_peek(int sno) { return GLOBAL_Stream[sno].stream_wpeek(sno); } -static int dopeek_byte(int sno) { return GLOBAL_Stream[sno].stream_wpeek(sno); } +static int dopeek_byte(int sno) { return GLOBAL_Stream[sno].stream_peek(sno); } bool store_code(int ch, Term t USES_REGS) { Term t2 = Deref(t); @@ -255,10 +262,7 @@ static Int at_end_of_stream(USES_REGS1) { /* at_end_of_stream */ out = (Yap_peek(sno) < 0); } } - UNLOCK(GLOBAL_Stream[sno].streamlock); - return out; -} - + UNLOCK(GLOBAL_Stream[sno].streaml /** @pred at_end_of_stream is iso diff --git a/os/iopreds.c b/os/iopreds.c index ca6ec681c..cefb24308 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -350,6 +350,7 @@ void Yap_DefaultStreamOps(StreamDesc *st) { st->stream_getc = Yap_popChar; st->stream_wgetc = Yap_popChar; } + /* if (st->file) { if (st->status & Readline_Stream_f) { st->stream_peek = Yap_ReadlinePeekChar; @@ -361,7 +362,9 @@ void Yap_DefaultStreamOps(StreamDesc *st) { } else if (st->status & Seekable_Stream_f) { st->stream_peek = Yap_peekWithSeek; st->stream_wpeek = Yap_peekWideWithSeek; - } else { + } else +*/ + { st->stream_peek = Yap_peekChar; st->stream_wpeek = Yap_peekWide; } diff --git a/packages/python/swig/prolog/yapi.yap b/packages/python/swig/prolog/yapi.yap index 93365df3f..b67467edc 100644 --- a/packages/python/swig/prolog/yapi.yap +++ b/packages/python/swig/prolog/yapi.yap @@ -2,10 +2,6 @@ %% @brief support yap shell %% -:- yap_flag(verbose, verbose). - -:- use_module( library(python) ). - :- module(yapi, [ python_ouput/0, show_answer/2, @@ -15,11 +11,20 @@ yapi_query/2 ]). + + :- yap_flag(verbose, verbose). + + :- use_module( library(lists) ). :- use_module( library(maplist) ). :- use_module( library(rbtrees) ). :- use_module( library(terms) ). -:- use_module( library(python) ). +:- reexport( library(python) ). + +:- current_op(X,Y,':='), writeln(X:Y). +:- current_op(X,Y,'.'), writeln(X:Y). + +:- stop_low_level_trace. :- python_import(yap4py.yapi). diff --git a/packages/python/swig/setup.py.in b/packages/python/swig/setup.py.in index a0ec33e80..ec54b6152 100644 --- a/packages/python/swig/setup.py.in +++ b/packages/python/swig/setup.py.in @@ -68,7 +68,7 @@ elif platform.system() == 'Darwin': win_libs = [] local_libs = ['Py4YAP'] elif platform.system() == 'Linux': - my_extra_link_args = ['-L','..'] + my_extra_link_args = ['-L','..','-Wl,-rpath','-Wl,${CMAKE_INSTALL_FULL_LIBDIR}'] win_libs = [] local_libs = ['Py4YAP'] diff --git a/packages/python/yap_kernel/CMakeLists.txt b/packages/python/yap_kernel/CMakeLists.txt index 541c4a54b..1eb508cf0 100644 --- a/packages/python/yap_kernel/CMakeLists.txt +++ b/packages/python/yap_kernel/CMakeLists.txt @@ -1,55 +1,364 @@ set (PYTHON_SOURCES - yap_ipython/core/getipython.py - yap_ipython/core/__init__.py - yap_ipython/core/interactiveshell.py - # yap_ipython/core/modulefind.py - yap_ipython/core/oinspect.py - yap_ipython/core/release.py - yap_ipython/core/shellapp.py - yap_ipython/display.py - yap_ipython/__init__.py - yap_ipython/shellapp.py - yap_kernel_launcher.py - yap_kernel/__init__.py - yap_kernel/__main__.py - yap_kernel/_version.py - yap_kernel/codeutil.py - yap_kernel/connect.py - yap_kernel/datapub.py - yap_kernel/displayhook.py - yap_kernel/embed.py - yap_kernel/eventloops.py - yap_kernel/heartbeat.py - yap_kernel/interactiveshell.py - yap_kernel/iostream.py - yap_kernel/jsonutil.py - yap_kernel/kernelapp.py - yap_kernel/kernelbase.py - yap_kernel/kernelspec.py - yap_kernel/log.py - yap_kernel/parentpoller.py - yap_kernel/pickleutil.py - yap_kernel/serialize.py - yap_kernel/yapkernel.py - yap_kernel/zmqshell.py - yap_kernel/comm/__init__.py - yap_kernel/comm/comm.py - yap_kernel/comm/manager.py - yap_kernel/gui/__init__.py - yap_kernel/gui/gtk3embed.py - yap_kernel/gui/gtkembed.py - yap_kernel/inprocess/__init__.py - yap_kernel/inprocess/blocking.py - yap_kernel/inprocess/channels.py - yap_kernel/inprocess/client.py - yap_kernel/inprocess/ipkernel.py - yap_kernel/inprocess/manager.py - yap_kernel/inprocess/socket.py - yap_kernel/pylab/__init__.py - yap_kernel/pylab/backend_inline.py - yap_kernel/pylab/config.py - ) +yap_kernel_launcher.py +docs/conf.py +yap_kernel/serialize.py +yap_kernel/_eventloop_macos.py +yap_kernel/jsonutil.py +yap_kernel/pickleutil.py +yap_kernel/pylab/backend_inline.py +yap_kernel/pylab/config.py +yap_kernel/pylab/__init__.py +yap_kernel/displayhook.py +yap_kernel/__main__.py +yap_kernel/gui/gtk3embed.py +yap_kernel/gui/gtkembed.py +yap_kernel/gui/__init__.py +yap_kernel/parentpoller.py +yap_kernel/_version.py +yap_kernel/eventloops.py +yap_kernel/connect.py +yap_kernel/comm/comm.py +yap_kernel/comm/__init__.py +yap_kernel/comm/manager.py +yap_kernel/kernelspec.py +yap_kernel/iostream.py +yap_kernel/zmqshell.py +yap_kernel/kernelbase.py +yap_kernel/heartbeat.py +yap_kernel/log.py +yap_kernel/datapub.py +yap_kernel/codeutil.py +yap_kernel/kernelapp.py +yap_kernel/embed.py +yap_kernel/tests/test_embed_kernel.py +yap_kernel/tests/test_kernelspec.py +yap_kernel/tests/_asyncio.py +yap_kernel/tests/test_serialize.py +yap_kernel/tests/test_pickleutil.py +yap_kernel/tests/test_eventloop.py +yap_kernel/tests/utils.py +yap_kernel/tests/test_kernel.py +yap_kernel/tests/test_io.py +yap_kernel/tests/test_jsonutil.py +yap_kernel/tests/test_connect.py +yap_kernel/tests/test_message_spec.py +yap_kernel/tests/__init__.py +yap_kernel/tests/test_start_kernel.py +yap_kernel/tests/test_zmq_shell.py +yap_kernel/__init__.py +yap_kernel/inprocess/blocking.py +yap_kernel/inprocess/socket.py +yap_kernel/inprocess/constants.py +yap_kernel/inprocess/channels.py +yap_kernel/inprocess/tests/test_kernelmanager.py +yap_kernel/inprocess/tests/test_kernel.py +yap_kernel/inprocess/tests/__init__.py +yap_kernel/inprocess/__init__.py +yap_kernel/inprocess/manager.py +yap_kernel/inprocess/client.py +yap_kernel/inprocess/ipkernel.py +yap_kernel/ipkernel.py +yap_ipython/display.py +yap_ipython/frontend.py +yap_ipython/parallel.py +yap_ipython/html.py +yap_ipython/__main__.py +yap_ipython/testing/iptest.py +yap_ipython/testing/skipdoctest.py +yap_ipython/testing/tools.py +yap_ipython/testing/iptestcontroller.py +yap_ipython/testing/__main__.py +yap_ipython/testing/decorators.py +yap_ipython/testing/ipunittest.py +yap_ipython/testing/tests/test_tools.py +yap_ipython/testing/tests/test_ipunittest.py +yap_ipython/testing/tests/test_decorators.py +yap_ipython/testing/tests/__init__.py +yap_ipython/testing/__init__.py +yap_ipython/testing/globalipapp.py +yap_ipython/testing/plugin/iptest.py +yap_ipython/testing/plugin/show_refs.py +yap_ipython/testing/plugin/simplevars.py +yap_ipython/testing/plugin/simple.py +yap_ipython/testing/plugin/ipdoctest.py +yap_ipython/testing/plugin/test_ipdoctest.py +yap_ipython/testing/plugin/setup.py +yap_ipython/testing/plugin/__init__.py +yap_ipython/testing/plugin/dtexample.py +yap_ipython/testing/plugin/test_refs.py +yap_ipython/terminal/ptutils.py +yap_ipython/terminal/shortcuts.py +yap_ipython/terminal/ipapp.py +yap_ipython/terminal/pt_inputhooks/wx.py +yap_ipython/terminal/pt_inputhooks/pyglet.py +yap_ipython/terminal/pt_inputhooks/osx.py +yap_ipython/terminal/pt_inputhooks/gtk.py +yap_ipython/terminal/pt_inputhooks/tk.py +yap_ipython/terminal/pt_inputhooks/glut.py +yap_ipython/terminal/pt_inputhooks/gtk3.py +yap_ipython/terminal/pt_inputhooks/__init__.py +yap_ipython/terminal/pt_inputhooks/qt.py +yap_ipython/terminal/console.py +yap_ipython/terminal/prompts.py +yap_ipython/terminal/ptshell.py +yap_ipython/terminal/embed.py +yap_ipython/terminal/tests/test_help.py +yap_ipython/terminal/tests/test_embed.py +yap_ipython/terminal/tests/test_interactivshell.py +yap_ipython/terminal/tests/__init__.py +yap_ipython/terminal/__init__.py +yap_ipython/terminal/interactiveshell.py +yap_ipython/terminal/debugger.py +yap_ipython/terminal/magics.py +yap_ipython/consoleapp.py +yap_ipython/core/display.py +yap_ipython/core/application.py +yap_ipython/core/builtin_trap.py +yap_ipython/core/formatters.py +yap_ipython/core/prefilter.py +yap_ipython/core/getipython.py +yap_ipython/core/usage.py +yap_ipython/core/oinspect.py +yap_ipython/core/displayhook.py +yap_ipython/core/hooks.py +yap_ipython/core/splitinput.py +yap_ipython/core/page.py +yap_ipython/core/history.py +yap_ipython/core/displaypub.py +yap_ipython/core/profiledir.py +yap_ipython/core/shellapp.py +yap_ipython/core/extensions.py +yap_ipython/core/compilerop.py +yap_ipython/core/events.py +yap_ipython/core/pylabtools.py +yap_ipython/core/completer.py +yap_ipython/core/prompts.py +yap_ipython/core/latex_symbols.py +yap_ipython/core/macro.py +yap_ipython/core/inputsplitter.py +yap_ipython/core/error.py +yap_ipython/core/profileapp.py +yap_ipython/core/magic_arguments.py +yap_ipython/core/logger.py +yap_ipython/core/inputtransformer.py +yap_ipython/core/payloadpage.py +yap_ipython/core/crashhandler.py +yap_ipython/core/magics/display.py +yap_ipython/core/magics/execution.py +yap_ipython/core/magics/namespace.py +yap_ipython/core/magics/basic.py +yap_ipython/core/magics/extension.py +yap_ipython/core/magics/history.py +yap_ipython/core/magics/pylab.py +yap_ipython/core/magics/config.py +yap_ipython/core/magics/osm.py +yap_ipython/core/magics/script.py +yap_ipython/core/magics/__init__.py +yap_ipython/core/magics/auto.py +yap_ipython/core/magics/logging.py +yap_ipython/core/magics/code.py +yap_ipython/core/ultratb.py +yap_ipython/core/tests/test_application.py +yap_ipython/core/tests/simpleerr.py +yap_ipython/core/tests/test_paths.py +yap_ipython/core/tests/bad_all.py +yap_ipython/core/tests/test_prefilter.py +yap_ipython/core/tests/test_logger.py +yap_ipython/core/tests/test_interactiveshell.py +yap_ipython/core/tests/test_events.py +yap_ipython/core/tests/test_display.py +yap_ipython/core/tests/test_autocall.py +yap_ipython/core/tests/test_formatters.py +yap_ipython/core/tests/test_alias.py +yap_ipython/core/tests/nonascii.py +yap_ipython/core/tests/test_displayhook.py +yap_ipython/core/tests/test_profile.py +yap_ipython/core/tests/test_imports.py +yap_ipython/core/tests/test_oinspect.py +yap_ipython/core/tests/test_inputtransformer.py +yap_ipython/core/tests/test_magic_arguments.py +yap_ipython/core/tests/test_debugger.py +yap_ipython/core/tests/test_hooks.py +yap_ipython/core/tests/test_run.py +yap_ipython/core/tests/test_pylabtools.py +yap_ipython/core/tests/print_argv.py +yap_ipython/core/tests/test_page.py +yap_ipython/core/tests/test_compilerop.py +yap_ipython/core/tests/test_prompts.py +yap_ipython/core/tests/test_magic_terminal.py +yap_ipython/core/tests/__init__.py +yap_ipython/core/tests/test_ultratb.py +yap_ipython/core/tests/test_magic.py +yap_ipython/core/tests/test_iplib.py +yap_ipython/core/tests/test_completer.py +yap_ipython/core/tests/test_shellapp.py +yap_ipython/core/tests/daft_extension/daft_extension.py +yap_ipython/core/tests/refbug.py +yap_ipython/core/tests/tclass.py +yap_ipython/core/tests/test_extension.py +yap_ipython/core/tests/test_splitinput.py +yap_ipython/core/tests/test_completerlib.py +yap_ipython/core/tests/nonascii2.py +yap_ipython/core/tests/test_inputsplitter.py +yap_ipython/core/tests/test_handlers.py +yap_ipython/core/tests/test_history.py +yap_ipython/core/__init__.py +yap_ipython/core/autocall.py +yap_ipython/core/alias.py +yap_ipython/core/completerlib.py +yap_ipython/core/magic.py +yap_ipython/core/interactiveshell.py +yap_ipython/core/excolors.py +yap_ipython/core/release.py +yap_ipython/core/display_trap.py +yap_ipython/core/debugger.py +yap_ipython/core/historyapp.py +yap_ipython/core/payload.py +yap_ipython/config.py +yap_ipython/utils/frame.py +yap_ipython/utils/ipstruct.py +yap_ipython/utils/module_paths.py +yap_ipython/utils/jsonutil.py +yap_ipython/utils/PyColorize.py +yap_ipython/utils/pickleutil.py +yap_ipython/utils/eventful.py +yap_ipython/utils/ulinecache.py +yap_ipython/utils/generics.py +yap_ipython/utils/version.py +yap_ipython/utils/tz.py +yap_ipython/utils/_process_cli.py +yap_ipython/utils/wildcard.py +yap_ipython/utils/dir2.py +yap_ipython/utils/strdispatch.py +yap_ipython/utils/sysinfo.py +yap_ipython/utils/io.py +yap_ipython/utils/decorators.py +yap_ipython/utils/contexts.py +yap_ipython/utils/data.py +yap_ipython/utils/terminal.py +yap_ipython/utils/syspathcontext.py +yap_ipython/utils/tokenize2.py +yap_ipython/utils/localinterfaces.py +yap_ipython/utils/_process_win32_controller.py +yap_ipython/utils/py3compat.py +yap_ipython/utils/sentinel.py +yap_ipython/utils/colorable.py +yap_ipython/utils/_sysinfo.py +yap_ipython/utils/importstring.py +yap_ipython/utils/tokenutil.py +yap_ipython/utils/traitlets.py +yap_ipython/utils/path.py +yap_ipython/utils/daemonize.py +yap_ipython/utils/log.py +yap_ipython/utils/openpy.py +yap_ipython/utils/tempdir.py +yap_ipython/utils/_process_common.py +yap_ipython/utils/tests/test_openpy.py +yap_ipython/utils/tests/test_path.py +yap_ipython/utils/tests/test_shimmodule.py +yap_ipython/utils/tests/test_sysinfo.py +yap_ipython/utils/tests/test_pycolorize.py +yap_ipython/utils/tests/test_wildcard.py +yap_ipython/utils/tests/test_imports.py +yap_ipython/utils/tests/test_importstring.py +yap_ipython/utils/tests/test_module_paths.py +yap_ipython/utils/tests/test_io.py +yap_ipython/utils/tests/test_text.py +yap_ipython/utils/tests/test_decorators.py +yap_ipython/utils/tests/test_tokenutil.py +yap_ipython/utils/tests/test_process.py +yap_ipython/utils/tests/test_dir2.py +yap_ipython/utils/tests/__init__.py +yap_ipython/utils/tests/test_capture.py +yap_ipython/utils/tests/test_tempdir.py +yap_ipython/utils/encoding.py +yap_ipython/utils/__init__.py +yap_ipython/utils/signatures.py +yap_ipython/utils/_process_win32.py +yap_ipython/utils/coloransi.py +yap_ipython/utils/_process_posix.py +yap_ipython/utils/shimmodule.py +yap_ipython/utils/timing.py +yap_ipython/utils/text.py +yap_ipython/utils/process.py +yap_ipython/utils/capture.py +yap_ipython/paths.py +yap_ipython/nbconvert.py +yap_ipython/external/mathjax.py +yap_ipython/external/qt_for_kernel.py +yap_ipython/external/decorators/_numpy_testing_noseclasses.py +yap_ipython/external/decorators/_decorators.py +yap_ipython/external/decorators/__init__.py +yap_ipython/external/__init__.py +yap_ipython/external/qt_loaders.py +yap_ipython/__init__.py +yap_ipython/sphinxext/ipython_console_highlighting.py +yap_ipython/sphinxext/ipython_directive.py +yap_ipython/sphinxext/custom_doctests.py +yap_ipython/sphinxext/__init__.py +yap_ipython/kernel/adapter.py +yap_ipython/kernel/channelsabc.py +yap_ipython/kernel/__main__.py +yap_ipython/kernel/launcher.py +yap_ipython/kernel/multikernelmanager.py +yap_ipython/kernel/restarter.py +yap_ipython/kernel/managerabc.py +yap_ipython/kernel/threaded.py +yap_ipython/kernel/clientabc.py +yap_ipython/kernel/connect.py +yap_ipython/kernel/kernelspecapp.py +yap_ipython/kernel/kernelspec.py +yap_ipython/kernel/channels.py +yap_ipython/kernel/__init__.py +yap_ipython/kernel/manager.py +yap_ipython/kernel/client.py +yap_ipython/nbformat.py +yap_ipython/extensions/cythonmagic.py +yap_ipython/extensions/storemagic.py +yap_ipython/extensions/tests/test_autoreload.py +yap_ipython/extensions/tests/test_storemagic.py +yap_ipython/extensions/tests/__init__.py +yap_ipython/extensions/__init__.py +yap_ipython/extensions/rmagic.py +yap_ipython/extensions/sympyprinting.py +yap_ipython/extensions/autoreload.py +yap_ipython/yapi.py +yap_ipython/qt.py +yap_ipython/lib/display.py +yap_ipython/lib/pretty.py +yap_ipython/lib/inputhookgtk.py +yap_ipython/lib/inputhookwx.py +yap_ipython/lib/lexers.py +yap_ipython/lib/demo.py +yap_ipython/lib/inputhookgtk3.py +yap_ipython/lib/kernel.py +yap_ipython/lib/inputhookpyglet.py +yap_ipython/lib/editorhooks.py +yap_ipython/lib/inputhook.py +yap_ipython/lib/backgroundjobs.py +yap_ipython/lib/latextools.py +yap_ipython/lib/deepreload.py +yap_ipython/lib/tests/test_editorhooks.py +yap_ipython/lib/tests/test_backgroundjobs.py +yap_ipython/lib/tests/test_display.py +yap_ipython/lib/tests/test_pretty.py +yap_ipython/lib/tests/test_imports.py +yap_ipython/lib/tests/test_clipboard.py +yap_ipython/lib/tests/test_lexers.py +yap_ipython/lib/tests/test_deepreload.py +yap_ipython/lib/tests/test_security.py +yap_ipython/lib/tests/__init__.py +yap_ipython/lib/tests/test_latextools.py +yap_ipython/lib/__init__.py +yap_ipython/lib/guisupport.py +yap_ipython/lib/security.py +yap_ipython/lib/inputhookglut.py +yap_ipython/lib/clipboard.py +yap_ipython/lib/inputhookqt4.py +__init__.py + + ) set (EXTRAS MANIFEST.in @@ -60,15 +369,13 @@ ) set (RESOURCES - resources/custom.js - resources/prolog.js - #resources/logo-32x32.png - #resources/logo-64x64.png + #yap_kernel/resources/logo-32x32.png + #yap_kernel/resourcess/logo-64x64.png ) set (RENAMED_RESOURCES - resources/logo-32x32.png - resources/logo-64x64.png - # resources/codemirror/mode/prolog/prolog.js + yap_kernel/resources/logo-32x32.png + yap_kernel/resources/logo-64x64.png + # yap_kernel/resources/codemirror/mode/prolog/prolog.js ) set (PL_SOURCES @@ -79,29 +386,44 @@ set(FILES ${PYTHON_SOURCES} ${PL_SOURCES} ${EXTRAS} ${RESOURCES}) set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${i} - COMMAND ${CMAKE_COMMAND} -E tar cvf ${CMAKE_CURRENT_BINARY_DIR}/yap.tgz ${FILESi} + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap.tgz + COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_CURRENT_BINARY_DIR}/yap.tgz ${FILES} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${FILES} ) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources/logo-32x32.png - COMMAND ${CMAKE_COMMAND} -E tar xvf yap.tgz - COMMAND ${CMAKE_COMMAND} -E copy_if_changed ${CMAKE_SOURCE_DIR}/docs/icons/yap_32z32x32.png ${CMAKE_CURRENT_BINARY_DIR}/resources/logo-32x32.png - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/docs/icons/yap_32x32x32.png +add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png + COMMAND ${CMAKE_COMMAND} -E make_directory yap_kernel/resources + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png + DEPENDS ${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png ) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources/logo-64x64.png - COMMAND ${CMAKE_COMMAND} -E copy_if_changed ${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png ${CMAKE_CURRENT_BINARY_DIR}/resources/logo-64x64.png + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png + DEPENDS ${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png ) - add_custom_target(YAP_KERNEL - COMMAND ${CMAKE_COMMAND} -E tar xvf yap.tgz + + + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kernel.js + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/kernel.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/kernel.js + ) + + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/misc/editors/yap.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js + DEPENDS ${CMAKE_SOURCE_DIR}/misc/editors/yap.js + ) + + add_custom_target(YAP_KERNEL ALL + COMMAND ${CMAKE_COMMAND} -E tar xzf yap.tgz COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build sdist bdist WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png yap.tgz ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kernel.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js ) diff --git a/packages/python/yap_kernel/setup.py b/packages/python/yap_kernel/setup.py index cc73098b7..1e1d49eed 100644 --- a/packages/python/yap_kernel/setup.py +++ b/packages/python/yap_kernel/setup.py @@ -37,12 +37,15 @@ from distutils.core import setup pjoin = os.path.join here = os.path.abspath(os.path.dirname(__file__)) +packages = [] # pkg_root = pjoin(here, name) -packages = setuptools.find_packages(here) -# for d, _, _ in os.walk(pjoin(here, name)): -# if os.path.exists(pjoin(d, '__init__.py')): -# packages.append(d[len(here)+1:].replace(os.path.sep, '.')) +for d, _, _ in os.walk(pjoin(here, 'yap_kernel')): + if os.path.exists(pjoin(d, '__init__.py')): + packages.append(d[len(here)+1:].replace(os.path.sep, '.')) +for d, _, _ in os.walk(pjoin(here, 'yap_ipython')): + if os.path.exists(pjoin(d, '__init__.py')): + packages.append(d[len(here)+1:].replace(os.path.sep, '.')) sys.path.insert(0, here) package_data = { @@ -50,13 +53,14 @@ package_data = { 'yap_kernel': ['resources/*.*'] } - -version_ns = {here, name, '_version.py')) as f: +version_ns = {} +with open(pjoin(here, name, '_version.py')) as f: exec(f.read(), {}, version_ns) + setup_args = dict( name = name, version = version_ns['__version__'], @@ -64,10 +68,10 @@ setup_args = dict( packages = packages, py_modules = ['yap_kernel_launcher'], package_data = package_data, - package_dir = {'':here}, + #package_dir = {'':here}, description = "YAP Kernel for Jupyter", author = 'YAP Development Team', - author_email = 'YAP-dev@scipy.org', + author_email = 'yap-dev@scipy.org', url = 'http://ipython.org', license = 'BSD', platforms = "Linux, Mac OS X, Windows", @@ -95,7 +99,7 @@ if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv): argv = make_yap_kernel_cmd(executable=sys.executable) - dest = os.path.join(here, 'resources') + dest = os.path.join(here, 'yap_kernel', 'resources') try: write_kernel_spec(dest, overrides={'argv': argv}) except: @@ -104,14 +108,14 @@ if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv): #setup_args['data_files'] = [(pjoin('share', 'jupyter', 'kernels', KERNEL_NAME), glob(pjoin(dest, '*')))] mode_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'components', 'codemirror', 'mode', 'prolog') custom_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'custom') - try: - shutil.copy( pjoin( custom_loc, "custom.js") , pjoin( custom_loc, "custom.js.orig")) - shutil.copy( pjoin( "resources", "custom.js") , pjoin( custom_loc, "custom.js")) - if not os.path.exists(mode_loc): - os.makedirs(mode_loc) - shutil.copy( pjoin( "resources","prolog.js") , mode_loc) - except: - pass +# try: +# shutil.copy( pjoin( custom_loc, "custom.js") , pjoin( custom_loc, "custom.js.orig")) +# shutil.copy( pjoin( "resources", "custom.js") , pjoin( custom_loc, "custom.js")) +# if not os.path.exists(mode_loc): +# os.makedirs(mode_loc) +# shutil.copy( pjoin( "resources","prolog.js") , mode_loc) +# except: +# pass extras_require = setuptools_args['extras_require'] = { 'test:python_version=="2.7"': ['mock'], diff --git a/packages/python/yap_kernel/yap_ipython/yapi.py b/packages/python/yap_kernel/yap_ipython/yapi.py index 2d02ede05..2ef5dbc3f 100644 --- a/packages/python/yap_kernel/yap_ipython/yapi.py +++ b/packages/python/yap_kernel/yap_ipython/yapi.py @@ -61,7 +61,7 @@ class YAPInputSplitter(InputSplitter): def __init__(self, line_input_checker=True, physical_line_transforms=None, logical_line_transforms=None): self._buffer_raw = [] -v self._validate = True + self._validate = True self.yapeng = None if physical_line_transforms is not None: @@ -551,7 +551,7 @@ class YAPRun: # variable names should match strings #for eq in vs: # if not isinstance(eq[0],str):x -xf # print( "Error: Variable Name matches a Python Symbol") + # print( "Error: Variable Name matches a Python Symbol") # return # ask = True # launch the query @@ -677,7 +677,7 @@ xf # print( "Error: Variable Name matches a Python Symbol") # preprocessing_exc_tuple = sys.exc_info() - e for i in self.syntaxErrors(raw_cell): + for i in self.syntaxErrors(raw_cell): try: (what,lin,_,text) = i e = SyntaxError(what, ("", lin, 1, text)) diff --git a/pl/boot.yap b/pl/boot.yap index 3b45c86f3..c44b49af5 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -165,8 +165,6 @@ print_message(L,E) :- % This is the YAP init file % should be consulted first step after booting -:- '$mk_dynamic'(term_expansion/2). - :- c_compile('top.yap'). % These are pseudo declarations @@ -214,14 +212,13 @@ print_message(L,E) :- C == end_of_file ). -:- '$init_system'. - :- c_compile('arith.yap'). :- c_compile('builtins.yap'). %:- stop_low_level_trace. :- '$all_current_modules'(M), yap_flag(M:unknown, error) ; true. +:- '$init_prolog'. :- compile_expressions. @@ -239,8 +236,6 @@ print_message(L,E) :- :- c_compile('os.yap'). :- c_compile('errors.yap'). -:- '$init_prolog'. - initialize_prolog :- '$init_prolog'. diff --git a/pl/directives.yap b/pl/directives.yap index 27e4f0c1c..862903057 100644 --- a/pl/directives.yap +++ b/pl/directives.yap @@ -156,8 +156,7 @@ considered. '$exec_directive'(module(N,P,Op), Status, _, _, _) :- '$module'(Status,N,P,Op). '$exec_directive'(meta_predicate(P), _, M, _, _) :- - '$yap_strip_module'(M:P,M0,P0), - '$meta_predicate'(P0,M0). + '$meta_predicate'(P,M). '$exec_directive'(module_transparent(P), _, M, _, _) :- '$module_transparent'(P, M). '$exec_directive'(noprofile(P), _, M, _, _) :- diff --git a/pl/meta.yap b/pl/meta.yap index dd899ccdd..6298d0735 100644 --- a/pl/meta.yap +++ b/pl/meta.yap @@ -61,17 +61,20 @@ meta_predicate declaration '$meta_predicate'( P, M1 ). '$meta_predicate'( D, M ) :- functor(D,F,N), - ( M = prolog -> M2 = _ ; M2 = M), - '$install_meta_predicate'(D,M2,F,N), + '$install_meta_predicate'(D,M,F,N), fail. '$meta_predicate'( _D, _M ). +'$install_meta_predicate'(P,M,_F,_N) :- + '$new_meta_pred'(P, M), + fail. '$install_meta_predicate'(_P,M,F,N) :- - retractall(prolog:'$meta_predicate'(F,M,N,_)), + ( M = prolog -> M2 = _ ; M2 = M), + retractall(prolog:'$meta_predicate'(F,M2,N,_)), fail. '$install_meta_predicate'(P,M,F,N) :- - '$new_meta_pred'(P, M), - assertz('$meta_predicate'(F,M,N,P)). + ( M = prolog -> M2 = _ ; M2 = M), + assertz('$meta_predicate'(F,M2,N,P)). % comma has its own problems. @@ -494,7 +497,14 @@ expand_goal(Input, Output) :- '$expand_goals'(IG, _, GF0, M, SM, M, HVars-G), '$yap_strip_module'(M:GF0, MF, GF). -:- '$install_meta_predicate'((0,0),_,(','),2). +:- '$install_meta_predicate'((0,0),prolog,(','),2). +:- '$install_meta_predicate'((0),prolog,(','),2). + +meta_predicate(P) :- + source_module(SM), +'$meta_predicate'(P, SM). + + :- meta_predicate abolish(:), @@ -594,5 +604,5 @@ expand_goal(Input, Output) :- '|'(2,2,?,?), ->(2,2,?,?), \+(2,?,?), - \+( 0 ) + \+( 0 ) . diff --git a/pl/modules.yap b/pl/modules.yap index f976016cf..9a1678954 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -194,7 +194,7 @@ X = 2 ? ; ERROR!! EXISTENCE ERROR- procedure c/1 is undefined, called from context prolog:$user_call/2 Goal was c:c(_131290) -vv~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The state of the module system after this error is undefined. @@ -452,10 +452,15 @@ export_resource(P0) :- ; recorda('$module','$module'(user_input,Mod,user_input,[P],1),_) ). export_resource(op(Prio,Assoc,Name)) :- !, - op(Prio,Assoc,prolog:Name). -export_resource(op(Prio,Assoc,Name)) :- !, - op(Prio,Assoc,user:Name). -export_resource(Resource) :- +'$current_module'(Mod), +op(Prio,Assoc,Mod:Name), +( recorded('$module','$module'(File,Mod,SourceF,ExportedPreds,Line),R) -> + erase(R), + recorda('$module','$module'(File,Mod,SourceF,[op(Prio,Assoc,Name)|ExportedPreds],Line ),_) +; prolog_load_context(file, File) -> + recorda('$module','$module'(File,Mod,SourceF,[op(Prio,Assoc,Name)],Line),_) +; recorda('$module','$module'(user_input,Mod,user_input,[op(Prio,Assoc,Name)],1),_) +).export_resource(Resource) :- '$do_error'(type_error(predicate_indicator,Resource),export(Resource)). export_list(Module, List) :- From 1cafba0529bd1ee924b91b4f7c5ab7bf044d014a Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 1 Feb 2018 01:44:34 +0000 Subject: [PATCH 3/3] meta & kernel --- C/absmi.c | 26 +- C/exec.c | 34 +- misc/editors/yap.js | 2114 ++++++++++------- os/charsio.c | 11 +- os/iopreds.c | 12 +- os/readterm.c | 42 +- packages/python/yap_kernel/kernel.js | 56 +- .../python/yap_kernel/yap_ipython/yapi.py | 3 +- pl/boot.yap | 6 +- pl/meta.yap | 1 - pl/modules.yap | 3 +- 11 files changed, 1353 insertions(+), 955 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 6821e09dc..1c33eabdc 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -917,7 +917,8 @@ static int interrupt_dexecute(USES_REGS1) { static void undef_goal(USES_REGS1) { PredEntry *pe = PredFromDefCode(P); CELL *b; - + CELL *b0; + BEGD(d0); /* avoid trouble with undefined dynamic procedures */ /* I assume they were not locked beforehand */ @@ -955,14 +956,23 @@ static void undef_goal(USES_REGS1) { PP = NULL; #endif d0 = pe->ArityOfPE; + if (pe->ModuleOfPred == PROLOG_MODULE) { + if (CurrentModule == PROLOG_MODULE) + HR[0] = MkAtomTerm(Yap_LookupAtom("prolog")); + else + HR[0] = CurrentModule; + } else { HR[0] = Yap_Module_Name(pe); - b = HR; - HR += 2; + } + b = b0 = HR; + HR += 2; if (d0 == 0) { b[1] = MkAtomTerm((Atom)(pe->FunctorOfPred)); } else { - b[1] = AbsAppl(HR); + b[1] = AbsAppl(b+2); *HR++ = (CELL)pe->FunctorOfPred; + b += 3; + HR += d0; BEGP(pt1); pt1 = XREGS + 1; for (; d0 > 0; --d0) { @@ -973,13 +983,13 @@ static void undef_goal(USES_REGS1) { deref_head(d1, undef_unk); undef_nonvar: /* just copy it to the heap */ - *HR++ = d1; + *b++ = d1; continue; derefa_body(d1, pt0, undef_unk, undef_nonvar); if (pt0 <= HR) { /* variable is safe */ - *HR++ = (CELL)pt0; + *b++ = (CELL)pt0; } else { /* bind it, in case it is a local variable */ d1 = Unsigned(HR); @@ -993,8 +1003,8 @@ static void undef_goal(USES_REGS1) { ENDP(pt1); } ENDD(d0); - ARG2 = Yap_getUnknownModule(Yap_GetModuleEntry(b[0])); - ARG1 = AbsPair(b); + ARG1 = AbsPair(b0); + ARG2 = Yap_getUnknownModule(Yap_GetModuleEntry(b0[0])); #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) low_level_trace(enter_pred, UndefCode, XREGS + 1); diff --git a/C/exec.c b/C/exec.c index 73a528d42..9564f2ac9 100755 --- a/C/exec.c +++ b/C/exec.c @@ -269,7 +269,7 @@ static bool CommaCall(Term t, Term mod) { } inline static bool do_execute(Term t, Term mod USES_REGS) { - Term t0 = t; + Term t0 = t, mod0 = mod; t = Yap_YapStripModule(t, &mod); /* first do predicate expansion, even before you process signals. This way you don't get to spy goal_expansion(). */ @@ -278,7 +278,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { return EnterCreepMode(t, mod PASS_REGS); } if (IsVarTerm(t) || IsVarTerm(mod)) { - return CallError(INSTANTIATION_ERROR, t0, mod PASS_REGS); + return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS); } if (IsApplTerm(t)) { register Functor f = FunctorOfTerm(t); @@ -290,9 +290,9 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { if (f == FunctorComma && false) { Term t2 = ArgOfTerm(2, t); if (IsVarTerm(t2)) - return CallMetaCall(t, mod PASS_REGS); + return CallMetaCall(t0, mod0 PASS_REGS); if (1 || !CommaCall(t2, mod)) - return CallMetaCall(t, mod PASS_REGS); + return CallMetaCall(t0, mod0 PASS_REGS); Term t1 = ArgOfTerm(1, t); t = t1; @@ -301,11 +301,11 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { return do_execute(t, mod); } } else if (IsExtensionFunctor(f)) { - return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS); + return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS); } arity = ArityOfFunctor(f); if (arity > MaxTemps) { - return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS); + return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS); } pen = RepPredProp(PredPropByFunc(f, mod)); /* You thought we would be over by now */ @@ -315,7 +315,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { otherwise I would dereference the argument and might skip a svar */ if (pen->PredFlags & (MetaPredFlag | UndefPredFlag)) { - return CallMetaCall(t, mod PASS_REGS); + return CallMetaCall(t0, mod0 PASS_REGS); } pt = RepAppl(t) + 1; for (i = 1; i <= arity; i++) { @@ -346,7 +346,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { pe = RepPredProp(PredPropByAtom(a, mod)); return (CallPredicate(pe, B, pe->CodeOfPred PASS_REGS)); } - return CallMetaCall(t, mod PASS_REGS); + return CallMetaCall(t0, mod0 PASS_REGS); } static Term copy_execn_to_heap(Functor f, CELL *pt, unsigned int n, @@ -390,17 +390,17 @@ inline static bool do_execute_n(Term t, Term mod, unsigned int n USES_REGS) { PredEntry *pen; unsigned int i, arity; int j = -n; - Term t0 = t; + Term t0 = t, mod0 = mod; restart_exec: if (IsVarTerm(t)) { - return CallError(INSTANTIATION_ERROR, t0, mod PASS_REGS); + return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS); } else if (IsAtomTerm(t)) { arity = n; Name = AtomOfTerm(t); pt = NULL; } else if (IsIntTerm(t)) { - return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS); + return CallError(TYPE_ERROR_CALLABLE, t, mod0 PASS_REGS); } else if (IsPairTerm(t)) { arity = n + 2; pt = RepPair(t); @@ -415,9 +415,9 @@ restart_exec: goto restart_exec; } else { if (IsVarTerm(tmod)) { - return CallError(INSTANTIATION_ERROR, t0, tmod PASS_REGS); + return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS); } else { - return CallError(TYPE_ERROR_ATOM, t0, tmod PASS_REGS); + return CallError(TYPE_ERROR_ATOM, t0, mod0 PASS_REGS); } } } @@ -427,7 +427,7 @@ restart_exec: } f = Yap_MkFunctor(Name, arity); if (IsExtensionFunctor(f)) { - return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS); + return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS); } if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled) { return EnterCreepMode( @@ -435,14 +435,14 @@ restart_exec: mod PASS_REGS); } if (arity > MaxTemps) { - return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS); + return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS); } pen = RepPredProp(PredPropByFunc(f, mod)); /* You thought we would be over by now */ /* but no meta calls require special preprocessing */ if (pen->PredFlags & (MetaPredFlag | UndefPredFlag)) { - Term t = copy_execn_to_heap(f, pt, n, arity, mod PASS_REGS); - return (CallMetaCall(t, mod PASS_REGS)); + // Term t = copy_execn_to_heap(f, pt, n, arity, mod PASS_REGS); + return (CallMetaCall(t0, mod0 PASS_REGS)); } /* now let us do what we wanted to do from the beginning !! */ /* I cannot use the standard macro here because diff --git a/misc/editors/yap.js b/misc/editors/yap.js index 47543475b..0e7cb9d91 100644 --- a/misc/editors/yap.js +++ b/misc/editors/yap.js @@ -1,861 +1,1273 @@ - // CodeMirror, copyright (c) by Marijn Haverbeke and others // Distributed under an MIT license: http://codemirror.net/LICENSE (function(mod) { - if (typeof exports == "object" && typeof module == "object") // CommonJS - mod(require("codemirror/lib/codemirror")); - else if (typeof define == "function" && define.amd) // AMD - define(["codemirror/lib/codemirror"], mod); - else // Plain browser env - mod(CodeMirror); +if (typeof exports == "object" && typeof module == "object") // CommonJS + mod(require("codemirror/lib/codemirror")); +else if (typeof define == "function" && define.amd) // AMD + define([ "codemirror/lib/codemirror" ], mod); +else // Plain browser env + mod(CodeMirror); })(function(CodeMirror) { - "use strict"; +"use strict"; - CodeMirror.modeInfo = [ - { - name : "Prolog", - mime : "text/x-prolog", - mode : "prolog", - ext : [ "pl", "yap", "pro", "P", "prolog" ] - }, - {name: "APL", mime: "text/apl", mode: "apl", ext: ["dyalog", "apl"]}, - {name: "PGP", mimes: ["application/pgp", "application/pgp-keys", "application/pgp-signature"], mode: "asciiarmor", ext: ["pgp"]}, - {name: "ASN.1", mime: "text/x-ttcn-asn", mode: "asn.1", ext: ["asn", "asn1"]}, - {name: "Asterisk", mime: "text/x-asterisk", mode: "asterisk", file: /^extensions\.conf$/i}, - {name: "Brainfuck", mime: "text/x-brainfuck", mode: "brainfuck", ext: ["b", "bf"]}, - {name: "C", mime: "text/x-csrc", mode: "clike", ext: ["c", "h"]}, - {name: "C++", mime: "text/x-c++src", mode: "clike", ext: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"], alias: ["cpp"]}, - {name: "Cobol", mime: "text/x-cobol", mode: "cobol", ext: ["cob", "cpy"]}, - {name: "C#", mime: "text/x-csharp", mode: "clike", ext: ["cs"], alias: ["csharp"]}, - {name: "Clojure", mime: "text/x-clojure", mode: "clojure", ext: ["clj", "cljc", "cljx"]}, - {name: "ClojureScript", mime: "text/x-clojurescript", mode: "clojure", ext: ["cljs"]}, - {name: "Closure Stylesheets (GSS)", mime: "text/x-gss", mode: "css", ext: ["gss"]}, - {name: "CMake", mime: "text/x-cmake", mode: "cmake", ext: ["cmake", "cmake.in"], file: /^CMakeLists.txt$/}, - {name: "CoffeeScript", mime: "text/x-coffeescript", mode: "coffeescript", ext: ["coffee"], alias: ["coffee", "coffee-script"]}, - {name: "Common Lisp", mime: "text/x-common-lisp", mode: "commonlisp", ext: ["cl", "lisp", "el"], alias: ["lisp"]}, - {name: "Cypher", mime: "application/x-cypher-query", mode: "cypher", ext: ["cyp", "cypher"]}, - {name: "Cython", mime: "text/x-cython", mode: "python", ext: ["pyx", "pxd", "pxi"]}, - {name: "Crystal", mime: "text/x-crystal", mode: "crystal", ext: ["cr"]}, - {name: "CSS", mime: "text/css", mode: "css", ext: ["css"]}, - {name: "CQL", mime: "text/x-cassandra", mode: "sql", ext: ["cql"]}, - {name: "D", mime: "text/x-d", mode: "d", ext: ["d"]}, - {name: "Dart", mimes: ["application/dart", "text/x-dart"], mode: "dart", ext: ["dart"]}, - {name: "diff", mime: "text/x-diff", mode: "diff", ext: ["diff", "patch"]}, - {name: "Django", mime: "text/x-django", mode: "django"}, - {name: "Dockerfile", mime: "text/x-dockerfile", mode: "dockerfile", file: /^Dockerfile$/}, - {name: "DTD", mime: "application/xml-dtd", mode: "dtd", ext: ["dtd"]}, - {name: "Dylan", mime: "text/x-dylan", mode: "dylan", ext: ["dylan", "dyl", "intr"]}, - {name: "EBNF", mime: "text/x-ebnf", mode: "ebnf"}, - {name: "ECL", mime: "text/x-ecl", mode: "ecl", ext: ["ecl"]}, - {name: "edn", mime: "application/edn", mode: "clojure", ext: ["edn"]}, - {name: "Eiffel", mime: "text/x-eiffel", mode: "eiffel", ext: ["e"]}, - {name: "Elm", mime: "text/x-elm", mode: "elm", ext: ["elm"]}, - {name: "Embedded Javascript", mime: "application/x-ejs", mode: "htmlembedded", ext: ["ejs"]}, - {name: "Embedded Ruby", mime: "application/x-erb", mode: "htmlembedded", ext: ["erb"]}, - {name: "Erlang", mime: "text/x-erlang", mode: "erlang", ext: ["erl"]}, - {name: "Factor", mime: "text/x-factor", mode: "factor", ext: ["factor"]}, - {name: "FCL", mime: "text/x-fcl", mode: "fcl"}, - {name: "Forth", mime: "text/x-forth", mode: "forth", ext: ["forth", "fth", "4th"]}, - {name: "Fortran", mime: "text/x-fortran", mode: "fortran", ext: ["f", "for", "f77", "f90"]}, - {name: "F#", mime: "text/x-fsharp", mode: "mllike", ext: ["fs"], alias: ["fsharp"]}, - {name: "Gas", mime: "text/x-gas", mode: "gas", ext: ["s"]}, - {name: "Gherkin", mime: "text/x-feature", mode: "gherkin", ext: ["feature"]}, - {name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm", file: /^(readme|contributing|history).md$/i}, - {name: "Go", mime: "text/x-go", mode: "go", ext: ["go"]}, - {name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy", "gradle"], file: /^Jenkinsfile$/}, - {name: "HAML", mime: "text/x-haml", mode: "haml", ext: ["haml"]}, - {name: "Haskell", mime: "text/x-haskell", mode: "haskell", ext: ["hs"]}, - {name: "Haskell (Literate)", mime: "text/x-literate-haskell", mode: "haskell-literate", ext: ["lhs"]}, - {name: "Haxe", mime: "text/x-haxe", mode: "haxe", ext: ["hx"]}, - {name: "HXML", mime: "text/x-hxml", mode: "haxe", ext: ["hxml"]}, - {name: "ASP.NET", mime: "application/x-aspx", mode: "htmlembedded", ext: ["aspx"], alias: ["asp", "aspx"]}, - {name: "HTML", mime: "text/html", mode: "htmlmixed", ext: ["html", "htm"], alias: ["xhtml"]}, - {name: "HTTP", mime: "message/http", mode: "http"}, - {name: "IDL", mime: "text/x-idl", mode: "idl", ext: ["pro"]}, - {name: "Pug", mime: "text/x-pug", mode: "pug", ext: ["jade", "pug"], alias: ["jade"]}, - {name: "Java", mime: "text/x-java", mode: "clike", ext: ["java"]}, - {name: "Java Server Pages", mime: "application/x-jsp", mode: "htmlembedded", ext: ["jsp"], alias: ["jsp"]}, - {name: "JavaScript", mimes: ["text/javascript", "text/ecmascript", "application/javascript", "application/x-javascript", "application/ecmascript"], - mode: "javascript", ext: ["js"], alias: ["ecmascript", "js", "node"]}, - {name: "JSON", mimes: ["application/json", "application/x-json"], mode: "javascript", ext: ["json", "map"], alias: ["json5"]}, - {name: "JSON-LD", mime: "application/ld+json", mode: "javascript", ext: ["jsonld"], alias: ["jsonld"]}, - {name: "JSX", mime: "text/jsx", mode: "jsx", ext: ["jsx"]}, - {name: "Jinja2", mime: "null", mode: "jinja2"}, - {name: "Julia", mime: "text/x-julia", mode: "julia", ext: ["jl"]}, - {name: "Kotlin", mime: "text/x-kotlin", mode: "clike", ext: ["kt"]}, - {name: "LESS", mime: "text/x-less", mode: "css", ext: ["less"]}, - {name: "LiveScript", mime: "text/x-livescript", mode: "livescript", ext: ["ls"], alias: ["ls"]}, - {name: "Lua", mime: "text/x-lua", mode: "lua", ext: ["lua"]}, - {name: "Markdown", mime: "text/x-markdown", mode: "markdown", ext: ["markdown", "md", "mkd"]}, - {name: "mIRC", mime: "text/mirc", mode: "mirc"}, - {name: "MariaDB SQL", mime: "text/x-mariadb", mode: "sql"}, - {name: "Mathematica", mime: "text/x-mathematica", mode: "mathematica", ext: ["m", "nb"]}, - {name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]}, - {name: "MUMPS", mime: "text/x-mumps", mode: "mumps", ext: ["mps"]}, - {name: "MS SQL", mime: "text/x-mssql", mode: "sql"}, - {name: "mbox", mime: "application/mbox", mode: "mbox", ext: ["mbox"]}, - {name: "MySQL", mime: "text/x-mysql", mode: "sql"}, - {name: "Nginx", mime: "text/x-nginx-conf", mode: "nginx", file: /nginx.*\.conf$/i}, - {name: "NSIS", mime: "text/x-nsis", mode: "nsis", ext: ["nsh", "nsi"]}, - {name: "NTriples", mime: "text/n-triples", mode: "ntriples", ext: ["nt"]}, - {name: "Objective C", mime: "text/x-objectivec", mode: "clike", ext: ["m", "mm"], alias: ["objective-c", "objc"]}, - {name: "OCaml", mime: "text/x-ocaml", mode: "mllike", ext: ["ml", "mli", "mll", "mly"]}, - {name: "Octave", mime: "text/x-octave", mode: "octave", ext: ["m"]}, - {name: "Oz", mime: "text/x-oz", mode: "oz", ext: ["oz"]}, - {name: "Pascal", mime: "text/x-pascal", mode: "pascal", ext: ["p", "pas"]}, - {name: "PEG.js", mime: "null", mode: "pegjs", ext: ["jsonld"]}, - {name: "Perl", mime: "text/x-perl", mode: "perl", ext: ["pl", "pm"]}, - {name: "PHP", mime: "application/x-httpd-php", mode: "php", ext: ["php", "php3", "php4", "php5", "phtml"]}, - {name: "Pig", mime: "text/x-pig", mode: "pig", ext: ["pig"]}, - {name: "Plain Text", mime: "text/plain", mode: "null", ext: ["txt", "text", "conf", "def", "list", "log"]}, - {name: "PLSQL", mime: "text/x-plsql", mode: "sql", ext: ["pls"]}, - {name: "PowerShell", mime: "application/x-powershell", mode: "powershell", ext: ["ps1", "psd1", "psm1"]}, - {name: "Properties files", mime: "text/x-properties", mode: "properties", ext: ["properties", "ini", "in"], alias: ["ini", "properties"]}, - {name: "ProtoBuf", mime: "text/x-protobuf", mode: "protobuf", ext: ["proto"]}, - {name: "Python", mime: "text/x-python", mode: "python", ext: ["BUILD", "bzl", "py", "pyw"], file: /^(BUCK|BUILD)$/}, - {name: "Puppet", mime: "text/x-puppet", mode: "puppet", ext: ["pp"]}, - {name: "Q", mime: "text/x-q", mode: "q", ext: ["q"]}, - {name: "R", mime: "text/x-rsrc", mode: "r", ext: ["r", "R"], alias: ["rscript"]}, - {name: "reStructuredText", mime: "text/x-rst", mode: "rst", ext: ["rst"], alias: ["rst"]}, - {name: "RPM Changes", mime: "text/x-rpm-changes", mode: "rpm"}, - {name: "RPM Spec", mime: "text/x-rpm-spec", mode: "rpm", ext: ["spec"]}, - {name: "Ruby", mime: "text/x-ruby", mode: "ruby", ext: ["rb"], alias: ["jruby", "macruby", "rake", "rb", "rbx"]}, - {name: "Rust", mime: "text/x-rustsrc", mode: "rust", ext: ["rs"]}, - {name: "SAS", mime: "text/x-sas", mode: "sas", ext: ["sas"]}, - {name: "Sass", mime: "text/x-sass", mode: "sass", ext: ["sass"]}, - {name: "Scala", mime: "text/x-scala", mode: "clike", ext: ["scala"]}, - {name: "Scheme", mime: "text/x-scheme", mode: "scheme", ext: ["scm", "ss"]}, - {name: "SCSS", mime: "text/x-scss", mode: "css", ext: ["scss"]}, - {name: "Shell", mime: "text/x-sh", mode: "shell", ext: ["sh", "ksh", "bash"], alias: ["bash", "sh", "zsh"], file: /^PKGBUILD$/}, - {name: "Sieve", mime: "application/sieve", mode: "sieve", ext: ["siv", "sieve"]}, - {name: "Slim", mimes: ["text/x-slim", "application/x-slim"], mode: "slim", ext: ["slim"]}, - {name: "Smalltalk", mime: "text/x-stsrc", mode: "smalltalk", ext: ["st"]}, - {name: "Smarty", mime: "text/x-smarty", mode: "smarty", ext: ["tpl"]}, - {name: "Solr", mime: "text/x-solr", mode: "solr"}, - {name: "Soy", mime: "text/x-soy", mode: "soy", ext: ["soy"], alias: ["closure template"]}, - {name: "SPARQL", mime: "application/sparql-query", mode: "sparql", ext: ["rq", "sparql"], alias: ["sparul"]}, - {name: "Spreadsheet", mime: "text/x-spreadsheet", mode: "spreadsheet", alias: ["excel", "formula"]}, - {name: "SQL", mime: "text/x-sql", mode: "sql", ext: ["sql"]}, - {name: "SQLite", mime: "text/x-sqlite", mode: "sql"}, - {name: "Squirrel", mime: "text/x-squirrel", mode: "clike", ext: ["nut"]}, - {name: "Stylus", mime: "text/x-styl", mode: "stylus", ext: ["styl"]}, - {name: "Swift", mime: "text/x-swift", mode: "swift", ext: ["swift"]}, - {name: "sTeX", mime: "text/x-stex", mode: "stex"}, - {name: "LaTeX", mime: "text/x-latex", mode: "stex", ext: ["text", "ltx"], alias: ["tex"]}, - {name: "SystemVerilog", mime: "text/x-systemverilog", mode: "verilog", ext: ["v"]}, - {name: "Tcl", mime: "text/x-tcl", mode: "tcl", ext: ["tcl"]}, - {name: "Textile", mime: "text/x-textile", mode: "textile", ext: ["textile"]}, - {name: "TiddlyWiki ", mime: "text/x-tiddlywiki", mode: "tiddlywiki"}, - {name: "Tiki wiki", mime: "text/tiki", mode: "tiki"}, - {name: "TOML", mime: "text/x-toml", mode: "toml", ext: ["toml"]}, - {name: "Tornado", mime: "text/x-tornado", mode: "tornado"}, - {name: "troff", mime: "text/troff", mode: "troff", ext: ["1", "2", "3", "4", "5", "6", "7", "8", "9"]}, - {name: "TTCN", mime: "text/x-ttcn", mode: "ttcn", ext: ["ttcn", "ttcn3", "ttcnpp"]}, - {name: "TTCN_CFG", mime: "text/x-ttcn-cfg", mode: "ttcn-cfg", ext: ["cfg"]}, - {name: "Turtle", mime: "text/turtle", mode: "turtle", ext: ["ttl"]}, - {name: "TypeScript", mime: "application/typescript", mode: "javascript", ext: ["ts"], alias: ["ts"]}, - {name: "TypeScript-JSX", mime: "text/typescript-jsx", mode: "jsx", ext: ["tsx"], alias: ["tsx"]}, - {name: "Twig", mime: "text/x-twig", mode: "twig"}, - {name: "Web IDL", mime: "text/x-webidl", mode: "webidl", ext: ["webidl"]}, - {name: "VB.NET", mime: "text/x-vb", mode: "vb", ext: ["vb"]}, - {name: "VBScript", mime: "text/vbscript", mode: "vbscript", ext: ["vbs"]}, - {name: "Velocity", mime: "text/velocity", mode: "velocity", ext: ["vtl"]}, - {name: "Verilog", mime: "text/x-verilog", mode: "verilog", ext: ["v"]}, - {name: "VHDL", mime: "text/x-vhdl", mode: "vhdl", ext: ["vhd", "vhdl"]}, - {name: "Vue.js Component", mimes: ["script/x-vue", "text/x-vue"], mode: "vue", ext: ["vue"]}, - {name: "XML", mimes: ["application/xml", "text/xml"], mode: "xml", ext: ["xml", "xsl", "xsd", "svg"], alias: ["rss", "wsdl", "xsd"]}, - {name: "XQuery", mime: "application/xquery", mode: "xquery", ext: ["xy", "xquery"]}, - {name: "Yacas", mime: "text/x-yacas", mode: "yacas", ext: ["ys"]}, - {name: "YAML", mimes: ["text/x-yaml", "text/yaml"], mode: "yaml", ext: ["yaml", "yml"], alias: ["yml"]}, - {name: "Z80", mime: "text/x-z80", mode: "z80", ext: ["z80"]}, - {name: "mscgen", mime: "text/x-mscgen", mode: "mscgen", ext: ["mscgen", "mscin", "msc"]}, - {name: "xu", mime: "text/x-xu", mode: "mscgen", ext: ["xu"]}, - {name: "msgenny", mime: "text/x-msgenny", mode: "mscgen", ext: ["msgenny"]} - ]; - // Ensure all modes have a mime property for backwards compatibility - for (var i = 0; i < CodeMirror.modeInfo.length; i++) { - var info = CodeMirror.modeInfo[i]; - if (info.mimes) info.mime = info.mimes[0]; - } +CodeMirror.defineMode("prolog", function(cm_config, parserConfig) { - CodeMirror.findModeByMIME = function(mime) { - mime = mime.toLowerCase(); - for (var i = 0; i < CodeMirror.modeInfo.length; i++) { - var info = CodeMirror.modeInfo[i]; - if (info.mime == mime) return info; - if (info.mimes) for (var j = 0; j < info.mimes.length; j++) - if (info.mimes[j] == mime) return info; - } - if (/\+xml$/.test(mime)) return CodeMirror.findModeByMIME("application/xml") - if (/\+json$/.test(mime)) return CodeMirror.findModeByMIME("application/json") - }; - - CodeMirror.findModeByExtension = function(ext) { - for (var i = 0; i < CodeMirror.modeInfo.length; i++) { - var info = CodeMirror.modeInfo[i]; - if (info.ext) for (var j = 0; j < info.ext.length; j++) - if (info.ext[j] == ext) return info; - } - }; - - CodeMirror.findModeByFileName = function(filename) { - for (var i = 0; i < CodeMirror.modeInfo.length; i++) { - var info = CodeMirror.modeInfo[i]; - if (info.file && info.file.test(filename)) return info; - } - var dot = filename.lastIndexOf("."); - var ext = dot > -1 && filename.substring(dot + 1, filename.length); - if (ext) return CodeMirror.findModeByExtension(ext); - }; - - CodeMirror.findModeByName = function(name) { - name = name.toLowerCase(); - for (var i = 0; i < CodeMirror.modeInfo.length; i++) { - var info = CodeMirror.modeInfo[i]; - if (info.name.toLowerCase() == name) return info; - if (info.alias) for (var j = 0; j < info.alias.length; j++) - if (info.alias[j].toLowerCase() == name) return info; - } - }; - - CodeMirror.defineMode("prolog", function(cmConfig) { - - function chain(stream, state, f) { - state.tokenize = f; - return f(stream, state); - } - - /******************************* - * CONFIG DATA * - *******************************/ - - var config = { quasiQuotations: false, /* {|Syntax||Quotation|} */ - dicts: false, /* tag{k:v, ...} */ - unicodeEscape: true, /* \uXXXX and \UXXXXXXXX */ - multiLineQuoted: true, /* "...\n..." */ - groupedIntegers: false /* 10 000 or 10_000 */ - }; - - var quoteType = { '"': "string", - "'": "qatom", - "`": "bqstring" - }; - - var isSingleEscChar = /[abref\\'"nrtsv]/; - var isOctalDigit = /[0-7]/; - var isHexDigit = /[0-9a-fA-F]/; - - var isSymbolChar = /[-#$&*+./:<=>?@\\^~]/; /* Prolog glueing symbols chars */ - var isSoloChar = /[[\]{}(),;|]/; /* Prolog solo chars] */ - var isNeck = /^(:-|-->)$/; - var isControlOp = /^(,|;|->|\*->|\\+|\|)$/; - - - /******************************* - * CHARACTER ESCAPES * - *******************************/ - - function readDigits(stream, re, count) { - if ( count > 0 ) { - while( count-- > 0 ) { - if ( !re.test(stream.next()) ) - return false; - } - } else { - while ( re.test(stream.peek()) ) - stream.next(); - } - return true; - } - - function readEsc(stream) { - var next = stream.next(); - if ( isSingleEscChar.test(next) ) - return true; - switch( next ) - { case "u": - if ( config.unicodeEscape ) - return readDigits(stream, isHexDigit, 4); /* SWI */ - return false; - case "U": - if ( config.unicodeEscape ) - return readDigits(stream, isHexDigit, 8); /* SWI */ - return false; - case null: return true; /* end of line */ - case "c": stream.eatSpace(); return true; - case "x": return readDigits(stream, isHexDigit, 2); - } - if ( isOctalDigit.test(next) ) { - if ( !readDigits(stream, isOctalDigit, -1) ) - return false; - if ( stream.peek() == "\\" ) /* SWI: optional closing \ */ - stream.next(); - return true; - } - return false; - } - - function nextUntilUnescaped(stream, state, end) { - var next; - while ((next = stream.next()) != null) { - if ( next == end && end != stream.peek() ) - { state.nesting.pop(); - return false; - } - if ( next == "\\" ) - { if ( !readEsc(stream) ) - return false; - } - } - return config.multiLineQuoted; - } - - /******************************* - * CONTEXT NESTING * - *******************************/ - - function nesting(state) { - return state.nesting.slice(-1)[0]; - } - - /* Called on every non-comment token */ - function setArg1(state) { - var nest = nesting(state); - if ( nest ) { - if ( nest.arg == 0 ) /* nested in a compound */ - nest.arg = 1; - else if ( nest.type == "control" ) - state.goalStart = false; - } else - state.goalStart = false; - } - - function setArgAlignment(state) { - var nest = nesting(state); - if ( nest && !nest.alignment && nest.arg != undefined ) { - if ( nest.arg == 0 ) - nest.alignment = nest.leftCol ? nest.leftCol+4 : nest.column+4; - else - nest.alignment = nest.column+1; - } - } - - function nextArg(state) { - var nest = nesting(state); - if ( nest ) { - if ( nest.arg ) /* nested in a compound */ - nest.arg++; - else if ( nest.type == "control" ) - state.goalStart = true; /* FIXME: also needed for ; and -> */ - } else - state.goalStart = true; - } - - function isControl(state) { /* our terms are goals */ - var nest = nesting(state); - if ( nest ) { - if ( nest.type == "control" ) { - return true; - } - return false; - } else - return state.inBody; - } - - // Used as scratch variables to communicate multiple values without - // consing up tons of objects. - var type, content; - function ret(tp, style, cont) { - type = tp; content = cont; - return style; - } - - function peekSpace(stream) { /* TBD: handle block comment as space */ - if ( stream.eol() || - /[\s%]/.test(stream.peek()) ) - return true; - return false; - } - - - /******************************* - * SUB TOKENISERS * - *******************************/ - - function plTokenBase(stream, state) { - var ch = stream.next(); - - if ( ch == "(" ) { - if ( state.lastType == "functor" ) { - state.nesting.push({ functor: state.functorName, - column: stream.column(), - leftCol: state.functorColumn, - arg: 0 - }); - delete state.functorName; - delete state.functorColumn; - } else { - state.nesting.push({ type: "control", - closeColumn: stream.column(), - alignment: stream.column()+4 - }); - } - return ret("solo", null, "("); - } - - if ( ch == "{" && state.lastType == "tag" ) { - state.nesting.push({ tag: state.tagName, - column: stream.column(), - leftCol: state.tagColumn, - arg: 0 - }); - delete state.tagName; - delete state.tagColumn; - return ret("dict_open", null); - } - - if ( ch == "/" && stream.eat("*") ) - return chain(stream, state, plTokenComment); - - if ( ch == "%" ) { - stream.skipToEnd(); - return ret("comment", "comment"); - } - - setArg1(state); - - if ( isSoloChar.test(ch) ) { - switch ( ch ) - { case ")": - state.nesting.pop(); - break; - case "]": - state.nesting.pop(); - return ret("list_close", null); - case "}": - { var nest = nesting(state); - var type = (nest && nest.tag) ? "dict_close" : "brace_term_close"; - - state.nesting.pop(); - return ret(type, null); - } - case ",": - if ( stream.eol() ) - state.commaAtEOL = true; - nextArg(state); - /*FALLTHROUGH*/ - case ";": - if ( isControl(state) ) - state.goalStart = true; - break; - case "[": - state.nesting.push({ type: "list", - closeColumn: stream.column(), - alignment: stream.column()+2 - }); - return ret("list_open", null); - break; - case "{": - if ( config.quasiQuotations && stream.eat("|") ) { - state.nesting.push({ type: "quasi-quotation", - alignment: stream.column()+1 - }); - return ret("qq_open", "qq_open"); - } else { - state.nesting.push({ type: "curly", - closeColumn: stream.column(), - alignment: stream.column()+2 - }); - return ret("brace_term_open", null); - } - break; - case "|": - if ( config.quasiQuotations ) { - if ( stream.eat("|") ) { - state.tokenize = plTokenQuasiQuotation; - return ret("qq_sep", "qq_sep"); - } else if ( stream.eat("}") ) { - state.nesting.pop(); - return ret("qq_close", "qq_close"); - } - } - if ( isControl(state) ) - state.goalStart = true; - break; - } - return ret("solo", null, ch); - } - - if (ch == '"' || ch == "'" || ch == "`") - { state.nesting.push({ type: "quoted", - alignment: stream.column()+1 - }); - return chain(stream, state, plTokenString(ch)); - } - - if ( ch == "0" ) { - if ( stream.eat(/x/i)) { - stream.eatWhile(/[\da-f]/i); - return ret("number", "number"); - } - if ( stream.eat(/o/i)) { - stream.eatWhile(/[0-7]/i); - return ret("number", "number"); - } - if ( stream.eat(/'/) ) { /* 0' */ - var next = stream.next(); - if ( next == "\\" ) { - if ( !readEsc(stream) ) - return ret("error", "error"); - } - return ret("code", "code"); - } - } - - if ( /\d/.test(ch) || /[+-]/.test(ch) && stream.eat(/\d/)) { - if ( config.groupedIntegers ) - stream.match(/^\d*((_|\s+)\d+)*(?:\.\d+)?(?:[eE][+\-]?\d+)?/); - else - stream.match(/^\d*(?:\.\d+)?(?:[eE][+\-]?\d+)?/); - return ret(ch == "-" ? "neg-number" : - ch == "+" ? "pos-number" : - "number"); - } - - if ( isSymbolChar.test(ch) ) { - stream.eatWhile(isSymbolChar); - var atom = stream.current(); - if ( atom == "." && peekSpace(stream) ) { - if ( nesting(state) ) { - return ret("fullstop", "error", atom); - } else { - } return ret("fullstop", "fullstop", atom); - } else if ( isNeck.test(atom) ) { - return ret("neck", "neck", atom); - } else if ( isControl(state) && isControlOp.test(atom) ) { - state.goalStart = true; - return ret("symbol", "operator", atom); - } else - return ret("symbol", "operator", atom); - } - - stream.eatWhile(/[\w_]/); - var word = stream.current(); - if ( stream.peek() == "{" && config.dicts ) { - state.tagName = word; /* tmp state extension */ - state.tagColumn = stream.column(); - return ret("tag", "tag", word); - } else if ( ch == "_" ) { - if ( word.length == 1 ) { - return ret("var", "anon", word); - } else { - var sec = word.charAt(1); - if ( sec == sec.toUpperCase() ) - return ret("var", "var-2", word); - } - return ret("var", "var", word); - } else if ( ch == ch.toUpperCase() ) { - return ret("var", "var", word); - } else if ( stream.peek() == "(" ) { - state.functorName = word; /* tmp state extension */ - state.functorColumn = stream.column(); - return ret("functor", "functor", word); - } else - return ret("atom", "atom", word); - } - - function plTokenString(quote) { - return function(stream, state) { - if (!nextUntilUnescaped(stream, state, quote)) { - state.tokenize = plTokenBase; - if ( stream.peek() == "(" ) { /* 'quoted functor'() */ - var word = stream.current(); - state.functorName = word; /* tmp state extension */ - return ret("functor", "functor", word); - } - if ( stream.peek() == "{" && config.dicts ) { /* 'quoted tag'{} */ - var word = stream.current(); - state.tagName = word; /* tmp state extension */ - return ret("tag", "tag", word); - } - } - return ret(quoteType[quote], quoteType[quote]); - }; - } - - function plTokenQuasiQuotation(stream, state) { - var maybeEnd = false, ch; - while (ch = stream.next()) { - if (ch == "}" && maybeEnd) { - state.tokenize = plTokenBase; - stream.backUp(2); - break; - } - maybeEnd = (ch == "|"); - } - return ret("qq_content", "qq_content"); - } - - function plTokenComment(stream, state) { - var maybeEnd = false, ch; - while (ch = stream.next()) { - if (ch == "/" && maybeEnd) { - state.tokenize = plTokenBase; - break; - } - maybeEnd = (ch == "*"); - } - return ret("comment", "comment"); - } - - - /******************************* - * ACTIVE KEYS * - *******************************/ - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Support if-then-else layout like this: - - goal :- - ( Condition - -> IfTrue - ; IfFalse - ). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - - CodeMirror.commands.prologStartIfThenElse = function(cm) { - var start = cm.getCursor("start"); - var token = cm.getTokenAt(start, true); - - if ( token.state.goalStart == true ) - { cm.replaceSelection("( ", "end"); - return; - } - - return CodeMirror.Pass; - } - - CodeMirror.commands.prologStartThen = function(cm) { - var start = cm.getCursor("start"); - var token = cm.getTokenAt(start, true); - - /* FIXME: These functions are copied from prolog.js. How - can we reuse these? - */ - function nesting(state) { - var len = state.nesting.length; - if ( len > 0 ) - return state.nesting[len-1]; - return null; - } - - function isControl(state) { /* our terms are goals */ - var nest = nesting(state); - if ( nest ) { - if ( nest.type == "control" ) { - return true; - } - return false; - } else - return state.inBody; - } - - if ( start.ch == token.end && - token.type == "operator" && - token.string == "-" && - isControl(token.state) ) - { cm.replaceSelection("> ", "end"); - return; - } - - return CodeMirror.Pass; - } - - CodeMirror.commands.prologStartElse = function(cm) { - var start = cm.getCursor("start"); - var token = cm.getTokenAt(start, true); - - if ( token.start == 0 && start.ch == token.end && - !/\S/.test(token.string) ) - { cm.replaceSelection("; ", "end"); - return; - } - - return CodeMirror.Pass; - } - - CodeMirror.defineOption("prologKeys", null, function(cm, val, prev) { - if (prev && prev != CodeMirror.Init) - cm.removeKeyMap("prolog"); - if ( val ) { - var map = { name: "prolog", - "'('": "prologStartIfThenElse", - "'>'": "prologStartThen", - "';'": "prologStartElse", - "Ctrl-L": "refreshHighlight" - }; - cm.addKeyMap(map); - } - }); - - }); - //Default (SWI-)Prolog operator table. To be used later to enhance the - //offline experience. - - var ops = { "-->": { p:1200, t:"xfx" }, - ":-": [ { p:1200, t:"xfx" }, - { p:1200, t:"fx" } - ], - "?-": { p:1200, t:"fx" }, - - "dynamic": { p:1150, t:"fx" }, - "discontiguous": { p:1150, t:"fx" }, - "initialization": { p:1150, t:"fx" }, - "meta_predicate": { p:1150, t:"fx" }, - "module_transparent": { p:1150, t:"fx" }, - "multifile": { p:1150, t:"fx" }, - "thread_local": { p:1150, t:"fx" }, - "volatile": { p:1150, t:"fx" }, - - ";": { p:1100, t:"xfy" }, - "|": { p:1100, t:"xfy" }, - - "->": { p:1050, t:"xfy" }, - "*->": { p:1050, t:"xfy" }, - - ",": { p:1000, t:"xfy" }, - - "\\+": { p:900, t:"fy" }, - - "~": { p:900, t:"fx" }, - - "<": { p:700, t:"xfx" }, - "=": { p:700, t:"xfx" }, - "=..": { p:700, t:"xfx" }, - "=@=": { p:700, t:"xfx" }, - "=:=": { p:700, t:"xfx" }, - "=<": { p:700, t:"xfx" }, - "==": { p:700, t:"xfx" }, - "=\\=": { p:700, t:"xfx" }, - ">": { p:700, t:"xfx" }, - ">=": { p:700, t:"xfx" }, - "@<": { p:700, t:"xfx" }, - "@=<": { p:700, t:"xfx" }, - "@>": { p:700, t:"xfx" }, - "@>=": { p:700, t:"xfx" }, - "\\=": { p:700, t:"xfx" }, - "\\==": { p:700, t:"xfx" }, - "is": { p:700, t:"xfx" }, - - ":": { p:600, t:"xfy" }, - - "+": [ { p:500, t:"yfx" }, - { p:200, t:"fy" } - ], - "-": [ { p:500, t:"yfx" }, - { p:200, t:"fy" } - ], - "/\\": { p:500, t:"yfx" }, - "\\/": { p:500, t:"yfx" }, - "xor": { p:500, t:"yfx" }, - - "?": { p:500, t:"fx" }, - - "*": { p:400, t:"yfx" }, - "/": { p:400, t:"yfx" }, - "//": { p:400, t:"yfx" }, - "rdiv": { p:400, t:"yfx" }, - "<<": { p:400, t:"yfx" }, - ">>": { p:400, t:"yfx" }, - "mod": { p:400, t:"yfx" }, - "rem": { p:400, t:"yfx" }, - - "**": { p:200, t:"xfx" }, - "^": { p:200, t:"xfy" }, - - "\\": { p:200, t:"fy" } - }; - - - /******************************* - * RETURN OBJECT * - *******************************/ - - return { - startState: function() { - return { - tokenize: plTokenBase, - inBody: false, - goalStart: false, - lastType: null, - nesting: new Array(), /* ([{}]) nesting FIXME: copy this */ - curTerm: null, /* term index in metainfo */ - curToken: null /* token in term */ - }; - }, - - token: function(stream, state) { - var nest; - - if ( state.curTerm == null /* && parserConfig.metainfo */ ) { - state.curTerm = 0; - state.curToken = 0; - } - - if ( stream.sol() ) - delete state.commaAtEOL; - - if ( state.tokenize == plTokenBase && stream.eatSpace() ) { - if ( stream.eol() ) - setArgAlignment(state); - return null; - } - - var style = state.tokenize(stream, state); - - if ( stream.eol() ) - setArgAlignment(state); - - if ( type == "neck" ) { - state.inBody = true; - state.goalStart = true; - } else if ( type == "fullstop" ) { - state.inBody = false; - state.goalStart = false; - } - - state.lastType = type; - - //if ( typeof(parserConfig.enrich) == "function" ) - // style = parserConfig.enrich(stream, state, type, content, style); - - return style; - }, - - indent: function(state, textAfter) { - if (state.tokenize == plTokenComment) return CodeMirror.Pass; - - var nest; - if ( (nest=nesting(state)) ) { - if ( nest.closeColumn && !state.commaAtEOL ) - return nest.closeColumn; - return nest.alignment; - } - if ( !state.inBody ) - return 0; - - return 4; - }, - - theme: "prolog", - - blockCommentStart: "/*", /* continuecomment.js support */ - blockCommentEnd: "*/", - blockCommentContinue: " * ", - lineComment: "%", - }); + function chain(stream, state, f) { + state.tokenize = f; + return f(stream, state); } + /******************************* + * CONFIG DATA * + *******************************/ + + var config = { + quasiQuotations : false, /* {|Syntax||Quotation|} */ + dicts : false, /* tag{k:v, ...} */ + unicodeEscape : true, /* \uXXXX and \UXXXXXXXX */ + multiLineQuoted : true, /* "...\n..." */ + groupedIntegers : false /* 10 000 or 10_000 */ + }; + + var quoteType = {'"' : "string", "'" : "qatom", "`" : "bqstring"}; + + var isSingleEscChar = /[abref\\'"nrtsv]/; + var isOctalDigit = /[0-7]/; + var isHexDigit = /[0-9a-fA-F]/; + + var isSymbolChar = /[-#$&*+./:<=>?@\\^~]/; /* Prolog glueing symbols chars */ + var isSoloChar = /[[\]{}(),;|!]/; /* Prolog solo chars */ + var isNeck = /^(:-|-->)$/; + var isControlOp = /^(,|;|->|\*->|\\+|\|)$/; + + /******************************* + * CHARACTER ESCAPES * + *******************************/ + + function readDigits(stream, re, count) { + if (count > 0) { + while (count-- > 0) { + if (!re.test(stream.next())) + return false; + } + } else { + while (re.test(stream.peek())) + stream.next(); + } + return true; + } + + function readEsc(stream) { + var next = stream.next(); + if (isSingleEscChar.test(next)) + return true; + switch (next) { + case "u": + if (config.unicodeEscape) + return readDigits(stream, isHexDigit, 4); /* SWI */ + return false; + case "U": + if (config.unicodeEscape) + return readDigits(stream, isHexDigit, 8); /* SWI */ + return false; + case null: + return true; /* end of line */ + case "c": + stream.eatSpace(); + return true; + case "x": + return readDigits(stream, isHexDigit, 2); + } + if (isOctalDigit.test(next)) { + if (!readDigits(stream, isOctalDigit, -1)) + return false; + if (stream.peek() == "\\") /* SWI: optional closing \ */ + stream.next(); + return true; + } + return false; + } + + function nextUntilUnescaped(stream, state, end) { + var next; + while ((next = stream.next()) != null) { + if (next == end && end != stream.peek()) { + state.nesting.pop(); + return false; + } + if (next == "\\") { + if (!readEsc(stream)) + return false; + } + } + return config.multiLineQuoted; + } + + /******************************* + * CONTEXT NESTING * + *******************************/ + + function nesting(state) { return state.nesting.slice(-1)[0]; } + + /* Called on every non-comment token */ + function setArg1(state) { + var nest = nesting(state); + if (nest) { + if (nest.arg == 0) /* nested in a compound */ + nest.arg = 1; + else if (nest.type == "control") + state.goalStart = false; + } else + state.goalStart = false; + } + + function setArgAlignment(state) { + var nest = nesting(state); + if (nest && !nest.alignment && nest.arg != undefined) { + if (nest.arg == 0) + nest.alignment = nest.leftCol ? nest.leftCol + 4 : nest.column + 4; + else + nest.alignment = nest.column + 1; + } + } + + function nextArg(state) { + var nest = nesting(state); + if (nest) { + if (nest.arg) /* nested in a compound */ + nest.arg++; + else if (nest.type == "control") { + state.goalStart = true; /* FIXME: also needed for ; and -> */ + } + } else { + state.goalStart = true; + } + } + + function isControl(state) { /* our terms are goals */ + var nest = nesting(state); + if (nest) { + if (nest.type == "control") { + return true; + } + return false; + } else + return state.inBody; + } + + // Used as scratch variables to communicate multiple values without + // consing up tons of objects. + var type, content; + function ret(tp, style, cont) { + type = tp; + content = cont; + return style; + } + + function peekSpace(stream) { /* TBD: handle block comment as space */ + if (stream.eol() || /[\s%]/.test(stream.peek())) + return true; + return false; + } + + /******************************* + * SUB TOKENISERS * + *******************************/ + + function plTokenBase(stream, state) { + var ch = stream.next(); + + if (ch == "(") { + if (state.lastType == "functor") { + state.nesting.push({ + functor : state.functorName, + column : stream.column(), + leftCol : state.functorColumn, + arg : 0 + }); + delete state.functorName; + delete state.functorColumn; + } else { + state.nesting.push({ + type : "control", + closeColumn : stream.column(), + alignment : stream.column() + 4 + }); + } + return ret("solo", null, "("); + } + + if (ch == "{" && state.lastType == "tag") { + state.nesting.push({ + tag : state.tagName, + column : stream.column(), + leftCol : state.tagColumn, + arg : 0 + }); + delete state.tagName; + delete state.tagColumn; + return ret("dict_open", "bracket"); + } + + if (ch == "/" && stream.eat("*")) + return chain(stream, state, plTokenComment); + + if (ch == "%") { + stream.skipToEnd(); + return ret("comment", "comment"); + } + + setArg1(state); + + if (isSoloChar.test(ch)) { + switch (ch) { + case ")": + state.nesting.pop(); + break; + case "]": + state.nesting.pop(); + return ret("list_close", "bracket"); + case "}": { + var nest = nesting(state); + var type = (nest && nest.tag) ? "dict_close" : "brace_term_close"; + + state.nesting.pop(); + return ret(type, null); + }; break; + case ",": + if (stream.eol()) + state.commaAtEOL = true; + nextArg(state); + /*FALLTHROUGH*/ + if (isControl(state)) { + state.goalStart = true; + } + break; + case ";": + if (isControl(state)) { + state.goalStart = true; + } + break; + case "[": + state.nesting.push({ + type : "list", + closeColumn : stream.column(), + alignment : stream.column() + 2 + }); + return ret("list_open", "bracket"); + break; + case "{": + if (config.quasiQuotations && stream.eat("|")) { + state.nesting.push( + {type : "quasi-quotation", alignment : stream.column() + 1}); + return ret("qq_open", "bracket"); + } else { + state.nesting.push({ + type : "curly", + closeColumn : stream.column(), + alignment : stream.column() + 2 + }); + return ret("brace_term_open", "bracket"); + } + break; + case "|": + if (config.quasiQuotations) { + if (stream.eat("|")) { + state.tokenize = plTokenQuasiQuotation; + return ret("qq_sep", "bracket"); + } else if (stream.eat("}")) { + state.nesting.pop(); + return ret("qq_close", "bracket"); + } + } + if (isControl(state)) { + state.goalStart = true; + } + break; + } + return ret("solo", null, ch); + } + + if (ch == '"' || ch == "'" || ch == "`") { + state.nesting.push({type : "quoted", alignment : stream.column() + 1}); + return chain(stream, state, plTokenString(ch)); + } + + if (ch == "0") { + if (stream.eat(/x/i)) { + stream.eatWhile(/[\da-f]/i); + return ret("number", "number"); + } + if (stream.eat(/o/i)) { + stream.eatWhile(/[0-7]/i); + return ret("number", "number"); + } + if (stream.eat(/'/)) { /* 0' */ + var next = stream.next(); + if (next == "\\") { + if (!readEsc(stream)) + return ret("error", "error"); + } + return ret("code", "number"); + } + } + + if (/\d/.test(ch) || /[+-]/.test(ch) && stream.eat(/\d/)) { + if (config.groupedIntegers) + stream.match(/^\d*((_|\s+)\d+)*(?:\.\d+)?(?:[eE][+\-]?\d+)?/); + else + stream.match(/^\d*(?:\.\d+)?(?:[eE][+\-]?\d+)?/); + return ret(ch == "-" ? "neg-number" + : ch == "+" ? "pos-number" : "number"); + } + + if (isSymbolChar.test(ch)) { + stream.eatWhile(isSymbolChar); + var atom = stream.current(); + if (atom == "." && peekSpace(stream)) { + if (nesting(state)) { + return ret("fullstop", "meta", atom); + } else { + state.headStart = true; + } + return ret("fullstop", null, atom); + } else if (isNeck.test(atom)) { + return ret("neck", "property", atom); + } else if (isControl(state) && isControlOp.test(atom)) { + state.goalStart = true; + return ret("symbol", "meta", atom); + } else + return ret("symbol", "meta", atom); + } + + stream.eatWhile(/[\w_]/); + var word = stream.current(), extra = ""; + if (stream.peek() == "{" && config.dicts) { + state.tagName = word; /* tmp state extension */ + state.tagColumn = stream.column(); + return ret("tag", "tag", word); + } else if (ch == "_") { + if (word.length == 1) { + return ret("var", "variable-3", word); + } else { + var sec = word.charAt(1); + if (sec == sec.toUpperCase()) + return ret("var", "variable-3", word); + } + return ret("var", "variable-3", word); + } else if (ch == ch.toUpperCase()) { + return ret("var", "variable-2", word); + } else if (stream.peek() == "(") { + state.functorName = word; /* tmp state extension */ + state.functorColumn = stream.column(); + if (state.headStart) { + state.headStart = false; + if (state.headFunctor != word) { + state.headFunctor = word; + return ret("functor", "def", word); + } + } + if (builtins[word]) + return ret("functor", "keyword", word); + return ret("functor", "atom", word); + } else if ((extra = stream.eat(/\/(\/)?\d\d?/)!="")) { + state.functorName = word; /* tmp state extension */ + state.functorColumn = stream.column(); + var w = stream.current(); + if (builtins[word]) + return ret("functor", "keyword", w); + return ret("functor", "atom", w); + } else + if (state.headStart) { + state.headStart = false; + if (state.headFunctor != word) { + state.headFunctor = word; + return ret("functor", "def", word); + } + } + if (builtins[word]) + return ret("functor", "keyword", word); + return ret("atom", "atom", word); + } + + function plTokenString(quote) { + return function(stream, state) { + if (!nextUntilUnescaped(stream, state, quote)) { + state.tokenize = plTokenBase; + if (stream.peek() == "(") { /* 'quoted functor'() */ + var word = stream.current(); + state.functorName = word; /* tmp state extension */ + if (state.headStart) { + state.headStart = false; + if (state.headFunctor != word) { + state.headFunctor = word; + return ret("functor", "def", word); + } + } + return ret("functor", "atom", word); + } + if (stream.peek() == "{" && config.dicts) { /* 'quoted tag'{} */ + var word = stream.current(); + state.tagName = word; /* tmp state extension */ + return ret("tag", "tag", word); + } + } + return ret(quoteType[quote], "string"); + }; + } + + function plTokenQuasiQuotation(stream, state) { + var maybeEnd = false, ch; + while (ch = stream.next()) { + if (ch == "}" && maybeEnd) { + state.tokenize = plTokenBase; + stream.backUp(2); + break; + } + maybeEnd = (ch == "|"); + } + return ret("qq_content", "string"); + } + + function plTokenComment(stream, state) { + var maybeEnd = false, ch; + while (ch = stream.next()) { + if (ch == "/" && maybeEnd) { + state.tokenize = plTokenBase; + break; + } + maybeEnd = (ch == "*"); + } + return ret("comment", "comment"); + } + + // /******************************* + // * ACTIVE KEYS * + // *******************************/ + + // /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // - - + // Support if-then-else layout like this: + + // goal :- + // ( Condition + // -> IfTrue + // ; IfFalse + // ). + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // - - */ + + // CodeMirror.commands.prologStartIfThenElse = function(cm) { + // var start = cm.getCursor("start"); + // var token = cm.getTokenAt(start, true); + + // if ( token.state.goalStart == true ) + // { cm.replaceSelection("( ", "end"); + // return; + // } + + // return CodeMirror.Pass; + // } + + // CodeMirror.commands.prologStartThen = function(cm) { + // var start = cm.getCursor("start"); + // var token = cm.getTokenAt(start, true); + + // /* FIXME: These functions are copied from prolog.js. How + // can we reuse these? + // */ + // function nesting(state) { + // var len = state.nesting.length; + // if ( len > 0 ) + // return state.nesting[len-1]; + // return null; + // } + + // function isControl(state) { /* our terms are goals */ + // var nest = nesting(state); + // if ( nest ) { + // if ( nest.type == "control" ) { + // return true; + // } + // return false; + // } else + // return state.inBody; + // } + + // if ( start.ch == token.end && + // token.type == "operator" && + // token.string == "-" && + // isControl(token.state) ) + // { cm.replaceSelection("> ", "end"); + // return; + // } + + // return CodeMirror.Pass; + // } + + // CodeMirror.commands.prologStartElse = function(cm) { + // var start = cm.getCursor("start"); + // var token = cm.getTokenAt(start, true); + + // if ( token.start == 0 && start.ch == token.end && + // !/\S/.test(token.string) ) + // { cm.replaceSelection("; ", "end"); + // return; + // } + + // return CodeMirror.Pass; + // } + + // CodeMirror.defineOption("prologKeys", null, function(cm, val, prev) { + // if (prev && prev != CodeMirror.Init) + // cm.removeKeyMap("prolog"); + // if ( val ) { + // var map = { name: "prolog", + // "'('": "prologStartIfThenElse", + // "'>'": "prologStartThen", + // "';'": "prologStartElse", + // "Ctrl-L": "refreshHighlight" + // }; + // cm.addKeyMap(map); + // } + // }); + + // }); + // Default (SWI-)Prolog operator table. To be used later to enhance the + // offline experience. + + var ops = { + "-->" : {p : 1200, t : "xfx"}, + ":-" : [ {p : 1200, t : "xfx"}, {p : 1200, t : "fx"} ], + "?-" : {p : 1200, t : "fx"}, + + "dynamic" : {p : 1150, t : "fx"}, + "discontiguous" : {p : 1150, t : "fx"}, + "initialization" : {p : 1150, t : "fx"}, + "meta_predicate" : {p : 1150, t : "fx"}, + "module_transparent" : {p : 1150, t : "fx"}, + "multifile" : {p : 1150, t : "fx"}, + "thread_local" : {p : 1150, t : "fx"}, + "volatile" : {p : 1150, t : "fx"}, + + ";" : {p : 1100, t : "xfy"}, + "|" : {p : 1100, t : "xfy"}, + + "->" : {p : 1050, t : "xfy"}, + "*->" : {p : 1050, t : "xfy"}, + + "," : {p : 1000, t : "xfy"}, + + "\\+" : {p : 900, t : "fy"}, + + "~" : {p : 900, t : "fx"}, + + "<" : {p : 700, t : "xfx"}, + "=" : {p : 700, t : "xfx"}, + "=.." : {p : 700, t : "xfx"}, + "=@=" : {p : 700, t : "xfx"}, + "=:=" : {p : 700, t : "xfx"}, + "=<" : {p : 700, t : "xfx"}, + "==" : {p : 700, t : "xfx"}, + "=\\=" : {p : 700, t : "xfx"}, + ">" : {p : 700, t : "xfx"}, + ">=" : {p : 700, t : "xfx"}, + "@<" : {p : 700, t : "xfx"}, + "@=<" : {p : 700, t : "xfx"}, + "@>" : {p : 700, t : "xfx"}, + "@>=" : {p : 700, t : "xfx"}, + "\\=" : {p : 700, t : "xfx"}, + "\\==" : {p : 700, t : "xfx"}, + "is" : {p : 700, t : "xfx"}, + + ":" : {p : 600, t : "xfy"}, + + "+" : [ {p : 500, t : "yfx"}, {p : 200, t : "fy"} ], + "-" : [ {p : 500, t : "yfx"}, {p : 200, t : "fy"} ], + "/\\" : {p : 500, t : "yfx"}, + "\\/" : {p : 500, t : "yfx"}, + "xor" : {p : 500, t : "yfx"}, + + "?" : {p : 500, t : "fx"}, + + "*" : {p : 400, t : "yfx"}, + "/" : {p : 400, t : "yfx"}, + "//" : {p : 400, t : "yfx"}, + "rdiv" : {p : 400, t : "yfx"}, + "<<" : {p : 400, t : "yfx"}, + ">>" : {p : 400, t : "yfx"}, + "mod" : {p : 400, t : "yfx"}, + "rem" : {p : 400, t : "yfx"}, + + "**" : {p : 200, t : "xfx"}, + "^" : {p : 200, t : "xfy"}, + + "\\" : {p : 200, t : "fy"} + }; + + var translType = { + "comment" : "comment", + "var" : "variable-2", /* JavaScript Types */ + "atom" : "atom", + "qatom" : "atom", + "bqstring" : "string", + "symbol" : "keyword", + "functor" : "keyword", + "tag" : "tag", + "number" : "number", + "string" : "string", + "code" : "number", + "neg-number" : "number", + "pos-number" : "number", + "list_open" : "bracket", + "list_close" : "bracket", + "qq_open" : "bracket", + "qq_sep" : "operator", + "qq_close" : "bracket", + "dict_open" : "bracket", + "dict_close" : "bracket", + "brace_term_open" : "bracket", + "brace_term_close" : "bracket", + "neck" : "keyword", + "fullstop" : "keyword" + }; + + var builtins = { + "C" : "prolog", + "abolish" : "prolog", + "abolish_all_tables" : "prolog", + "abolish_frozen_choice_points" : "prolog", + "abolish_module" : "prolog", + "abolish_table" : "prolog", + "abort" : "prolog", + "absolute_file_name" : "prolog", + "absolute_file_system_path" : "prolog", + "access" : "prolog", + "access_file" : "prolog", + "acyclic_term" : "prolog", + "add_import_module" : "prolog", + "add_to_array_element" : "prolog", + "add_to_path" : "prolog", + "alarm" : "prolog", + "all" : "prolog", + "always_prompt_user" : "prolog", + "arena_size" : "prolog", + "arg" : "prolog", + "array" : "prolog", + "array_element" : "prolog", + "assert" : "prolog", + "assert_static" : "prolog", + "asserta" : "prolog", + "asserta_static" : "prolog", + "assertz" : "prolog", + "assertz_static" : "prolog", + "at_end_of_line" : "prolog", + "at_end_of_stream" : "prolog", + "at_end_of_stream_0" : "prolog", + "at_halt" : "prolog", + "atom" : "prolog", + "atom_chars" : "prolog", + "atom_codes" : "prolog", + "atom_concat" : "prolog", + "atom_length" : "prolog", + "atom_number" : "prolog", + "atom_string" : "prolog", + "atom_to_term" : "prolog", + "atomic_concat" : "prolog", + "atomic_length" : "prolog", + "atomic_list_concat" : "prolog", + "atomics_to_string" : "prolog", + "attvar" : "prolog", + "b_getval" : "prolog", + "b_setval" : "prolog", + "bagof" : "prolog", + "bb_delete" : "prolog", + "bb_get" : "prolog", + "bb_put" : "prolog", + "bb_update" : "prolog", + "between" : "prolog", + "bootstrap" : "prolog", + "break" : "prolog", + "call" : "prolog", + "call_cleanup" : "prolog", + "call_count" : "prolog", + "call_count_data" : "prolog", + "call_count_reset" : "prolog", + "call_residue" : "prolog", + "call_residue_vars" : "prolog", + "call_shared_object_function" : "prolog", + "call_with_args" : "prolog", + "callable" : "prolog", + "catch" : "prolog", + "catch_ball" : "prolog", + "cd" : "prolog", + "cfile_search_path" : "prolog", + "char_code" : "prolog", + "char_conversion" : "prolog", + "char_type" : "prolog", + "clause" : "prolog", + "clause_property" : "prolog", + "close" : "prolog", + "close_shared_object" : "prolog", + "close_static_array" : "prolog", + "code_type" : "prolog", + "commons_directory" : "prolog", + "commons_library" : "prolog", + "compare" : "prolog", + "compile" : "prolog", + "compile_expressions" : "prolog", + "compile_predicates" : "prolog", + "compound" : "prolog", + "consult" : "prolog", + "consult_depth" : "prolog", + "context_module" : "prolog", + "copy_term" : "prolog", + "copy_term_nat" : "prolog", + "create_mutable" : "prolog", + "create_prolog_flag" : "prolog", + "creep_allowed" : "prolog", + "current_atom" : "prolog", + "current_char_conversion" : "prolog", + "current_host" : "prolog", + "current_input" : "prolog", + "current_key" : "prolog", + "current_line_number" : "prolog", + "current_module" : "prolog", + "current_mutex" : "prolog", + "current_op" : "prolog", + "current_predicate" : "prolog", + "current_prolog_flag" : "prolog", + "current_reference_count" : "prolog", + "current_stream" : "prolog", + "current_thread" : "prolog", + "db_files" : "prolog", + "db_reference" : "prolog", + "debug" : "prolog", + "debugging" : "prolog", + "decrease_reference_count" : "prolog", + "del_attr" : "prolog", + "del_attrs" : "prolog", + "delete_import_module" : "prolog", + "depth_bound_call" : "prolog", + "dif" : "prolog", + "discontiguous" : "prolog", + "display" : "prolog", + "do_c_built_in" : "prolog", + "do_c_built_metacall" : "prolog", + "do_not_compile_expressions" : "prolog", + "dule" : "prolog", + "dum" : "prolog", + "dump_active_goals" : "prolog", + "duplicate_term" : "prolog", + "dynamic" : "prolog", + "dynamic_predicate" : "prolog", + "dynamic_update_array" : "prolog", + "eamconsult" : "prolog", + "eamtrans" : "prolog", + "end_of_file" : "prolog", + "ensure_loaded" : "prolog", + "erase" : "prolog", + "eraseall" : "prolog", + "erased" : "prolog", + "exists" : "prolog", + "exists_directory" : "prolog", + "exists_file" : "prolog", + "exists_source" : "prolog", + "exo_files" : "prolog", + "expand_expr" : "prolog", + "expand_exprs" : "prolog", + "expand_file_name" : "prolog", + "expand_goal" : "prolog", + "expand_term" : "prolog", + "expects_dialect" : "prolog", + "export" : "prolog", + "export_list" : "prolog", + "export_resource" : "prolog", + "extend" : "prolog", + "fail" : "prolog", + "false" : "prolog", + "file_base_name" : "prolog", + "file_directory_name" : "prolog", + "file_exists" : "prolog", + "file_name_extension" : "prolog", + "file_search_path" : "prolog", + "file_size" : "prolog", + "fileerrors" : "prolog", + "findall" : "prolog", + "float" : "prolog", + "flush_output" : "prolog", + "forall" : "prolog", + "foreign_directory" : "prolog", + "format" : "prolog", + "freeze" : "prolog", + "freeze_choice_point" : "prolog", + "frozen" : "prolog", + "functor" : "prolog", + "garbage_collect" : "prolog", + "garbage_collect_atoms" : "prolog", + "gc" : "prolog", + "get" : "prolog", + "get0" : "prolog", + "get_attr" : "prolog", + "get_attrs" : "prolog", + "get_byte" : "prolog", + "get_char" : "prolog", + "get_code" : "prolog", + "get_depth_limit" : "prolog", + "get_mutable" : "prolog", + "get_string_code" : "prolog", + "get_value" : "prolog", + "getcwd" : "prolog", + "getenv" : "prolog", + "global_trie_statistics" : "prolog", + "ground" : "prolog", + "grow_heap" : "prolog", + "grow_stack" : "prolog", + "halt" : "prolog", + "heap_space_info" : "prolog", + "hide_atom" : "prolog", + "hide_predicate" : "prolog", + "hostname_address" : "prolog", + "hread_get_message" : "prolog", + "hread_signal" : "prolog", + "if" : "prolog", + "ignore" : "prolog", + "import_module" : "prolog", + "incore" : "prolog", + "increase_reference_count" : "prolog", + "init_random_state" : "prolog", + "initialization" : "prolog", + "instance" : "prolog", + "instance_property" : "prolog", + "int_message" : "prolog", + "integer" : "prolog", + "is" : "prolog", + "is_absolute_file_name" : "prolog", + "is_list" : "prolog", + "is_mutable" : "prolog", + "is_tabled" : "prolog", + "isinf" : "prolog", + "isnan" : "prolog", + "key_erased_statistics" : "prolog", + "key_statistics" : "prolog", + "keysort" : "prolog", + "leash" : "prolog", + "length" : "prolog", + "libraries_directories" : "prolog", + "line_count" : "prolog", + "listing" : "prolog", + "load_absolute_foreign_files" : "prolog", + "load_db" : "prolog", + "load_files" : "prolog", + "load_foreign_files" : "prolog", + "log_event" : "prolog", + "logsum" : "prolog", + "ls" : "prolog", + "ls_imports" : "prolog", + "make" : "prolog", + "make_directory" : "prolog", + "make_library_index" : "prolog", + "message_queue_create" : "prolog", + "message_queue_destroy" : "prolog", + "message_queue_property" : "prolog", + "message_to_string" : "prolog", + "mmapped_array" : "prolog", + "module" : "prolog", + "module_property" : "prolog", + "module_state" : "prolog", + "msort" : "prolog", + "multifile" : "prolog", + "must_be_of_type" : "prolog", + "mutex_create" : "prolog", + "mutex_property" : "prolog", + "mutex_unlock_all" : "prolog", + "name" : "prolog", + "nb_create" : "prolog", + "nb_current" : "prolog", + "nb_delete" : "prolog", + "nb_getval" : "prolog", + "nb_linkarg" : "prolog", + "nb_linkval" : "prolog", + "nb_set_bit" : "prolog", + "nb_set_shared_arg" : "prolog", + "nb_set_shared_val" : "prolog", + "nb_setarg" : "prolog", + "nb_setval" : "prolog", + "new_system_module" : "prolog", + "nl" : "prolog", + "no_source" : "prolog", + "no_style_check" : "prolog", + "nodebug" : "prolog", + "nofileeleerrors" : "prolog", + "nogc" : "prolog", + "nonvar" : "prolog", + "nospy" : "prolog", + "nospyall" : "prolog", + "not" : "prolog", + "notrace" : "prolog", + "nth_clause" : "prolog", + "nth_instance" : "prolog", + "number" : "prolog", + "number_atom" : "prolog", + "number_chars" : "prolog", + "number_codes" : "prolog", + "number_string" : "prolog", + "numbervars" : "prolog", + "on_exception" : "prolog", + "on_signal" : "prolog", + "once" : "prolog", + "op" : "prolog", + "opaque" : "prolog", + "open" : "prolog", + "open_pipe_stream" : "prolog", + "open_shared_object" : "prolog", + "opt_statistics" : "prolog", + "or_statistics" : "prolog", + "ortray_clause" : "prolog", + "otherwise" : "prolog", + "parallel" : "prolog", + "parallel_findall" : "prolog", + "parallel_findfirst" : "prolog", + "parallel_once" : "prolog", + "path" : "prolog", + "peek" : "prolog", + "peek_byte" : "prolog", + "peek_char" : "prolog", + "peek_code" : "prolog", + "phrase" : "prolog", + "plus" : "prolog", + "portray_clause" : "prolog", + "predicate_erased_statistics" : "prolog", + "predicate_property" : "prolog", + "predicate_statistics" : "prolog", + "predmerge" : "prolog", + "predsort" : "prolog", + "primitive" : "prolog", + "print" : "prolog", + "print_message" : "prolog", + "print_message_lines" : "prolog", + "private" : "prolog", + "profalt" : "prolog", + "profend" : "prolog", + "profile_data" : "prolog", + "profile_reset" : "prolog", + "profinit" : "prolog", + "profoff" : "prolog", + "profon" : "prolog", + "prolog" : "prolog", + "prolog_current_frame" : "prolog", + "prolog_file_name" : "prolog", + "prolog_file_type" : "prolog", + "prolog_flag" : "prolog", + "prolog_flag_property" : "prolog", + "prolog_initialization" : "prolog", + "prolog_load_context" : "prolog", + "prolog_to_os_filename" : "prolog", + "prompt" : "prolog", + "prompt1" : "prolog", + "put" : "prolog", + "put_attr" : "prolog", + "put_attrs" : "prolog", + "put_byte" : "prolog", + "put_char" : "prolog", + "put_char1" : "prolog", + "put_code" : "prolog", + "putenv" : "prolog", + "pwd" : "prolog", + "qend_program" : "prolog", + "qload_file" : "prolog", + "qload_module" : "prolog", + "qpack_clean_up_to_disjunction" : "prolog", + "qsave_file" : "prolog", + "qsave_module" : "prolog", + "qsave_program" : "prolog", + "raise_exception" : "prolog", + "rational" : "prolog", + "rational_term_to_tree" : "prolog", + "read" : "prolog", + "read_clause" : "prolog", + "read_sig" : "prolog", + "read_term" : "prolog", + "read_term_from_atom" : "prolog", + "read_term_from_atomic" : "prolog", + "read_term_from_string" : "prolog", + "real_path" : "prolog", + "reconsult" : "prolog", + "recorda" : "prolog", + "recorda_at" : "prolog", + "recordaifnot" : "prolog", + "recorded" : "prolog", + "recordz" : "prolog", + "recordz_at" : "prolog", + "recordzifnot" : "prolog", + "release_random_state" : "prolog", + "remove_from_path" : "prolog", + "rename" : "prolog", + "repeat" : "prolog", + "reset_static_array" : "prolog", + "reset_total_choicepoints" : "prolog", + "resize_static_array" : "prolog", + "restore" : "prolog", + "retract" : "prolog", + "retractall" : "prolog", + "rmdir" : "prolog", + "same_file" : "prolog", + "save_program" : "prolog", + "see" : "prolog", + "seeing" : "prolog", + "seen" : "prolog", + "set_base_module" : "prolog", + "set_input" : "prolog", + "set_output" : "prolog", + "set_prolog_flag" : "prolog", + "set_random_state" : "prolog", + "set_stream" : "prolog", + "set_stream_position" : "prolog", + "set_value" : "prolog", + "setarg" : "prolog", + "setenv" : "prolog", + "setof" : "prolog", + "setup_call_catcher_cleanup" : "prolog", + "setup_call_cleanup" : "prolog", + "sformat" : "prolog", + "sh" : "prolog", + "show_all_local_tables" : "prolog", + "show_all_tables" : "prolog", + "show_global_trie" : "prolog", + "show_global_trieshow_tabled_predicates" : "prolog", + "show_low_level_trace" : "prolog", + "show_table" : "prolog", + "show_tabled_predicates" : "prolog", + "showprofres" : "prolog", + "simple" : "prolog", + "skip" : "prolog", + "skip1" : "prolog", + "socket" : "prolog", + "socket_accept" : "prolog", + "socket_bind" : "prolog", + "socket_close" : "prolog", + "socket_connect" : "prolog", + "socket_listen" : "prolog", + "sort" : "prolog", + "sort2" : "prolog", + "source" : "prolog", + "source_file" : "prolog", + "source_file_property" : "prolog", + "source_location" : "prolog", + "source_mode" : "prolog", + "source_module" : "prolog", + "split_path_file" : "prolog", + "spy" : "prolog", + "srandom" : "prolog", + "start_low_level_trace" : "prolog", + "stash_predicate" : "prolog", + "static_array" : "prolog", + "static_array_location" : "prolog", + "static_array_properties" : "prolog", + "static_array_to_term" : "prolog", + "statistics" : "prolog", + "stop_low_level_trace" : "prolog", + "stream_position" : "prolog", + "stream_position_data" : "prolog", + "stream_property" : "prolog", + "stream_select" : "prolog", + "string" : "prolog", + "string_chars" : "prolog", + "string_code" : "prolog", + "string_codes" : "prolog", + "string_concat" : "prolog", + "string_length" : "prolog", + "string_number" : "prolog", + "string_to_atom" : "prolog", + "string_to_atomic" : "prolog", + "string_to_list" : "prolog", + "strip_module" : "prolog", + "style_check" : "prolog", + "sub_atom" : "prolog", + "sub_string" : "prolog", + "subsumes_term" : "prolog", + "succ" : "prolog", + "sys_debug" : "prolog", + "system" : "prolog", + "system_error" : "prolog", + "system_library" : "prolog", + "system_module" : "prolog", + "system_predicate" : "prolog", + "t_body" : "prolog", + "t_head" : "prolog", + "t_hgoal" : "prolog", + "t_hlist" : "prolog", + "t_tidy" : "prolog", + "tab" : "prolog", + "tab1" : "prolog", + "table" : "prolog", + "table_statistics" : "prolog", + "tabling_mode" : "prolog", + "tabling_statistics" : "prolog", + "tell" : "prolog", + "telling" : "prolog", + "term_attvars" : "prolog", + "term_factorized" : "prolog", + "term_to_atom" : "prolog", + "term_to_string" : "prolog", + "term_variables" : "prolog", + "thread_at_exit" : "prolog", + "thread_cancel" : "prolog", + "thread_create" : "prolog", + "thread_default" : "prolog", + "thread_defaults" : "prolog", + "thread_detach" : "prolog", + "thread_exit" : "prolog", + "thread_get_message" : "prolog", + "thread_join" : "prolog", + "thread_local" : "prolog", + "thread_peek_message" : "prolog", + "thread_property" : "prolog", + "thread_self" : "prolog", + "thread_send_message" : "prolog", + "thread_set_default" : "prolog", + "thread_set_defaults" : "prolog", + "thread_signal" : "prolog", + "thread_sleep" : "prolog", + "thread_statistics" : "prolog", + "threads" : "prolog", + "throw" : "prolog", + "time" : "prolog", + "time_file" : "prolog", + "time_file64" : "prolog", + "told" : "prolog", + "tolower" : "prolog", + "total_choicepoints" : "prolog", + "total_erased" : "prolog", + "toupper" : "prolog", + "trace" : "prolog", + "true" : "prolog", + "true_file_name" : "prolog", + "tthread_peek_message" : "prolog", + "ttyget" : "prolog", + "ttyget0" : "prolog", + "ttynl" : "prolog", + "ttyput" : "prolog", + "ttyskip" : "prolog", + "udi" : "prolog", + "unhide_atom" : "prolog", + "unify_with_occurs_check" : "prolog", + "unix" : "prolog", + "unknown" : "prolog", + "unload_file" : "prolog", + "unload_module" : "prolog", + "unnumbervars" : "prolog", + "update_array" : "prolog", + "update_mutable" : "prolog", + "use_module" : "prolog", + "use_system_module" : "prolog", + "user_defined_directive" : "prolog", + "var" : "prolog", + "version" : "prolog", + "volatile" : "prolog", + "wake_choice_point" : "prolog", + "when" : "prolog", + "with_mutex" : "prolog", + "with_output_to" : "prolog", + "working_directory" : "prolog", + "write" : "prolog", + "write_canonical" : "prolog", + "write_depth" : "prolog", + "write_term" : "prolog", + "writeln" : "prolog", + "writeq" : "prolog", + "yap_flag" : "prolog" + }; + + /******************************* + * RETURN OBJECT * + *******************************/ + + return { + startState : function() { + return { + tokenize : plTokenBase, + inBody : false, + goalStart : false, + headStart : true, + headFunctor : "", + lastType : null, + nesting : new Array(), /* ([{}]) nesting FIXME: copy this */ + curTerm : null, /* term index in metainfo */ + curToken : null /* token in term */ + }; + }, + token : function(stream, state) { + // var nest; + + if (state.curTerm == null && parserConfig.metainfo) { + state.curTerm = 0; + state.curToken = 0; + } + + if (stream.sol()) + delete state.commaAtEOL; + + if (state.tokenize == plTokenBase && stream.eatSpace()) { + if (stream.eol()) + setArgAlignment(state); + return null; + } + + var style = state.tokenize(stream, state); + + if (stream.eol()) + setArgAlignment(state); + + if (type == "neck") { + state.inBody = true; + state.goalStart = true; + } else if (type == "fullstop") { + state.inBody = false; + state.goalStart = true; + } + + state.lastType = type; + + if (builtins[state.curToken] == "prolog") + return "builtin"; + //if (ops[state.curToken]) + // return "operator"; + + //if (typeof(parserConfig.enrich) == "function") + // style = parserConfig.enrich(stream, state, type, content, style); + + return style; + + }, + + indent : function(state, textAfter) { + if (state.tokenize == plTokenComment) + return CodeMirror.Pass; + + var nest; + if ((nest = nesting(state))) { + if (nest.closeColumn && !state.commaAtEOL) + return nest.closeColumn; + return nest.alignment; + } + if (!state.inBody) + return 0; + + return 4; + }, + + // theme: "prolog", + + blockCommentStart : "/*", /* continuecomment.js support */ + blockCommentEnd : "*/", + blockCommentContinue : " * ", + lineComment : "%", + }; + +}); + +CodeMirror.defineMIME("text/x-prolog", "prolog"); + }); diff --git a/os/charsio.c b/os/charsio.c index 34ba3e880..c995bc376 100644 --- a/os/charsio.c +++ b/os/charsio.c @@ -77,7 +77,6 @@ static Int put_code(USES_REGS1); static Int put_byte(USES_REGS1); static Int skip(USES_REGS1); static Int flush_output(USES_REGS1); -static Int flush_all_streams(USES_REGS1); /** * CharOfAtom: convert an atom into a single character. @@ -167,7 +166,6 @@ int Yap_peekWide(int sno) { Int line = s->linecount; Int lpos = s->linepos; int ch = s->stream_wgetc(sno); - fprintf(stderr, "%d=%c\n", fileno(s->file), ch); if (ch == EOF) { if (s->file) clearerr(s->file); @@ -183,7 +181,7 @@ int Yap_peekWide(int sno) { s->linecount = line; s->linepos = lpos; s->stream_wgetc = Yap_popChar; - s->stream_getc = NU; + s->stream_getc = NULL; s->stream_peek= NULL; s->stream_wpeek= NULL; s->stream_getc = Yap_popChar; @@ -214,7 +212,7 @@ int Yap_peekChar(int sno) { s->linecount = line; s->linepos = lpos; s->stream_getc = Yap_popChar; - s->stream_wgetc = NU; + s->stream_wgetc = NULL; s->stream_peek= NULL; s->stream_wpeek= NULL; //Yap_SetCurInpPos(sno, pos); @@ -262,7 +260,10 @@ static Int at_end_of_stream(USES_REGS1) { /* at_end_of_stream */ out = (Yap_peek(sno) < 0); } } - UNLOCK(GLOBAL_Stream[sno].streaml + UNLOCK(GLOBAL_Stream[sno].streamlock); + return out; +} + /** @pred at_end_of_stream is iso diff --git a/os/iopreds.c b/os/iopreds.c index cefb24308..d7a2c3240 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -350,21 +350,19 @@ void Yap_DefaultStreamOps(StreamDesc *st) { st->stream_getc = Yap_popChar; st->stream_wgetc = Yap_popChar; } - /* - if (st->file) { - if (st->status & Readline_Stream_f) { + if (st->status & Readline_Stream_f) { st->stream_peek = Yap_ReadlinePeekChar; st->stream_wpeek = Yap_ReadlinePeekChar; - } else { + } + /* else { st->stream_peek = Yap_peekWithGetc; st->stream_wpeek = Yap_peekWideWithGetwc; } } else if (st->status & Seekable_Stream_f) { st->stream_peek = Yap_peekWithSeek; st->stream_wpeek = Yap_peekWideWithSeek; - } else -*/ - { + } */ + else { st->stream_peek = Yap_peekChar; st->stream_wpeek = Yap_peekWide; } diff --git a/os/readterm.c b/os/readterm.c index 1111e23ea..e760c10c0 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -337,28 +337,30 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos) { else { tm = MkStringTerm("syntax error"); } + if (GLOBAL_Stream[sno].status & Seekable_Stream_f) { if (errpos && newpos >= 0) { - char o[128 + 1]; - diff = errpos - startpos; - if (diff > 128) { - diff = 128; - startpos = errpos - diff; + char o[128 + 1]; + diff = errpos - startpos; + if (diff > 128) { + diff = 128; + startpos = errpos - diff; + } +#if HAVE_FTELLO + Int curpos = ftello(GLOBAL_Stream[sno].file); + fseeko(GLOBAL_Stream[sno].file, startpos, SEEK_SET); +#else + Int curpos = ftell(GLOBAL_Stream[sno].file); + fseek(GLOBAL_Stream[sno].file, startpos, SEEK_SET); +#endif + fread(o, diff, 1, GLOBAL_Stream[sno].file); +#if HAVE_FTELLO + fseeko(GLOBAL_Stream[sno].file, curpos, SEEK_SET); +#else + fseek(GLOBAL_Stream[sno].file, curpos, SEEK_SET); +#endif + o[diff] = '\0'; + tf[3] = MkStringTerm(o); } -#if HAVE_FTELLO - Int curpos = ftello(GLOBAL_Stream[sno].file); - fseeko(GLOBAL_Stream[sno].file, startpos, SEEK_SET); -#else - Int curpos = ftell(GLOBAL_Stream[sno].file); - fseek(GLOBAL_Stream[sno].file, startpos, SEEK_SET); -#endif - fread(o, diff, 1, GLOBAL_Stream[sno].file); -#if HAVE_FTELLO - fseeko(GLOBAL_Stream[sno].file, curpos, SEEK_SET); -#else - fseek(GLOBAL_Stream[sno].file, curpos, SEEK_SET); -#endif - o[diff] = '\0'; - tf[3] = MkStringTerm(o); } else { while (tok) { diff --git a/packages/python/yap_kernel/kernel.js b/packages/python/yap_kernel/kernel.js index 71cc6cb74..da9b12d94 100644 --- a/packages/python/yap_kernel/kernel.js +++ b/packages/python/yap_kernel/kernel.js @@ -1,42 +1,18 @@ -;(function(window_CodeMirror){ - "use strict"; +define([ + "/kernelspecs/yap_kernel/prolog.js"],function(CodeMirror){ - // the `require` namespace for codemirror - CM_PATH = "components/codemirror/"; - - define( - [ - "underscore", - "jquery", - CM_PATH + "lib/codemirror", - "base/js/namespace", - // silent upgrades - "./jshint.js", - CM_PATH + "addon/lint/javascript-lint", - CM_PATH + "addon/hint/javascript-hint", - CM_PATH + "addon/lint/lint", - CM_PATH + "addon/hint/show-hint", - "./prolog.js" - ], - function(_, $, CodeMirror, Jupyter){ - - // the main function - cm_tweak_js = function(cell){ - var editor = cell.code_mirror, - opts = {}, - meta = ensure_ns(cell), - keys = editor.getOption("extraKeys") || {}, - mode = editor.getMode(); - - // only update editors we care about, reset ones we might have messed - if(!editor){ - return; - } else { - editor.setOption("mode", "x-text/prolog"); - } - } - } - } // the `define` callback - ); // the `define` - ).call(this, window.CodeMirror); + var onload = function(){ + console.log("I am being loaded"); + var cell = Jupyter.notebook.get_selected_cell(); + var cm = cell.config; + var patch = { + CodeCell:{ + cm_config:{mode: "prolog"} // only change here. + } + }; + config.update(patch); + return {onload:onload}; + } + } + ); diff --git a/packages/python/yap_kernel/yap_ipython/yapi.py b/packages/python/yap_kernel/yap_ipython/yapi.py index 2ef5dbc3f..779359a3f 100644 --- a/packages/python/yap_kernel/yap_ipython/yapi.py +++ b/packages/python/yap_kernel/yap_ipython/yapi.py @@ -524,7 +524,6 @@ class YAPRun: return self.errors def jupyter_query(self, s): - import pdb; pdb.set_trace() # # construct a self.query from a one-line string # self.q is opaque to Python @@ -715,7 +714,7 @@ class YAPRun: mcell = cell.lstrip('%') txt0 = mcell.split(maxsplit = 2, sep = '\n') txt = txt0[0].split(maxsplit = 2) - magic = txt[0] + magic = txt[0] if len(txt) == 2: line = txt[1] else: diff --git a/pl/boot.yap b/pl/boot.yap index c44b49af5..1c3be8b4e 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -213,13 +213,12 @@ print_message(L,E) :- ). :- c_compile('arith.yap'). -:- c_compile('builtins.yap'). %:- stop_low_level_trace. -:- '$all_current_modules'(M), yap_flag(M:unknown, error) ; true. - :- '$init_prolog'. +:- '$all_current_modules'(M), yap_flag(M:unknown, error) ; true. + :- compile_expressions. @@ -230,6 +229,7 @@ print_message(L,E) :- :- c_compile('preddecls.yap'). :- c_compile('preddyns.yap'). :- c_compile('meta.yap'). +:- c_compile('builtins.yap'). :- c_compile('newmod.yap'). :- c_compile('atoms.yap'). diff --git a/pl/meta.yap b/pl/meta.yap index 6298d0735..e65c1dd8c 100644 --- a/pl/meta.yap +++ b/pl/meta.yap @@ -498,7 +498,6 @@ expand_goal(Input, Output) :- '$yap_strip_module'(M:GF0, MF, GF). :- '$install_meta_predicate'((0,0),prolog,(','),2). -:- '$install_meta_predicate'((0),prolog,(','),2). meta_predicate(P) :- source_module(SM), diff --git a/pl/modules.yap b/pl/modules.yap index 9a1678954..5c8fda87f 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -460,7 +460,8 @@ op(Prio,Assoc,Mod:Name), ; prolog_load_context(file, File) -> recorda('$module','$module'(File,Mod,SourceF,[op(Prio,Assoc,Name)],Line),_) ; recorda('$module','$module'(user_input,Mod,user_input,[op(Prio,Assoc,Name)],1),_) -).export_resource(Resource) :- +). +export_resource(Resource) :- '$do_error'(type_error(predicate_indicator,Resource),export(Resource)). export_list(Module, List) :-