pull/1405/head
parent
8572331ebd
commit
90c6521b31
@ -1,237 +0,0 @@
|
||||
import os
|
||||
import warnings
|
||||
|
||||
from flask import Blueprint, current_app, request, g, send_from_directory
|
||||
from flask.globals import _request_ctx_stack
|
||||
from jinja2 import Environment, PackageLoader
|
||||
from werkzeug.urls import url_quote_plus
|
||||
|
||||
from flask_debugtoolbar.compat import iteritems
|
||||
from flask_debugtoolbar.toolbar import DebugToolbar
|
||||
from flask_debugtoolbar.utils import decode_text
|
||||
|
||||
|
||||
module = Blueprint('debugtoolbar', __name__)
|
||||
|
||||
|
||||
def replace_insensitive(string, target, replacement):
|
||||
"""Similar to string.replace() but is case insensitive
|
||||
Code borrowed from:
|
||||
http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html
|
||||
"""
|
||||
no_case = string.lower()
|
||||
index = no_case.rfind(target.lower())
|
||||
if index >= 0:
|
||||
return string[:index] + replacement + string[index + len(target):]
|
||||
else: # no results so return the original string
|
||||
return string
|
||||
|
||||
|
||||
def _printable(value):
|
||||
try:
|
||||
return decode_text(repr(value))
|
||||
except Exception as e:
|
||||
return '<repr(%s) raised %s: %s>' % (
|
||||
object.__repr__(value), type(e).__name__, e)
|
||||
|
||||
|
||||
class DebugToolbarExtension(object):
|
||||
_static_dir = os.path.realpath(
|
||||
os.path.join(os.path.dirname(__file__), 'static'))
|
||||
|
||||
_redirect_codes = [301, 302, 303, 304]
|
||||
|
||||
def __init__(self, app=None):
|
||||
self.app = app
|
||||
self.debug_toolbars = {}
|
||||
|
||||
# Configure jinja for the internal templates and add url rules
|
||||
# for static data
|
||||
self.jinja_env = Environment(
|
||||
autoescape=True,
|
||||
extensions=['jinja2.ext.i18n', 'jinja2.ext.with_'],
|
||||
loader=PackageLoader(__name__, 'templates'))
|
||||
self.jinja_env.filters['urlencode'] = url_quote_plus
|
||||
self.jinja_env.filters['printable'] = _printable
|
||||
|
||||
if app is not None:
|
||||
self.init_app(app)
|
||||
|
||||
def init_app(self, app):
|
||||
for k, v in iteritems(self._default_config(app)):
|
||||
app.config.setdefault(k, v)
|
||||
|
||||
if not app.config['DEBUG_TB_ENABLED']:
|
||||
return
|
||||
|
||||
if not app.config.get('SECRET_KEY'):
|
||||
raise RuntimeError(
|
||||
"The Flask-DebugToolbar requires the 'SECRET_KEY' config "
|
||||
"var to be set")
|
||||
|
||||
DebugToolbar.load_panels(app)
|
||||
|
||||
app.before_request(self.process_request)
|
||||
app.after_request(self.process_response)
|
||||
app.teardown_request(self.teardown_request)
|
||||
|
||||
# Monkey-patch the Flask.dispatch_request method
|
||||
app.dispatch_request = self.dispatch_request
|
||||
|
||||
app.add_url_rule('/_debug_toolbar/static/<path:filename>',
|
||||
'_debug_toolbar.static', self.send_static_file)
|
||||
|
||||
app.register_blueprint(module, url_prefix='/_debug_toolbar/views')
|
||||
|
||||
def _default_config(self, app):
|
||||
return {
|
||||
'DEBUG_TB_ENABLED': app.debug,
|
||||
'DEBUG_TB_HOSTS': (),
|
||||
'DEBUG_TB_INTERCEPT_REDIRECTS': True,
|
||||
'DEBUG_TB_PANELS': (
|
||||
'flask_debugtoolbar.panels.versions.VersionDebugPanel',
|
||||
'flask_debugtoolbar.panels.timer.TimerDebugPanel',
|
||||
'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
|
||||
'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
|
||||
'flask_debugtoolbar.panels.config_vars.ConfigVarsDebugPanel',
|
||||
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
|
||||
'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
|
||||
'flask_debugtoolbar.panels.logger.LoggingPanel',
|
||||
'flask_debugtoolbar.panels.route_list.RouteListDebugPanel',
|
||||
'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
|
||||
),
|
||||
}
|
||||
|
||||
def dispatch_request(self):
|
||||
"""Modified version of Flask.dispatch_request to call process_view."""
|
||||
req = _request_ctx_stack.top.request
|
||||
app = current_app
|
||||
|
||||
if req.routing_exception is not None:
|
||||
app.raise_routing_exception(req)
|
||||
|
||||
rule = req.url_rule
|
||||
|
||||
# if we provide automatic options for this URL and the
|
||||
# request came with the OPTIONS method, reply automatically
|
||||
if getattr(rule, 'provide_automatic_options', False) \
|
||||
and req.method == 'OPTIONS':
|
||||
return app.make_default_options_response()
|
||||
|
||||
# otherwise dispatch to the handler for that endpoint
|
||||
view_func = app.view_functions[rule.endpoint]
|
||||
view_func = self.process_view(app, view_func, req.view_args)
|
||||
|
||||
return view_func(**req.view_args)
|
||||
|
||||
def _show_toolbar(self):
|
||||
"""Return a boolean to indicate if we need to show the toolbar."""
|
||||
if request.blueprint == 'debugtoolbar':
|
||||
return False
|
||||
|
||||
hosts = current_app.config['DEBUG_TB_HOSTS']
|
||||
if hosts and request.remote_addr not in hosts:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def send_static_file(self, filename):
|
||||
"""Send a static file from the flask-debugtoolbar static directory."""
|
||||
return send_from_directory(self._static_dir, filename)
|
||||
|
||||
def process_request(self):
|
||||
g.debug_toolbar = self
|
||||
|
||||
if not self._show_toolbar():
|
||||
return
|
||||
|
||||
real_request = request._get_current_object()
|
||||
|
||||
self.debug_toolbars[real_request] = (
|
||||
DebugToolbar(real_request, self.jinja_env))
|
||||
|
||||
for panel in self.debug_toolbars[real_request].panels:
|
||||
panel.process_request(real_request)
|
||||
|
||||
def process_view(self, app, view_func, view_kwargs):
|
||||
""" This method is called just before the flask view is called.
|
||||
This is done by the dispatch_request method.
|
||||
"""
|
||||
real_request = request._get_current_object()
|
||||
try:
|
||||
toolbar = self.debug_toolbars[real_request]
|
||||
except KeyError:
|
||||
return view_func
|
||||
|
||||
for panel in toolbar.panels:
|
||||
new_view = panel.process_view(real_request, view_func, view_kwargs)
|
||||
if new_view:
|
||||
view_func = new_view
|
||||
|
||||
return view_func
|
||||
|
||||
def process_response(self, response):
|
||||
real_request = request._get_current_object()
|
||||
if real_request not in self.debug_toolbars:
|
||||
return response
|
||||
|
||||
# Intercept http redirect codes and display an html page with a
|
||||
# link to the target.
|
||||
if current_app.config['DEBUG_TB_INTERCEPT_REDIRECTS']:
|
||||
if (response.status_code in self._redirect_codes and
|
||||
not real_request.is_xhr):
|
||||
redirect_to = response.location
|
||||
redirect_code = response.status_code
|
||||
if redirect_to:
|
||||
content = self.render('redirect.html', {
|
||||
'redirect_to': redirect_to,
|
||||
'redirect_code': redirect_code
|
||||
})
|
||||
response.content_length = len(content)
|
||||
response.location = None
|
||||
response.response = [content]
|
||||
response.status_code = 200
|
||||
|
||||
# If the http response code is 200 then we process to add the
|
||||
# toolbar to the returned html response.
|
||||
if not (response.status_code == 200 and
|
||||
response.is_sequence and
|
||||
response.headers['content-type'].startswith('text/html')):
|
||||
return response
|
||||
|
||||
response_html = response.data.decode(response.charset)
|
||||
|
||||
no_case = response_html.lower()
|
||||
body_end = no_case.rfind('</body>')
|
||||
|
||||
if body_end >= 0:
|
||||
before = response_html[:body_end]
|
||||
after = response_html[body_end:]
|
||||
elif no_case.startswith('<!doctype html>'):
|
||||
before = response_html
|
||||
after = ''
|
||||
else:
|
||||
warnings.warn('Could not insert debug toolbar.'
|
||||
' </body> tag not found in response.')
|
||||
return response
|
||||
|
||||
toolbar = self.debug_toolbars[real_request]
|
||||
|
||||
for panel in toolbar.panels:
|
||||
panel.process_response(real_request, response)
|
||||
|
||||
toolbar_html = toolbar.render_toolbar()
|
||||
|
||||
content = ''.join((before, toolbar_html, after))
|
||||
content = content.encode(response.charset)
|
||||
response.response = [content]
|
||||
response.content_length = len(content)
|
||||
|
||||
return response
|
||||
|
||||
def teardown_request(self, exc):
|
||||
self.debug_toolbars.pop(request._get_current_object(), None)
|
||||
|
||||
def render(self, template_name, context):
|
||||
template = self.jinja_env.get_template(template_name)
|
||||
return template.render(**context)
|
@ -1,9 +0,0 @@
|
||||
import sys
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
|
||||
if PY2:
|
||||
iteritems = lambda d: d.iteritems()
|
||||
else:
|
||||
iteritems = lambda d: iter(d.items())
|
@ -1,61 +0,0 @@
|
||||
"""Base DebugPanel class"""
|
||||
|
||||
|
||||
class DebugPanel(object):
|
||||
"""
|
||||
Base class for debug panels.
|
||||
"""
|
||||
# name = Base
|
||||
|
||||
# If content returns something, set to true in subclass
|
||||
has_content = False
|
||||
|
||||
# If the client is able to activate/de-activate the panel
|
||||
user_enable = False
|
||||
|
||||
# We'll maintain a local context instance so we can expose our template
|
||||
# context variables to panels which need them:
|
||||
context = {}
|
||||
|
||||
# Panel methods
|
||||
def __init__(self, jinja_env, context={}):
|
||||
self.context.update(context)
|
||||
self.jinja_env = jinja_env
|
||||
|
||||
# If the client enabled the panel
|
||||
self.is_active = False
|
||||
|
||||
def render(self, template_name, context):
|
||||
template = self.jinja_env.get_template(template_name)
|
||||
return template.render(**context)
|
||||
|
||||
def dom_id(self):
|
||||
return 'flDebug%sPanel' % (self.name.replace(' ', ''))
|
||||
|
||||
def nav_title(self):
|
||||
"""Title showing in toolbar"""
|
||||
raise NotImplementedError
|
||||
|
||||
def nav_subtitle(self):
|
||||
"""Subtitle showing until title in toolbar"""
|
||||
return ''
|
||||
|
||||
def title(self):
|
||||
"""Title showing in panel"""
|
||||
raise NotImplementedError
|
||||
|
||||
def url(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def content(self):
|
||||
raise NotImplementedError
|
||||
|
||||
# Standard middleware methods
|
||||
def process_request(self, request):
|
||||
pass
|
||||
|
||||
def process_view(self, request, view_func, view_kwargs):
|
||||
pass
|
||||
|
||||
def process_response(self, request, response):
|
||||
pass
|
@ -1,29 +0,0 @@
|
||||
from flask import current_app
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class ConfigVarsDebugPanel(DebugPanel):
|
||||
"""
|
||||
A panel to display all variables from Flask configuration
|
||||
"""
|
||||
name = 'ConfigVars'
|
||||
has_content = True
|
||||
|
||||
def nav_title(self):
|
||||
return _('Config')
|
||||
|
||||
def title(self):
|
||||
return _('Config')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def content(self):
|
||||
context = self.context.copy()
|
||||
context.update({
|
||||
'config': current_app.config,
|
||||
})
|
||||
|
||||
return self.render('panels/config_vars.html', context)
|
@ -1,56 +0,0 @@
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class HeaderDebugPanel(DebugPanel):
|
||||
"""
|
||||
A panel to display HTTP headers.
|
||||
"""
|
||||
name = 'Header'
|
||||
has_content = True
|
||||
# List of headers we want to display
|
||||
header_filter = (
|
||||
'CONTENT_TYPE',
|
||||
'HTTP_ACCEPT',
|
||||
'HTTP_ACCEPT_CHARSET',
|
||||
'HTTP_ACCEPT_ENCODING',
|
||||
'HTTP_ACCEPT_LANGUAGE',
|
||||
'HTTP_CACHE_CONTROL',
|
||||
'HTTP_CONNECTION',
|
||||
'HTTP_HOST',
|
||||
'HTTP_KEEP_ALIVE',
|
||||
'HTTP_REFERER',
|
||||
'HTTP_USER_AGENT',
|
||||
'QUERY_STRING',
|
||||
'REMOTE_ADDR',
|
||||
'REMOTE_HOST',
|
||||
'REQUEST_METHOD',
|
||||
'SCRIPT_NAME',
|
||||
'SERVER_NAME',
|
||||
'SERVER_PORT',
|
||||
'SERVER_PROTOCOL',
|
||||
'SERVER_SOFTWARE',
|
||||
)
|
||||
|
||||
def nav_title(self):
|
||||
return _('HTTP Headers')
|
||||
|
||||
def title(self):
|
||||
return _('HTTP Headers')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def process_request(self, request):
|
||||
self.headers = dict(
|
||||
[(k, request.environ[k])
|
||||
for k in self.header_filter if k in request.environ]
|
||||
)
|
||||
|
||||
def content(self):
|
||||
context = self.context.copy()
|
||||
context.update({
|
||||
'headers': self.headers
|
||||
})
|
||||
return self.render('panels/headers.html', context)
|
@ -1,115 +0,0 @@
|
||||
from __future__ import with_statement
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
threading = None
|
||||
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
from flask_debugtoolbar.utils import format_fname
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class ThreadTrackingHandler(logging.Handler):
|
||||
def __init__(self):
|
||||
if threading is None:
|
||||
raise NotImplementedError("threading module is not available, \
|
||||
the logging panel cannot be used without it")
|
||||
logging.Handler.__init__(self)
|
||||
self.records = {} # a dictionary that maps threads to log records
|
||||
|
||||
def emit(self, record):
|
||||
self.get_records().append(record)
|
||||
|
||||
def get_records(self, thread=None):
|
||||
"""
|
||||
Returns a list of records for the provided thread, of if none is
|
||||
provided, returns a list for the current thread.
|
||||
"""
|
||||
if thread is None:
|
||||
thread = threading.currentThread()
|
||||
if thread not in self.records:
|
||||
self.records[thread] = []
|
||||
return self.records[thread]
|
||||
|
||||
def clear_records(self, thread=None):
|
||||
if thread is None:
|
||||
thread = threading.currentThread()
|
||||
if thread in self.records:
|
||||
del self.records[thread]
|
||||
|
||||
|
||||
handler = None
|
||||
_init_lock = threading.Lock()
|
||||
|
||||
|
||||
def _init_once():
|
||||
global handler
|
||||
if handler is not None:
|
||||
return
|
||||
with _init_lock:
|
||||
if handler is not None:
|
||||
return
|
||||
|
||||
# Call werkzeug's internal logging to make sure it gets configured
|
||||
# before we add our handler. Otherwise werkzeug will see our handler
|
||||
# and not configure console logging for the request log.
|
||||
# Werkzeug's default log level is INFO so this message probably won't
|
||||
# be seen.
|
||||
try:
|
||||
from werkzeug._internal import _log
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
_log('debug', 'Initializing Flask-DebugToolbar log handler')
|
||||
|
||||
handler = ThreadTrackingHandler()
|
||||
logging.root.addHandler(handler)
|
||||
|
||||
|
||||
class LoggingPanel(DebugPanel):
|
||||
name = 'Logging'
|
||||
has_content = True
|
||||
|
||||
def process_request(self, request):
|
||||
_init_once()
|
||||
handler.clear_records()
|
||||
|
||||
def get_and_delete(self):
|
||||
records = handler.get_records()
|
||||
handler.clear_records()
|
||||
return records
|
||||
|
||||
def nav_title(self):
|
||||
return _("Logging")
|
||||
|
||||
def nav_subtitle(self):
|
||||
# FIXME l10n: use ngettext
|
||||
num_records = len(handler.get_records())
|
||||
return '%s message%s' % (num_records, '' if num_records == 1 else 's')
|
||||
|
||||
def title(self):
|
||||
return _('Log Messages')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def content(self):
|
||||
records = []
|
||||
for record in self.get_and_delete():
|
||||
records.append({
|
||||
'message': record.getMessage(),
|
||||
'time': datetime.datetime.fromtimestamp(record.created),
|
||||
'level': record.levelname,
|
||||
'file': format_fname(record.pathname),
|
||||
'file_long': record.pathname,
|
||||
'line': record.lineno,
|
||||
})
|
||||
|
||||
context = self.context.copy()
|
||||
context.update({'records': records})
|
||||
|
||||
return self.render('panels/logger.html', context)
|
@ -1,118 +0,0 @@
|
||||
try:
|
||||
import cProfile as profile
|
||||
except ImportError:
|
||||
import profile
|
||||
import functools
|
||||
import pstats
|
||||
|
||||
from flask import current_app
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
from flask_debugtoolbar.utils import format_fname
|
||||
|
||||
|
||||
class ProfilerDebugPanel(DebugPanel):
|
||||
"""
|
||||
Panel that displays the time a response took with cProfile output.
|
||||
"""
|
||||
name = 'Profiler'
|
||||
|
||||
user_activate = True
|
||||
|
||||
def __init__(self, jinja_env, context={}):
|
||||
DebugPanel.__init__(self, jinja_env, context=context)
|
||||
if current_app.config.get('DEBUG_TB_PROFILER_ENABLED'):
|
||||
self.is_active = True
|
||||
|
||||
def has_content(self):
|
||||
return bool(self.profiler)
|
||||
|
||||
def process_request(self, request):
|
||||
if not self.is_active:
|
||||
return
|
||||
|
||||
self.profiler = profile.Profile()
|
||||
self.stats = None
|
||||
|
||||
def process_view(self, request, view_func, view_kwargs):
|
||||
if self.is_active:
|
||||
func = functools.partial(self.profiler.runcall, view_func)
|
||||
functools.update_wrapper(func, view_func)
|
||||
return func
|
||||
|
||||
def process_response(self, request, response):
|
||||
if not self.is_active:
|
||||
return False
|
||||
|
||||
if self.profiler is not None:
|
||||
self.profiler.disable()
|
||||
try:
|
||||
stats = pstats.Stats(self.profiler)
|
||||
except TypeError:
|
||||
self.is_active = False
|
||||
return False
|
||||
function_calls = []
|
||||
for func in stats.sort_stats(1).fcn_list:
|
||||
current = {}
|
||||
info = stats.stats[func]
|
||||
|
||||
# Number of calls
|
||||
if info[0] != info[1]:
|
||||
current['ncalls'] = '%d/%d' % (info[1], info[0])
|
||||
else:
|
||||
current['ncalls'] = info[1]
|
||||
|
||||
# Total time
|
||||
current['tottime'] = info[2] * 1000
|
||||
|
||||
# Quotient of total time divided by number of calls
|
||||
if info[1]:
|
||||
current['percall'] = info[2] * 1000 / info[1]
|
||||
else:
|
||||
current['percall'] = 0
|
||||
|
||||
# Cumulative time
|
||||
current['cumtime'] = info[3] * 1000
|
||||
|
||||
# Quotient of the cumulative time divded by the number of
|
||||
# primitive calls.
|
||||
if info[0]:
|
||||
current['percall_cum'] = info[3] * 1000 / info[0]
|
||||
else:
|
||||
current['percall_cum'] = 0
|
||||
|
||||
# Filename
|
||||
filename = pstats.func_std_string(func)
|
||||
current['filename_long'] = filename
|
||||
current['filename'] = format_fname(filename)
|
||||
function_calls.append(current)
|
||||
|
||||
self.stats = stats
|
||||
self.function_calls = function_calls
|
||||
# destroy the profiler just in case
|
||||
return response
|
||||
|
||||
def title(self):
|
||||
if not self.is_active:
|
||||
return "Profiler not active"
|
||||
return 'View: %.2fms' % (float(self.stats.total_tt)*1000,)
|
||||
|
||||
def nav_title(self):
|
||||
return 'Profiler'
|
||||
|
||||
def nav_subtitle(self):
|
||||
if not self.is_active:
|
||||
return "in-active"
|
||||
return 'View: %.2fms' % (float(self.stats.total_tt)*1000,)
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def content(self):
|
||||
if not self.is_active:
|
||||
return "The profiler is not activated, activate it to use it"
|
||||
|
||||
context = {
|
||||
'stats': self.stats,
|
||||
'function_calls': self.function_calls,
|
||||
}
|
||||
return self.render('panels/profiler.html', context)
|
@ -1,49 +0,0 @@
|
||||
from flask import session
|
||||
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class RequestVarsDebugPanel(DebugPanel):
|
||||
"""
|
||||
A panel to display request variables (POST/GET, session, cookies).
|
||||
"""
|
||||
name = 'RequestVars'
|
||||
has_content = True
|
||||
|
||||
def nav_title(self):
|
||||
return _('Request Vars')
|
||||
|
||||
def title(self):
|
||||
return _('Request Vars')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def process_request(self, request):
|
||||
self.request = request
|
||||
self.session = session
|
||||
self.view_func = None
|
||||
self.view_args = []
|
||||
self.view_kwargs = {}
|
||||
|
||||
def process_view(self, request, view_func, view_kwargs):
|
||||
self.view_func = view_func
|
||||
self.view_kwargs = view_kwargs
|
||||
|
||||
def content(self):
|
||||
context = self.context.copy()
|
||||
context.update({
|
||||
'get': self.request.args.lists(),
|
||||
'post': self.request.form.lists(),
|
||||
'cookies': self.request.cookies.items(),
|
||||
'view_func': ('%s.%s' % (self.view_func.__module__,
|
||||
self.view_func.__name__)
|
||||
if self.view_func else '[unknown]'),
|
||||
'view_args': self.view_args,
|
||||
'view_kwargs': self.view_kwargs or {},
|
||||
'session': self.session.items(),
|
||||
})
|
||||
|
||||
return self.render('panels/request_vars.html', context)
|
@ -1,34 +0,0 @@
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
from flask import current_app
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class RouteListDebugPanel(DebugPanel):
|
||||
"""
|
||||
Panel that displays the URL routing rules.
|
||||
"""
|
||||
name = 'RouteList'
|
||||
has_content = True
|
||||
routes = []
|
||||
|
||||
def nav_title(self):
|
||||
return _('Route List')
|
||||
|
||||
def title(self):
|
||||
return _('Route List')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def nav_subtitle(self):
|
||||
count = len(self.routes)
|
||||
return '%s %s' % (count, 'route' if count == 1 else 'routes')
|
||||
|
||||
def process_request(self, request):
|
||||
self.routes = list(current_app.url_map.iter_rules())
|
||||
|
||||
def content(self):
|
||||
return self.render('panels/route_list.html', {
|
||||
'routes': self.routes,
|
||||
})
|
@ -1,150 +0,0 @@
|
||||
try:
|
||||
from flask_sqlalchemy import get_debug_queries, SQLAlchemy
|
||||
except ImportError:
|
||||
sqlalchemy_available = False
|
||||
get_debug_queries = SQLAlchemy = None
|
||||
else:
|
||||
sqlalchemy_available = True
|
||||
|
||||
from flask import request, current_app, abort, json_available, g
|
||||
from flask_debugtoolbar import module
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
from flask_debugtoolbar.utils import format_fname, format_sql
|
||||
import itsdangerous
|
||||
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
def query_signer():
|
||||
return itsdangerous.URLSafeSerializer(current_app.config['SECRET_KEY'],
|
||||
salt='fdt-sql-query')
|
||||
|
||||
|
||||
def is_select(statement):
|
||||
prefix = b'select' if isinstance(statement, bytes) else 'select'
|
||||
return statement.lower().strip().startswith(prefix)
|
||||
|
||||
|
||||
def dump_query(statement, params):
|
||||
if not params or not is_select(statement):
|
||||
return None
|
||||
|
||||
try:
|
||||
return query_signer().dumps([statement, params])
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
|
||||
def load_query(data):
|
||||
try:
|
||||
statement, params = query_signer().loads(request.args['query'])
|
||||
except (itsdangerous.BadSignature, TypeError):
|
||||
abort(406)
|
||||
|
||||
# Make sure it is a select statement
|
||||
if not is_select(statement):
|
||||
abort(406)
|
||||
|
||||
return statement, params
|
||||
|
||||
|
||||
def extension_used():
|
||||
return 'sqlalchemy' in current_app.extensions
|
||||
|
||||
|
||||
def recording_enabled():
|
||||
return (current_app.debug
|
||||
or current_app.config.get('SQLALCHEMY_RECORD_QUERIES'))
|
||||
|
||||
|
||||
def is_available():
|
||||
return (json_available and sqlalchemy_available
|
||||
and extension_used() and recording_enabled())
|
||||
|
||||
|
||||
def get_queries():
|
||||
if get_debug_queries:
|
||||
return get_debug_queries()
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
class SQLAlchemyDebugPanel(DebugPanel):
|
||||
"""
|
||||
Panel that displays the time a response took in milliseconds.
|
||||
"""
|
||||
name = 'SQLAlchemy'
|
||||
|
||||
@property
|
||||
def has_content(self):
|
||||
return bool(get_queries()) or not is_available()
|
||||
|
||||
def process_request(self, request):
|
||||
pass
|
||||
|
||||
def process_response(self, request, response):
|
||||
pass
|
||||
|
||||
def nav_title(self):
|
||||
return _('SQLAlchemy')
|
||||
|
||||
def nav_subtitle(self):
|
||||
count = len(get_queries())
|
||||
|
||||
if not count and not is_available():
|
||||
return 'Unavailable'
|
||||
|
||||
return '%d %s' % (count, 'query' if count == 1 else 'queries')
|
||||
|
||||
def title(self):
|
||||
return _('SQLAlchemy queries')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def content(self):
|
||||
queries = get_queries()
|
||||
|
||||
if not queries and not is_available():
|
||||
return self.render('panels/sqlalchemy_error.html', {
|
||||
'json_available': json_available,
|
||||
'sqlalchemy_available': sqlalchemy_available,
|
||||
'extension_used': extension_used(),
|
||||
'recording_enabled': recording_enabled(),
|
||||
})
|
||||
|
||||
data = []
|
||||
for query in queries:
|
||||
data.append({
|
||||
'duration': query.duration,
|
||||
'sql': format_sql(query.statement, query.parameters),
|
||||
'signed_query': dump_query(query.statement, query.parameters),
|
||||
'context_long': query.context,
|
||||
'context': format_fname(query.context)
|
||||
})
|
||||
return self.render('panels/sqlalchemy.html', {'queries': data})
|
||||
|
||||
# Panel views
|
||||
|
||||
|
||||
@module.route('/sqlalchemy/sql_select', methods=['GET', 'POST'])
|
||||
@module.route('/sqlalchemy/sql_explain', methods=['GET', 'POST'],
|
||||
defaults=dict(explain=True))
|
||||
def sql_select(explain=False):
|
||||
statement, params = load_query(request.args['query'])
|
||||
engine = SQLAlchemy().get_engine(current_app)
|
||||
|
||||
if explain:
|
||||
if engine.driver == 'pysqlite':
|
||||
statement = 'EXPLAIN QUERY PLAN\n%s' % statement
|
||||
else:
|
||||
statement = 'EXPLAIN\n%s' % statement
|
||||
|
||||
result = engine.execute(statement, params)
|
||||
return g.debug_toolbar.render('panels/sqlalchemy_select.html', {
|
||||
'result': result.fetchall(),
|
||||
'headers': result.keys(),
|
||||
'sql': format_sql(statement, params),
|
||||
'duration': float(request.args['duration']),
|
||||
})
|
@ -1,136 +0,0 @@
|
||||
import collections
|
||||
import json
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
from flask import (
|
||||
template_rendered, request, g,
|
||||
Response, current_app, abort, url_for
|
||||
)
|
||||
from flask_debugtoolbar import module
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class TemplateDebugPanel(DebugPanel):
|
||||
"""
|
||||
Panel that displays the time a response took in milliseconds.
|
||||
"""
|
||||
name = 'Template'
|
||||
has_content = True
|
||||
|
||||
# save the context for the 5 most recent requests
|
||||
template_cache = collections.deque(maxlen=5)
|
||||
|
||||
@classmethod
|
||||
def get_cache_for_key(self, key):
|
||||
for cache_key, value in self.template_cache:
|
||||
if key == cache_key:
|
||||
return value
|
||||
raise KeyError(key)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(self.__class__, self).__init__(*args, **kwargs)
|
||||
self.key = str(uuid.uuid4())
|
||||
self.templates = []
|
||||
template_rendered.connect(self._store_template_info)
|
||||
|
||||
def _store_template_info(self, sender, **kwargs):
|
||||
# only record in the cache if the editor is enabled and there is
|
||||
# actually a template for this request
|
||||
if not self.templates and is_editor_enabled():
|
||||
self.template_cache.append((self.key, self.templates))
|
||||
self.templates.append(kwargs)
|
||||
|
||||
def process_request(self, request):
|
||||
pass
|
||||
|
||||
def process_response(self, request, response):
|
||||
pass
|
||||
|
||||
def nav_title(self):
|
||||
return _('Templates')
|
||||
|
||||
def nav_subtitle(self):
|
||||
return "%d rendered" % len(self.templates)
|
||||
|
||||
def title(self):
|
||||
return _('Templates')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def content(self):
|
||||
return self.render('panels/template.html', {
|
||||
'key': self.key,
|
||||
'templates': self.templates,
|
||||
'editable': is_editor_enabled(),
|
||||
})
|
||||
|
||||
|
||||
def is_editor_enabled():
|
||||
return current_app.config.get('DEBUG_TB_TEMPLATE_EDITOR_ENABLED')
|
||||
|
||||
|
||||
def require_enabled():
|
||||
if not is_editor_enabled():
|
||||
abort(403)
|
||||
|
||||
|
||||
def _get_source(template):
|
||||
with open(template.filename, 'rb') as fp:
|
||||
source = fp.read()
|
||||
return source.decode(_template_encoding())
|
||||
|
||||
|
||||
def _template_encoding():
|
||||
return getattr(current_app.jinja_loader, 'encoding', 'utf-8')
|
||||
|
||||
|
||||
@module.route('/template/<key>')
|
||||
def template_editor(key):
|
||||
require_enabled()
|
||||
# TODO set up special loader that caches templates it loads
|
||||
# and can override template contents
|
||||
templates = [t['template'] for t in
|
||||
TemplateDebugPanel.get_cache_for_key(key)]
|
||||
return g.debug_toolbar.render('panels/template_editor.html', {
|
||||
'static_path': url_for('_debug_toolbar.static', filename=''),
|
||||
'request': request,
|
||||
'templates': [
|
||||
{'name': t.name, 'source': _get_source(t)}
|
||||
for t in templates
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
@module.route('/template/<key>/save', methods=['POST'])
|
||||
def save_template(key):
|
||||
require_enabled()
|
||||
template = TemplateDebugPanel.get_cache_for_key(key)[0]['template']
|
||||
content = request.form['content'].encode(_template_encoding())
|
||||
with open(template.filename, 'wb') as fp:
|
||||
fp.write(content)
|
||||
return 'ok'
|
||||
|
||||
|
||||
@module.route('/template/<key>', methods=['POST'])
|
||||
def template_preview(key):
|
||||
require_enabled()
|
||||
context = TemplateDebugPanel.get_cache_for_key(key)[0]['context']
|
||||
content = request.form['content']
|
||||
env = current_app.jinja_env.overlay(autoescape=True)
|
||||
try:
|
||||
template = env.from_string(content)
|
||||
return template.render(context)
|
||||
except Exception as e:
|
||||
tb = sys.exc_info()[2]
|
||||
try:
|
||||
while tb.tb_next:
|
||||
tb = tb.tb_next
|
||||
msg = {'lineno': tb.tb_lineno, 'error': str(e)}
|
||||
return Response(json.dumps(msg), status=400,
|
||||
mimetype='application/json')
|
||||
finally:
|
||||
del tb
|
@ -1,96 +0,0 @@
|
||||
try:
|
||||
import resource
|
||||
except ImportError:
|
||||
pass # Will fail on Win32 systems
|
||||
import time
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class TimerDebugPanel(DebugPanel):
|
||||
"""
|
||||
Panel that displays the time a response took in milliseconds.
|
||||
"""
|
||||
name = 'Timer'
|
||||
try: # if resource module not available, don't show content panel
|
||||
resource
|
||||
except NameError:
|
||||
has_content = False
|
||||
has_resource = False
|
||||
else:
|
||||
has_content = True
|
||||
has_resource = True
|
||||
|
||||
def process_request(self, request):
|
||||
self._start_time = time.time()
|
||||
if self.has_resource:
|
||||
self._start_rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||
|
||||
def process_response(self, request, response):
|
||||
self.total_time = (time.time() - self._start_time) * 1000
|
||||
if self.has_resource:
|
||||
self._end_rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||
|
||||
def nav_title(self):
|
||||
return _('Time')
|
||||
|
||||
def nav_subtitle(self):
|
||||
# TODO l10n
|
||||
if not self.has_resource:
|
||||
return 'TOTAL: %0.2fms' % (self.total_time)
|
||||
|
||||
utime = self._end_rusage.ru_utime - self._start_rusage.ru_utime
|
||||
stime = self._end_rusage.ru_stime - self._start_rusage.ru_stime
|
||||
return 'CPU: %0.2fms (%0.2fms)' % (
|
||||
(utime + stime) * 1000.0, self.total_time)
|
||||
|
||||
def title(self):
|
||||
return _('Resource Usage')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def _elapsed_ru(self, name):
|
||||
return (getattr(self._end_rusage, name)
|
||||
- getattr(self._start_rusage, name))
|
||||
|
||||
def content(self):
|
||||
|
||||
utime = 1000 * self._elapsed_ru('ru_utime')
|
||||
stime = 1000 * self._elapsed_ru('ru_stime')
|
||||
vcsw = self._elapsed_ru('ru_nvcsw')
|
||||
ivcsw = self._elapsed_ru('ru_nivcsw')
|
||||
# minflt = self._elapsed_ru('ru_minflt')
|
||||
# majflt = self._elapsed_ru('ru_majflt')
|
||||
|
||||
# these are documented as not meaningful under Linux. If you're running BSD
|
||||
# feel free to enable them, and add any others that I hadn't gotten to before
|
||||
# I noticed that I was getting nothing but zeroes and that the docs agreed. :-(
|
||||
#
|
||||
# blkin = self._elapsed_ru('ru_inblock')
|
||||
# blkout = self._elapsed_ru('ru_oublock')
|
||||
# swap = self._elapsed_ru('ru_nswap')
|
||||
# rss = self._end_rusage.ru_maxrss
|
||||
# srss = self._end_rusage.ru_ixrss
|
||||
# urss = self._end_rusage.ru_idrss
|
||||
# usrss = self._end_rusage.ru_isrss
|
||||
|
||||
# TODO l10n on values
|
||||
rows = (
|
||||
(_('User CPU time'), '%0.3f msec' % utime),
|
||||
(_('System CPU time'), '%0.3f msec' % stime),
|
||||
(_('Total CPU time'), '%0.3f msec' % (utime + stime)),
|
||||
(_('Elapsed time'), '%0.3f msec' % self.total_time),
|
||||
(_('Context switches'), '%d voluntary, %d involuntary' % (vcsw, ivcsw)),
|
||||
# ('Memory use', '%d max RSS, %d shared, %d unshared' % (rss, srss, urss + usrss)),
|
||||
# ('Page faults', '%d no i/o, %d requiring i/o' % (minflt, majflt)),
|
||||
# ('Disk operations', '%d in, %d out, %d swapout' % (blkin, blkout, swap)),
|
||||
)
|
||||
|
||||
context = self.context.copy()
|
||||
context.update({
|
||||
'rows': rows,
|
||||
})
|
||||
|
||||
return self.render('panels/timer.html', context)
|
@ -1,52 +0,0 @@
|
||||
import os
|
||||
from distutils.sysconfig import get_python_lib
|
||||
|
||||
from flask import __version__ as flask_version
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
def relpath(location, python_lib):
|
||||
location = os.path.normpath(location)
|
||||
relative = os.path.relpath(location, python_lib)
|
||||
if relative == os.path.curdir:
|
||||
return ''
|
||||
elif relative.startswith(os.path.pardir):
|
||||
return location
|
||||
return relative
|
||||
|
||||
|
||||
class VersionDebugPanel(DebugPanel):
|
||||
"""
|
||||
Panel that displays the Flask version.
|
||||
"""
|
||||
name = 'Version'
|
||||
has_content = True
|
||||
|
||||
def nav_title(self):
|
||||
return _('Versions')
|
||||
|
||||
def nav_subtitle(self):
|
||||
return 'Flask %s' % flask_version
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def title(self):
|
||||
return _('Versions')
|
||||
|
||||
def content(self):
|
||||
try:
|
||||
import pkg_resources
|
||||
except ImportError:
|
||||
packages = []
|
||||
else:
|
||||
packages = sorted(pkg_resources.working_set,
|
||||
key=lambda p: p.project_name.lower())
|
||||
|
||||
return self.render('panels/versions.html', {
|
||||
'packages': packages,
|
||||
'python_lib': os.path.normpath(get_python_lib()),
|
||||
'relpath': relpath,
|
||||
})
|
@ -1,112 +0,0 @@
|
||||
.CodeMirror {
|
||||
line-height: 1em;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.CodeMirror-scroll {
|
||||
overflow: auto;
|
||||
height: 300px;
|
||||
/* This is needed to prevent an IE[67] bug where the scrolled content
|
||||
is visible outside of the scrolling box. */
|
||||
position: relative;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.CodeMirror-gutter {
|
||||
position: absolute; left: 0; top: 0;
|
||||
z-index: 10;
|
||||
background-color: #f7f7f7;
|
||||
border-right: 1px solid #eee;
|
||||
min-width: 2em;
|
||||
height: 100%;
|
||||
}
|
||||
.CodeMirror-gutter-text {
|
||||
color: #aaa;
|
||||
text-align: right;
|
||||
padding: .4em .2em .4em .4em;
|
||||
white-space: pre !important;
|
||||
}
|
||||
.CodeMirror-lines {
|
||||
padding: .4em;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.CodeMirror pre {
|
||||
-moz-border-radius: 0;
|
||||
-webkit-border-radius: 0;
|
||||
-o-border-radius: 0;
|
||||
border-radius: 0;
|
||||
border-width: 0; margin: 0; padding: 0; background: transparent;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
padding: 0; margin: 0;
|
||||
white-space: pre;
|
||||
word-wrap: normal;
|
||||
}
|
||||
|
||||
.CodeMirror-wrap pre {
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.CodeMirror-wrap .CodeMirror-scroll {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.CodeMirror textarea {
|
||||
outline: none !important;
|
||||
}
|
||||
|
||||
.CodeMirror pre.CodeMirror-cursor {
|
||||
z-index: 10;
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
border-left: 1px solid black;
|
||||
border-right:none;
|
||||
width:0;
|
||||
}
|
||||
.CodeMirror pre.CodeMirror-cursor.CodeMirror-overwrite {}
|
||||
.CodeMirror-focused pre.CodeMirror-cursor {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
div.CodeMirror-selected { background: #d9d9d9; }
|
||||
.CodeMirror-focused div.CodeMirror-selected { background: #d7d4f0; }
|
||||
|
||||
.CodeMirror-searching {
|
||||
background: #ffa;
|
||||
background: rgba(255, 255, 0, .4);
|
||||
}
|
||||
|
||||
/* Default theme */
|
||||
|
||||
.cm-s-default span.cm-keyword {color: #708;}
|
||||
.cm-s-default span.cm-atom {color: #219;}
|
||||
.cm-s-default span.cm-number {color: #164;}
|
||||
.cm-s-default span.cm-def {color: #00f;}
|
||||
.cm-s-default span.cm-variable {color: black;}
|
||||
.cm-s-default span.cm-variable-2 {color: #05a;}
|
||||
.cm-s-default span.cm-variable-3 {color: #085;}
|
||||
.cm-s-default span.cm-property {color: black;}
|
||||
.cm-s-default span.cm-operator {color: black;}
|
||||
.cm-s-default span.cm-comment {color: #a50;}
|
||||
.cm-s-default span.cm-string {color: #a11;}
|
||||
.cm-s-default span.cm-string-2 {color: #f50;}
|
||||
.cm-s-default span.cm-meta {color: #555;}
|
||||
.cm-s-default span.cm-error {color: #f00;}
|
||||
.cm-s-default span.cm-qualifier {color: #555;}
|
||||
.cm-s-default span.cm-builtin {color: #30a;}
|
||||
.cm-s-default span.cm-bracket {color: #cc7;}
|
||||
.cm-s-default span.cm-tag {color: #170;}
|
||||
.cm-s-default span.cm-attribute {color: #00c;}
|
||||
.cm-s-default span.cm-header {color: #a0a;}
|
||||
.cm-s-default span.cm-quote {color: #090;}
|
||||
.cm-s-default span.cm-hr {color: #999;}
|
||||
.cm-s-default span.cm-link {color: #00c;}
|
||||
|
||||
span.cm-header, span.cm-strong {font-weight: bold;}
|
||||
span.cm-em {font-style: italic;}
|
||||
span.cm-emstrong {font-style: italic; font-weight: bold;}
|
||||
span.cm-link {text-decoration: underline;}
|
||||
|
||||
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
|
||||
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
|
File diff suppressed because it is too large
Load Diff
@ -1,234 +0,0 @@
|
||||
CodeMirror.defineMode("clike", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit,
|
||||
keywords = parserConfig.keywords || {},
|
||||
blockKeywords = parserConfig.blockKeywords || {},
|
||||
atoms = parserConfig.atoms || {},
|
||||
hooks = parserConfig.hooks || {},
|
||||
multiLineStrings = parserConfig.multiLineStrings;
|
||||
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
||||
|
||||
var curPunc;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (hooks[ch]) {
|
||||
var result = hooks[ch](stream, state);
|
||||
if (result !== false) return result;
|
||||
}
|
||||
if (ch == '"' || ch == "'") {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null
|
||||
}
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
return "number";
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
}
|
||||
if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
var cur = stream.current();
|
||||
if (keywords.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "keyword";
|
||||
}
|
||||
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
||||
return "word";
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {end = true; break;}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !(escaped || multiLineStrings))
|
||||
state.tokenize = null;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function Context(indented, column, type, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type) {
|
||||
return state.context = new Context(state.indented, col, type, null, state.context);
|
||||
}
|
||||
function popContext(state) {
|
||||
var t = state.context.type;
|
||||
if (t == ")" || t == "]" || t == "}")
|
||||
state.indented = state.context.indented;
|
||||
return state.context = state.context.prev;
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: null,
|
||||
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
||||
indented: 0,
|
||||
startOfLine: true
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
var style = (state.tokenize || tokenBase)(stream, state);
|
||||
if (style == "comment" || style == "meta") return style;
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
|
||||
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
||||
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
||||
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
||||
else if (curPunc == "}") {
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
if (ctx.type == "}") ctx = popContext(state);
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
}
|
||||
else if (curPunc == ctx.type) popContext(state);
|
||||
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
|
||||
pushContext(state, stream.column(), "statement");
|
||||
state.startOfLine = false;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
|
||||
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
||||
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
||||
var closing = firstChar == ctx.type;
|
||||
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indented + (closing ? 0 : indentUnit);
|
||||
},
|
||||
|
||||
electricChars: "{}"
|
||||
};
|
||||
});
|
||||
|
||||
(function() {
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
|
||||
"double static else struct entry switch extern typedef float union for unsigned " +
|
||||
"goto while enum void const signed volatile";
|
||||
|
||||
function cppHook(stream, state) {
|
||||
if (!state.startOfLine) return false;
|
||||
stream.skipToEnd();
|
||||
return "meta";
|
||||
}
|
||||
|
||||
// C#-style strings where "" escapes a quote.
|
||||
function tokenAtString(stream, state) {
|
||||
var next;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == '"' && !stream.eat('"')) {
|
||||
state.tokenize = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "string";
|
||||
}
|
||||
|
||||
CodeMirror.defineMIME("text/x-csrc", {
|
||||
name: "clike",
|
||||
keywords: words(cKeywords),
|
||||
blockKeywords: words("case do else for if switch while struct"),
|
||||
atoms: words("null"),
|
||||
hooks: {"#": cppHook}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-c++src", {
|
||||
name: "clike",
|
||||
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
|
||||
"static_cast typeid catch operator template typename class friend private " +
|
||||
"this using const_cast inline public throw virtual delete mutable protected " +
|
||||
"wchar_t"),
|
||||
blockKeywords: words("catch class do else finally for if struct switch try while"),
|
||||
atoms: words("true false null"),
|
||||
hooks: {"#": cppHook}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-java", {
|
||||
name: "clike",
|
||||
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
|
||||
"do double else enum extends final finally float for goto if implements import " +
|
||||
"instanceof int interface long native new package private protected public " +
|
||||
"return short static strictfp super switch synchronized this throw throws transient " +
|
||||
"try void volatile while"),
|
||||
blockKeywords: words("catch class do else finally for if switch try while"),
|
||||
atoms: words("true false null"),
|
||||
hooks: {
|
||||
"@": function(stream, state) {
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
return "meta";
|
||||
}
|
||||
}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-csharp", {
|
||||
name: "clike",
|
||||
keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
|
||||
" default delegate do double else enum event explicit extern finally fixed float for" +
|
||||
" foreach goto if implicit in int interface internal is lock long namespace new object" +
|
||||
" operator out override params private protected public readonly ref return sbyte sealed short" +
|
||||
" sizeof stackalloc static string struct switch this throw try typeof uint ulong unchecked" +
|
||||
" unsafe ushort using virtual void volatile while add alias ascending descending dynamic from get" +
|
||||
" global group into join let orderby partial remove select set value var yield"),
|
||||
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
|
||||
atoms: words("true false null"),
|
||||
hooks: {
|
||||
"@": function(stream, state) {
|
||||
if (stream.eat('"')) {
|
||||
state.tokenize = tokenAtString;
|
||||
return tokenAtString(stream, state);
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
return "meta";
|
||||
}
|
||||
}
|
||||
});
|
||||
}());
|
@ -1,101 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: C-like mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="clike.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style>.CodeMirror {border: 2px inset #dee;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: C-like mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
/* C demo code */
|
||||
|
||||
#include <zmq.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <malloc.h>
|
||||
|
||||
typedef struct {
|
||||
void* arg_socket;
|
||||
zmq_msg_t* arg_msg;
|
||||
char* arg_string;
|
||||
unsigned long arg_len;
|
||||
int arg_int, arg_command;
|
||||
|
||||
int signal_fd;
|
||||
int pad;
|
||||
void* context;
|
||||
sem_t sem;
|
||||
} acl_zmq_context;
|
||||
|
||||
#define p(X) (context->arg_##X)
|
||||
|
||||
void* zmq_thread(void* context_pointer) {
|
||||
acl_zmq_context* context = (acl_zmq_context*)context_pointer;
|
||||
char ok = 'K', err = 'X';
|
||||
int res;
|
||||
|
||||
while (1) {
|
||||
while ((res = sem_wait(&context->sem)) == EINTR);
|
||||
if (res) {write(context->signal_fd, &err, 1); goto cleanup;}
|
||||
switch(p(command)) {
|
||||
case 0: goto cleanup;
|
||||
case 1: p(socket) = zmq_socket(context->context, p(int)); break;
|
||||
case 2: p(int) = zmq_close(p(socket)); break;
|
||||
case 3: p(int) = zmq_bind(p(socket), p(string)); break;
|
||||
case 4: p(int) = zmq_connect(p(socket), p(string)); break;
|
||||
case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break;
|
||||
case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
|
||||
case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
|
||||
case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
|
||||
case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
|
||||
}
|
||||
p(command) = errno;
|
||||
write(context->signal_fd, &ok, 1);
|
||||
}
|
||||
cleanup:
|
||||
close(context->signal_fd);
|
||||
free(context_pointer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* zmq_thread_init(void* zmq_context, int signal_fd) {
|
||||
acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
|
||||
pthread_t thread;
|
||||
|
||||
context->context = zmq_context;
|
||||
context->signal_fd = signal_fd;
|
||||
sem_init(&context->sem, 1, 0);
|
||||
pthread_create(&thread, 0, &zmq_thread, context);
|
||||
pthread_detach(thread);
|
||||
return context;
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "text/x-csrc"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Simple mode that tries to handle C-like languages as well as it
|
||||
can. Takes two configuration parameters: <code>keywords</code>, an
|
||||
object whose property names are the keywords in the language,
|
||||
and <code>useCPP</code>, which determines whether C preprocessor
|
||||
directives are recognized.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-csrc</code>
|
||||
(C code), <code>text/x-c++src</code> (C++
|
||||
code), <code>text/x-java</code> (Java
|
||||
code), <code>text/x-csharp</code> (C#).</p>
|
||||
</body>
|
||||
</html>
|
@ -1,207 +0,0 @@
|
||||
/**
|
||||
* Author: Hans Engel
|
||||
* Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementation by Koh Zi Chun)
|
||||
*/
|
||||
CodeMirror.defineMode("clojure", function (config, mode) {
|
||||
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", TAG = "tag",
|
||||
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword";
|
||||
var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
|
||||
|
||||
function makeKeywords(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
var atoms = makeKeywords("true false nil");
|
||||
|
||||
var keywords = makeKeywords(
|
||||
"defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype defprotocol defrecord defproject deftest slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do case cond condp for loop recur when when-not when-let when-first if if-let if-not . .. -> ->> doto and or dosync doseq dotimes dorun doall load import unimport ns in-ns refer try catch finally throw with-open with-local-vars binding gen-class gen-and-load-class gen-and-save-class handler-case handle");
|
||||
|
||||
var builtins = makeKeywords(
|
||||
"* *1 *2 *3 *agent* *allow-unresolved-vars* *assert *clojure-version* *command-line-args* *compile-files* *compile-path* *e *err* *file* *flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *read-eval* *source-path* *use-context-classloader* *warn-on-reflection* + - / < <= = == > >= accessor aclone agent agent-errors aget alength alias all-ns alter alter-meta! alter-var-root amap ancestors and apply areduce array-map aset aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in associative? atom await await-for await1 bases bean bigdec bigint binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array booleans bound-fn bound-fn* butlast byte byte-array bytes case cast char char-array char-escape-string char-name-string char? chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? class class? clear-agent-errors clojure-version coll? comment commute comp comparator compare compare-and-set! compile complement concat cond condp conj conj! cons constantly construct-proxy contains? count counted? create-ns create-struct cycle dec decimal? declare definline defmacro defmethod defmulti defn defn- defonce defstruct delay delay? deliver deref derive descendants destructure disj disj! dissoc dissoc! distinct distinct? doall doc dorun doseq dosync dotimes doto double double-array doubles drop drop-last drop-while empty empty? ensure enumeration-seq eval even? every? extend extend-protocol extend-type extends? extenders false? ffirst file-seq filter find find-doc find-ns find-var first float float-array float? floats flush fn fn? fnext for force format future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface gensym get get-in get-method get-proxy-class get-thread-bindings get-validator hash hash-map hash-set identical? identity if-let if-not ifn? import in-ns inc init-proxy instance? int int-array integer? interleave intern interpose into into-array ints io! isa? iterate iterator-seq juxt key keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list* list? load load-file load-reader load-string loaded-libs locking long long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy map map? mapcat max max-key memfn memoize merge merge-with meta method-sig methods min min-key mod name namespace neg? newline next nfirst nil? nnext not not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? or parents partial partition pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str prefer-method prefers primitives-classnames print print-ctor print-doc print-dup print-method print-namespace-doc print-simple print-special-doc print-str printf println println-str prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot rand rand-int range ratio? rational? rationalize re-find re-groups re-matcher re-matches re-pattern re-seq read read-line read-string reify reduce ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure release-pending-sends rem remove remove-method remove-ns repeat repeatedly replace replicate require reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq rsubseq satisfies? second select-keys send send-off seq seq? seque sequence sequential? set set-validator! set? short short-array shorts shutdown-agents slurp some sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-form-anchor special-symbol? split-at split-with str stream? string? struct struct-map subs subseq subvec supers swap! symbol symbol? sync syntax-symbol-anchor take take-last take-nth take-while test the-ns time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-dec unchecked-divide unchecked-inc unchecked-multiply unchecked-negate unchecked-remainder unchecked-subtract underive unquote unquote-splicing update-in update-proxy use val vals var-get var-set var? vary-meta vec vector vector? when when-first when-let when-not while with-bindings with-bindings* with-in-str with-loading-context with-local-vars with-meta with-open with-out-str with-precision xml-seq");
|
||||
|
||||
var indentKeys = makeKeywords(
|
||||
// Built-ins
|
||||
"ns fn def defn defmethod bound-fn if if-not case condp when while when-not when-first do future comment doto locking proxy with-open with-precision reify deftype defrecord defprotocol extend extend-protocol extend-type try catch " +
|
||||
|
||||
// Binding forms
|
||||
"let letfn binding loop for doseq dotimes when-let if-let " +
|
||||
|
||||
// Data structures
|
||||
"defstruct struct-map assoc " +
|
||||
|
||||
// clojure.test
|
||||
"testing deftest " +
|
||||
|
||||
// contrib
|
||||
"handler-case handle dotrace deftrace");
|
||||
|
||||
var tests = {
|
||||
digit: /\d/,
|
||||
digit_or_colon: /[\d:]/,
|
||||
hex: /[0-9a-fA-F]/,
|
||||
sign: /[+-]/,
|
||||
exponent: /[eE]/,
|
||||
keyword_char: /[^\s\(\[\;\)\]]/,
|
||||
basic: /[\w\$_\-]/,
|
||||
lang_keyword: /[\w*+!\-_?:\/]/
|
||||
};
|
||||
|
||||
function stateStack(indent, type, prev) { // represents a state stack object
|
||||
this.indent = indent;
|
||||
this.type = type;
|
||||
this.prev = prev;
|
||||
}
|
||||
|
||||
function pushStack(state, indent, type) {
|
||||
state.indentStack = new stateStack(indent, type, state.indentStack);
|
||||
}
|
||||
|
||||
function popStack(state) {
|
||||
state.indentStack = state.indentStack.prev;
|
||||
}
|
||||
|
||||
function isNumber(ch, stream){
|
||||
// hex
|
||||
if ( ch === '0' && 'x' == stream.peek().toLowerCase() ) {
|
||||
stream.eat('x');
|
||||
stream.eatWhile(tests.hex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// leading sign
|
||||
if ( ch == '+' || ch == '-' ) {
|
||||
stream.eat(tests.sign);
|
||||
ch = stream.next();
|
||||
}
|
||||
|
||||
if ( tests.digit.test(ch) ) {
|
||||
stream.eat(ch);
|
||||
stream.eatWhile(tests.digit);
|
||||
|
||||
if ( '.' == stream.peek() ) {
|
||||
stream.eat('.');
|
||||
stream.eatWhile(tests.digit);
|
||||
}
|
||||
|
||||
if ( 'e' == stream.peek().toLowerCase() ) {
|
||||
stream.eat(tests.exponent);
|
||||
stream.eat(tests.sign);
|
||||
stream.eatWhile(tests.digit);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function () {
|
||||
return {
|
||||
indentStack: null,
|
||||
indentation: 0,
|
||||
mode: false
|
||||
};
|
||||
},
|
||||
|
||||
token: function (stream, state) {
|
||||
if (state.indentStack == null && stream.sol()) {
|
||||
// update indentation, but only if indentStack is empty
|
||||
state.indentation = stream.indentation();
|
||||
}
|
||||
|
||||
// skip spaces
|
||||
if (stream.eatSpace()) {
|
||||
return null;
|
||||
}
|
||||
var returnType = null;
|
||||
|
||||
switch(state.mode){
|
||||
case "string": // multi-line string parsing mode
|
||||
var next, escaped = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == "\"" && !escaped) {
|
||||
|
||||
state.mode = false;
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
returnType = STRING; // continue on in string mode
|
||||
break;
|
||||
default: // default parsing mode
|
||||
var ch = stream.next();
|
||||
|
||||
if (ch == "\"") {
|
||||
state.mode = "string";
|
||||
returnType = STRING;
|
||||
} else if (ch == "'" && !( tests.digit_or_colon.test(stream.peek()) )) {
|
||||
returnType = ATOM;
|
||||
} else if (ch == ";") { // comment
|
||||
stream.skipToEnd(); // rest of the line is a comment
|
||||
returnType = COMMENT;
|
||||
} else if (isNumber(ch,stream)){
|
||||
returnType = NUMBER;
|
||||
} else if (ch == "(" || ch == "[") {
|
||||
var keyWord = ''; var indentTemp = stream.column();
|
||||
/**
|
||||
Either
|
||||
(indent-word ..
|
||||
(non-indent-word ..
|
||||
(;something else, bracket, etc.
|
||||
*/
|
||||
|
||||
if (ch == "(") while ((letter = stream.eat(tests.keyword_char)) != null) {
|
||||
keyWord += letter;
|
||||
}
|
||||
|
||||
if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
|
||||
pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
|
||||
} else { // non-indent word
|
||||
// we continue eating the spaces
|
||||
stream.eatSpace();
|
||||
if (stream.eol() || stream.peek() == ";") {
|
||||
// nothing significant after
|
||||
// we restart indentation 1 space after
|
||||
pushStack(state, indentTemp + 1, ch);
|
||||
} else {
|
||||
pushStack(state, indentTemp + stream.current().length, ch); // else we match
|
||||
}
|
||||
}
|
||||
stream.backUp(stream.current().length - 1); // undo all the eating
|
||||
|
||||
returnType = BRACKET;
|
||||
} else if (ch == ")" || ch == "]") {
|
||||
returnType = BRACKET;
|
||||
if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
|
||||
popStack(state);
|
||||
}
|
||||
} else if ( ch == ":" ) {
|
||||
stream.eatWhile(tests.lang_keyword);
|
||||
return ATOM;
|
||||
} else {
|
||||
stream.eatWhile(tests.basic);
|
||||
|
||||
if (keywords && keywords.propertyIsEnumerable(stream.current())) {
|
||||
returnType = KEYWORD;
|
||||
} else if (builtins && builtins.propertyIsEnumerable(stream.current())) {
|
||||
returnType = BUILTIN;
|
||||
} else if (atoms && atoms.propertyIsEnumerable(stream.current())) {
|
||||
returnType = ATOM;
|
||||
} else returnType = null;
|
||||
}
|
||||
}
|
||||
|
||||
return returnType;
|
||||
},
|
||||
|
||||
indent: function (state, textAfter) {
|
||||
if (state.indentStack == null) return state.indentation;
|
||||
return state.indentStack.indent;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-clojure", "clojure");
|
@ -1,66 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Clojure mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="clojure.js"></script>
|
||||
<style>.CodeMirror {background: #f8f8f8;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Clojure mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
; Conway's Game of Life, based on the work of:
|
||||
;; Laurent Petit https://gist.github.com/1200343
|
||||
;; Christophe Grand http://clj-me.cgrand.net/2011/08/19/conways-game-of-life
|
||||
|
||||
(ns ^{:doc "Conway's Game of Life."}
|
||||
game-of-life)
|
||||
|
||||
;; Core game of life's algorithm functions
|
||||
|
||||
(defn neighbours
|
||||
"Given a cell's coordinates, returns the coordinates of its neighbours."
|
||||
[[x y]]
|
||||
(for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
|
||||
[(+ dx x) (+ dy y)]))
|
||||
|
||||
(defn step
|
||||
"Given a set of living cells, computes the new set of living cells."
|
||||
[cells]
|
||||
(set (for [[cell n] (frequencies (mapcat neighbours cells))
|
||||
:when (or (= n 3) (and (= n 2) (cells cell)))]
|
||||
cell)))
|
||||
|
||||
;; Utility methods for displaying game on a text terminal
|
||||
|
||||
(defn print-board
|
||||
"Prints a board on *out*, representing a step in the game."
|
||||
[board w h]
|
||||
(doseq [x (range (inc w)) y (range (inc h))]
|
||||
(if (= y 0) (print "\n"))
|
||||
(print (if (board [x y]) "[X]" " . "))))
|
||||
|
||||
(defn display-grids
|
||||
"Prints a squence of boards on *out*, representing several steps."
|
||||
[grids w h]
|
||||
(doseq [board grids]
|
||||
(print-board board w h)
|
||||
(print "\n")))
|
||||
|
||||
;; Launches an example board
|
||||
|
||||
(def
|
||||
^{:doc "board represents the initial set of living cells"}
|
||||
board #{[2 1] [2 2] [2 3]})
|
||||
|
||||
(display-grids (take 3 (iterate step board)) 5 5) </textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-clojure</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,22 +0,0 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2011 Jeff Pickhardt
|
||||
Modified from the Python CodeMirror mode, Copyright (c) 2010 Timothy Farrell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -1,341 +0,0 @@
|
||||
/**
|
||||
* Link to the project's GitHub page:
|
||||
* https://github.com/pickhardt/coffeescript-codemirror-mode
|
||||
*/
|
||||
CodeMirror.defineMode('coffeescript', function(conf) {
|
||||
var ERRORCLASS = 'error';
|
||||
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
||||
}
|
||||
|
||||
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]");
|
||||
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
|
||||
var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))");
|
||||
var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
||||
var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))");
|
||||
var identifiers = new RegExp("^[_A-Za-z$][_A-Za-z$0-9]*");
|
||||
|
||||
var wordOperators = wordRegexp(['and', 'or', 'not',
|
||||
'is', 'isnt', 'in',
|
||||
'instanceof', 'typeof']);
|
||||
var indentKeywords = ['for', 'while', 'loop', 'if', 'unless', 'else',
|
||||
'switch', 'try', 'catch', 'finally', 'class'];
|
||||
var commonKeywords = ['break', 'by', 'continue', 'debugger', 'delete',
|
||||
'do', 'in', 'of', 'new', 'return', 'then',
|
||||
'this', 'throw', 'when', 'until'];
|
||||
|
||||
var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
|
||||
|
||||
indentKeywords = wordRegexp(indentKeywords);
|
||||
|
||||
|
||||
var stringPrefixes = new RegExp("^('{3}|\"{3}|['\"])");
|
||||
var regexPrefixes = new RegExp("^(/{3}|/)");
|
||||
var commonConstants = ['Infinity', 'NaN', 'undefined', 'null', 'true', 'false', 'on', 'off', 'yes', 'no'];
|
||||
var constants = wordRegexp(commonConstants);
|
||||
|
||||
// Tokenizers
|
||||
function tokenBase(stream, state) {
|
||||
// Handle scope changes
|
||||
if (stream.sol()) {
|
||||
var scopeOffset = state.scopes[0].offset;
|
||||
if (stream.eatSpace()) {
|
||||
var lineOffset = stream.indentation();
|
||||
if (lineOffset > scopeOffset) {
|
||||
return 'indent';
|
||||
} else if (lineOffset < scopeOffset) {
|
||||
return 'dedent';
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
if (scopeOffset > 0) {
|
||||
dedent(stream, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stream.eatSpace()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ch = stream.peek();
|
||||
|
||||
// Handle multi line comments
|
||||
if (stream.match("###")) {
|
||||
state.tokenize = longComment;
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
|
||||
// Single line comment
|
||||
if (ch === '#') {
|
||||
stream.skipToEnd();
|
||||
return 'comment';
|
||||
}
|
||||
|
||||
// Handle number literals
|
||||
if (stream.match(/^-?[0-9\.]/, false)) {
|
||||
var floatLiteral = false;
|
||||
// Floats
|
||||
if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) {
|
||||
floatLiteral = true;
|
||||
}
|
||||
if (stream.match(/^-?\d+\.\d*/)) {
|
||||
floatLiteral = true;
|
||||
}
|
||||
if (stream.match(/^-?\.\d+/)) {
|
||||
floatLiteral = true;
|
||||
}
|
||||
|
||||
if (floatLiteral) {
|
||||
// prevent from getting extra . on 1..
|
||||
if (stream.peek() == "."){
|
||||
stream.backUp(1);
|
||||
}
|
||||
return 'number';
|
||||
}
|
||||
// Integers
|
||||
var intLiteral = false;
|
||||
// Hex
|
||||
if (stream.match(/^-?0x[0-9a-f]+/i)) {
|
||||
intLiteral = true;
|
||||
}
|
||||
// Decimal
|
||||
if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) {
|
||||
intLiteral = true;
|
||||
}
|
||||
// Zero by itself with no other piece of number.
|
||||
if (stream.match(/^-?0(?![\dx])/i)) {
|
||||
intLiteral = true;
|
||||
}
|
||||
if (intLiteral) {
|
||||
return 'number';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle strings
|
||||
if (stream.match(stringPrefixes)) {
|
||||
state.tokenize = tokenFactory(stream.current(), 'string');
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
// Handle regex literals
|
||||
if (stream.match(regexPrefixes)) {
|
||||
if (stream.current() != '/' || stream.match(/^.*\//, false)) { // prevent highlight of division
|
||||
state.tokenize = tokenFactory(stream.current(), 'string-2');
|
||||
return state.tokenize(stream, state);
|
||||
} else {
|
||||
stream.backUp(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle operators and delimiters
|
||||
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
|
||||
return 'punctuation';
|
||||
}
|
||||
if (stream.match(doubleOperators)
|
||||
|| stream.match(singleOperators)
|
||||
|| stream.match(wordOperators)) {
|
||||
return 'operator';
|
||||
}
|
||||
if (stream.match(singleDelimiters)) {
|
||||
return 'punctuation';
|
||||
}
|
||||
|
||||
if (stream.match(constants)) {
|
||||
return 'atom';
|
||||
}
|
||||
|
||||
if (stream.match(keywords)) {
|
||||
return 'keyword';
|
||||
}
|
||||
|
||||
if (stream.match(identifiers)) {
|
||||
return 'variable';
|
||||
}
|
||||
|
||||
// Handle non-detected items
|
||||
stream.next();
|
||||
return ERRORCLASS;
|
||||
}
|
||||
|
||||
function tokenFactory(delimiter, outclass) {
|
||||
var singleline = delimiter.length == 1;
|
||||
return function tokenString(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
stream.eatWhile(/[^'"\/\\]/);
|
||||
if (stream.eat('\\')) {
|
||||
stream.next();
|
||||
if (singleline && stream.eol()) {
|
||||
return outclass;
|
||||
}
|
||||
} else if (stream.match(delimiter)) {
|
||||
state.tokenize = tokenBase;
|
||||
return outclass;
|
||||
} else {
|
||||
stream.eat(/['"\/]/);
|
||||
}
|
||||
}
|
||||
if (singleline) {
|
||||
if (conf.mode.singleLineStringErrors) {
|
||||
outclass = ERRORCLASS
|
||||
} else {
|
||||
state.tokenize = tokenBase;
|
||||
}
|
||||
}
|
||||
return outclass;
|
||||
};
|
||||
}
|
||||
|
||||
function longComment(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
stream.eatWhile(/[^#]/);
|
||||
if (stream.match("###")) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
stream.eatWhile("#");
|
||||
}
|
||||
return "comment"
|
||||
}
|
||||
|
||||
function indent(stream, state, type) {
|
||||
type = type || 'coffee';
|
||||
var indentUnit = 0;
|
||||
if (type === 'coffee') {
|
||||
for (var i = 0; i < state.scopes.length; i++) {
|
||||
if (state.scopes[i].type === 'coffee') {
|
||||
indentUnit = state.scopes[i].offset + conf.indentUnit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
indentUnit = stream.column() + stream.current().length;
|
||||
}
|
||||
state.scopes.unshift({
|
||||
offset: indentUnit,
|
||||
type: type
|
||||
});
|
||||
}
|
||||
|
||||
function dedent(stream, state) {
|
||||
if (state.scopes.length == 1) return;
|
||||
if (state.scopes[0].type === 'coffee') {
|
||||
var _indent = stream.indentation();
|
||||
var _indent_index = -1;
|
||||
for (var i = 0; i < state.scopes.length; ++i) {
|
||||
if (_indent === state.scopes[i].offset) {
|
||||
_indent_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_indent_index === -1) {
|
||||
return true;
|
||||
}
|
||||
while (state.scopes[0].offset !== _indent) {
|
||||
state.scopes.shift();
|
||||
}
|
||||
return false
|
||||
} else {
|
||||
state.scopes.shift();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function tokenLexer(stream, state) {
|
||||
var style = state.tokenize(stream, state);
|
||||
var current = stream.current();
|
||||
|
||||
// Handle '.' connected identifiers
|
||||
if (current === '.') {
|
||||
style = state.tokenize(stream, state);
|
||||
current = stream.current();
|
||||
if (style === 'variable') {
|
||||
return 'variable';
|
||||
} else {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle properties
|
||||
if (current === '@') {
|
||||
stream.eat('@');
|
||||
return 'keyword';
|
||||
}
|
||||
|
||||
// Handle scope changes.
|
||||
if (current === 'return') {
|
||||
state.dedent += 1;
|
||||
}
|
||||
if (((current === '->' || current === '=>') &&
|
||||
!state.lambda &&
|
||||
state.scopes[0].type == 'coffee' &&
|
||||
stream.peek() === '')
|
||||
|| style === 'indent') {
|
||||
indent(stream, state);
|
||||
}
|
||||
var delimiter_index = '[({'.indexOf(current);
|
||||
if (delimiter_index !== -1) {
|
||||
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
|
||||
}
|
||||
if (indentKeywords.exec(current)){
|
||||
indent(stream, state);
|
||||
}
|
||||
if (current == 'then'){
|
||||
dedent(stream, state);
|
||||
}
|
||||
|
||||
|
||||
if (style === 'dedent') {
|
||||
if (dedent(stream, state)) {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
delimiter_index = '])}'.indexOf(current);
|
||||
if (delimiter_index !== -1) {
|
||||
if (dedent(stream, state)) {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'coffee') {
|
||||
if (state.scopes.length > 1) state.scopes.shift();
|
||||
state.dedent -= 1;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
var external = {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: tokenBase,
|
||||
scopes: [{offset:basecolumn || 0, type:'coffee'}],
|
||||
lastToken: null,
|
||||
lambda: false,
|
||||
dedent: 0
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var style = tokenLexer(stream, state);
|
||||
|
||||
state.lastToken = {style:style, content: stream.current()};
|
||||
|
||||
if (stream.eol() && stream.lambda) {
|
||||
state.lambda = false;
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return state.scopes[0].offset;
|
||||
}
|
||||
|
||||
};
|
||||
return external;
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript');
|
@ -1,124 +0,0 @@
|
||||
CodeMirror.defineMode("css", function(config) {
|
||||
var indentUnit = config.indentUnit, type;
|
||||
function ret(style, tp) {type = tp; return style;}
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
|
||||
else if (ch == "/" && stream.eat("*")) {
|
||||
state.tokenize = tokenCComment;
|
||||
return tokenCComment(stream, state);
|
||||
}
|
||||
else if (ch == "<" && stream.eat("!")) {
|
||||
state.tokenize = tokenSGMLComment;
|
||||
return tokenSGMLComment(stream, state);
|
||||
}
|
||||
else if (ch == "=") ret(null, "compare");
|
||||
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
else if (ch == "#") {
|
||||
stream.eatWhile(/[\w\\\-]/);
|
||||
return ret("atom", "hash");
|
||||
}
|
||||
else if (ch == "!") {
|
||||
stream.match(/^\s*\w*/);
|
||||
return ret("keyword", "important");
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w.%]/);
|
||||
return ret("number", "unit");
|
||||
}
|
||||
else if (/[,.+>*\/]/.test(ch)) {
|
||||
return ret(null, "select-op");
|
||||
}
|
||||
else if (/[;{}:\[\]]/.test(ch)) {
|
||||
return ret(null, ch);
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(/[\w\\\-]/);
|
||||
return ret("variable", "variable");
|
||||
}
|
||||
}
|
||||
|
||||
function tokenCComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (maybeEnd && ch == "/") {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
|
||||
function tokenSGMLComment(stream, state) {
|
||||
var dashes = 0, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (dashes >= 2 && ch == ">") {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
dashes = (ch == "-") ? dashes + 1 : 0;
|
||||
}
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == quote && !escaped)
|
||||
break;
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
if (!escaped) state.tokenize = tokenBase;
|
||||
return ret("string", "string");
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function(base) {
|
||||
return {tokenize: tokenBase,
|
||||
baseIndent: base || 0,
|
||||
stack: []};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
|
||||
var context = state.stack[state.stack.length-1];
|
||||
if (type == "hash" && context != "rule") style = "string-2";
|
||||
else if (style == "variable") {
|
||||
if (context == "rule") style = "number";
|
||||
else if (!context || context == "@media{") style = "tag";
|
||||
}
|
||||
|
||||
if (context == "rule" && /^[\{\};]$/.test(type))
|
||||
state.stack.pop();
|
||||
if (type == "{") {
|
||||
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
|
||||
else state.stack.push("{");
|
||||
}
|
||||
else if (type == "}") state.stack.pop();
|
||||
else if (type == "@media") state.stack.push("@media");
|
||||
else if (context == "{" && type != "comment") state.stack.push("rule");
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var n = state.stack.length;
|
||||
if (/^\}/.test(textAfter))
|
||||
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
|
||||
return state.baseIndent + n * indentUnit;
|
||||
},
|
||||
|
||||
electricChars: "}"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/css", "css");
|
@ -1,55 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: CSS mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="css.js"></script>
|
||||
<style>.CodeMirror {background: #f8f8f8;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: CSS mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
/* Some example CSS */
|
||||
|
||||
@import url("something.css");
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 3em 6em;
|
||||
font-family: tahoma, arial, sans-serif;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#navigation a {
|
||||
font-weight: bold;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.7em;
|
||||
}
|
||||
|
||||
h1:before, h2:before {
|
||||
content: "::";
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: courier, monospace;
|
||||
font-size: 80%;
|
||||
color: #418A8A;
|
||||
}
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/css</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,3 +0,0 @@
|
||||
span.cm-rangeinfo {color: #a0b;}
|
||||
span.cm-minus {color: red;}
|
||||
span.cm-plus {color: #2b2;}
|
@ -1,13 +0,0 @@
|
||||
CodeMirror.defineMode("diff", function() {
|
||||
return {
|
||||
token: function(stream) {
|
||||
var ch = stream.next();
|
||||
stream.skipToEnd();
|
||||
if (ch == "+") return "plus";
|
||||
if (ch == "-") return "minus";
|
||||
if (ch == "@") return "rangeinfo";
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-diff", "diff");
|
@ -1,99 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Diff mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="diff.js"></script>
|
||||
<link rel="stylesheet" href="diff.css">
|
||||
<style>.CodeMirror {border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Diff mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
diff --git a/index.html b/index.html
|
||||
index c1d9156..7764744 100644
|
||||
--- a/index.html
|
||||
+++ b/index.html
|
||||
@@ -95,7 +95,8 @@ StringStream.prototype = {
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
- autoMatchBrackets: true
|
||||
+ autoMatchBrackets: true,
|
||||
+ onGutterClick: function(x){console.log(x);}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
diff --git a/lib/codemirror.js b/lib/codemirror.js
|
||||
index 04646a9..9a39cc7 100644
|
||||
--- a/lib/codemirror.js
|
||||
+++ b/lib/codemirror.js
|
||||
@@ -399,10 +399,16 @@ var CodeMirror = (function() {
|
||||
}
|
||||
|
||||
function onMouseDown(e) {
|
||||
- var start = posFromMouse(e), last = start;
|
||||
+ var start = posFromMouse(e), last = start, target = e.target();
|
||||
if (!start) return;
|
||||
setCursor(start.line, start.ch, false);
|
||||
if (e.button() != 1) return;
|
||||
+ if (target.parentNode == gutter) {
|
||||
+ if (options.onGutterClick)
|
||||
+ options.onGutterClick(indexOf(gutter.childNodes, target) + showingFrom);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
if (!focused) onFocus();
|
||||
|
||||
e.stop();
|
||||
@@ -808,7 +814,7 @@ var CodeMirror = (function() {
|
||||
for (var i = showingFrom; i < showingTo; ++i) {
|
||||
var marker = lines[i].gutterMarker;
|
||||
if (marker) html.push('<div class="' + marker.style + '">' + htmlEscape(marker.text) + '</div>');
|
||||
- else html.push("<div>" + (options.lineNumbers ? i + 1 : "\u00a0") + "</div>");
|
||||
+ else html.push("<div>" + (options.lineNumbers ? i + options.firstLineNumber : "\u00a0") + "</div>");
|
||||
}
|
||||
gutter.style.display = "none"; // TODO test whether this actually helps
|
||||
gutter.innerHTML = html.join("");
|
||||
@@ -1371,10 +1377,8 @@ var CodeMirror = (function() {
|
||||
if (option == "parser") setParser(value);
|
||||
else if (option === "lineNumbers") setLineNumbers(value);
|
||||
else if (option === "gutter") setGutter(value);
|
||||
- else if (option === "readOnly") options.readOnly = value;
|
||||
- else if (option === "indentUnit") {options.indentUnit = indentUnit = value; setParser(options.parser);}
|
||||
- else if (/^(?:enterMode|tabMode|indentWithTabs|readOnly|autoMatchBrackets|undoDepth)$/.test(option)) options[option] = value;
|
||||
- else throw new Error("Can't set option " + option);
|
||||
+ else if (option === "indentUnit") {options.indentUnit = value; setParser(options.parser);}
|
||||
+ else options[option] = value;
|
||||
},
|
||||
cursorCoords: cursorCoords,
|
||||
undo: operation(undo),
|
||||
@@ -1402,7 +1406,8 @@ var CodeMirror = (function() {
|
||||
replaceRange: operation(replaceRange),
|
||||
|
||||
operation: function(f){return operation(f)();},
|
||||
- refresh: function(){updateDisplay([{from: 0, to: lines.length}]);}
|
||||
+ refresh: function(){updateDisplay([{from: 0, to: lines.length}]);},
|
||||
+ getInputField: function(){return input;}
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
@@ -1420,6 +1425,7 @@ var CodeMirror = (function() {
|
||||
readOnly: false,
|
||||
onChange: null,
|
||||
onCursorActivity: null,
|
||||
+ onGutterClick: null,
|
||||
autoMatchBrackets: false,
|
||||
workTime: 200,
|
||||
workDelay: 300,
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-diff</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,203 +0,0 @@
|
||||
CodeMirror.defineMode("ecl", function(config) {
|
||||
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
function metaHook(stream, state) {
|
||||
if (!state.startOfLine) return false;
|
||||
stream.skipToEnd();
|
||||
return "meta";
|
||||
}
|
||||
|
||||
function tokenAtString(stream, state) {
|
||||
var next;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == '"' && !stream.eat('"')) {
|
||||
state.tokenize = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "string";
|
||||
}
|
||||
|
||||
var indentUnit = config.indentUnit;
|
||||
var keyword = words("abs acos allnodes ascii asin asstring atan atan2 ave case choose choosen choosesets clustersize combine correlation cos cosh count covariance cron dataset dedup define denormalize distribute distributed distribution ebcdic enth error evaluate event eventextra eventname exists exp failcode failmessage fetch fromunicode getisvalid global graph group hash hash32 hash64 hashcrc hashmd5 having if index intformat isvalid iterate join keyunicode length library limit ln local log loop map matched matchlength matchposition matchtext matchunicode max merge mergejoin min nolocal nonempty normalize parse pipe power preload process project pull random range rank ranked realformat recordof regexfind regexreplace regroup rejected rollup round roundup row rowdiff sample set sin sinh sizeof soapcall sort sorted sqrt stepped stored sum table tan tanh thisnode topn tounicode transfer trim truncate typeof ungroup unicodeorder variance which workunit xmldecode xmlencode xmltext xmlunicode");
|
||||
var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait");
|
||||
var variable_2 = words("__compressed__ all and any as atmost before beginc++ best between case const counter csv descend encrypt end endc++ endmacro except exclusive expire export extend false few first flat from full function group header heading hole ifblock import in interface joined keep keyed last left limit load local locale lookup macro many maxcount maxlength min skew module named nocase noroot noscan nosort not of only opt or outer overwrite packed partition penalty physicallength pipe quote record relationship repeat return right scan self separator service shared skew skip sql store terminator thor threshold token transform trim true type unicodeorder unsorted validate virtual whole wild within xml xpath");
|
||||
var variable_3 = words("ascii big_endian boolean data decimal ebcdic integer pattern qstring real record rule set of string token udecimal unicode unsigned varstring varunicode");
|
||||
var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when");
|
||||
var blockKeywords = words("catch class do else finally for if switch try while");
|
||||
var atoms = words("true false null");
|
||||
var hooks = {"#": metaHook};
|
||||
var multiLineStrings;
|
||||
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
||||
|
||||
var curPunc;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (hooks[ch]) {
|
||||
var result = hooks[ch](stream, state);
|
||||
if (result !== false) return result;
|
||||
}
|
||||
if (ch == '"' || ch == "'") {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null
|
||||
}
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
return "number";
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
}
|
||||
if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
var cur = stream.current().toLowerCase();
|
||||
if (keyword.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "keyword";
|
||||
} else if (variable.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "variable";
|
||||
} else if (variable_2.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "variable-2";
|
||||
} else if (variable_3.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "variable-3";
|
||||
} else if (builtin.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "builtin";
|
||||
} else { //Data types are of from KEYWORD##
|
||||
var i = cur.length - 1;
|
||||
while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
|
||||
--i;
|
||||
|
||||
if (i > 0) {
|
||||
var cur2 = cur.substr(0, i + 1);
|
||||
if (variable_3.propertyIsEnumerable(cur2)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
|
||||
return "variable-3";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
||||
return "word";
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {end = true; break;}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !(escaped || multiLineStrings))
|
||||
state.tokenize = tokenBase;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function Context(indented, column, type, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type) {
|
||||
return state.context = new Context(state.indented, col, type, null, state.context);
|
||||
}
|
||||
function popContext(state) {
|
||||
var t = state.context.type;
|
||||
if (t == ")" || t == "]" || t == "}")
|
||||
state.indented = state.context.indented;
|
||||
return state.context = state.context.prev;
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: null,
|
||||
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
||||
indented: 0,
|
||||
startOfLine: true
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
var style = (state.tokenize || tokenBase)(stream, state);
|
||||
if (style == "comment" || style == "meta") return style;
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
|
||||
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
||||
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
||||
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
||||
else if (curPunc == "}") {
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
if (ctx.type == "}") ctx = popContext(state);
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
}
|
||||
else if (curPunc == ctx.type) popContext(state);
|
||||
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
|
||||
pushContext(state, stream.column(), "statement");
|
||||
state.startOfLine = false;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
|
||||
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
||||
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
||||
var closing = firstChar == ctx.type;
|
||||
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indented + (closing ? 0 : indentUnit);
|
||||
},
|
||||
|
||||
electricChars: "{}"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-ecl");
|
@ -1,108 +0,0 @@
|
||||
CodeMirror.defineMode("gfm", function(config, parserConfig) {
|
||||
var mdMode = CodeMirror.getMode(config, "markdown");
|
||||
var aliases = {
|
||||
html: "htmlmixed",
|
||||
js: "javascript",
|
||||
json: "application/json",
|
||||
c: "text/x-csrc",
|
||||
"c++": "text/x-c++src",
|
||||
java: "text/x-java",
|
||||
csharp: "text/x-csharp",
|
||||
"c#": "text/x-csharp"
|
||||
};
|
||||
|
||||
// make this lazy so that we don't need to load GFM last
|
||||
var getMode = (function () {
|
||||
var i, modes = {}, mimes = {}, mime;
|
||||
|
||||
var list = CodeMirror.listModes();
|
||||
for (i = 0; i < list.length; i++) {
|
||||
modes[list[i]] = list[i];
|
||||
}
|
||||
var mimesList = CodeMirror.listMIMEs();
|
||||
for (i = 0; i < mimesList.length; i++) {
|
||||
mime = mimesList[i].mime;
|
||||
mimes[mime] = mimesList[i].mime;
|
||||
}
|
||||
|
||||
for (var a in aliases) {
|
||||
if (aliases[a] in modes || aliases[a] in mimes)
|
||||
modes[a] = aliases[a];
|
||||
}
|
||||
|
||||
return function (lang) {
|
||||
return modes[lang] ? CodeMirror.getMode(config, modes[lang]) : null;
|
||||
}
|
||||
}());
|
||||
|
||||
function markdown(stream, state) {
|
||||
// intercept fenced code blocks
|
||||
if (stream.sol() && stream.match(/^```([\w+#]*)/)) {
|
||||
// try switching mode
|
||||
state.localMode = getMode(RegExp.$1)
|
||||
if (state.localMode)
|
||||
state.localState = state.localMode.startState();
|
||||
|
||||
state.token = local;
|
||||
return 'code';
|
||||
}
|
||||
|
||||
return mdMode.token(stream, state.mdState);
|
||||
}
|
||||
|
||||
function local(stream, state) {
|
||||
if (stream.sol() && stream.match(/^```/)) {
|
||||
state.localMode = state.localState = null;
|
||||
state.token = markdown;
|
||||
return 'code';
|
||||
}
|
||||
else if (state.localMode) {
|
||||
return state.localMode.token(stream, state.localState);
|
||||
} else {
|
||||
stream.skipToEnd();
|
||||
return 'code';
|
||||
}
|
||||
}
|
||||
|
||||
// custom handleText to prevent emphasis in the middle of a word
|
||||
// and add autolinking
|
||||
function handleText(stream, mdState) {
|
||||
var match;
|
||||
if (stream.match(/^\w+:\/\/\S+/)) {
|
||||
return 'linkhref';
|
||||
}
|
||||
if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) {
|
||||
return mdMode.getType(mdState);
|
||||
}
|
||||
if (match = stream.match(/^[^\[*\\<>` ]+/)) {
|
||||
var word = match[0];
|
||||
if (word[0] === '_' && word[word.length-1] === '_') {
|
||||
stream.backUp(word.length);
|
||||
return undefined;
|
||||
}
|
||||
return mdMode.getType(mdState);
|
||||
}
|
||||
if (stream.eatSpace()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
var mdState = mdMode.startState();
|
||||
mdState.text = handleText;
|
||||
return {token: markdown, mode: "markdown", mdState: mdState,
|
||||
localMode: null, localState: null};
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
return {token: state.token, mode: state.mode, mdState: CodeMirror.copyState(mdMode, state.mdState),
|
||||
localMode: state.localMode,
|
||||
localState: state.localMode ? CodeMirror.copyState(state.localMode, state.localState) : null};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
return state.token(stream, state);
|
||||
}
|
||||
}
|
||||
});
|
@ -1,47 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: GFM mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../xml/xml.js"></script>
|
||||
<script src="../markdown/markdown.js"></script>
|
||||
<script src="gfm.js"></script>
|
||||
<script src="../javascript/javascript.js"></script>
|
||||
<link rel="stylesheet" href="../markdown/markdown.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: GFM mode</h1>
|
||||
|
||||
<!-- source: http://daringfireball.net/projects/markdown/basics.text -->
|
||||
<form><textarea id="code" name="code">
|
||||
Github Flavored Markdown
|
||||
========================
|
||||
|
||||
Everything from markdown plus GFM features:
|
||||
|
||||
## Fenced code blocks
|
||||
|
||||
```javascript
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
console.log(items[i], i); // log them
|
||||
}
|
||||
```
|
||||
|
||||
See http://github.github.com/github-flavored-markdown/
|
||||
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: 'gfm',
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
theme: "default"
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,170 +0,0 @@
|
||||
CodeMirror.defineMode("go", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit;
|
||||
|
||||
var keywords = {
|
||||
"break":true, "case":true, "chan":true, "const":true, "continue":true,
|
||||
"default":true, "defer":true, "else":true, "fallthrough":true, "for":true,
|
||||
"func":true, "go":true, "goto":true, "if":true, "import":true,
|
||||
"interface":true, "map":true, "package":true, "range":true, "return":true,
|
||||
"select":true, "struct":true, "switch":true, "type":true, "var":true,
|
||||
"bool":true, "byte":true, "complex64":true, "complex128":true,
|
||||
"float32":true, "float64":true, "int8":true, "int16":true, "int32":true,
|
||||
"int64":true, "string":true, "uint8":true, "uint16":true, "uint32":true,
|
||||
"uint64":true, "int":true, "uint":true, "uintptr":true
|
||||
};
|
||||
|
||||
var atoms = {
|
||||
"true":true, "false":true, "iota":true, "nil":true, "append":true,
|
||||
"cap":true, "close":true, "complex":true, "copy":true, "imag":true,
|
||||
"len":true, "make":true, "new":true, "panic":true, "print":true,
|
||||
"println":true, "real":true, "recover":true
|
||||
};
|
||||
|
||||
var blockKeywords = {
|
||||
"else":true, "for":true, "func":true, "if":true, "interface":true,
|
||||
"select":true, "struct":true, "switch":true
|
||||
};
|
||||
|
||||
var isOperatorChar = /[+\-*&^%:=<>!|\/]/;
|
||||
|
||||
var curPunc;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == '"' || ch == "'" || ch == "`") {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
if (/[\d\.]/.test(ch)) {
|
||||
if (ch == ".") {
|
||||
stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/);
|
||||
} else if (ch == "0") {
|
||||
stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/);
|
||||
} else {
|
||||
stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/);
|
||||
}
|
||||
return "number";
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
}
|
||||
if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
var cur = stream.current();
|
||||
if (keywords.propertyIsEnumerable(cur)) {
|
||||
if (cur == "case" || cur == "default") curPunc = "case";
|
||||
return "keyword";
|
||||
}
|
||||
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
||||
return "word";
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {end = true; break;}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !(escaped || quote == "`"))
|
||||
state.tokenize = tokenBase;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function Context(indented, column, type, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type) {
|
||||
return state.context = new Context(state.indented, col, type, null, state.context);
|
||||
}
|
||||
function popContext(state) {
|
||||
var t = state.context.type;
|
||||
if (t == ")" || t == "]" || t == "}")
|
||||
state.indented = state.context.indented;
|
||||
return state.context = state.context.prev;
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: null,
|
||||
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
||||
indented: 0,
|
||||
startOfLine: true
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
if (ctx.type == "case") ctx.type = "}";
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
var style = (state.tokenize || tokenBase)(stream, state);
|
||||
if (style == "comment") return style;
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
if (curPunc == "{") pushContext(state, stream.column(), "}");
|
||||
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
||||
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
||||
else if (curPunc == "case") ctx.type = "case"
|
||||
else if (curPunc == "}" && ctx.type == "}") ctx = popContext(state);
|
||||
else if (curPunc == ctx.type) popContext(state);
|
||||
state.startOfLine = false;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
|
||||
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
||||
if (ctx.type == "case" && /^(?:case|default)\b/.test(textAfter)) {
|
||||
state.context.type = "}";
|
||||
return ctx.indented;
|
||||
}
|
||||
var closing = firstChar == ctx.type;
|
||||
if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indented + (closing ? 0 : indentUnit);
|
||||
},
|
||||
|
||||
electricChars: "{}:"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-go", "go");
|
@ -1,72 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Go mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../../theme/elegant.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="go.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style>.CodeMirror {border:1px solid #999; background:#ffc}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Go mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
// Prime Sieve in Go.
|
||||
// Taken from the Go specification.
|
||||
// Copyright © The Go Authors.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Send the sequence 2, 3, 4, ... to channel 'ch'.
|
||||
func generate(ch chan<- int) {
|
||||
for i := 2; ; i++ {
|
||||
ch <- i // Send 'i' to channel 'ch'
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the values from channel 'src' to channel 'dst',
|
||||
// removing those divisible by 'prime'.
|
||||
func filter(src <-chan int, dst chan<- int, prime int) {
|
||||
for i := range src { // Loop over values received from 'src'.
|
||||
if i%prime != 0 {
|
||||
dst <- i // Send 'i' to channel 'dst'.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The prime sieve: Daisy-chain filter processes together.
|
||||
func sieve() {
|
||||
ch := make(chan int) // Create a new channel.
|
||||
go generate(ch) // Start generate() as a subprocess.
|
||||
for {
|
||||
prime := <-ch
|
||||
fmt.Print(prime, "\n")
|
||||
ch1 := make(chan int)
|
||||
go filter(ch, ch1, prime)
|
||||
ch = ch1
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
sieve()
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
theme: "elegant",
|
||||
matchBrackets: true,
|
||||
indentUnit: 8,
|
||||
tabSize: 8,
|
||||
indentWithTabs: true,
|
||||
mode: "text/x-go"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME type:</strong> <code>text/x-go</code></p>
|
||||
</body>
|
||||
</html>
|
@ -1,210 +0,0 @@
|
||||
CodeMirror.defineMode("groovy", function(config, parserConfig) {
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
var keywords = words(
|
||||
"abstract as assert boolean break byte case catch char class const continue def default " +
|
||||
"do double else enum extends final finally float for goto if implements import in " +
|
||||
"instanceof int interface long native new package private protected public return " +
|
||||
"short static strictfp super switch synchronized threadsafe throw throws transient " +
|
||||
"try void volatile while");
|
||||
var blockKeywords = words("catch class do else finally for if switch try while enum interface def");
|
||||
var atoms = words("null true false this");
|
||||
|
||||
var curPunc;
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == '"' || ch == "'") {
|
||||
return startString(ch, stream, state);
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null
|
||||
}
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
if (stream.eat(/eE/)) { stream.eat(/\+\-/); stream.eatWhile(/\d/); }
|
||||
return "number";
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize.push(tokenComment);
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
if (expectExpression(state.lastToken)) {
|
||||
return startString(ch, stream, state);
|
||||
}
|
||||
}
|
||||
if (ch == "-" && stream.eat(">")) {
|
||||
curPunc = "->";
|
||||
return null;
|
||||
}
|
||||
if (/[+\-*&%=<>!?|\/~]/.test(ch)) {
|
||||
stream.eatWhile(/[+\-*&%=<>|~]/);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
if (ch == "@") { stream.eatWhile(/[\w\$_\.]/); return "meta"; }
|
||||
if (state.lastToken == ".") return "property";
|
||||
if (stream.eat(":")) { curPunc = "proplabel"; return "property"; }
|
||||
var cur = stream.current();
|
||||
if (atoms.propertyIsEnumerable(cur)) { return "atom"; }
|
||||
if (keywords.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "keyword";
|
||||
}
|
||||
return "word";
|
||||
}
|
||||
tokenBase.isBase = true;
|
||||
|
||||
function startString(quote, stream, state) {
|
||||
var tripleQuoted = false;
|
||||
if (quote != "/" && stream.eat(quote)) {
|
||||
if (stream.eat(quote)) tripleQuoted = true;
|
||||
else return "string";
|
||||
}
|
||||
function t(stream, state) {
|
||||
var escaped = false, next, end = !tripleQuoted;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {
|
||||
if (!tripleQuoted) { break; }
|
||||
if (stream.match(quote + quote)) { end = true; break; }
|
||||
}
|
||||
if (quote == '"' && next == "$" && !escaped && stream.eat("{")) {
|
||||
state.tokenize.push(tokenBaseUntilBrace());
|
||||
return "string";
|
||||
}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end) state.tokenize.pop();
|
||||
return "string";
|
||||
}
|
||||
state.tokenize.push(t);
|
||||
return t(stream, state);
|
||||
}
|
||||
|
||||
function tokenBaseUntilBrace() {
|
||||
var depth = 1;
|
||||
function t(stream, state) {
|
||||
if (stream.peek() == "}") {
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
state.tokenize.pop();
|
||||
return state.tokenize[state.tokenize.length-1](stream, state);
|
||||
}
|
||||
} else if (stream.peek() == "{") {
|
||||
depth++;
|
||||
}
|
||||
return tokenBase(stream, state);
|
||||
}
|
||||
t.isBase = true;
|
||||
return t;
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize.pop();
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function expectExpression(last) {
|
||||
return !last || last == "operator" || last == "->" || /[\.\[\{\(,;:]/.test(last) ||
|
||||
last == "newstatement" || last == "keyword" || last == "proplabel";
|
||||
}
|
||||
|
||||
function Context(indented, column, type, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type) {
|
||||
return state.context = new Context(state.indented, col, type, null, state.context);
|
||||
}
|
||||
function popContext(state) {
|
||||
var t = state.context.type;
|
||||
if (t == ")" || t == "]" || t == "}")
|
||||
state.indented = state.context.indented;
|
||||
return state.context = state.context.prev;
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: [tokenBase],
|
||||
context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
|
||||
indented: 0,
|
||||
startOfLine: true,
|
||||
lastToken: null
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
// Automatic semicolon insertion
|
||||
if (ctx.type == "statement" && !expectExpression(state.lastToken)) {
|
||||
popContext(state); ctx = state.context;
|
||||
}
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
var style = state.tokenize[state.tokenize.length-1](stream, state);
|
||||
if (style == "comment") return style;
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
|
||||
// Handle indentation for {x -> \n ... }
|
||||
else if (curPunc == "->" && ctx.type == "statement" && ctx.prev.type == "}") {
|
||||
popContext(state);
|
||||
state.context.align = false;
|
||||
}
|
||||
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
||||
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
||||
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
||||
else if (curPunc == "}") {
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
if (ctx.type == "}") ctx = popContext(state);
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
}
|
||||
else if (curPunc == ctx.type) popContext(state);
|
||||
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
|
||||
pushContext(state, stream.column(), "statement");
|
||||
state.startOfLine = false;
|
||||
state.lastToken = curPunc || style;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (!state.tokenize[state.tokenize.length-1].isBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), ctx = state.context;
|
||||
if (ctx.type == "statement" && !expectExpression(state.lastToken)) ctx = ctx.prev;
|
||||
var closing = firstChar == ctx.type;
|
||||
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : config.indentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indented + (closing ? 0 : config.indentUnit);
|
||||
},
|
||||
|
||||
electricChars: "{}"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-groovy", "groovy");
|
@ -1,71 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Groovy mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="groovy.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style>.CodeMirror {border-top: 1px solid #500; border-bottom: 1px solid #500;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Groovy mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
//Pattern for groovy script
|
||||
def p = ~/.*\.groovy/
|
||||
new File( 'd:\\scripts' ).eachFileMatch(p) {f ->
|
||||
// imports list
|
||||
def imports = []
|
||||
f.eachLine {
|
||||
// condition to detect an import instruction
|
||||
ln -> if ( ln =~ '^import .*' ) {
|
||||
imports << "${ln - 'import '}"
|
||||
}
|
||||
}
|
||||
// print thmen
|
||||
if ( ! imports.empty ) {
|
||||
println f
|
||||
imports.each{ println " $it" }
|
||||
}
|
||||
}
|
||||
|
||||
/* Coin changer demo code from http://groovy.codehaus.org */
|
||||
|
||||
enum UsCoin {
|
||||
quarter(25), dime(10), nickel(5), penny(1)
|
||||
UsCoin(v) { value = v }
|
||||
final value
|
||||
}
|
||||
|
||||
enum OzzieCoin {
|
||||
fifty(50), twenty(20), ten(10), five(5)
|
||||
OzzieCoin(v) { value = v }
|
||||
final value
|
||||
}
|
||||
|
||||
def plural(word, count) {
|
||||
if (count == 1) return word
|
||||
word[-1] == 'y' ? word[0..-2] + "ies" : word + "s"
|
||||
}
|
||||
|
||||
def change(currency, amount) {
|
||||
currency.values().inject([]){ list, coin ->
|
||||
int count = amount / coin.value
|
||||
amount = amount % coin.value
|
||||
list += "$count ${plural(coin.toString(), count)}"
|
||||
}
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "text/x-groovy"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-groovy</code></p>
|
||||
</body>
|
||||
</html>
|
@ -1,242 +0,0 @@
|
||||
CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
|
||||
|
||||
function switchState(source, setState, f) {
|
||||
setState(f);
|
||||
return f(source, setState);
|
||||
}
|
||||
|
||||
// These should all be Unicode extended, as per the Haskell 2010 report
|
||||
var smallRE = /[a-z_]/;
|
||||
var largeRE = /[A-Z]/;
|
||||
var digitRE = /[0-9]/;
|
||||
var hexitRE = /[0-9A-Fa-f]/;
|
||||
var octitRE = /[0-7]/;
|
||||
var idRE = /[a-z_A-Z0-9']/;
|
||||
var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;
|
||||
var specialRE = /[(),;[\]`{}]/;
|
||||
var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer
|
||||
|
||||
function normal(source, setState) {
|
||||
if (source.eatWhile(whiteCharRE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ch = source.next();
|
||||
if (specialRE.test(ch)) {
|
||||
if (ch == '{' && source.eat('-')) {
|
||||
var t = "comment";
|
||||
if (source.eat('#')) {
|
||||
t = "meta";
|
||||
}
|
||||
return switchState(source, setState, ncomment(t, 1));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ch == '\'') {
|
||||
if (source.eat('\\')) {
|
||||
source.next(); // should handle other escapes here
|
||||
}
|
||||
else {
|
||||
source.next();
|
||||
}
|
||||
if (source.eat('\'')) {
|
||||
return "string";
|
||||
}
|
||||
return "error";
|
||||
}
|
||||
|
||||
if (ch == '"') {
|
||||
return switchState(source, setState, stringLiteral);
|
||||
}
|
||||
|
||||
if (largeRE.test(ch)) {
|
||||
source.eatWhile(idRE);
|
||||
if (source.eat('.')) {
|
||||
return "qualifier";
|
||||
}
|
||||
return "variable-2";
|
||||
}
|
||||
|
||||
if (smallRE.test(ch)) {
|
||||
source.eatWhile(idRE);
|
||||
return "variable";
|
||||
}
|
||||
|
||||
if (digitRE.test(ch)) {
|
||||
if (ch == '0') {
|
||||
if (source.eat(/[xX]/)) {
|
||||
source.eatWhile(hexitRE); // should require at least 1
|
||||
return "integer";
|
||||
}
|
||||
if (source.eat(/[oO]/)) {
|
||||
source.eatWhile(octitRE); // should require at least 1
|
||||
return "number";
|
||||
}
|
||||
}
|
||||
source.eatWhile(digitRE);
|
||||
var t = "number";
|
||||
if (source.eat('.')) {
|
||||
t = "number";
|
||||
source.eatWhile(digitRE); // should require at least 1
|
||||
}
|
||||
if (source.eat(/[eE]/)) {
|
||||
t = "number";
|
||||
source.eat(/[-+]/);
|
||||
source.eatWhile(digitRE); // should require at least 1
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
if (symbolRE.test(ch)) {
|
||||
if (ch == '-' && source.eat(/-/)) {
|
||||
source.eatWhile(/-/);
|
||||
if (!source.eat(symbolRE)) {
|
||||
source.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
}
|
||||
var t = "variable";
|
||||
if (ch == ':') {
|
||||
t = "variable-2";
|
||||
}
|
||||
source.eatWhile(symbolRE);
|
||||
return t;
|
||||
}
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
function ncomment(type, nest) {
|
||||
if (nest == 0) {
|
||||
return normal;
|
||||
}
|
||||
return function(source, setState) {
|
||||
var currNest = nest;
|
||||
while (!source.eol()) {
|
||||
var ch = source.next();
|
||||
if (ch == '{' && source.eat('-')) {
|
||||
++currNest;
|
||||
}
|
||||
else if (ch == '-' && source.eat('}')) {
|
||||
--currNest;
|
||||
if (currNest == 0) {
|
||||
setState(normal);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
setState(ncomment(type, currNest));
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
function stringLiteral(source, setState) {
|
||||
while (!source.eol()) {
|
||||
var ch = source.next();
|
||||
if (ch == '"') {
|
||||
setState(normal);
|
||||
return "string";
|
||||
}
|
||||
if (ch == '\\') {
|
||||
if (source.eol() || source.eat(whiteCharRE)) {
|
||||
setState(stringGap);
|
||||
return "string";
|
||||
}
|
||||
if (source.eat('&')) {
|
||||
}
|
||||
else {
|
||||
source.next(); // should handle other escapes here
|
||||
}
|
||||
}
|
||||
}
|
||||
setState(normal);
|
||||
return "error";
|
||||
}
|
||||
|
||||
function stringGap(source, setState) {
|
||||
if (source.eat('\\')) {
|
||||
return switchState(source, setState, stringLiteral);
|
||||
}
|
||||
source.next();
|
||||
setState(normal);
|
||||
return "error";
|
||||
}
|
||||
|
||||
|
||||
var wellKnownWords = (function() {
|
||||
var wkw = {};
|
||||
function setType(t) {
|
||||
return function () {
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
wkw[arguments[i]] = t;
|
||||
}
|
||||
}
|
||||
|
||||
setType("keyword")(
|
||||
"case", "class", "data", "default", "deriving", "do", "else", "foreign",
|
||||
"if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
|
||||
"module", "newtype", "of", "then", "type", "where", "_");
|
||||
|
||||
setType("keyword")(
|
||||
"\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");
|
||||
|
||||
setType("builtin")(
|
||||
"!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",
|
||||
"==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");
|
||||
|
||||
setType("builtin")(
|
||||
"Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",
|
||||
"False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",
|
||||
"IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",
|
||||
"Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
|
||||
"ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
|
||||
"String", "True");
|
||||
|
||||
setType("builtin")(
|
||||
"abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
|
||||
"asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
|
||||
"compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
|
||||
"cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
|
||||
"elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
|
||||
"enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
|
||||
"flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
|
||||
"foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
|
||||
"fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
|
||||
"getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
|
||||
"isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
|
||||
"lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
|
||||
"mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
|
||||
"minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
|
||||
"otherwise", "pi", "pred", "print", "product", "properFraction",
|
||||
"putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
|
||||
"readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
|
||||
"realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
|
||||
"round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
|
||||
"sequence", "sequence_", "show", "showChar", "showList", "showParen",
|
||||
"showString", "shows", "showsPrec", "significand", "signum", "sin",
|
||||
"sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
|
||||
"tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
|
||||
"toRational", "truncate", "uncurry", "undefined", "unlines", "until",
|
||||
"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
|
||||
"zip3", "zipWith", "zipWith3");
|
||||
|
||||
return wkw;
|
||||
})();
|
||||
|
||||
|
||||
|
||||
return {
|
||||
startState: function () { return { f: normal }; },
|
||||
copyState: function (s) { return { f: s.f }; },
|
||||
|
||||
token: function(stream, state) {
|
||||
var t = state.f(stream, function(s) { state.f = s; });
|
||||
var w = stream.current();
|
||||
return (w in wellKnownWords) ? wellKnownWords[w] : t;
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-haskell", "haskell");
|
@ -1,60 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Haskell mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="haskell.js"></script>
|
||||
<link rel="stylesheet" href="../../theme/elegant.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Haskell mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
module UniquePerms (
|
||||
uniquePerms
|
||||
)
|
||||
where
|
||||
|
||||
-- | Find all unique permutations of a list where there might be duplicates.
|
||||
uniquePerms :: (Eq a) => [a] -> [[a]]
|
||||
uniquePerms = permBag . makeBag
|
||||
|
||||
-- | An unordered collection where duplicate values are allowed,
|
||||
-- but represented with a single value and a count.
|
||||
type Bag a = [(a, Int)]
|
||||
|
||||
makeBag :: (Eq a) => [a] -> Bag a
|
||||
makeBag [] = []
|
||||
makeBag (a:as) = mix a $ makeBag as
|
||||
where
|
||||
mix a [] = [(a,1)]
|
||||
mix a (bn@(b,n):bs) | a == b = (b,n+1):bs
|
||||
| otherwise = bn : mix a bs
|
||||
|
||||
permBag :: Bag a -> [[a]]
|
||||
permBag [] = [[]]
|
||||
permBag bs = concatMap (\(f,cs) -> map (f:) $ permBag cs) . oneOfEach $ bs
|
||||
where
|
||||
oneOfEach [] = []
|
||||
oneOfEach (an@(a,n):bs) =
|
||||
let bs' = if n == 1 then bs else (a,n-1):bs
|
||||
in (a,bs') : mapSnd (an:) (oneOfEach bs)
|
||||
|
||||
apSnd f (a,b) = (a, f b)
|
||||
mapSnd = map . apSnd
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
theme: "elegant"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-haskell</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,68 +0,0 @@
|
||||
CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
|
||||
|
||||
//config settings
|
||||
var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
|
||||
scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
|
||||
|
||||
//inner modes
|
||||
var scriptingMode, htmlMixedMode;
|
||||
|
||||
//tokenizer when in html mode
|
||||
function htmlDispatch(stream, state) {
|
||||
if (stream.match(scriptStartRegex, false)) {
|
||||
state.token=scriptingDispatch;
|
||||
return scriptingMode.token(stream, state.scriptState);
|
||||
}
|
||||
else
|
||||
return htmlMixedMode.token(stream, state.htmlState);
|
||||
}
|
||||
|
||||
//tokenizer when in scripting mode
|
||||
function scriptingDispatch(stream, state) {
|
||||
if (stream.match(scriptEndRegex, false)) {
|
||||
state.token=htmlDispatch;
|
||||
return htmlMixedMode.token(stream, state.htmlState);
|
||||
}
|
||||
else
|
||||
return scriptingMode.token(stream, state.scriptState);
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
|
||||
htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
|
||||
return {
|
||||
token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
|
||||
htmlState : htmlMixedMode.startState(),
|
||||
scriptState : scriptingMode.startState()
|
||||
}
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
return state.token(stream, state);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.token == htmlDispatch)
|
||||
return htmlMixedMode.indent(state.htmlState, textAfter);
|
||||
else
|
||||
return scriptingMode.indent(state.scriptState, textAfter);
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
return {
|
||||
token : state.token,
|
||||
htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
|
||||
scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
electricChars: "/{}:"
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
|
||||
CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
|
||||
CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
|
@ -1,49 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Html Embedded Scripts mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../xml/xml.js"></script>
|
||||
<script src="../javascript/javascript.js"></script>
|
||||
<script src="../css/css.js"></script>
|
||||
<script src="../htmlmixed/htmlmixed.js"></script>
|
||||
<script src="htmlembedded.js"></script>
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Html Embedded Scripts mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
<%
|
||||
function hello(who) {
|
||||
return "Hello " + who;
|
||||
}
|
||||
%>
|
||||
This is an example of EJS (embedded javascript)
|
||||
<p>The program says <%= hello("world") %>.</p>
|
||||
<script>
|
||||
alert("And here is some normal JS code"); // also colored
|
||||
</script>
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "application/x-ejs",
|
||||
indentUnit: 4,
|
||||
indentWithTabs: true,
|
||||
enterMode: "keep",
|
||||
tabMode: "shift"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Mode for html embedded scripts like JSP and ASP.NET. Depends on HtmlMixed which in turn depends on
|
||||
JavaScript, CSS and XML.<br />Other dependancies include those of the scriping language chosen.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>application/x-aspx</code> (ASP.NET),
|
||||
<code>application/x-ejs</code> (Embedded Javascript), <code>application/x-jsp</code> (JavaServer Pages)</p>
|
||||
</body>
|
||||
</html>
|
@ -1,83 +0,0 @@
|
||||
CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
|
||||
var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
|
||||
var jsMode = CodeMirror.getMode(config, "javascript");
|
||||
var cssMode = CodeMirror.getMode(config, "css");
|
||||
|
||||
function html(stream, state) {
|
||||
var style = htmlMode.token(stream, state.htmlState);
|
||||
if (style == "tag" && stream.current() == ">" && state.htmlState.context) {
|
||||
if (/^script$/i.test(state.htmlState.context.tagName)) {
|
||||
state.token = javascript;
|
||||
state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
|
||||
state.mode = "javascript";
|
||||
}
|
||||
else if (/^style$/i.test(state.htmlState.context.tagName)) {
|
||||
state.token = css;
|
||||
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
|
||||
state.mode = "css";
|
||||
}
|
||||
}
|
||||
return style;
|
||||
}
|
||||
function maybeBackup(stream, pat, style) {
|
||||
var cur = stream.current();
|
||||
var close = cur.search(pat);
|
||||
if (close > -1) stream.backUp(cur.length - close);
|
||||
return style;
|
||||
}
|
||||
function javascript(stream, state) {
|
||||
if (stream.match(/^<\/\s*script\s*>/i, false)) {
|
||||
state.token = html;
|
||||
state.localState = null;
|
||||
state.mode = "html";
|
||||
return html(stream, state);
|
||||
}
|
||||
return maybeBackup(stream, /<\/\s*script\s*>/,
|
||||
jsMode.token(stream, state.localState));
|
||||
}
|
||||
function css(stream, state) {
|
||||
if (stream.match(/^<\/\s*style\s*>/i, false)) {
|
||||
state.token = html;
|
||||
state.localState = null;
|
||||
state.mode = "html";
|
||||
return html(stream, state);
|
||||
}
|
||||
return maybeBackup(stream, /<\/\s*style\s*>/,
|
||||
cssMode.token(stream, state.localState));
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
var state = htmlMode.startState();
|
||||
return {token: html, localState: null, mode: "html", htmlState: state};
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
if (state.localState)
|
||||
var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
|
||||
return {token: state.token, localState: local, mode: state.mode,
|
||||
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
return state.token(stream, state);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.token == html || /^\s*<\//.test(textAfter))
|
||||
return htmlMode.indent(state.htmlState, textAfter);
|
||||
else if (state.token == javascript)
|
||||
return jsMode.indent(state.localState, textAfter);
|
||||
else
|
||||
return cssMode.indent(state.localState, textAfter);
|
||||
},
|
||||
|
||||
compareStates: function(a, b) {
|
||||
return htmlMode.compareStates(a.htmlState, b.htmlState);
|
||||
},
|
||||
|
||||
electricChars: "/{}:"
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/html", "htmlmixed");
|
@ -1,51 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: HTML mixed mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../xml/xml.js"></script>
|
||||
<script src="../javascript/javascript.js"></script>
|
||||
<script src="../css/css.js"></script>
|
||||
<script src="htmlmixed.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: HTML mixed mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
<html style="color: green">
|
||||
<!-- this is a comment -->
|
||||
<head>
|
||||
<title>Mixed HTML Example</title>
|
||||
<style type="text/css">
|
||||
h1 {font-family: comic sans; color: #f0f;}
|
||||
div {background: yellow !important;}
|
||||
body {
|
||||
max-width: 50em;
|
||||
margin: 1em 2em 1em 5em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mixed HTML Example</h1>
|
||||
<script>
|
||||
function jsFunc(arg1, arg2) {
|
||||
if (arg1 && arg2) document.body.innerHTML = "achoo";
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: "text/html", tabMode: "indent"});
|
||||
</script>
|
||||
|
||||
<p>The HTML mixed mode depends on the XML, JavaScript, and CSS modes.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/html</code>
|
||||
(redefined, only takes effect if you load this parser after the
|
||||
XML parser).</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,77 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: JavaScript mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="javascript.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: JavaScript mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
// Demo code (the actual new parser character stream implementation)
|
||||
|
||||
function StringStream(string) {
|
||||
this.pos = 0;
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
StringStream.prototype = {
|
||||
done: function() {return this.pos >= this.string.length;},
|
||||
peek: function() {return this.string.charAt(this.pos);},
|
||||
next: function() {
|
||||
if (this.pos < this.string.length)
|
||||
return this.string.charAt(this.pos++);
|
||||
},
|
||||
eat: function(match) {
|
||||
var ch = this.string.charAt(this.pos);
|
||||
if (typeof match == "string") var ok = ch == match;
|
||||
else var ok = ch && match.test ? match.test(ch) : match(ch);
|
||||
if (ok) {this.pos++; return ch;}
|
||||
},
|
||||
eatWhile: function(match) {
|
||||
var start = this.pos;
|
||||
while (this.eat(match));
|
||||
if (this.pos > start) return this.string.slice(start, this.pos);
|
||||
},
|
||||
backUp: function(n) {this.pos -= n;},
|
||||
column: function() {return this.pos;},
|
||||
eatSpace: function() {
|
||||
var start = this.pos;
|
||||
while (/\s/.test(this.string.charAt(this.pos))) this.pos++;
|
||||
return this.pos - start;
|
||||
},
|
||||
match: function(pattern, consume, caseInsensitive) {
|
||||
if (typeof pattern == "string") {
|
||||
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
||||
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
|
||||
if (consume !== false) this.pos += str.length;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
var match = this.string.slice(this.pos).match(pattern);
|
||||
if (match && consume !== false) this.pos += match[0].length;
|
||||
return match;
|
||||
}
|
||||
}
|
||||
};
|
||||
</textarea></div>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>JavaScript mode supports a single configuration
|
||||
option, <code>json</code>, which will set the mode to expect JSON
|
||||
data rather than a JavaScript program.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/javascript</code>, <code>application/json</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,360 +0,0 @@
|
||||
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit;
|
||||
var jsonMode = parserConfig.json;
|
||||
|
||||
// Tokenizer
|
||||
|
||||
var keywords = function(){
|
||||
function kw(type) {return {type: type, style: "keyword"};}
|
||||
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
||||
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
||||
return {
|
||||
"if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
||||
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
|
||||
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
||||
"function": kw("function"), "catch": kw("catch"),
|
||||
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
|
||||
};
|
||||
}();
|
||||
|
||||
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
||||
|
||||
function chain(stream, state, f) {
|
||||
state.tokenize = f;
|
||||
return f(stream, state);
|
||||
}
|
||||
|
||||
function nextUntilUnescaped(stream, end) {
|
||||
var escaped = false, next;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// 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 jsTokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == '"' || ch == "'")
|
||||
return chain(stream, state, jsTokenString(ch));
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return ret(ch);
|
||||
else if (ch == "0" && stream.eat(/x/i)) {
|
||||
stream.eatWhile(/[\da-f]/i);
|
||||
return ret("number", "number");
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
|
||||
return ret("number", "number");
|
||||
}
|
||||
else if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
return chain(stream, state, jsTokenComment);
|
||||
}
|
||||
else if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
else if (state.reAllowed) {
|
||||
nextUntilUnescaped(stream, "/");
|
||||
stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
|
||||
return ret("regexp", "string-2");
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return ret("operator", null, stream.current());
|
||||
}
|
||||
}
|
||||
else if (ch == "#") {
|
||||
stream.skipToEnd();
|
||||
return ret("error", "error");
|
||||
}
|
||||
else if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return ret("operator", null, stream.current());
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return (known && state.kwAllowed) ? ret(known.type, known.style, word) :
|
||||
ret("variable", "variable", word);
|
||||
}
|
||||
}
|
||||
|
||||
function jsTokenString(quote) {
|
||||
return function(stream, state) {
|
||||
if (!nextUntilUnescaped(stream, quote))
|
||||
state.tokenize = jsTokenBase;
|
||||
return ret("string", "string");
|
||||
};
|
||||
}
|
||||
|
||||
function jsTokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = jsTokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
|
||||
// Parser
|
||||
|
||||
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
|
||||
|
||||
function JSLexical(indented, column, type, align, prev, info) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
if (align != null) this.align = align;
|
||||
}
|
||||
|
||||
function inScope(state, varname) {
|
||||
for (var v = state.localVars; v; v = v.next)
|
||||
if (v.name == varname) return true;
|
||||
}
|
||||
|
||||
function parseJS(state, style, type, content, stream) {
|
||||
var cc = state.cc;
|
||||
// Communicate our context to the combinators.
|
||||
// (Less wasteful than consing up a hundred closures on every call.)
|
||||
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
|
||||
|
||||
if (!state.lexical.hasOwnProperty("align"))
|
||||
state.lexical.align = true;
|
||||
|
||||
while(true) {
|
||||
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
||||
if (combinator(type, content)) {
|
||||
while(cc.length && cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
if (cx.marked) return cx.marked;
|
||||
if (type == "variable" && inScope(state, content)) return "variable-2";
|
||||
return style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combinator utils
|
||||
|
||||
var cx = {state: null, column: null, marked: null, cc: null};
|
||||
function pass() {
|
||||
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
||||
}
|
||||
function cont() {
|
||||
pass.apply(null, arguments);
|
||||
return true;
|
||||
}
|
||||
function register(varname) {
|
||||
var state = cx.state;
|
||||
if (state.context) {
|
||||
cx.marked = "def";
|
||||
for (var v = state.localVars; v; v = v.next)
|
||||
if (v.name == varname) return;
|
||||
state.localVars = {name: varname, next: state.localVars};
|
||||
}
|
||||
}
|
||||
|
||||
// Combinators
|
||||
|
||||
var defaultVars = {name: "this", next: {name: "arguments"}};
|
||||
function pushcontext() {
|
||||
if (!cx.state.context) cx.state.localVars = defaultVars;
|
||||
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
||||
}
|
||||
function popcontext() {
|
||||
cx.state.localVars = cx.state.context.vars;
|
||||
cx.state.context = cx.state.context.prev;
|
||||
}
|
||||
function pushlex(type, info) {
|
||||
var result = function() {
|
||||
var state = cx.state;
|
||||
state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
function poplex() {
|
||||
var state = cx.state;
|
||||
if (state.lexical.prev) {
|
||||
if (state.lexical.type == ")")
|
||||
state.indented = state.lexical.indented;
|
||||
state.lexical = state.lexical.prev;
|
||||
}
|
||||
}
|
||||
poplex.lex = true;
|
||||
|
||||
function expect(wanted) {
|
||||
return function expecting(type) {
|
||||
if (type == wanted) return cont();
|
||||
else if (wanted == ";") return pass();
|
||||
else return cont(arguments.callee);
|
||||
};
|
||||
}
|
||||
|
||||
function statement(type) {
|
||||
if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex);
|
||||
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
|
||||
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
||||
if (type == "{") return cont(pushlex("}"), block, poplex);
|
||||
if (type == ";") return cont();
|
||||
if (type == "function") return cont(functiondef);
|
||||
if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"),
|
||||
poplex, statement, poplex);
|
||||
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
||||
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
|
||||
block, poplex, poplex);
|
||||
if (type == "case") return cont(expression, expect(":"));
|
||||
if (type == "default") return cont(expect(":"));
|
||||
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
||||
statement, poplex, popcontext);
|
||||
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||
}
|
||||
function expression(type) {
|
||||
if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
|
||||
if (type == "function") return cont(functiondef);
|
||||
if (type == "keyword c") return cont(maybeexpression);
|
||||
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeoperator);
|
||||
if (type == "operator") return cont(expression);
|
||||
if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
||||
if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
||||
return cont();
|
||||
}
|
||||
function maybeexpression(type) {
|
||||
if (type.match(/[;\}\)\],]/)) return pass();
|
||||
return pass(expression);
|
||||
}
|
||||
|
||||
function maybeoperator(type, value) {
|
||||
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
|
||||
if (type == "operator") return cont(expression);
|
||||
if (type == ";") return;
|
||||
if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
|
||||
if (type == ".") return cont(property, maybeoperator);
|
||||
if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
||||
}
|
||||
function maybelabel(type) {
|
||||
if (type == ":") return cont(poplex, statement);
|
||||
return pass(maybeoperator, expect(";"), poplex);
|
||||
}
|
||||
function property(type) {
|
||||
if (type == "variable") {cx.marked = "property"; return cont();}
|
||||
}
|
||||
function objprop(type) {
|
||||
if (type == "variable") cx.marked = "property";
|
||||
if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression);
|
||||
}
|
||||
function commasep(what, end) {
|
||||
function proceed(type) {
|
||||
if (type == ",") return cont(what, proceed);
|
||||
if (type == end) return cont();
|
||||
return cont(expect(end));
|
||||
}
|
||||
return function commaSeparated(type) {
|
||||
if (type == end) return cont();
|
||||
else return pass(what, proceed);
|
||||
};
|
||||
}
|
||||
function block(type) {
|
||||
if (type == "}") return cont();
|
||||
return pass(statement, block);
|
||||
}
|
||||
function vardef1(type, value) {
|
||||
if (type == "variable"){register(value); return cont(vardef2);}
|
||||
return cont();
|
||||
}
|
||||
function vardef2(type, value) {
|
||||
if (value == "=") return cont(expression, vardef2);
|
||||
if (type == ",") return cont(vardef1);
|
||||
}
|
||||
function forspec1(type) {
|
||||
if (type == "var") return cont(vardef1, forspec2);
|
||||
if (type == ";") return pass(forspec2);
|
||||
if (type == "variable") return cont(formaybein);
|
||||
return pass(forspec2);
|
||||
}
|
||||
function formaybein(type, value) {
|
||||
if (value == "in") return cont(expression);
|
||||
return cont(maybeoperator, forspec2);
|
||||
}
|
||||
function forspec2(type, value) {
|
||||
if (type == ";") return cont(forspec3);
|
||||
if (value == "in") return cont(expression);
|
||||
return cont(expression, expect(";"), forspec3);
|
||||
}
|
||||
function forspec3(type) {
|
||||
if (type != ")") cont(expression);
|
||||
}
|
||||
function functiondef(type, value) {
|
||||
if (type == "variable") {register(value); return cont(functiondef);}
|
||||
if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, statement, popcontext);
|
||||
}
|
||||
function funarg(type, value) {
|
||||
if (type == "variable") {register(value); return cont();}
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: jsTokenBase,
|
||||
reAllowed: true,
|
||||
kwAllowed: true,
|
||||
cc: [],
|
||||
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
||||
localVars: parserConfig.localVars,
|
||||
context: parserConfig.localVars && {vars: parserConfig.localVars},
|
||||
indented: 0
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) {
|
||||
if (!state.lexical.hasOwnProperty("align"))
|
||||
state.lexical.align = false;
|
||||
state.indented = stream.indentation();
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
if (type == "comment") return style;
|
||||
state.reAllowed = !!(type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/));
|
||||
state.kwAllowed = type != '.';
|
||||
return parseJS(state, style, type, content, stream);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != jsTokenBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
|
||||
type = lexical.type, closing = firstChar == type;
|
||||
if (type == "vardef") return lexical.indented + 4;
|
||||
else if (type == "form" && firstChar == "{") return lexical.indented;
|
||||
else if (type == "stat" || type == "form") return lexical.indented + indentUnit;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
||||
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
||||
else return lexical.indented + (closing ? 0 : indentUnit);
|
||||
},
|
||||
|
||||
electricChars: ":{}"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/javascript", "javascript");
|
||||
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
@ -1,37 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Jinja2 mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="jinja2.js"></script>
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Jinja2 mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
<html style="color: green">
|
||||
<!-- this is a comment -->
|
||||
<head>
|
||||
<title>Jinja2 Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<ul>
|
||||
{# this is a comment #}
|
||||
{%- for item in li -%}
|
||||
<li>
|
||||
{{ item.label }}
|
||||
</li>
|
||||
{% endfor -%}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor =
|
||||
CodeMirror.fromTextArea(document.getElementById("code"), {mode:
|
||||
{name: "jinja2", htmlMode: true}});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,51 +0,0 @@
|
||||
CodeMirror.defineMode("jinja2", function(config, parserConf) {
|
||||
var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false",
|
||||
"loop", "none", "self", "super", "if", "as", "not", "and",
|
||||
"else", "import", "with", "without", "context", 'extends', 'macro', 'endmacro'];
|
||||
|
||||
var blocks = ['block', 'for', 'if', 'import', 'with', 'macro', 'raw', 'call', 'filter'];
|
||||
// TODO raw should stop highlighting until the endraw
|
||||
var standalone = ['extends', 'import', 'else', 'elif', 'from', 'include', 'set'];
|
||||
var special = ['in', 'is', 'true', 'false', 'loop', 'none', 'self', 'super',
|
||||
'as', 'not', 'and', 'if', 'else', 'without', 'with',
|
||||
'context', 'ignore', 'missing', 'import'];
|
||||
// TODO list builtin filters and tests
|
||||
|
||||
keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b");
|
||||
|
||||
function tokenBase (stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == "{") {
|
||||
if (ch = stream.eat(/\{|%|#/)) {
|
||||
stream.eat("-");
|
||||
state.tokenize = inTag(ch);
|
||||
return "tag";
|
||||
}
|
||||
}
|
||||
}
|
||||
function inTag (close) {
|
||||
if (close == "{") {
|
||||
close = "}";
|
||||
}
|
||||
return function (stream, state) {
|
||||
var ch = stream.next();
|
||||
if ((ch == close || (ch == "-" && stream.eat(close)))
|
||||
&& stream.eat("}")) {
|
||||
state.tokenize = tokenBase;
|
||||
return "tag";
|
||||
}
|
||||
if (stream.match(keywords)) {
|
||||
return "keyword";
|
||||
}
|
||||
return close == "#" ? "comment" : "string";
|
||||
};
|
||||
}
|
||||
return {
|
||||
startState: function () {
|
||||
return {tokenize: tokenBase};
|
||||
},
|
||||
token: function (stream, state) {
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
};
|
||||
});
|
@ -1,603 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: LESS mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="less.js"></script>
|
||||
<style>.CodeMirror {background: #f8f8f8; border: 1px solid #ddd;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<link rel="stylesheet" href="../../theme/lesser-dark.css">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: LESS mode</h1>
|
||||
<form><textarea id="code" name="code">/* Some LESS code */
|
||||
|
||||
@test_a: #eeeQQQ;//this is not a valid hex value and thus parsed as an element id
|
||||
@test_b: #eeeFFF//this is a valid hex value but the declaration doesn't end with a semicolon and thus parsed as an element id
|
||||
|
||||
#eee aaa .box
|
||||
{
|
||||
#test bbb {
|
||||
width: 500px;
|
||||
height: 250px;
|
||||
background-image: url(sheep.png), url(betweengrassandsky.png);
|
||||
background-position: center bottom, left top;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
}
|
||||
|
||||
@base: #f938ab;
|
||||
|
||||
.box-shadow(@style, @c) when (iscolor(@c)) {
|
||||
box-shadow: @style @c;
|
||||
-webkit-box-shadow: @style @c;
|
||||
-moz-box-shadow: @style @c;
|
||||
}
|
||||
.box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) {
|
||||
.box-shadow(@style, rgba(0, 0, 0, @alpha));
|
||||
}
|
||||
|
||||
@color: #4D926F;
|
||||
|
||||
#header {
|
||||
color: @color;
|
||||
color: #000000;
|
||||
}
|
||||
h2 {
|
||||
color: @color;
|
||||
}
|
||||
|
||||
.rounded-corners (@radius: 5px) {
|
||||
border-radius: @radius;
|
||||
-webkit-border-radius: @radius;
|
||||
-moz-border-radius: @radius;
|
||||
}
|
||||
|
||||
#header {
|
||||
.rounded-corners;
|
||||
}
|
||||
#footer {
|
||||
.rounded-corners(10px);
|
||||
}
|
||||
|
||||
.box-shadow (@x: 0, @y: 0, @blur: 1px, @alpha) {
|
||||
@val: @x @y @blur rgba(0, 0, 0, @alpha);
|
||||
|
||||
box-shadow: @val;
|
||||
-webkit-box-shadow: @val;
|
||||
-moz-box-shadow: @val;
|
||||
}
|
||||
.box { @base: #f938ab;
|
||||
color: saturate(@base, 5%);
|
||||
border-color: lighten(@base, 30%);
|
||||
div { .box-shadow(0, 0, 5px, 0.4) }
|
||||
}
|
||||
|
||||
@import url("something.css");
|
||||
|
||||
@light-blue: hsl(190, 50%, 65%);
|
||||
@light-yellow: desaturate(#fefec8, 10%);
|
||||
@dark-yellow: desaturate(darken(@light-yellow, 10%), 40%);
|
||||
@darkest: hsl(20, 0%, 15%);
|
||||
@dark: hsl(190, 20%, 30%);
|
||||
@medium: hsl(10, 60%, 30%);
|
||||
@light: hsl(90, 40%, 20%);
|
||||
@lightest: hsl(90, 20%, 90%);
|
||||
@highlight: hsl(80, 50%, 90%);
|
||||
@blue: hsl(210, 60%, 20%);
|
||||
@alpha-blue: hsla(210, 60%, 40%, 0.5);
|
||||
|
||||
.box-shadow (@x, @y, @blur, @alpha) {
|
||||
@value: @x @y @blur rgba(0, 0, 0, @alpha);
|
||||
box-shadow: @value;
|
||||
-moz-box-shadow: @value;
|
||||
-webkit-box-shadow: @value;
|
||||
}
|
||||
.border-radius (@radius) {
|
||||
border-radius: @radius;
|
||||
-moz-border-radius: @radius;
|
||||
-webkit-border-radius: @radius;
|
||||
}
|
||||
|
||||
.border-radius (@radius, bottom) {
|
||||
border-top-right-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
-moz-border-top-right-radius: 0;
|
||||
-moz-border-top-left-radius: 0;
|
||||
-webkit-border-top-left-radius: 0;
|
||||
-webkit-border-top-right-radius: 0;
|
||||
}
|
||||
.border-radius (@radius, right) {
|
||||
border-bottom-left-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
-moz-border-bottom-left-radius: 0;
|
||||
-moz-border-top-left-radius: 0;
|
||||
-webkit-border-bottom-left-radius: 0;
|
||||
-webkit-border-top-left-radius: 0;
|
||||
}
|
||||
.box-shadow-inset (@x, @y, @blur, @color) {
|
||||
box-shadow: @x @y @blur @color inset;
|
||||
-moz-box-shadow: @x @y @blur @color inset;
|
||||
-webkit-box-shadow: @x @y @blur @color inset;
|
||||
}
|
||||
.code () {
|
||||
font-family: 'Bitstream Vera Sans Mono',
|
||||
'DejaVu Sans Mono',
|
||||
'Monaco',
|
||||
Courier,
|
||||
monospace !important;
|
||||
}
|
||||
.wrap () {
|
||||
text-wrap: wrap;
|
||||
white-space: pre-wrap; /* css-3 */
|
||||
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
||||
white-space: -pre-wrap; /* Opera 4-6 */
|
||||
white-space: -o-pre-wrap; /* Opera 7 */
|
||||
word-wrap: break-word; /* Internet Explorer 5.5+ */
|
||||
}
|
||||
|
||||
html { margin: 0 }
|
||||
body {
|
||||
background-color: @darkest;
|
||||
margin: 0 auto;
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 100%;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
nav, header, footer, section, article {
|
||||
display: block;
|
||||
}
|
||||
a {
|
||||
color: #b83000;
|
||||
}
|
||||
h1 a {
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
h1, h2, h3, h4 {
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
ul, li {
|
||||
list-style-type: none;
|
||||
}
|
||||
code { .code; }
|
||||
code {
|
||||
.string, .regexp { color: @dark }
|
||||
.keyword { font-weight: bold }
|
||||
.comment { color: rgba(0, 0, 0, 0.5) }
|
||||
.number { color: @blue }
|
||||
.class, .special { color: rgba(0, 50, 100, 0.8) }
|
||||
}
|
||||
pre {
|
||||
padding: 0 30px;
|
||||
.wrap;
|
||||
}
|
||||
blockquote {
|
||||
font-style: italic;
|
||||
}
|
||||
body > footer {
|
||||
text-align: left;
|
||||
margin-left: 10px;
|
||||
font-style: italic;
|
||||
font-size: 18px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
#logo {
|
||||
margin-top: 30px;
|
||||
margin-bottom: 30px;
|
||||
display: block;
|
||||
width: 199px;
|
||||
height: 81px;
|
||||
background: url(/images/logo.png) no-repeat;
|
||||
}
|
||||
nav {
|
||||
margin-left: 15px;
|
||||
}
|
||||
nav a, #dropdown li {
|
||||
display: inline-block;
|
||||
color: white;
|
||||
line-height: 42px;
|
||||
margin: 0;
|
||||
padding: 0px 15px;
|
||||
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.5);
|
||||
text-decoration: none;
|
||||
border: 2px solid transparent;
|
||||
border-width: 0 2px;
|
||||
&:hover {
|
||||
.dark-red;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
.dark-red {
|
||||
@red: @medium;
|
||||
border: 2px solid darken(@red, 25%);
|
||||
border-left-color: darken(@red, 15%);
|
||||
border-right-color: darken(@red, 15%);
|
||||
border-bottom: 0;
|
||||
border-top: 0;
|
||||
background-color: darken(@red, 10%);
|
||||
}
|
||||
|
||||
.content {
|
||||
margin: 0 auto;
|
||||
width: 980px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 3;
|
||||
clear: both;
|
||||
display: block;
|
||||
background-color: @blue;
|
||||
height: 42px;
|
||||
border-top: 2px solid lighten(@alpha-blue, 20%);
|
||||
border-bottom: 2px solid darken(@alpha-blue, 25%);
|
||||
.box-shadow(0, 1px, 8px, 0.6);
|
||||
-moz-box-shadow: 0 0 0 #000; // Because firefox sucks.
|
||||
|
||||
&.docked {
|
||||
background-color: hsla(210, 60%, 40%, 0.4);
|
||||
}
|
||||
&:hover {
|
||||
background-color: @blue;
|
||||
}
|
||||
|
||||
#dropdown {
|
||||
margin: 0 0 0 117px;
|
||||
padding: 0;
|
||||
padding-top: 5px;
|
||||
display: none;
|
||||
width: 190px;
|
||||
border-top: 2px solid @medium;
|
||||
color: @highlight;
|
||||
border: 2px solid darken(@medium, 25%);
|
||||
border-left-color: darken(@medium, 15%);
|
||||
border-right-color: darken(@medium, 15%);
|
||||
border-top-width: 0;
|
||||
background-color: darken(@medium, 10%);
|
||||
ul {
|
||||
padding: 0px;
|
||||
}
|
||||
li {
|
||||
font-size: 14px;
|
||||
display: block;
|
||||
text-align: left;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
a {
|
||||
display: block;
|
||||
padding: 0px 15px;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
&:hover {
|
||||
background-color: darken(@medium, 15%);
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
.border-radius(5px, bottom);
|
||||
.box-shadow(0, 6px, 8px, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
#main {
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
background-color: @light-blue;
|
||||
border-top: 8px solid darken(@light-blue, 5%);
|
||||
|
||||
#intro {
|
||||
background-color: lighten(@light-blue, 25%);
|
||||
float: left;
|
||||
margin-top: -8px;
|
||||
margin-right: 5px;
|
||||
|
||||
height: 380px;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
font-family: 'Droid Serif', 'Georgia';
|
||||
width: 395px;
|
||||
padding: 45px 20px 23px 30px;
|
||||
border: 2px dashed darken(@light-blue, 10%);
|
||||
.box-shadow(1px, 0px, 6px, 0.5);
|
||||
border-bottom: 0;
|
||||
border-top: 0;
|
||||
#download { color: transparent; border: 0; float: left; display: inline-block; margin: 15px 0 15px -5px; }
|
||||
#download img { display: inline-block}
|
||||
#download-info {
|
||||
code {
|
||||
font-size: 13px;
|
||||
}
|
||||
color: @blue + #333; display: inline; float: left; margin: 36px 0 0 15px }
|
||||
}
|
||||
h2 {
|
||||
span {
|
||||
color: @medium;
|
||||
}
|
||||
color: @blue;
|
||||
margin: 20px 0;
|
||||
font-size: 24px;
|
||||
line-height: 1.2em;
|
||||
}
|
||||
h3 {
|
||||
color: @blue;
|
||||
line-height: 1.4em;
|
||||
margin: 30px 0 15px 0;
|
||||
font-size: 1em;
|
||||
text-shadow: 0px 0px 0px @lightest;
|
||||
span { color: @medium }
|
||||
}
|
||||
#example {
|
||||
p {
|
||||
font-size: 18px;
|
||||
color: @blue;
|
||||
font-weight: bold;
|
||||
text-shadow: 0px 1px 1px @lightest;
|
||||
}
|
||||
pre {
|
||||
margin: 0;
|
||||
text-shadow: 0 -1px 1px @darkest;
|
||||
margin-top: 20px;
|
||||
background-color: desaturate(@darkest, 8%);
|
||||
border: 0;
|
||||
width: 450px;
|
||||
color: lighten(@lightest, 2%);
|
||||
background-repeat: repeat;
|
||||
padding: 15px;
|
||||
border: 1px dashed @lightest;
|
||||
line-height: 15px;
|
||||
.box-shadow(0, 0px, 15px, 0.5);
|
||||
.code;
|
||||
.border-radius(2px);
|
||||
code .attribute { color: hsl(40, 50%, 70%) }
|
||||
code .variable { color: hsl(120, 10%, 50%) }
|
||||
code .element { color: hsl(170, 20%, 50%) }
|
||||
|
||||
code .string, .regexp { color: hsl(75, 50%, 65%) }
|
||||
code .class { color: hsl(40, 40%, 60%); font-weight: normal }
|
||||
code .id { color: hsl(50, 40%, 60%); font-weight: normal }
|
||||
code .comment { color: rgba(255, 255, 255, 0.2) }
|
||||
code .number, .color { color: hsl(10, 40%, 50%) }
|
||||
code .class, code .mixin, .special { color: hsl(190, 20%, 50%) }
|
||||
#time { color: #aaa }
|
||||
}
|
||||
float: right;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
margin-top: 15px;
|
||||
padding: 0;
|
||||
width: 500px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.page {
|
||||
.content {
|
||||
width: 870px;
|
||||
padding: 45px;
|
||||
}
|
||||
margin: 0 auto;
|
||||
font-family: 'Georgia', serif;
|
||||
font-size: 18px;
|
||||
line-height: 26px;
|
||||
padding: 0 60px;
|
||||
code {
|
||||
font-size: 16px;
|
||||
}
|
||||
pre {
|
||||
border-width: 1px;
|
||||
border-style: dashed;
|
||||
padding: 15px;
|
||||
margin: 15px 0;
|
||||
}
|
||||
h1 {
|
||||
text-align: left;
|
||||
font-size: 40px;
|
||||
margin-top: 15px;
|
||||
margin-bottom: 35px;
|
||||
}
|
||||
p + h1 { margin-top: 60px }
|
||||
h2, h3 {
|
||||
margin: 30px 0 15px 0;
|
||||
}
|
||||
p + h2, pre + h2, code + h2 {
|
||||
border-top: 6px solid rgba(255, 255, 255, 0.1);
|
||||
padding-top: 30px;
|
||||
}
|
||||
h3 {
|
||||
margin: 15px 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#docs {
|
||||
@bg: lighten(@light-blue, 5%);
|
||||
border-top: 2px solid lighten(@bg, 5%);
|
||||
color: @blue;
|
||||
background-color: @light-blue;
|
||||
.box-shadow(0, -2px, 5px, 0.2);
|
||||
|
||||
h1 {
|
||||
font-family: 'Droid Serif', 'Georgia', serif;
|
||||
padding-top: 30px;
|
||||
padding-left: 45px;
|
||||
font-size: 44px;
|
||||
text-align: left;
|
||||
margin: 30px 0 !important;
|
||||
text-shadow: 0px 1px 1px @lightest;
|
||||
font-weight: bold;
|
||||
}
|
||||
.content {
|
||||
clear: both;
|
||||
border-color: transparent;
|
||||
background-color: lighten(@light-blue, 25%);
|
||||
.box-shadow(0, 5px, 5px, 0.4);
|
||||
}
|
||||
pre {
|
||||
@background: lighten(@bg, 30%);
|
||||
color: lighten(@blue, 10%);
|
||||
background-color: @background;
|
||||
border-color: lighten(@light-blue, 25%);
|
||||
border-width: 2px;
|
||||
code .attribute { color: hsl(40, 50%, 30%) }
|
||||
code .variable { color: hsl(120, 10%, 30%) }
|
||||
code .element { color: hsl(170, 20%, 30%) }
|
||||
|
||||
code .string, .regexp { color: hsl(75, 50%, 35%) }
|
||||
code .class { color: hsl(40, 40%, 30%); font-weight: normal }
|
||||
code .id { color: hsl(50, 40%, 30%); font-weight: normal }
|
||||
code .comment { color: rgba(0, 0, 0, 0.4) }
|
||||
code .number, .color { color: hsl(10, 40%, 30%) }
|
||||
code .class, code .mixin, .special { color: hsl(190, 20%, 30%) }
|
||||
}
|
||||
pre code { font-size: 15px }
|
||||
p + h2, pre + h2, code + h2 { border-top-color: rgba(0, 0, 0, 0.1) }
|
||||
}
|
||||
|
||||
td {
|
||||
padding-right: 30px;
|
||||
}
|
||||
#synopsis {
|
||||
.box-shadow(0, 5px, 5px, 0.2);
|
||||
}
|
||||
#synopsis, #about {
|
||||
h2 {
|
||||
font-size: 30px;
|
||||
padding: 10px 0;
|
||||
}
|
||||
h1 + h2 {
|
||||
margin-top: 15px;
|
||||
}
|
||||
h3 { font-size: 22px }
|
||||
|
||||
.code-example {
|
||||
border-spacing: 0;
|
||||
border-width: 1px;
|
||||
border-style: dashed;
|
||||
padding: 0;
|
||||
pre { border: 0; margin: 0 }
|
||||
td {
|
||||
border: 0;
|
||||
margin: 0;
|
||||
background-color: desaturate(darken(@darkest, 5%), 20%);
|
||||
vertical-align: top;
|
||||
padding: 0;
|
||||
}
|
||||
tr { padding: 0 }
|
||||
}
|
||||
.css-output {
|
||||
td {
|
||||
border-left: 0;
|
||||
}
|
||||
}
|
||||
.less-example {
|
||||
//border-right: 1px dotted rgba(255, 255, 255, 0.5) !important;
|
||||
}
|
||||
.css-output, .less-example {
|
||||
width: 390px;
|
||||
}
|
||||
pre {
|
||||
padding: 20px;
|
||||
line-height: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
#about, #synopsis, #guide {
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: @light-yellow;
|
||||
border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
|
||||
&:hover {
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dashed @light-yellow;
|
||||
}
|
||||
}
|
||||
@bg: desaturate(darken(@darkest, 5%), 20%);
|
||||
text-shadow: 0 -1px 1px lighten(@bg, 5%);
|
||||
color: @highlight;
|
||||
background-color: @bg;
|
||||
.content {
|
||||
background-color: desaturate(@darkest, 20%);
|
||||
clear: both;
|
||||
.box-shadow(0, 5px, 5px, 0.4);
|
||||
}
|
||||
h1, h2, h3 {
|
||||
color: @dark-yellow;
|
||||
}
|
||||
pre {
|
||||
code .attribute { color: hsl(40, 50%, 70%) }
|
||||
code .variable { color: hsl(120, 10%, 50%) }
|
||||
code .element { color: hsl(170, 20%, 50%) }
|
||||
|
||||
code .string, .regexp { color: hsl(75, 50%, 65%) }
|
||||
code .class { color: hsl(40, 40%, 60%); font-weight: normal }
|
||||
code .id { color: hsl(50, 40%, 60%); font-weight: normal }
|
||||
code .comment { color: rgba(255, 255, 255, 0.2) }
|
||||
code .number, .color { color: hsl(10, 40%, 50%) }
|
||||
code .class, code .mixin, .special { color: hsl(190, 20%, 50%) }
|
||||
background-color: @bg;
|
||||
border-color: darken(@light-yellow, 5%);
|
||||
}
|
||||
code {
|
||||
color: darken(@dark-yellow, 5%);
|
||||
.string, .regexp { color: desaturate(@light-blue, 15%) }
|
||||
.keyword { color: hsl(40, 40%, 60%); font-weight: normal }
|
||||
.comment { color: rgba(255, 255, 255, 0.2) }
|
||||
.number { color: lighten(@blue, 10%) }
|
||||
.class, .special { color: hsl(190, 20%, 50%) }
|
||||
}
|
||||
}
|
||||
#guide {
|
||||
background-color: @darkest;
|
||||
.content {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#about {
|
||||
background-color: @darkest !important;
|
||||
.content {
|
||||
background-color: desaturate(lighten(@darkest, 3%), 5%);
|
||||
}
|
||||
}
|
||||
#synopsis {
|
||||
background-color: desaturate(lighten(@darkest, 3%), 5%) !important;
|
||||
.content {
|
||||
background-color: desaturate(lighten(@darkest, 3%), 5%);
|
||||
}
|
||||
pre {}
|
||||
}
|
||||
#synopsis, #guide {
|
||||
.content {
|
||||
.box-shadow(0, 0px, 0px, 0.0);
|
||||
}
|
||||
}
|
||||
#about footer {
|
||||
margin-top: 30px;
|
||||
padding-top: 30px;
|
||||
border-top: 6px solid rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
color: rgba(255, 255, 255, 0.35);
|
||||
#copy { font-size: 12px }
|
||||
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.02);
|
||||
}
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
theme: "lesser-dark"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/less</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,218 +0,0 @@
|
||||
/*
|
||||
LESS mode - http://www.lesscss.org/
|
||||
Ported to CodeMirror by Peter Kroon
|
||||
*/
|
||||
|
||||
CodeMirror.defineMode("css", function(config) {
|
||||
var indentUnit = config.indentUnit, type;
|
||||
function ret(style, tp) {type = tp; return style;}
|
||||
//html5 tags
|
||||
var tags = ["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","command","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","keygen","kbd","label","legend","li","link","map","mark","menu","meta","meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr"];
|
||||
|
||||
function inTagsArray(val){
|
||||
for(var i=0; i<tags.length; i++){
|
||||
if(val === tags[i]){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
|
||||
if (ch == "@") {stream.eatWhile(/[\w\-]/); return ret("meta", stream.current());}
|
||||
else if (ch == "/" && stream.eat("*")) {
|
||||
state.tokenize = tokenCComment;
|
||||
return tokenCComment(stream, state);
|
||||
}
|
||||
else if (ch == "<" && stream.eat("!")) {
|
||||
state.tokenize = tokenSGMLComment;
|
||||
return tokenSGMLComment(stream, state);
|
||||
}
|
||||
else if (ch == "=") ret(null, "compare");
|
||||
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
else if (ch == "/") { // lesscss e.g.: .png will not be parsed as a class
|
||||
if(stream.eat("/")){
|
||||
state.tokenize = tokenSComment
|
||||
return tokenSComment(stream, state);
|
||||
}else{
|
||||
stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/);
|
||||
if(/\/|\)/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")))return ret("string", "string");//let url(/images/logo.png) without quotes return as string
|
||||
return ret("number", "unit");
|
||||
}
|
||||
}
|
||||
else if (ch == "!") {
|
||||
stream.match(/^\s*\w*/);
|
||||
return ret("keyword", "important");
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w.%]/);
|
||||
return ret("number", "unit");
|
||||
}
|
||||
else if (/[,+<>*\/]/.test(ch)) {//removed . dot character original was [,.+>*\/]
|
||||
return ret(null, "select-op");
|
||||
}
|
||||
else if (/[;{}:\[\]()]/.test(ch)) { //added () char for lesscss original was [;{}:\[\]]
|
||||
if(ch == ":"){
|
||||
stream.eatWhile(/[active|hover|link|visited]/);
|
||||
if( stream.current().match(/active|hover|link|visited/)){
|
||||
return ret("tag", "tag");
|
||||
}else{
|
||||
return ret(null, ch);
|
||||
}
|
||||
}else{
|
||||
return ret(null, ch);
|
||||
}
|
||||
}
|
||||
else if (ch == ".") { // lesscss
|
||||
stream.eatWhile(/[\a-zA-Z0-9\-_]/);
|
||||
return ret("tag", "tag");
|
||||
}
|
||||
else if (ch == "#") { // lesscss
|
||||
//we don't eat white-space, we want the hex color and or id only
|
||||
stream.eatWhile(/[A-Za-z0-9]/);
|
||||
//check if there is a proper hex color length e.g. #eee || #eeeEEE
|
||||
if(stream.current().length ===4 || stream.current().length ===7){
|
||||
if(stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false) != null){//is there a valid hex color value present in the current stream
|
||||
//when not a valid hex value, parse as id
|
||||
if(stream.current().substring(1) != stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false))return ret("atom", "tag");
|
||||
//eat white-space
|
||||
stream.eatSpace();
|
||||
//when hex value declaration doesn't end with [;,] but is does with a slash/cc comment treat it as an id, just like the other hex values that don't end with[;,]
|
||||
if( /[\/<>.(){!$%^&*_\-\\?=+\|#'~`]/.test(stream.peek()) )return ret("atom", "tag");
|
||||
//#time { color: #aaa }
|
||||
else if(stream.peek() == "}" )return ret("number", "unit");
|
||||
//we have a valid hex color value, parse as id whenever an element/class is defined after the hex(id) value e.g. #eee aaa || #eee .aaa
|
||||
else if( /[a-zA-Z\\]/.test(stream.peek()) )return ret("atom", "tag");
|
||||
//when a hex value is on the end of a line, parse as id
|
||||
else if(stream.eol())return ret("atom", "tag");
|
||||
//default
|
||||
else return ret("number", "unit");
|
||||
}else{//when not a valid hexvalue in the current stream e.g. #footer
|
||||
stream.eatWhile(/[\w\\\-]/);
|
||||
return ret("atom", "tag");
|
||||
}
|
||||
}else{
|
||||
stream.eatWhile(/[\w\\\-]/);
|
||||
return ret("atom", "tag");
|
||||
}
|
||||
}
|
||||
else if (ch == "&") {
|
||||
stream.eatWhile(/[\w\-]/);
|
||||
return ret(null, ch);
|
||||
}
|
||||
else if (ch == "&") {
|
||||
stream.eatWhile(/[\w\-]/);
|
||||
return ret(null, ch);
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(/[\w\\\-_.%]/);
|
||||
if( stream.peek().match(/\(/) != null ){// lesscss
|
||||
stream.eatWhile(/[a-zA-Z\s]/);
|
||||
if(stream.peek() == "(")return ret(null, ch);
|
||||
}else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc...
|
||||
return ret("number", "unit");
|
||||
}else if( inTagsArray(stream.current()) ){ // lesscss match html tags
|
||||
return ret("tag", "tag");
|
||||
}else if( /\/|\)/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")) && stream.current().indexOf(".") !== -1){
|
||||
return ret("string", "string");//let url(/images/logo.png) without quotes return as string
|
||||
}else{
|
||||
return ret("variable", "variable");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function tokenSComment(stream, state) {// SComment = Slash comment
|
||||
stream.skipToEnd();
|
||||
state.tokenize = tokenBase;
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
|
||||
function tokenCComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (maybeEnd && ch == "/") {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
|
||||
function tokenSGMLComment(stream, state) {
|
||||
var dashes = 0, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (dashes >= 2 && ch == ">") {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
dashes = (ch == "-") ? dashes + 1 : 0;
|
||||
}
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == quote && !escaped)
|
||||
break;
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
if (!escaped) state.tokenize = tokenBase;
|
||||
return ret("string", "string");
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function(base) {
|
||||
return {tokenize: tokenBase,
|
||||
baseIndent: base || 0,
|
||||
stack: []};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
|
||||
var context = state.stack[state.stack.length-1];
|
||||
if (type == "hash" && context == "rule") style = "atom";
|
||||
else if (style == "variable") {
|
||||
if (context == "rule") style = null; //"tag"
|
||||
else if (!context || context == "@media{"){
|
||||
style = stream.current() == "when" ? "variable" :
|
||||
stream.string.match(/#/g) != undefined ? null :
|
||||
/[\s,|\s\)]/.test(stream.peek()) ? "tag" : null;
|
||||
}
|
||||
}
|
||||
|
||||
if (context == "rule" && /^[\{\};]$/.test(type))
|
||||
state.stack.pop();
|
||||
if (type == "{") {
|
||||
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
|
||||
else state.stack.push("{");
|
||||
}
|
||||
else if (type == "}") state.stack.pop();
|
||||
else if (type == "@media") state.stack.push("@media");
|
||||
else if (context == "{" && type != "comment") state.stack.push("rule");
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var n = state.stack.length;
|
||||
if (/^\}/.test(textAfter))
|
||||
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
|
||||
return state.baseIndent + n * indentUnit;
|
||||
},
|
||||
|
||||
electricChars: "}"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/css", "css");
|
@ -1,72 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Lua mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="lua.js"></script>
|
||||
<link rel="stylesheet" href="../../theme/neat.css">
|
||||
<style>.CodeMirror {border: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Lua mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
--[[
|
||||
example useless code to show lua syntax highlighting
|
||||
this is multiline comment
|
||||
]]
|
||||
|
||||
function blahblahblah(x)
|
||||
|
||||
local table = {
|
||||
"asd" = 123,
|
||||
"x" = 0.34,
|
||||
}
|
||||
if x ~= 3 then
|
||||
print( x )
|
||||
elseif x == "string"
|
||||
my_custom_function( 0x34 )
|
||||
else
|
||||
unknown_function( "some string" )
|
||||
end
|
||||
|
||||
--single line comment
|
||||
|
||||
end
|
||||
|
||||
function blablabla3()
|
||||
|
||||
for k,v in ipairs( table ) do
|
||||
--abcde..
|
||||
y=[=[
|
||||
x=[[
|
||||
x is a multi line string
|
||||
]]
|
||||
but its definition is iside a highest level string!
|
||||
]=]
|
||||
print(" \"\" ")
|
||||
|
||||
s = math.sin( x )
|
||||
end
|
||||
|
||||
end
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
tabMode: "indent",
|
||||
matchBrackets: true,
|
||||
theme: "neat"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Loosely based on Franciszek
|
||||
Wawrzak's <a href="http://codemirror.net/1/contrib/lua">CodeMirror
|
||||
1 mode</a>. One configuration parameter is
|
||||
supported, <code>specials</code>, to which you can provide an
|
||||
array of strings to have those identifiers highlighted with
|
||||
the <code>lua-special</code> style.</p>
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-lua</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,140 +0,0 @@
|
||||
// LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's
|
||||
// CodeMirror 1 mode.
|
||||
// highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting
|
||||
|
||||
CodeMirror.defineMode("lua", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit;
|
||||
|
||||
function prefixRE(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")", "i");
|
||||
}
|
||||
function wordRE(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
var specials = wordRE(parserConfig.specials || []);
|
||||
|
||||
// long list of standard functions from lua manual
|
||||
var builtins = wordRE([
|
||||
"_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load",
|
||||
"loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require",
|
||||
"select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall",
|
||||
|
||||
"coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield",
|
||||
|
||||
"debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable",
|
||||
"debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable",
|
||||
"debug.setupvalue","debug.traceback",
|
||||
|
||||
"close","flush","lines","read","seek","setvbuf","write",
|
||||
|
||||
"io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin",
|
||||
"io.stdout","io.tmpfile","io.type","io.write",
|
||||
|
||||
"math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg",
|
||||
"math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max",
|
||||
"math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh",
|
||||
"math.sqrt","math.tan","math.tanh",
|
||||
|
||||
"os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale",
|
||||
"os.time","os.tmpname",
|
||||
|
||||
"package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload",
|
||||
"package.seeall",
|
||||
|
||||
"string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub",
|
||||
"string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper",
|
||||
|
||||
"table.concat","table.insert","table.maxn","table.remove","table.sort"
|
||||
]);
|
||||
var keywords = wordRE(["and","break","elseif","false","nil","not","or","return",
|
||||
"true","function", "end", "if", "then", "else", "do",
|
||||
"while", "repeat", "until", "for", "in", "local" ]);
|
||||
|
||||
var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]);
|
||||
var dedentTokens = wordRE(["end", "until", "\\)", "}"]);
|
||||
var dedentPartial = prefixRE(["end", "until", "\\)", "}", "else", "elseif"]);
|
||||
|
||||
function readBracket(stream) {
|
||||
var level = 0;
|
||||
while (stream.eat("=")) ++level;
|
||||
stream.eat("[");
|
||||
return level;
|
||||
}
|
||||
|
||||
function normal(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == "-" && stream.eat("-")) {
|
||||
if (stream.eat("["))
|
||||
return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state);
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
if (ch == "\"" || ch == "'")
|
||||
return (state.cur = string(ch))(stream, state);
|
||||
if (ch == "[" && /[\[=]/.test(stream.peek()))
|
||||
return (state.cur = bracketed(readBracket(stream), "string"))(stream, state);
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w.%]/);
|
||||
return "number";
|
||||
}
|
||||
if (/[\w_]/.test(ch)) {
|
||||
stream.eatWhile(/[\w\\\-_.]/);
|
||||
return "variable";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function bracketed(level, style) {
|
||||
return function(stream, state) {
|
||||
var curlev = null, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (curlev == null) {if (ch == "]") curlev = 0;}
|
||||
else if (ch == "=") ++curlev;
|
||||
else if (ch == "]" && curlev == level) { state.cur = normal; break; }
|
||||
else curlev = null;
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
|
||||
function string(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == quote && !escaped) break;
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
if (!escaped) state.cur = normal;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function(basecol) {
|
||||
return {basecol: basecol || 0, indentDepth: 0, cur: normal};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.cur(stream, state);
|
||||
var word = stream.current();
|
||||
if (style == "variable") {
|
||||
if (keywords.test(word)) style = "keyword";
|
||||
else if (builtins.test(word)) style = "builtin";
|
||||
else if (specials.test(word)) style = "variable-2";
|
||||
}
|
||||
if ((style != "comment") && (style != "string")){
|
||||
if (indentTokens.test(word)) ++state.indentDepth;
|
||||
else if (dedentTokens.test(word)) --state.indentDepth;
|
||||
}
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var closing = dedentPartial.test(textAfter);
|
||||
return state.basecol + indentUnit * (state.indentDepth - (closing ? 1 : 0));
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-lua", "lua");
|
@ -1,338 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Markdown mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../xml/xml.js"></script>
|
||||
<script src="markdown.js"></script>
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Markdown mode</h1>
|
||||
|
||||
<!-- source: http://daringfireball.net/projects/markdown/basics.text -->
|
||||
<form><textarea id="code" name="code">
|
||||
Markdown: Basics
|
||||
================
|
||||
|
||||
<ul id="ProjectSubmenu">
|
||||
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
|
||||
<li><a class="selected" title="Markdown Basics">Basics</a></li>
|
||||
<li><a href="/projects/markdown/syntax" title="Markdown Syntax Documentation">Syntax</a></li>
|
||||
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
|
||||
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
Getting the Gist of Markdown's Formatting Syntax
|
||||
------------------------------------------------
|
||||
|
||||
This page offers a brief overview of what it's like to use Markdown.
|
||||
The [syntax page] [s] provides complete, detailed documentation for
|
||||
every feature, but Markdown should be very easy to pick up simply by
|
||||
looking at a few examples of it in action. The examples on this page
|
||||
are written in a before/after style, showing example syntax and the
|
||||
HTML output produced by Markdown.
|
||||
|
||||
It's also helpful to simply try Markdown out; the [Dingus] [d] is a
|
||||
web application that allows you type your own Markdown-formatted text
|
||||
and translate it to XHTML.
|
||||
|
||||
**Note:** This document is itself written using Markdown; you
|
||||
can [see the source for it by adding '.text' to the URL] [src].
|
||||
|
||||
[s]: /projects/markdown/syntax "Markdown Syntax"
|
||||
[d]: /projects/markdown/dingus "Markdown Dingus"
|
||||
[src]: /projects/markdown/basics.text
|
||||
|
||||
|
||||
## Paragraphs, Headers, Blockquotes ##
|
||||
|
||||
A paragraph is simply one or more consecutive lines of text, separated
|
||||
by one or more blank lines. (A blank line is any line that looks like
|
||||
a blank line -- a line containing nothing but spaces or tabs is
|
||||
considered blank.) Normal paragraphs should not be indented with
|
||||
spaces or tabs.
|
||||
|
||||
Markdown offers two styles of headers: *Setext* and *atx*.
|
||||
Setext-style headers for `<h1>` and `<h2>` are created by
|
||||
"underlining" with equal signs (`=`) and hyphens (`-`), respectively.
|
||||
To create an atx-style header, you put 1-6 hash marks (`#`) at the
|
||||
beginning of the line -- the number of hashes equals the resulting
|
||||
HTML header level.
|
||||
|
||||
Blockquotes are indicated using email-style '`>`' angle brackets.
|
||||
|
||||
Markdown:
|
||||
|
||||
A First Level Header
|
||||
====================
|
||||
|
||||
A Second Level Header
|
||||
---------------------
|
||||
|
||||
Now is the time for all good men to come to
|
||||
the aid of their country. This is just a
|
||||
regular paragraph.
|
||||
|
||||
The quick brown fox jumped over the lazy
|
||||
dog's back.
|
||||
|
||||
### Header 3
|
||||
|
||||
> This is a blockquote.
|
||||
>
|
||||
> This is the second paragraph in the blockquote.
|
||||
>
|
||||
> ## This is an H2 in a blockquote
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
<h1>A First Level Header</h1>
|
||||
|
||||
<h2>A Second Level Header</h2>
|
||||
|
||||
<p>Now is the time for all good men to come to
|
||||
the aid of their country. This is just a
|
||||
regular paragraph.</p>
|
||||
|
||||
<p>The quick brown fox jumped over the lazy
|
||||
dog's back.</p>
|
||||
|
||||
<h3>Header 3</h3>
|
||||
|
||||
<blockquote>
|
||||
<p>This is a blockquote.</p>
|
||||
|
||||
<p>This is the second paragraph in the blockquote.</p>
|
||||
|
||||
<h2>This is an H2 in a blockquote</h2>
|
||||
</blockquote>
|
||||
|
||||
|
||||
|
||||
### Phrase Emphasis ###
|
||||
|
||||
Markdown uses asterisks and underscores to indicate spans of emphasis.
|
||||
|
||||
Markdown:
|
||||
|
||||
Some of these words *are emphasized*.
|
||||
Some of these words _are emphasized also_.
|
||||
|
||||
Use two asterisks for **strong emphasis**.
|
||||
Or, if you prefer, __use two underscores instead__.
|
||||
|
||||
Output:
|
||||
|
||||
<p>Some of these words <em>are emphasized</em>.
|
||||
Some of these words <em>are emphasized also</em>.</p>
|
||||
|
||||
<p>Use two asterisks for <strong>strong emphasis</strong>.
|
||||
Or, if you prefer, <strong>use two underscores instead</strong>.</p>
|
||||
|
||||
|
||||
|
||||
## Lists ##
|
||||
|
||||
Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`,
|
||||
`+`, and `-`) as list markers. These three markers are
|
||||
interchangable; this:
|
||||
|
||||
* Candy.
|
||||
* Gum.
|
||||
* Booze.
|
||||
|
||||
this:
|
||||
|
||||
+ Candy.
|
||||
+ Gum.
|
||||
+ Booze.
|
||||
|
||||
and this:
|
||||
|
||||
- Candy.
|
||||
- Gum.
|
||||
- Booze.
|
||||
|
||||
all produce the same output:
|
||||
|
||||
<ul>
|
||||
<li>Candy.</li>
|
||||
<li>Gum.</li>
|
||||
<li>Booze.</li>
|
||||
</ul>
|
||||
|
||||
Ordered (numbered) lists use regular numbers, followed by periods, as
|
||||
list markers:
|
||||
|
||||
1. Red
|
||||
2. Green
|
||||
3. Blue
|
||||
|
||||
Output:
|
||||
|
||||
<ol>
|
||||
<li>Red</li>
|
||||
<li>Green</li>
|
||||
<li>Blue</li>
|
||||
</ol>
|
||||
|
||||
If you put blank lines between items, you'll get `<p>` tags for the
|
||||
list item text. You can create multi-paragraph list items by indenting
|
||||
the paragraphs by 4 spaces or 1 tab:
|
||||
|
||||
* A list item.
|
||||
|
||||
With multiple paragraphs.
|
||||
|
||||
* Another item in the list.
|
||||
|
||||
Output:
|
||||
|
||||
<ul>
|
||||
<li><p>A list item.</p>
|
||||
<p>With multiple paragraphs.</p></li>
|
||||
<li><p>Another item in the list.</p></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
### Links ###
|
||||
|
||||
Markdown supports two styles for creating links: *inline* and
|
||||
*reference*. With both styles, you use square brackets to delimit the
|
||||
text you want to turn into a link.
|
||||
|
||||
Inline-style links use parentheses immediately after the link text.
|
||||
For example:
|
||||
|
||||
This is an [example link](http://example.com/).
|
||||
|
||||
Output:
|
||||
|
||||
<p>This is an <a href="http://example.com/">
|
||||
example link</a>.</p>
|
||||
|
||||
Optionally, you may include a title attribute in the parentheses:
|
||||
|
||||
This is an [example link](http://example.com/ "With a Title").
|
||||
|
||||
Output:
|
||||
|
||||
<p>This is an <a href="http://example.com/" title="With a Title">
|
||||
example link</a>.</p>
|
||||
|
||||
Reference-style links allow you to refer to your links by names, which
|
||||
you define elsewhere in your document:
|
||||
|
||||
I get 10 times more traffic from [Google][1] than from
|
||||
[Yahoo][2] or [MSN][3].
|
||||
|
||||
[1]: http://google.com/ "Google"
|
||||
[2]: http://search.yahoo.com/ "Yahoo Search"
|
||||
[3]: http://search.msn.com/ "MSN Search"
|
||||
|
||||
Output:
|
||||
|
||||
<p>I get 10 times more traffic from <a href="http://google.com/"
|
||||
title="Google">Google</a> than from <a href="http://search.yahoo.com/"
|
||||
title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/"
|
||||
title="MSN Search">MSN</a>.</p>
|
||||
|
||||
The title attribute is optional. Link names may contain letters,
|
||||
numbers and spaces, but are *not* case sensitive:
|
||||
|
||||
I start my morning with a cup of coffee and
|
||||
[The New York Times][NY Times].
|
||||
|
||||
[ny times]: http://www.nytimes.com/
|
||||
|
||||
Output:
|
||||
|
||||
<p>I start my morning with a cup of coffee and
|
||||
<a href="http://www.nytimes.com/">The New York Times</a>.</p>
|
||||
|
||||
|
||||
### Images ###
|
||||
|
||||
Image syntax is very much like link syntax.
|
||||
|
||||
Inline (titles are optional):
|
||||
|
||||

|
||||
|
||||
Reference-style:
|
||||
|
||||
![alt text][id]
|
||||
|
||||
[id]: /path/to/img.jpg "Title"
|
||||
|
||||
Both of the above examples produce the same output:
|
||||
|
||||
<img src="/path/to/img.jpg" alt="alt text" title="Title" />
|
||||
|
||||
|
||||
|
||||
### Code ###
|
||||
|
||||
In a regular paragraph, you can create code span by wrapping text in
|
||||
backtick quotes. Any ampersands (`&`) and angle brackets (`<` or
|
||||
`>`) will automatically be translated into HTML entities. This makes
|
||||
it easy to use Markdown to write about HTML example code:
|
||||
|
||||
I strongly recommend against using any `<blink>` tags.
|
||||
|
||||
I wish SmartyPants used named entities like `&mdash;`
|
||||
instead of decimal-encoded entites like `&#8212;`.
|
||||
|
||||
Output:
|
||||
|
||||
<p>I strongly recommend against using any
|
||||
<code>&lt;blink&gt;</code> tags.</p>
|
||||
|
||||
<p>I wish SmartyPants used named entities like
|
||||
<code>&amp;mdash;</code> instead of decimal-encoded
|
||||
entites like <code>&amp;#8212;</code>.</p>
|
||||
|
||||
|
||||
To specify an entire block of pre-formatted code, indent every line of
|
||||
the block by 4 spaces or 1 tab. Just like with code spans, `&`, `<`,
|
||||
and `>` characters will be escaped automatically.
|
||||
|
||||
Markdown:
|
||||
|
||||
If you want your page to validate under XHTML 1.0 Strict,
|
||||
you've got to put paragraph tags in your blockquotes:
|
||||
|
||||
<blockquote>
|
||||
<p>For example.</p>
|
||||
</blockquote>
|
||||
|
||||
Output:
|
||||
|
||||
<p>If you want your page to validate under XHTML 1.0 Strict,
|
||||
you've got to put paragraph tags in your blockquotes:</p>
|
||||
|
||||
<pre><code>&lt;blockquote&gt;
|
||||
&lt;p&gt;For example.&lt;/p&gt;
|
||||
&lt;/blockquote&gt;
|
||||
</code></pre>
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: 'markdown',
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
theme: "default"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-markdown</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,245 +0,0 @@
|
||||
CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
||||
|
||||
var htmlMode = CodeMirror.getMode(cmCfg, { name: 'xml', htmlMode: true });
|
||||
|
||||
var header = 'header'
|
||||
, code = 'comment'
|
||||
, quote = 'quote'
|
||||
, list = 'string'
|
||||
, hr = 'hr'
|
||||
, linktext = 'link'
|
||||
, linkhref = 'string'
|
||||
, em = 'em'
|
||||
, strong = 'strong'
|
||||
, emstrong = 'emstrong';
|
||||
|
||||
var hrRE = /^([*\-=_])(?:\s*\1){2,}\s*$/
|
||||
, ulRE = /^[*\-+]\s+/
|
||||
, olRE = /^[0-9]+\.\s+/
|
||||
, headerRE = /^(?:\={3,}|-{3,})$/
|
||||
, textRE = /^[^\[*_\\<>`]+/;
|
||||
|
||||
function switchInline(stream, state, f) {
|
||||
state.f = state.inline = f;
|
||||
return f(stream, state);
|
||||
}
|
||||
|
||||
function switchBlock(stream, state, f) {
|
||||
state.f = state.block = f;
|
||||
return f(stream, state);
|
||||
}
|
||||
|
||||
|
||||
// Blocks
|
||||
|
||||
function blankLine(state) {
|
||||
// Reset EM state
|
||||
state.em = false;
|
||||
// Reset STRONG state
|
||||
state.strong = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
function blockNormal(stream, state) {
|
||||
var match;
|
||||
if (state.indentationDiff >= 4) {
|
||||
state.indentation -= state.indentationDiff;
|
||||
stream.skipToEnd();
|
||||
return code;
|
||||
} else if (stream.eatSpace()) {
|
||||
return null;
|
||||
} else if (stream.peek() === '#' || stream.match(headerRE)) {
|
||||
state.header = true;
|
||||
} else if (stream.eat('>')) {
|
||||
state.indentation++;
|
||||
state.quote = true;
|
||||
} else if (stream.peek() === '[') {
|
||||
return switchInline(stream, state, footnoteLink);
|
||||
} else if (stream.match(hrRE, true)) {
|
||||
return hr;
|
||||
} else if (match = stream.match(ulRE, true) || stream.match(olRE, true)) {
|
||||
state.indentation += match[0].length;
|
||||
return list;
|
||||
}
|
||||
|
||||
return switchInline(stream, state, state.inline);
|
||||
}
|
||||
|
||||
function htmlBlock(stream, state) {
|
||||
var style = htmlMode.token(stream, state.htmlState);
|
||||
if (style === 'tag' && state.htmlState.type !== 'openTag' && !state.htmlState.context) {
|
||||
state.f = inlineNormal;
|
||||
state.block = blockNormal;
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
|
||||
// Inline
|
||||
function getType(state) {
|
||||
var styles = [];
|
||||
|
||||
if (state.strong) { styles.push(state.em ? emstrong : strong); }
|
||||
else if (state.em) { styles.push(em); }
|
||||
|
||||
if (state.header) { styles.push(header); }
|
||||
if (state.quote) { styles.push(quote); }
|
||||
|
||||
return styles.length ? styles.join(' ') : null;
|
||||
}
|
||||
|
||||
function handleText(stream, state) {
|
||||
if (stream.match(textRE, true)) {
|
||||
return getType(state);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function inlineNormal(stream, state) {
|
||||
var style = state.text(stream, state)
|
||||
if (typeof style !== 'undefined')
|
||||
return style;
|
||||
|
||||
var ch = stream.next();
|
||||
|
||||
if (ch === '\\') {
|
||||
stream.next();
|
||||
return getType(state);
|
||||
}
|
||||
if (ch === '`') {
|
||||
return switchInline(stream, state, inlineElement(code, '`'));
|
||||
}
|
||||
if (ch === '[') {
|
||||
return switchInline(stream, state, linkText);
|
||||
}
|
||||
if (ch === '<' && stream.match(/^\w/, false)) {
|
||||
stream.backUp(1);
|
||||
return switchBlock(stream, state, htmlBlock);
|
||||
}
|
||||
|
||||
var t = getType(state);
|
||||
if (ch === '*' || ch === '_') {
|
||||
if (stream.eat(ch)) {
|
||||
return (state.strong = !state.strong) ? getType(state) : t;
|
||||
}
|
||||
return (state.em = !state.em) ? getType(state) : t;
|
||||
}
|
||||
|
||||
return getType(state);
|
||||
}
|
||||
|
||||
function linkText(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
var ch = stream.next();
|
||||
if (ch === '\\') stream.next();
|
||||
if (ch === ']') {
|
||||
state.inline = state.f = linkHref;
|
||||
return linktext;
|
||||
}
|
||||
}
|
||||
return linktext;
|
||||
}
|
||||
|
||||
function linkHref(stream, state) {
|
||||
stream.eatSpace();
|
||||
var ch = stream.next();
|
||||
if (ch === '(' || ch === '[') {
|
||||
return switchInline(stream, state, inlineElement(linkhref, ch === '(' ? ')' : ']'));
|
||||
}
|
||||
return 'error';
|
||||
}
|
||||
|
||||
function footnoteLink(stream, state) {
|
||||
if (stream.match(/^[^\]]*\]:/, true)) {
|
||||
state.f = footnoteUrl;
|
||||
return linktext;
|
||||
}
|
||||
return switchInline(stream, state, inlineNormal);
|
||||
}
|
||||
|
||||
function footnoteUrl(stream, state) {
|
||||
stream.eatSpace();
|
||||
stream.match(/^[^\s]+/, true);
|
||||
state.f = state.inline = inlineNormal;
|
||||
return linkhref;
|
||||
}
|
||||
|
||||
function inlineRE(endChar) {
|
||||
if (!inlineRE[endChar]) {
|
||||
// match any not-escaped-non-endChar and any escaped char
|
||||
// then match endChar or eol
|
||||
inlineRE[endChar] = new RegExp('^(?:[^\\\\\\' + endChar + ']|\\\\.)*(?:\\' + endChar + '|$)');
|
||||
}
|
||||
return inlineRE[endChar];
|
||||
}
|
||||
|
||||
function inlineElement(type, endChar, next) {
|
||||
next = next || inlineNormal;
|
||||
return function(stream, state) {
|
||||
stream.match(inlineRE(endChar));
|
||||
state.inline = state.f = next;
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return {
|
||||
f: blockNormal,
|
||||
|
||||
block: blockNormal,
|
||||
htmlState: htmlMode.startState(),
|
||||
indentation: 0,
|
||||
|
||||
inline: inlineNormal,
|
||||
text: handleText,
|
||||
em: false,
|
||||
strong: false,
|
||||
header: false,
|
||||
quote: false
|
||||
};
|
||||
},
|
||||
|
||||
copyState: function(s) {
|
||||
return {
|
||||
f: s.f,
|
||||
|
||||
block: s.block,
|
||||
htmlState: CodeMirror.copyState(htmlMode, s.htmlState),
|
||||
indentation: s.indentation,
|
||||
|
||||
inline: s.inline,
|
||||
text: s.text,
|
||||
em: s.em,
|
||||
strong: s.strong,
|
||||
header: s.header,
|
||||
quote: s.quote
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) {
|
||||
if (stream.match(/^\s*$/, true)) { return blankLine(state); }
|
||||
|
||||
// Reset state.header
|
||||
state.header = false;
|
||||
// Reset state.quote
|
||||
state.quote = false;
|
||||
|
||||
state.f = state.block;
|
||||
var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length;
|
||||
state.indentationDiff = indentation - state.indentation;
|
||||
state.indentation = indentation;
|
||||
if (indentation > 0) { return null; }
|
||||
}
|
||||
return state.f(stream, state);
|
||||
},
|
||||
|
||||
blankLine: blankLine,
|
||||
|
||||
getType: getType
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-markdown", "markdown");
|
@ -1,41 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: MySQL mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="mysql.js"></script>
|
||||
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: MySQL mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
-- Comment for the code
|
||||
-- MySQL Mode for CodeMirror2 by MySQLTools http://github.com/partydroid/MySQL-Tools
|
||||
SELECT UNIQUE `var1` as `variable`,
|
||||
MAX(`var5`) as `max`,
|
||||
MIN(`var5`) as `min`,
|
||||
STDEV(`var5`) as `dev`
|
||||
FROM `table`
|
||||
|
||||
LEFT JOIN `table2` ON `var2` = `variable`
|
||||
|
||||
ORDER BY `var3` DESC
|
||||
GROUP BY `groupvar`
|
||||
|
||||
LIMIT 0,30;
|
||||
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "text/x-mysql",
|
||||
tabMode: "indent",
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-mysql</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,188 +0,0 @@
|
||||
/*
|
||||
* MySQL Mode for CodeMirror 2 by MySQL-Tools
|
||||
* @author James Thorne (partydroid)
|
||||
* @link http://github.com/partydroid/MySQL-Tools
|
||||
* @link http://mysqltools.org
|
||||
* @version 02/Jan/2012
|
||||
*/
|
||||
CodeMirror.defineMode("mysql", function(config) {
|
||||
var indentUnit = config.indentUnit;
|
||||
var curPunc;
|
||||
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
|
||||
"isblank", "isliteral", "union", "a"]);
|
||||
var keywords = wordRegexp([
|
||||
('ACCESSIBLE'),('ALTER'),('AS'),('BEFORE'),('BINARY'),('BY'),('CASE'),('CHARACTER'),('COLUMN'),('CONTINUE'),('CROSS'),('CURRENT_TIMESTAMP'),('DATABASE'),('DAY_MICROSECOND'),('DEC'),('DEFAULT'),
|
||||
('DESC'),('DISTINCT'),('DOUBLE'),('EACH'),('ENCLOSED'),('EXIT'),('FETCH'),('FLOAT8'),('FOREIGN'),('GRANT'),('HIGH_PRIORITY'),('HOUR_SECOND'),('IN'),('INNER'),('INSERT'),('INT2'),('INT8'),
|
||||
('INTO'),('JOIN'),('KILL'),('LEFT'),('LINEAR'),('LOCALTIME'),('LONG'),('LOOP'),('MATCH'),('MEDIUMTEXT'),('MINUTE_SECOND'),('NATURAL'),('NULL'),('OPTIMIZE'),('OR'),('OUTER'),('PRIMARY'),
|
||||
('RANGE'),('READ_WRITE'),('REGEXP'),('REPEAT'),('RESTRICT'),('RIGHT'),('SCHEMAS'),('SENSITIVE'),('SHOW'),('SPECIFIC'),('SQLSTATE'),('SQL_CALC_FOUND_ROWS'),('STARTING'),('TERMINATED'),
|
||||
('TINYINT'),('TRAILING'),('UNDO'),('UNLOCK'),('USAGE'),('UTC_DATE'),('VALUES'),('VARCHARACTER'),('WHERE'),('WRITE'),('ZEROFILL'),('ALL'),('AND'),('ASENSITIVE'),('BIGINT'),('BOTH'),('CASCADE'),
|
||||
('CHAR'),('COLLATE'),('CONSTRAINT'),('CREATE'),('CURRENT_TIME'),('CURSOR'),('DAY_HOUR'),('DAY_SECOND'),('DECLARE'),('DELETE'),('DETERMINISTIC'),('DIV'),('DUAL'),('ELSEIF'),('EXISTS'),('FALSE'),
|
||||
('FLOAT4'),('FORCE'),('FULLTEXT'),('HAVING'),('HOUR_MINUTE'),('IGNORE'),('INFILE'),('INSENSITIVE'),('INT1'),('INT4'),('INTERVAL'),('ITERATE'),('KEYS'),('LEAVE'),('LIMIT'),('LOAD'),('LOCK'),
|
||||
('LONGTEXT'),('MASTER_SSL_VERIFY_SERVER_CERT'),('MEDIUMINT'),('MINUTE_MICROSECOND'),('MODIFIES'),('NO_WRITE_TO_BINLOG'),('ON'),('OPTIONALLY'),('OUT'),('PRECISION'),('PURGE'),('READS'),
|
||||
('REFERENCES'),('RENAME'),('REQUIRE'),('REVOKE'),('SCHEMA'),('SELECT'),('SET'),('SPATIAL'),('SQLEXCEPTION'),('SQL_BIG_RESULT'),('SSL'),('TABLE'),('TINYBLOB'),('TO'),('TRUE'),('UNIQUE'),
|
||||
('UPDATE'),('USING'),('UTC_TIMESTAMP'),('VARCHAR'),('WHEN'),('WITH'),('YEAR_MONTH'),('ADD'),('ANALYZE'),('ASC'),('BETWEEN'),('BLOB'),('CALL'),('CHANGE'),('CHECK'),('CONDITION'),('CONVERT'),
|
||||
('CURRENT_DATE'),('CURRENT_USER'),('DATABASES'),('DAY_MINUTE'),('DECIMAL'),('DELAYED'),('DESCRIBE'),('DISTINCTROW'),('DROP'),('ELSE'),('ESCAPED'),('EXPLAIN'),('FLOAT'),('FOR'),('FROM'),
|
||||
('GROUP'),('HOUR_MICROSECOND'),('IF'),('INDEX'),('INOUT'),('INT'),('INT3'),('INTEGER'),('IS'),('KEY'),('LEADING'),('LIKE'),('LINES'),('LOCALTIMESTAMP'),('LONGBLOB'),('LOW_PRIORITY'),
|
||||
('MEDIUMBLOB'),('MIDDLEINT'),('MOD'),('NOT'),('NUMERIC'),('OPTION'),('ORDER'),('OUTFILE'),('PROCEDURE'),('READ'),('REAL'),('RELEASE'),('REPLACE'),('RETURN'),('RLIKE'),('SECOND_MICROSECOND'),
|
||||
('SEPARATOR'),('SMALLINT'),('SQL'),('SQLWARNING'),('SQL_SMALL_RESULT'),('STRAIGHT_JOIN'),('THEN'),('TINYTEXT'),('TRIGGER'),('UNION'),('UNSIGNED'),('USE'),('UTC_TIME'),('VARBINARY'),('VARYING'),
|
||||
('WHILE'),('XOR'),('FULL'),('COLUMNS'),('MIN'),('MAX'),('STDEV'),('COUNT')
|
||||
]);
|
||||
var operatorChars = /[*+\-<>=&|]/;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
curPunc = null;
|
||||
if (ch == "$" || ch == "?") {
|
||||
stream.match(/^[\w\d]*/);
|
||||
return "variable-2";
|
||||
}
|
||||
else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
|
||||
stream.match(/^[^\s\u00a0>]*>?/);
|
||||
return "atom";
|
||||
}
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
state.tokenize = tokenLiteral(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
else if (ch == "`") {
|
||||
state.tokenize = tokenOpLiteral(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
else if (/[{}\(\),\.;\[\]]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null;
|
||||
}
|
||||
else if (ch == "-") {
|
||||
ch2 = stream.next();
|
||||
if(ch2=="-")
|
||||
{
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
|
||||
}
|
||||
else if (operatorChars.test(ch)) {
|
||||
stream.eatWhile(operatorChars);
|
||||
return null;
|
||||
}
|
||||
else if (ch == ":") {
|
||||
stream.eatWhile(/[\w\d\._\-]/);
|
||||
return "atom";
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(/[_\w\d]/);
|
||||
if (stream.eat(":")) {
|
||||
stream.eatWhile(/[\w\d_\-]/);
|
||||
return "atom";
|
||||
}
|
||||
var word = stream.current(), type;
|
||||
if (ops.test(word))
|
||||
return null;
|
||||
else if (keywords.test(word))
|
||||
return "keyword";
|
||||
else
|
||||
return "variable";
|
||||
}
|
||||
}
|
||||
|
||||
function tokenLiteral(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == quote && !escaped) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenOpLiteral(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == quote && !escaped) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
return "variable-2";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function pushContext(state, type, col) {
|
||||
state.context = {prev: state.context, indent: state.indent, col: col, type: type};
|
||||
}
|
||||
function popContext(state) {
|
||||
state.indent = state.context.indent;
|
||||
state.context = state.context.prev;
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function(base) {
|
||||
return {tokenize: tokenBase,
|
||||
context: null,
|
||||
indent: 0,
|
||||
col: 0};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) {
|
||||
if (state.context && state.context.align == null) state.context.align = false;
|
||||
state.indent = stream.indentation();
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
|
||||
if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
|
||||
state.context.align = true;
|
||||
}
|
||||
|
||||
if (curPunc == "(") pushContext(state, ")", stream.column());
|
||||
else if (curPunc == "[") pushContext(state, "]", stream.column());
|
||||
else if (curPunc == "{") pushContext(state, "}", stream.column());
|
||||
else if (/[\]\}\)]/.test(curPunc)) {
|
||||
while (state.context && state.context.type == "pattern") popContext(state);
|
||||
if (state.context && curPunc == state.context.type) popContext(state);
|
||||
}
|
||||
else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
|
||||
else if (/atom|string|variable/.test(style) && state.context) {
|
||||
if (/[\}\]]/.test(state.context.type))
|
||||
pushContext(state, "pattern", stream.column());
|
||||
else if (state.context.type == "pattern" && !state.context.align) {
|
||||
state.context.align = true;
|
||||
state.context.col = stream.column();
|
||||
}
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var firstChar = textAfter && textAfter.charAt(0);
|
||||
var context = state.context;
|
||||
if (/[\]\}]/.test(firstChar))
|
||||
while (context && context.type == "pattern") context = context.prev;
|
||||
|
||||
var closing = context && firstChar == context.type;
|
||||
if (!context)
|
||||
return 0;
|
||||
else if (context.type == "pattern")
|
||||
return context.col;
|
||||
else if (context.align)
|
||||
return context.col + (closing ? 0 : 1);
|
||||
else
|
||||
return context.indent + (closing ? 0 : indentUnit);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-mysql", "mysql");
|
@ -1,32 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: NTriples mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="ntriples.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style type="text/css">
|
||||
.CodeMirror {
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: NTriples mode</h1>
|
||||
<form>
|
||||
<textarea id="ntriples" name="ntriples">
|
||||
<http://Sub1> <http://pred1> <http://obj> .
|
||||
<http://Sub2> <http://pred2#an2> "literal 1" .
|
||||
<http://Sub3#an3> <http://pred3> _:bnode3 .
|
||||
_:bnode4 <http://pred4> "literal 2"@lang .
|
||||
_:bnode5 <http://pred5> "literal 3"^^<http://type> .
|
||||
</textarea>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("ntriples"), {});
|
||||
</script>
|
||||
<p><strong>MIME types defined:</strong> <code>text/n-triples</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,172 +0,0 @@
|
||||
/**********************************************************
|
||||
* This script provides syntax highlighting support for
|
||||
* the Ntriples format.
|
||||
* Ntriples format specification:
|
||||
* http://www.w3.org/TR/rdf-testcases/#ntriples
|
||||
***********************************************************/
|
||||
|
||||
/*
|
||||
The following expression defines the defined ASF grammar transitions.
|
||||
|
||||
pre_subject ->
|
||||
{
|
||||
( writing_subject_uri | writing_bnode_uri )
|
||||
-> pre_predicate
|
||||
-> writing_predicate_uri
|
||||
-> pre_object
|
||||
-> writing_object_uri | writing_object_bnode |
|
||||
(
|
||||
writing_object_literal
|
||||
-> writing_literal_lang | writing_literal_type
|
||||
)
|
||||
-> post_object
|
||||
-> BEGIN
|
||||
} otherwise {
|
||||
-> ERROR
|
||||
}
|
||||
*/
|
||||
CodeMirror.defineMode("ntriples", function() {
|
||||
|
||||
Location = {
|
||||
PRE_SUBJECT : 0,
|
||||
WRITING_SUB_URI : 1,
|
||||
WRITING_BNODE_URI : 2,
|
||||
PRE_PRED : 3,
|
||||
WRITING_PRED_URI : 4,
|
||||
PRE_OBJ : 5,
|
||||
WRITING_OBJ_URI : 6,
|
||||
WRITING_OBJ_BNODE : 7,
|
||||
WRITING_OBJ_LITERAL : 8,
|
||||
WRITING_LIT_LANG : 9,
|
||||
WRITING_LIT_TYPE : 10,
|
||||
POST_OBJ : 11,
|
||||
ERROR : 12
|
||||
};
|
||||
function transitState(currState, c) {
|
||||
var currLocation = currState.location;
|
||||
var ret;
|
||||
|
||||
// Opening.
|
||||
if (currLocation == Location.PRE_SUBJECT && c == '<') ret = Location.WRITING_SUB_URI;
|
||||
else if(currLocation == Location.PRE_SUBJECT && c == '_') ret = Location.WRITING_BNODE_URI;
|
||||
else if(currLocation == Location.PRE_PRED && c == '<') ret = Location.WRITING_PRED_URI;
|
||||
else if(currLocation == Location.PRE_OBJ && c == '<') ret = Location.WRITING_OBJ_URI;
|
||||
else if(currLocation == Location.PRE_OBJ && c == '_') ret = Location.WRITING_OBJ_BNODE;
|
||||
else if(currLocation == Location.PRE_OBJ && c == '"') ret = Location.WRITING_OBJ_LITERAL;
|
||||
|
||||
// Closing.
|
||||
else if(currLocation == Location.WRITING_SUB_URI && c == '>') ret = Location.PRE_PRED;
|
||||
else if(currLocation == Location.WRITING_BNODE_URI && c == ' ') ret = Location.PRE_PRED;
|
||||
else if(currLocation == Location.WRITING_PRED_URI && c == '>') ret = Location.PRE_OBJ;
|
||||
else if(currLocation == Location.WRITING_OBJ_URI && c == '>') ret = Location.POST_OBJ;
|
||||
else if(currLocation == Location.WRITING_OBJ_BNODE && c == ' ') ret = Location.POST_OBJ;
|
||||
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '"') ret = Location.POST_OBJ;
|
||||
else if(currLocation == Location.WRITING_LIT_LANG && c == ' ') ret = Location.POST_OBJ;
|
||||
else if(currLocation == Location.WRITING_LIT_TYPE && c == '>') ret = Location.POST_OBJ;
|
||||
|
||||
// Closing typed and language literal.
|
||||
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '@') ret = Location.WRITING_LIT_LANG;
|
||||
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '^') ret = Location.WRITING_LIT_TYPE;
|
||||
|
||||
// Spaces.
|
||||
else if( c == ' ' &&
|
||||
(
|
||||
currLocation == Location.PRE_SUBJECT ||
|
||||
currLocation == Location.PRE_PRED ||
|
||||
currLocation == Location.PRE_OBJ ||
|
||||
currLocation == Location.POST_OBJ
|
||||
)
|
||||
) ret = currLocation;
|
||||
|
||||
// Reset.
|
||||
else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT;
|
||||
|
||||
// Error
|
||||
else ret = Location.ERROR;
|
||||
|
||||
currState.location=ret;
|
||||
}
|
||||
|
||||
untilSpace = function(c) { return c != ' '; };
|
||||
untilEndURI = function(c) { return c != '>'; };
|
||||
return {
|
||||
startState: function() {
|
||||
return {
|
||||
location : Location.PRE_SUBJECT,
|
||||
uris : [],
|
||||
anchors : [],
|
||||
bnodes : [],
|
||||
langs : [],
|
||||
types : []
|
||||
};
|
||||
},
|
||||
token: function(stream, state) {
|
||||
var ch = stream.next();
|
||||
if(ch == '<') {
|
||||
transitState(state, ch);
|
||||
var parsedURI = '';
|
||||
stream.eatWhile( function(c) { if( c != '#' && c != '>' ) { parsedURI += c; return true; } return false;} );
|
||||
state.uris.push(parsedURI);
|
||||
if( stream.match('#', false) ) return 'variable';
|
||||
stream.next();
|
||||
transitState(state, '>');
|
||||
return 'variable';
|
||||
}
|
||||
if(ch == '#') {
|
||||
var parsedAnchor = '';
|
||||
stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false});
|
||||
state.anchors.push(parsedAnchor);
|
||||
return 'variable-2';
|
||||
}
|
||||
if(ch == '>') {
|
||||
transitState(state, '>');
|
||||
return 'variable';
|
||||
}
|
||||
if(ch == '_') {
|
||||
transitState(state, ch);
|
||||
var parsedBNode = '';
|
||||
stream.eatWhile(function(c) { if( c != ' ' ) { parsedBNode += c; return true; } return false;});
|
||||
state.bnodes.push(parsedBNode);
|
||||
stream.next();
|
||||
transitState(state, ' ');
|
||||
return 'builtin';
|
||||
}
|
||||
if(ch == '"') {
|
||||
transitState(state, ch);
|
||||
stream.eatWhile( function(c) { return c != '"'; } );
|
||||
stream.next();
|
||||
if( stream.peek() != '@' && stream.peek() != '^' ) {
|
||||
transitState(state, '"');
|
||||
}
|
||||
return 'string';
|
||||
}
|
||||
if( ch == '@' ) {
|
||||
transitState(state, '@');
|
||||
var parsedLang = '';
|
||||
stream.eatWhile(function(c) { if( c != ' ' ) { parsedLang += c; return true; } return false;});
|
||||
state.langs.push(parsedLang);
|
||||
stream.next();
|
||||
transitState(state, ' ');
|
||||
return 'string-2';
|
||||
}
|
||||
if( ch == '^' ) {
|
||||
stream.next();
|
||||
transitState(state, '^');
|
||||
var parsedType = '';
|
||||
stream.eatWhile(function(c) { if( c != '>' ) { parsedType += c; return true; } return false;} );
|
||||
state.types.push(parsedType);
|
||||
stream.next();
|
||||
transitState(state, '>');
|
||||
return 'variable';
|
||||
}
|
||||
if( ch == ' ' ) {
|
||||
transitState(state, ch);
|
||||
}
|
||||
if( ch == '.' ) {
|
||||
transitState(state, ch);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/n-triples", "ntriples");
|
@ -1,7 +0,0 @@
|
||||
Copyright (c) 2011 souceLair <support@sourcelair.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -1,48 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Pascal mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="pascal.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Pascal mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
(* Example Pascal code *)
|
||||
|
||||
while a <> b do writeln('Waiting');
|
||||
|
||||
if a > b then
|
||||
writeln('Condition met')
|
||||
else
|
||||
writeln('Condition not met');
|
||||
|
||||
for i := 1 to 10 do
|
||||
writeln('Iteration: ', i:1);
|
||||
|
||||
repeat
|
||||
a := a + 1
|
||||
until a = 10;
|
||||
|
||||
case i of
|
||||
0: write('zero');
|
||||
1: write('one');
|
||||
2: write('two')
|
||||
end;
|
||||
</textarea></div>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "text/x-pascal"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-pascal</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,94 +0,0 @@
|
||||
CodeMirror.defineMode("pascal", function(config) {
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
var keywords = words("and array begin case const div do downto else end file for forward integer " +
|
||||
"boolean char function goto if in label mod nil not of or packed procedure " +
|
||||
"program record repeat set string then to type until var while with");
|
||||
var atoms = {"null": true};
|
||||
|
||||
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == "#" && state.startOfLine) {
|
||||
stream.skipToEnd();
|
||||
return "meta";
|
||||
}
|
||||
if (ch == '"' || ch == "'") {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
if (ch == "(" && stream.eat("*")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
return null
|
||||
}
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
return "number";
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
}
|
||||
if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
var cur = stream.current();
|
||||
if (keywords.propertyIsEnumerable(cur)) return "keyword";
|
||||
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
||||
return "word";
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {end = true; break;}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !escaped) state.tokenize = null;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == ")" && maybeEnd) {
|
||||
state.tokenize = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {tokenize: null};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = (state.tokenize || tokenBase)(stream, state);
|
||||
if (style == "comment" || style == "meta") return style;
|
||||
return style;
|
||||
},
|
||||
|
||||
electricChars: "{}"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-pascal", "pascal");
|
@ -1,19 +0,0 @@
|
||||
Copyright (C) 2011 by Sabaca <mail@sabaca.com> under the MIT license.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -1,62 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Perl mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="perl.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Perl mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
#!/usr/bin/perl
|
||||
|
||||
use Something qw(func1 func2);
|
||||
|
||||
# strings
|
||||
my $s1 = qq'single line';
|
||||
our $s2 = q(multi-
|
||||
line);
|
||||
|
||||
=item Something
|
||||
Example.
|
||||
=cut
|
||||
|
||||
my $html=<<'HTML'
|
||||
<html>
|
||||
<title>hi!</title>
|
||||
</html>
|
||||
HTML
|
||||
|
||||
print "first,".join(',', 'second', qq~third~);
|
||||
|
||||
if($s1 =~ m[(?<!\s)(l.ne)\z]o) {
|
||||
$h->{$1}=$$.' predefined variables';
|
||||
$s2 =~ s/\-line//ox;
|
||||
$s1 =~ s[
|
||||
line ]
|
||||
[
|
||||
block
|
||||
]ox;
|
||||
}
|
||||
|
||||
1; # numbers and comments
|
||||
|
||||
__END__
|
||||
something...
|
||||
|
||||
</textarea></div>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-perl</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,816 +0,0 @@
|
||||
// CodeMirror2 mode/perl/perl.js (text/x-perl) beta 0.10 (2011-11-08)
|
||||
// This is a part of CodeMirror from https://github.com/sabaca/CodeMirror_mode_perl (mail@sabaca.com)
|
||||
CodeMirror.defineMode("perl",function(config,parserConfig){
|
||||
// http://perldoc.perl.org
|
||||
var PERL={ // null - magic touch
|
||||
// 1 - keyword
|
||||
// 2 - def
|
||||
// 3 - atom
|
||||
// 4 - operator
|
||||
// 5 - variable-2 (predefined)
|
||||
// [x,y] - x=1,2,3; y=must be defined if x{...}
|
||||
// PERL operators
|
||||
'->' : 4,
|
||||
'++' : 4,
|
||||
'--' : 4,
|
||||
'**' : 4,
|
||||
// ! ~ \ and unary + and -
|
||||
'=~' : 4,
|
||||
'!~' : 4,
|
||||
'*' : 4,
|
||||
'/' : 4,
|
||||
'%' : 4,
|
||||
'x' : 4,
|
||||
'+' : 4,
|
||||
'-' : 4,
|
||||
'.' : 4,
|
||||
'<<' : 4,
|
||||
'>>' : 4,
|
||||
// named unary operators
|
||||
'<' : 4,
|
||||
'>' : 4,
|
||||
'<=' : 4,
|
||||
'>=' : 4,
|
||||
'lt' : 4,
|
||||
'gt' : 4,
|
||||
'le' : 4,
|
||||
'ge' : 4,
|
||||
'==' : 4,
|
||||
'!=' : 4,
|
||||
'<=>' : 4,
|
||||
'eq' : 4,
|
||||
'ne' : 4,
|
||||
'cmp' : 4,
|
||||
'~~' : 4,
|
||||
'&' : 4,
|
||||
'|' : 4,
|
||||
'^' : 4,
|
||||
'&&' : 4,
|
||||
'||' : 4,
|
||||
'//' : 4,
|
||||
'..' : 4,
|
||||
'...' : 4,
|
||||
'?' : 4,
|
||||
':' : 4,
|
||||
'=' : 4,
|
||||
'+=' : 4,
|
||||
'-=' : 4,
|
||||
'*=' : 4, // etc. ???
|
||||
',' : 4,
|
||||
'=>' : 4,
|
||||
'::' : 4,
|
||||
// list operators (rightward)
|
||||
'not' : 4,
|
||||
'and' : 4,
|
||||
'or' : 4,
|
||||
'xor' : 4,
|
||||
// PERL predefined variables (I know, what this is a paranoid idea, but may be needed for people, who learn PERL, and for me as well, ...and may be for you?;)
|
||||
'BEGIN' : [5,1],
|
||||
'END' : [5,1],
|
||||
'PRINT' : [5,1],
|
||||
'PRINTF' : [5,1],
|
||||
'GETC' : [5,1],
|
||||
'READ' : [5,1],
|
||||
'READLINE' : [5,1],
|
||||
'DESTROY' : [5,1],
|
||||
'TIE' : [5,1],
|
||||
'TIEHANDLE' : [5,1],
|
||||
'UNTIE' : [5,1],
|
||||
'STDIN' : 5,
|
||||
'STDIN_TOP' : 5,
|
||||
'STDOUT' : 5,
|
||||
'STDOUT_TOP' : 5,
|
||||
'STDERR' : 5,
|
||||
'STDERR_TOP' : 5,
|
||||
'$ARG' : 5,
|
||||
'$_' : 5,
|
||||
'@ARG' : 5,
|
||||
'@_' : 5,
|
||||
'$LIST_SEPARATOR' : 5,
|
||||
'$"' : 5,
|
||||
'$PROCESS_ID' : 5,
|
||||
'$PID' : 5,
|
||||
'$$' : 5,
|
||||
'$REAL_GROUP_ID' : 5,
|
||||
'$GID' : 5,
|
||||
'$(' : 5,
|
||||
'$EFFECTIVE_GROUP_ID' : 5,
|
||||
'$EGID' : 5,
|
||||
'$)' : 5,
|
||||
'$PROGRAM_NAME' : 5,
|
||||
'$0' : 5,
|
||||
'$SUBSCRIPT_SEPARATOR' : 5,
|
||||
'$SUBSEP' : 5,
|
||||
'$;' : 5,
|
||||
'$REAL_USER_ID' : 5,
|
||||
'$UID' : 5,
|
||||
'$<' : 5,
|
||||
'$EFFECTIVE_USER_ID' : 5,
|
||||
'$EUID' : 5,
|
||||
'$>' : 5,
|
||||
'$a' : 5,
|
||||
'$b' : 5,
|
||||
'$COMPILING' : 5,
|
||||
'$^C' : 5,
|
||||
'$DEBUGGING' : 5,
|
||||
'$^D' : 5,
|
||||
'${^ENCODING}' : 5,
|
||||
'$ENV' : 5,
|
||||
'%ENV' : 5,
|
||||
'$SYSTEM_FD_MAX' : 5,
|
||||
'$^F' : 5,
|
||||
'@F' : 5,
|
||||
'${^GLOBAL_PHASE}' : 5,
|
||||
'$^H' : 5,
|
||||
'%^H' : 5,
|
||||
'@INC' : 5,
|
||||
'%INC' : 5,
|
||||
'$INPLACE_EDIT' : 5,
|
||||
'$^I' : 5,
|
||||
'$^M' : 5,
|
||||
'$OSNAME' : 5,
|
||||
'$^O' : 5,
|
||||
'${^OPEN}' : 5,
|
||||
'$PERLDB' : 5,
|
||||
'$^P' : 5,
|
||||
'$SIG' : 5,
|
||||
'%SIG' : 5,
|
||||
'$BASETIME' : 5,
|
||||
'$^T' : 5,
|
||||
'${^TAINT}' : 5,
|
||||
'${^UNICODE}' : 5,
|
||||
'${^UTF8CACHE}' : 5,
|
||||
'${^UTF8LOCALE}' : 5,
|
||||
'$PERL_VERSION' : 5,
|
||||
'$^V' : 5,
|
||||
'${^WIN32_SLOPPY_STAT}' : 5,
|
||||
'$EXECUTABLE_NAME' : 5,
|
||||
'$^X' : 5,
|
||||
'$1' : 5, // - regexp $1, $2...
|
||||
'$MATCH' : 5,
|
||||
'$&' : 5,
|
||||
'${^MATCH}' : 5,
|
||||
'$PREMATCH' : 5,
|
||||
'$`' : 5,
|
||||
'${^PREMATCH}' : 5,
|
||||
'$POSTMATCH' : 5,
|
||||
"$'" : 5,
|
||||
'${^POSTMATCH}' : 5,
|
||||
'$LAST_PAREN_MATCH' : 5,
|
||||
'$+' : 5,
|
||||
'$LAST_SUBMATCH_RESULT' : 5,
|
||||
'$^N' : 5,
|
||||
'@LAST_MATCH_END' : 5,
|
||||
'@+' : 5,
|
||||
'%LAST_PAREN_MATCH' : 5,
|
||||
'%+' : 5,
|
||||
'@LAST_MATCH_START' : 5,
|
||||
'@-' : 5,
|
||||
'%LAST_MATCH_START' : 5,
|
||||
'%-' : 5,
|
||||
'$LAST_REGEXP_CODE_RESULT' : 5,
|
||||
'$^R' : 5,
|
||||
'${^RE_DEBUG_FLAGS}' : 5,
|
||||
'${^RE_TRIE_MAXBUF}' : 5,
|
||||
'$ARGV' : 5,
|
||||
'@ARGV' : 5,
|
||||
'ARGV' : 5,
|
||||
'ARGVOUT' : 5,
|
||||
'$OUTPUT_FIELD_SEPARATOR' : 5,
|
||||
'$OFS' : 5,
|
||||
'$,' : 5,
|
||||
'$INPUT_LINE_NUMBER' : 5,
|
||||
'$NR' : 5,
|
||||
'$.' : 5,
|
||||
'$INPUT_RECORD_SEPARATOR' : 5,
|
||||
'$RS' : 5,
|
||||
'$/' : 5,
|
||||
'$OUTPUT_RECORD_SEPARATOR' : 5,
|
||||
'$ORS' : 5,
|
||||
'$\\' : 5,
|
||||
'$OUTPUT_AUTOFLUSH' : 5,
|
||||
'$|' : 5,
|
||||
'$ACCUMULATOR' : 5,
|
||||
'$^A' : 5,
|
||||
'$FORMAT_FORMFEED' : 5,
|
||||
'$^L' : 5,
|
||||
'$FORMAT_PAGE_NUMBER' : 5,
|
||||
'$%' : 5,
|
||||
'$FORMAT_LINES_LEFT' : 5,
|
||||
'$-' : 5,
|
||||
'$FORMAT_LINE_BREAK_CHARACTERS' : 5,
|
||||
'$:' : 5,
|
||||
'$FORMAT_LINES_PER_PAGE' : 5,
|
||||
'$=' : 5,
|
||||
'$FORMAT_TOP_NAME' : 5,
|
||||
'$^' : 5,
|
||||
'$FORMAT_NAME' : 5,
|
||||
'$~' : 5,
|
||||
'${^CHILD_ERROR_NATIVE}' : 5,
|
||||
'$EXTENDED_OS_ERROR' : 5,
|
||||
'$^E' : 5,
|
||||
'$EXCEPTIONS_BEING_CAUGHT' : 5,
|
||||
'$^S' : 5,
|
||||
'$WARNING' : 5,
|
||||
'$^W' : 5,
|
||||
'${^WARNING_BITS}' : 5,
|
||||
'$OS_ERROR' : 5,
|
||||
'$ERRNO' : 5,
|
||||
'$!' : 5,
|
||||
'%OS_ERROR' : 5,
|
||||
'%ERRNO' : 5,
|
||||
'%!' : 5,
|
||||
'$CHILD_ERROR' : 5,
|
||||
'$?' : 5,
|
||||
'$EVAL_ERROR' : 5,
|
||||
'$@' : 5,
|
||||
'$OFMT' : 5,
|
||||
'$#' : 5,
|
||||
'$*' : 5,
|
||||
'$ARRAY_BASE' : 5,
|
||||
'$[' : 5,
|
||||
'$OLD_PERL_VERSION' : 5,
|
||||
'$]' : 5,
|
||||
// PERL blocks
|
||||
'if' :[1,1],
|
||||
elsif :[1,1],
|
||||
'else' :[1,1],
|
||||
'while' :[1,1],
|
||||
unless :[1,1],
|
||||
'for' :[1,1],
|
||||
foreach :[1,1],
|
||||
// PERL functions
|
||||
'abs' :1, // - absolute value function
|
||||
accept :1, // - accept an incoming socket connect
|
||||
alarm :1, // - schedule a SIGALRM
|
||||
'atan2' :1, // - arctangent of Y/X in the range -PI to PI
|
||||
bind :1, // - binds an address to a socket
|
||||
binmode :1, // - prepare binary files for I/O
|
||||
bless :1, // - create an object
|
||||
bootstrap :1, //
|
||||
'break' :1, // - break out of a "given" block
|
||||
caller :1, // - get context of the current subroutine call
|
||||
chdir :1, // - change your current working directory
|
||||
chmod :1, // - changes the permissions on a list of files
|
||||
chomp :1, // - remove a trailing record separator from a string
|
||||
chop :1, // - remove the last character from a string
|
||||
chown :1, // - change the owership on a list of files
|
||||
chr :1, // - get character this number represents
|
||||
chroot :1, // - make directory new root for path lookups
|
||||
close :1, // - close file (or pipe or socket) handle
|
||||
closedir :1, // - close directory handle
|
||||
connect :1, // - connect to a remote socket
|
||||
'continue' :[1,1], // - optional trailing block in a while or foreach
|
||||
'cos' :1, // - cosine function
|
||||
crypt :1, // - one-way passwd-style encryption
|
||||
dbmclose :1, // - breaks binding on a tied dbm file
|
||||
dbmopen :1, // - create binding on a tied dbm file
|
||||
'default' :1, //
|
||||
defined :1, // - test whether a value, variable, or function is defined
|
||||
'delete' :1, // - deletes a value from a hash
|
||||
die :1, // - raise an exception or bail out
|
||||
'do' :1, // - turn a BLOCK into a TERM
|
||||
dump :1, // - create an immediate core dump
|
||||
each :1, // - retrieve the next key/value pair from a hash
|
||||
endgrent :1, // - be done using group file
|
||||
endhostent :1, // - be done using hosts file
|
||||
endnetent :1, // - be done using networks file
|
||||
endprotoent :1, // - be done using protocols file
|
||||
endpwent :1, // - be done using passwd file
|
||||
endservent :1, // - be done using services file
|
||||
eof :1, // - test a filehandle for its end
|
||||
'eval' :1, // - catch exceptions or compile and run code
|
||||
'exec' :1, // - abandon this program to run another
|
||||
exists :1, // - test whether a hash key is present
|
||||
exit :1, // - terminate this program
|
||||
'exp' :1, // - raise I to a power
|
||||
fcntl :1, // - file control system call
|
||||
fileno :1, // - return file descriptor from filehandle
|
||||
flock :1, // - lock an entire file with an advisory lock
|
||||
fork :1, // - create a new process just like this one
|
||||
format :1, // - declare a picture format with use by the write() function
|
||||
formline :1, // - internal function used for formats
|
||||
getc :1, // - get the next character from the filehandle
|
||||
getgrent :1, // - get next group record
|
||||
getgrgid :1, // - get group record given group user ID
|
||||
getgrnam :1, // - get group record given group name
|
||||
gethostbyaddr :1, // - get host record given its address
|
||||
gethostbyname :1, // - get host record given name
|
||||
gethostent :1, // - get next hosts record
|
||||
getlogin :1, // - return who logged in at this tty
|
||||
getnetbyaddr :1, // - get network record given its address
|
||||
getnetbyname :1, // - get networks record given name
|
||||
getnetent :1, // - get next networks record
|
||||
getpeername :1, // - find the other end of a socket connection
|
||||
getpgrp :1, // - get process group
|
||||
getppid :1, // - get parent process ID
|
||||
getpriority :1, // - get current nice value
|
||||
getprotobyname :1, // - get protocol record given name
|
||||
getprotobynumber :1, // - get protocol record numeric protocol
|
||||
getprotoent :1, // - get next protocols record
|
||||
getpwent :1, // - get next passwd record
|
||||
getpwnam :1, // - get passwd record given user login name
|
||||
getpwuid :1, // - get passwd record given user ID
|
||||
getservbyname :1, // - get services record given its name
|
||||
getservbyport :1, // - get services record given numeric port
|
||||
getservent :1, // - get next services record
|
||||
getsockname :1, // - retrieve the sockaddr for a given socket
|
||||
getsockopt :1, // - get socket options on a given socket
|
||||
given :1, //
|
||||
glob :1, // - expand filenames using wildcards
|
||||
gmtime :1, // - convert UNIX time into record or string using Greenwich time
|
||||
'goto' :1, // - create spaghetti code
|
||||
grep :1, // - locate elements in a list test true against a given criterion
|
||||
hex :1, // - convert a string to a hexadecimal number
|
||||
'import' :1, // - patch a module's namespace into your own
|
||||
index :1, // - find a substring within a string
|
||||
'int' :1, // - get the integer portion of a number
|
||||
ioctl :1, // - system-dependent device control system call
|
||||
'join' :1, // - join a list into a string using a separator
|
||||
keys :1, // - retrieve list of indices from a hash
|
||||
kill :1, // - send a signal to a process or process group
|
||||
last :1, // - exit a block prematurely
|
||||
lc :1, // - return lower-case version of a string
|
||||
lcfirst :1, // - return a string with just the next letter in lower case
|
||||
length :1, // - return the number of bytes in a string
|
||||
'link' :1, // - create a hard link in the filesytem
|
||||
listen :1, // - register your socket as a server
|
||||
local : 2, // - create a temporary value for a global variable (dynamic scoping)
|
||||
localtime :1, // - convert UNIX time into record or string using local time
|
||||
lock :1, // - get a thread lock on a variable, subroutine, or method
|
||||
'log' :1, // - retrieve the natural logarithm for a number
|
||||
lstat :1, // - stat a symbolic link
|
||||
m :null, // - match a string with a regular expression pattern
|
||||
map :1, // - apply a change to a list to get back a new list with the changes
|
||||
mkdir :1, // - create a directory
|
||||
msgctl :1, // - SysV IPC message control operations
|
||||
msgget :1, // - get SysV IPC message queue
|
||||
msgrcv :1, // - receive a SysV IPC message from a message queue
|
||||
msgsnd :1, // - send a SysV IPC message to a message queue
|
||||
my : 2, // - declare and assign a local variable (lexical scoping)
|
||||
'new' :1, //
|
||||
next :1, // - iterate a block prematurely
|
||||
no :1, // - unimport some module symbols or semantics at compile time
|
||||
oct :1, // - convert a string to an octal number
|
||||
open :1, // - open a file, pipe, or descriptor
|
||||
opendir :1, // - open a directory
|
||||
ord :1, // - find a character's numeric representation
|
||||
our : 2, // - declare and assign a package variable (lexical scoping)
|
||||
pack :1, // - convert a list into a binary representation
|
||||
'package' :1, // - declare a separate global namespace
|
||||
pipe :1, // - open a pair of connected filehandles
|
||||
pop :1, // - remove the last element from an array and return it
|
||||
pos :1, // - find or set the offset for the last/next m//g search
|
||||
print :1, // - output a list to a filehandle
|
||||
printf :1, // - output a formatted list to a filehandle
|
||||
prototype :1, // - get the prototype (if any) of a subroutine
|
||||
push :1, // - append one or more elements to an array
|
||||
q :null, // - singly quote a string
|
||||
qq :null, // - doubly quote a string
|
||||
qr :null, // - Compile pattern
|
||||
quotemeta :null, // - quote regular expression magic characters
|
||||
qw :null, // - quote a list of words
|
||||
qx :null, // - backquote quote a string
|
||||
rand :1, // - retrieve the next pseudorandom number
|
||||
read :1, // - fixed-length buffered input from a filehandle
|
||||
readdir :1, // - get a directory from a directory handle
|
||||
readline :1, // - fetch a record from a file
|
||||
readlink :1, // - determine where a symbolic link is pointing
|
||||
readpipe :1, // - execute a system command and collect standard output
|
||||
recv :1, // - receive a message over a Socket
|
||||
redo :1, // - start this loop iteration over again
|
||||
ref :1, // - find out the type of thing being referenced
|
||||
rename :1, // - change a filename
|
||||
require :1, // - load in external functions from a library at runtime
|
||||
reset :1, // - clear all variables of a given name
|
||||
'return' :1, // - get out of a function early
|
||||
reverse :1, // - flip a string or a list
|
||||
rewinddir :1, // - reset directory handle
|
||||
rindex :1, // - right-to-left substring search
|
||||
rmdir :1, // - remove a directory
|
||||
s :null, // - replace a pattern with a string
|
||||
say :1, // - print with newline
|
||||
scalar :1, // - force a scalar context
|
||||
seek :1, // - reposition file pointer for random-access I/O
|
||||
seekdir :1, // - reposition directory pointer
|
||||
select :1, // - reset default output or do I/O multiplexing
|
||||
semctl :1, // - SysV semaphore control operations
|
||||
semget :1, // - get set of SysV semaphores
|
||||
semop :1, // - SysV semaphore operations
|
||||
send :1, // - send a message over a socket
|
||||
setgrent :1, // - prepare group file for use
|
||||
sethostent :1, // - prepare hosts file for use
|
||||
setnetent :1, // - prepare networks file for use
|
||||
setpgrp :1, // - set the process group of a process
|
||||
setpriority :1, // - set a process's nice value
|
||||
setprotoent :1, // - prepare protocols file for use
|
||||
setpwent :1, // - prepare passwd file for use
|
||||
setservent :1, // - prepare services file for use
|
||||
setsockopt :1, // - set some socket options
|
||||
shift :1, // - remove the first element of an array, and return it
|
||||
shmctl :1, // - SysV shared memory operations
|
||||
shmget :1, // - get SysV shared memory segment identifier
|
||||
shmread :1, // - read SysV shared memory
|
||||
shmwrite :1, // - write SysV shared memory
|
||||
shutdown :1, // - close down just half of a socket connection
|
||||
'sin' :1, // - return the sine of a number
|
||||
sleep :1, // - block for some number of seconds
|
||||
socket :1, // - create a socket
|
||||
socketpair :1, // - create a pair of sockets
|
||||
'sort' :1, // - sort a list of values
|
||||
splice :1, // - add or remove elements anywhere in an array
|
||||
'split' :1, // - split up a string using a regexp delimiter
|
||||
sprintf :1, // - formatted print into a string
|
||||
'sqrt' :1, // - square root function
|
||||
srand :1, // - seed the random number generator
|
||||
stat :1, // - get a file's status information
|
||||
state :1, // - declare and assign a state variable (persistent lexical scoping)
|
||||
study :1, // - optimize input data for repeated searches
|
||||
'sub' :1, // - declare a subroutine, possibly anonymously
|
||||
'substr' :1, // - get or alter a portion of a stirng
|
||||
symlink :1, // - create a symbolic link to a file
|
||||
syscall :1, // - execute an arbitrary system call
|
||||
sysopen :1, // - open a file, pipe, or descriptor
|
||||
sysread :1, // - fixed-length unbuffered input from a filehandle
|
||||
sysseek :1, // - position I/O pointer on handle used with sysread and syswrite
|
||||
system :1, // - run a separate program
|
||||
syswrite :1, // - fixed-length unbuffered output to a filehandle
|
||||
tell :1, // - get current seekpointer on a filehandle
|
||||
telldir :1, // - get current seekpointer on a directory handle
|
||||
tie :1, // - bind a variable to an object class
|
||||
tied :1, // - get a reference to the object underlying a tied variable
|
||||
time :1, // - return number of seconds since 1970
|
||||
times :1, // - return elapsed time for self and child processes
|
||||
tr :null, // - transliterate a string
|
||||
truncate :1, // - shorten a file
|
||||
uc :1, // - return upper-case version of a string
|
||||
ucfirst :1, // - return a string with just the next letter in upper case
|
||||
umask :1, // - set file creation mode mask
|
||||
undef :1, // - remove a variable or function definition
|
||||
unlink :1, // - remove one link to a file
|
||||
unpack :1, // - convert binary structure into normal perl variables
|
||||
unshift :1, // - prepend more elements to the beginning of a list
|
||||
untie :1, // - break a tie binding to a variable
|
||||
use :1, // - load in a module at compile time
|
||||
utime :1, // - set a file's last access and modify times
|
||||
values :1, // - return a list of the values in a hash
|
||||
vec :1, // - test or set particular bits in a string
|
||||
wait :1, // - wait for any child process to die
|
||||
waitpid :1, // - wait for a particular child process to die
|
||||
wantarray :1, // - get void vs scalar vs list context of current subroutine call
|
||||
warn :1, // - print debugging info
|
||||
when :1, //
|
||||
write :1, // - print a picture record
|
||||
y :null}; // - transliterate a string
|
||||
|
||||
var RXstyle="string-2";
|
||||
var RXmodifiers=/[goseximacplud]/; // NOTE: "m", "s", "y" and "tr" need to correct real modifiers for each regexp type
|
||||
|
||||
function tokenChain(stream,state,chain,style,tail){ // NOTE: chain.length > 2 is not working now (it's for s[...][...]geos;)
|
||||
state.chain=null; // 12 3tail
|
||||
state.style=null;
|
||||
state.tail=null;
|
||||
state.tokenize=function(stream,state){
|
||||
var e=false,c,i=0;
|
||||
while(c=stream.next()){
|
||||
if(c===chain[i]&&!e){
|
||||
if(chain[++i]!==undefined){
|
||||
state.chain=chain[i];
|
||||
state.style=style;
|
||||
state.tail=tail}
|
||||
else if(tail)
|
||||
stream.eatWhile(tail);
|
||||
state.tokenize=tokenPerl;
|
||||
return style}
|
||||
e=!e&&c=="\\"}
|
||||
return style};
|
||||
return state.tokenize(stream,state)}
|
||||
|
||||
function tokenSOMETHING(stream,state,string){
|
||||
state.tokenize=function(stream,state){
|
||||
if(stream.string==string)
|
||||
state.tokenize=tokenPerl;
|
||||
stream.skipToEnd();
|
||||
return "string"};
|
||||
return state.tokenize(stream,state)}
|
||||
|
||||
function tokenPerl(stream,state){
|
||||
if(stream.eatSpace())
|
||||
return null;
|
||||
if(state.chain)
|
||||
return tokenChain(stream,state,state.chain,state.style,state.tail);
|
||||
if(stream.match(/^\-?[\d\.]/,false))
|
||||
if(stream.match(/^(\-?(\d*\.\d+(e[+-]?\d+)?|\d+\.\d*)|0x[\da-fA-F]+|0b[01]+|\d+(e[+-]?\d+)?)/))
|
||||
return 'number';
|
||||
if(stream.match(/^<<(?=\w)/)){ // NOTE: <<SOMETHING\n...\nSOMETHING\n
|
||||
stream.eatWhile(/\w/);
|
||||
return tokenSOMETHING(stream,state,stream.current().substr(2))}
|
||||
if(stream.sol()&&stream.match(/^\=item(?!\w)/)){// NOTE: \n=item...\n=cut\n
|
||||
return tokenSOMETHING(stream,state,'=cut')}
|
||||
var ch=stream.next();
|
||||
if(ch=='"'||ch=="'"){ // NOTE: ' or " or <<'SOMETHING'\n...\nSOMETHING\n or <<"SOMETHING"\n...\nSOMETHING\n
|
||||
if(stream.prefix(3)=="<<"+ch){
|
||||
var p=stream.pos;
|
||||
stream.eatWhile(/\w/);
|
||||
var n=stream.current().substr(1);
|
||||
if(n&&stream.eat(ch))
|
||||
return tokenSOMETHING(stream,state,n);
|
||||
stream.pos=p}
|
||||
return tokenChain(stream,state,[ch],"string")}
|
||||
if(ch=="q"){
|
||||
var c=stream.look(-2);
|
||||
if(!(c&&/\w/.test(c))){
|
||||
c=stream.look(0);
|
||||
if(c=="x"){
|
||||
c=stream.look(1);
|
||||
if(c=="("){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers)}
|
||||
if(c=="["){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers)}
|
||||
if(c=="{"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers)}
|
||||
if(c=="<"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers)}
|
||||
if(/[\^'"!~\/]/.test(c)){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers)}}
|
||||
else if(c=="q"){
|
||||
c=stream.look(1);
|
||||
if(c=="("){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[")"],"string")}
|
||||
if(c=="["){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["]"],"string")}
|
||||
if(c=="{"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["}"],"string")}
|
||||
if(c=="<"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[">"],"string")}
|
||||
if(/[\^'"!~\/]/.test(c)){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,[stream.eat(c)],"string")}}
|
||||
else if(c=="w"){
|
||||
c=stream.look(1);
|
||||
if(c=="("){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[")"],"bracket")}
|
||||
if(c=="["){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["]"],"bracket")}
|
||||
if(c=="{"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["}"],"bracket")}
|
||||
if(c=="<"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[">"],"bracket")}
|
||||
if(/[\^'"!~\/]/.test(c)){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,[stream.eat(c)],"bracket")}}
|
||||
else if(c=="r"){
|
||||
c=stream.look(1);
|
||||
if(c=="("){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers)}
|
||||
if(c=="["){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers)}
|
||||
if(c=="{"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers)}
|
||||
if(c=="<"){
|
||||
stream.eatSuffix(2);
|
||||
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers)}
|
||||
if(/[\^'"!~\/]/.test(c)){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers)}}
|
||||
else if(/[\^'"!~\/(\[{<]/.test(c)){
|
||||
if(c=="("){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,[")"],"string")}
|
||||
if(c=="["){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,["]"],"string")}
|
||||
if(c=="{"){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,["}"],"string")}
|
||||
if(c=="<"){
|
||||
stream.eatSuffix(1);
|
||||
return tokenChain(stream,state,[">"],"string")}
|
||||
if(/[\^'"!~\/]/.test(c)){
|
||||
return tokenChain(stream,state,[stream.eat(c)],"string")}}}}
|
||||
if(ch=="m"){
|
||||
var c=stream.look(-2);
|
||||
if(!(c&&/\w/.test(c))){
|
||||
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
||||
if(c){
|
||||
if(/[\^'"!~\/]/.test(c)){
|
||||
return tokenChain(stream,state,[c],RXstyle,RXmodifiers)}
|
||||
if(c=="("){
|
||||
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers)}
|
||||
if(c=="["){
|
||||
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers)}
|
||||
if(c=="{"){
|
||||
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers)}
|
||||
if(c=="<"){
|
||||
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers)}}}}
|
||||
if(ch=="s"){
|
||||
var c=/[\/>\]})\w]/.test(stream.look(-2));
|
||||
if(!c){
|
||||
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
||||
if(c){
|
||||
if(c=="[")
|
||||
return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
|
||||
if(c=="{")
|
||||
return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
|
||||
if(c=="<")
|
||||
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
|
||||
if(c=="(")
|
||||
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
|
||||
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers)}}}
|
||||
if(ch=="y"){
|
||||
var c=/[\/>\]})\w]/.test(stream.look(-2));
|
||||
if(!c){
|
||||
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
||||
if(c){
|
||||
if(c=="[")
|
||||
return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
|
||||
if(c=="{")
|
||||
return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
|
||||
if(c=="<")
|
||||
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
|
||||
if(c=="(")
|
||||
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
|
||||
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers)}}}
|
||||
if(ch=="t"){
|
||||
var c=/[\/>\]})\w]/.test(stream.look(-2));
|
||||
if(!c){
|
||||
c=stream.eat("r");if(c){
|
||||
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
||||
if(c){
|
||||
if(c=="[")
|
||||
return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
|
||||
if(c=="{")
|
||||
return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
|
||||
if(c=="<")
|
||||
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
|
||||
if(c=="(")
|
||||
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
|
||||
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers)}}}}
|
||||
if(ch=="`"){
|
||||
return tokenChain(stream,state,[ch],"variable-2")}
|
||||
if(ch=="/"){
|
||||
if(!/~\s*$/.test(stream.prefix()))
|
||||
return "operator";
|
||||
else
|
||||
return tokenChain(stream,state,[ch],RXstyle,RXmodifiers)}
|
||||
if(ch=="$"){
|
||||
var p=stream.pos;
|
||||
if(stream.eatWhile(/\d/)||stream.eat("{")&&stream.eatWhile(/\d/)&&stream.eat("}"))
|
||||
return "variable-2";
|
||||
else
|
||||
stream.pos=p}
|
||||
if(/[$@%]/.test(ch)){
|
||||
var p=stream.pos;
|
||||
if(stream.eat("^")&&stream.eat(/[A-Z]/)||!/[@$%&]/.test(stream.look(-2))&&stream.eat(/[=|\\\-#?@;:&`~\^!\[\]*'"$+.,\/<>()]/)){
|
||||
var c=stream.current();
|
||||
if(PERL[c])
|
||||
return "variable-2"}
|
||||
stream.pos=p}
|
||||
if(/[$@%&]/.test(ch)){
|
||||
if(stream.eatWhile(/[\w$\[\]]/)||stream.eat("{")&&stream.eatWhile(/[\w$\[\]]/)&&stream.eat("}")){
|
||||
var c=stream.current();
|
||||
if(PERL[c])
|
||||
return "variable-2";
|
||||
else
|
||||
return "variable"}}
|
||||
if(ch=="#"){
|
||||
if(stream.look(-2)!="$"){
|
||||
stream.skipToEnd();
|
||||
return "comment"}}
|
||||
if(/[:+\-\^*$&%@=<>!?|\/~\.]/.test(ch)){
|
||||
var p=stream.pos;
|
||||
stream.eatWhile(/[:+\-\^*$&%@=<>!?|\/~\.]/);
|
||||
if(PERL[stream.current()])
|
||||
return "operator";
|
||||
else
|
||||
stream.pos=p}
|
||||
if(ch=="_"){
|
||||
if(stream.pos==1){
|
||||
if(stream.suffix(6)=="_END__"){
|
||||
return tokenChain(stream,state,['\0'],"comment")}
|
||||
else if(stream.suffix(7)=="_DATA__"){
|
||||
return tokenChain(stream,state,['\0'],"variable-2")}
|
||||
else if(stream.suffix(7)=="_C__"){
|
||||
return tokenChain(stream,state,['\0'],"string")}}}
|
||||
if(/\w/.test(ch)){
|
||||
var p=stream.pos;
|
||||
if(stream.look(-2)=="{"&&(stream.look(0)=="}"||stream.eatWhile(/\w/)&&stream.look(0)=="}"))
|
||||
return "string";
|
||||
else
|
||||
stream.pos=p}
|
||||
if(/[A-Z]/.test(ch)){
|
||||
var l=stream.look(-2);
|
||||
var p=stream.pos;
|
||||
stream.eatWhile(/[A-Z_]/);
|
||||
if(/[\da-z]/.test(stream.look(0))){
|
||||
stream.pos=p}
|
||||
else{
|
||||
var c=PERL[stream.current()];
|
||||
if(!c)
|
||||
return "meta";
|
||||
if(c[1])
|
||||
c=c[0];
|
||||
if(l!=":"){
|
||||
if(c==1)
|
||||
return "keyword";
|
||||
else if(c==2)
|
||||
return "def";
|
||||
else if(c==3)
|
||||
return "atom";
|
||||
else if(c==4)
|
||||
return "operator";
|
||||
else if(c==5)
|
||||
return "variable-2";
|
||||
else
|
||||
return "meta"}
|
||||
else
|
||||
return "meta"}}
|
||||
if(/[a-zA-Z_]/.test(ch)){
|
||||
var l=stream.look(-2);
|
||||
stream.eatWhile(/\w/);
|
||||
var c=PERL[stream.current()];
|
||||
if(!c)
|
||||
return "meta";
|
||||
if(c[1])
|
||||
c=c[0];
|
||||
if(l!=":"){
|
||||
if(c==1)
|
||||
return "keyword";
|
||||
else if(c==2)
|
||||
return "def";
|
||||
else if(c==3)
|
||||
return "atom";
|
||||
else if(c==4)
|
||||
return "operator";
|
||||
else if(c==5)
|
||||
return "variable-2";
|
||||
else
|
||||
return "meta"}
|
||||
else
|
||||
return "meta"}
|
||||
return null}
|
||||
|
||||
return{
|
||||
startState:function(){
|
||||
return{
|
||||
tokenize:tokenPerl,
|
||||
chain:null,
|
||||
style:null,
|
||||
tail:null}},
|
||||
token:function(stream,state){
|
||||
return (state.tokenize||tokenPerl)(stream,state)},
|
||||
electricChars:"{}"}});
|
||||
|
||||
CodeMirror.defineMIME("text/x-perl", "perl");
|
||||
|
||||
// it's like "peek", but need for look-ahead or look-behind if index < 0
|
||||
CodeMirror.StringStream.prototype.look=function(c){
|
||||
return this.string.charAt(this.pos+(c||0))};
|
||||
|
||||
// return a part of prefix of current stream from current position
|
||||
CodeMirror.StringStream.prototype.prefix=function(c){
|
||||
if(c){
|
||||
var x=this.pos-c;
|
||||
return this.string.substr((x>=0?x:0),c)}
|
||||
else{
|
||||
return this.string.substr(0,this.pos-1)}};
|
||||
|
||||
// return a part of suffix of current stream from current position
|
||||
CodeMirror.StringStream.prototype.suffix=function(c){
|
||||
var y=this.string.length;
|
||||
var x=y-this.pos+1;
|
||||
return this.string.substr(this.pos,(c&&c<y?c:x))};
|
||||
|
||||
// return a part of suffix of current stream from current position and change current position
|
||||
CodeMirror.StringStream.prototype.nsuffix=function(c){
|
||||
var p=this.pos;
|
||||
var l=c||(this.string.length-this.pos+1);
|
||||
this.pos+=l;
|
||||
return this.string.substr(p,l)};
|
||||
|
||||
// eating and vomiting a part of stream from current position
|
||||
CodeMirror.StringStream.prototype.eatSuffix=function(c){
|
||||
var x=this.pos+c;
|
||||
var y;
|
||||
if(x<=0)
|
||||
this.pos=0;
|
||||
else if(x>=(y=this.string.length-1))
|
||||
this.pos=y;
|
||||
else
|
||||
this.pos=x};
|
@ -1,48 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: PHP mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../xml/xml.js"></script>
|
||||
<script src="../javascript/javascript.js"></script>
|
||||
<script src="../css/css.js"></script>
|
||||
<script src="../clike/clike.js"></script>
|
||||
<script src="php.js"></script>
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: PHP mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
<?php
|
||||
function hello($who) {
|
||||
return "Hello " . $who;
|
||||
}
|
||||
?>
|
||||
<p>The program says <?= hello("World") ?>.</p>
|
||||
<script>
|
||||
alert("And here is some JS code"); // also colored
|
||||
</script>
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "application/x-httpd-php",
|
||||
indentUnit: 4,
|
||||
indentWithTabs: true,
|
||||
enterMode: "keep",
|
||||
tabMode: "shift"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Simple HTML/PHP mode based on
|
||||
the <a href="../clike/">C-like</a> mode. Depends on XML,
|
||||
JavaScript, CSS, and C-like modes.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>application/x-httpd-php</code> (HTML with PHP code), <code>text/x-php</code> (plain, non-wrapped PHP code).</p>
|
||||
</body>
|
||||
</html>
|
@ -1,150 +0,0 @@
|
||||
(function() {
|
||||
function keywords(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
function heredoc(delim) {
|
||||
return function(stream, state) {
|
||||
if (stream.match(delim)) state.tokenize = null;
|
||||
else stream.skipToEnd();
|
||||
return "string";
|
||||
}
|
||||
}
|
||||
var phpConfig = {
|
||||
name: "clike",
|
||||
keywords: keywords("abstract and array as break case catch class clone const continue declare default " +
|
||||
"do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
|
||||
"for foreach function global goto if implements interface instanceof namespace " +
|
||||
"new or private protected public static switch throw trait try use var while xor " +
|
||||
"die echo empty exit eval include include_once isset list require require_once return " +
|
||||
"print unset __halt_compiler self static parent"),
|
||||
blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
|
||||
atoms: keywords("true false null TRUE FALSE NULL"),
|
||||
multiLineStrings: true,
|
||||
hooks: {
|
||||
"$": function(stream, state) {
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
return "variable-2";
|
||||
},
|
||||
"<": function(stream, state) {
|
||||
if (stream.match(/<</)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
state.tokenize = heredoc(stream.current().slice(3));
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
"#": function(stream, state) {
|
||||
while (!stream.eol() && !stream.match("?>", false)) stream.next();
|
||||
return "comment";
|
||||
},
|
||||
"/": function(stream, state) {
|
||||
if (stream.eat("/")) {
|
||||
while (!stream.eol() && !stream.match("?>", false)) stream.next();
|
||||
return "comment";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.defineMode("php", function(config, parserConfig) {
|
||||
var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
|
||||
var jsMode = CodeMirror.getMode(config, "javascript");
|
||||
var cssMode = CodeMirror.getMode(config, "css");
|
||||
var phpMode = CodeMirror.getMode(config, phpConfig);
|
||||
|
||||
function dispatch(stream, state) { // TODO open PHP inside text/css
|
||||
var isPHP = state.mode == "php";
|
||||
if (stream.sol() && state.pending != '"') state.pending = null;
|
||||
if (state.curMode == htmlMode) {
|
||||
if (stream.match(/^<\?\w*/)) {
|
||||
state.curMode = phpMode;
|
||||
state.curState = state.php;
|
||||
state.curClose = "?>";
|
||||
state.mode = "php";
|
||||
return "meta";
|
||||
}
|
||||
if (state.pending == '"') {
|
||||
while (!stream.eol() && stream.next() != '"') {}
|
||||
var style = "string";
|
||||
} else if (state.pending && stream.pos < state.pending.end) {
|
||||
stream.pos = state.pending.end;
|
||||
var style = state.pending.style;
|
||||
} else {
|
||||
var style = htmlMode.token(stream, state.curState);
|
||||
}
|
||||
state.pending = null;
|
||||
var cur = stream.current(), openPHP = cur.search(/<\?/);
|
||||
if (openPHP != -1) {
|
||||
if (style == "string" && /\"$/.test(cur) && !/\?>/.test(cur)) state.pending = '"';
|
||||
else state.pending = {end: stream.pos, style: style};
|
||||
stream.backUp(cur.length - openPHP);
|
||||
} else if (style == "tag" && stream.current() == ">" && state.curState.context) {
|
||||
if (/^script$/i.test(state.curState.context.tagName)) {
|
||||
state.curMode = jsMode;
|
||||
state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
|
||||
state.curClose = /^<\/\s*script\s*>/i;
|
||||
state.mode = "javascript";
|
||||
}
|
||||
else if (/^style$/i.test(state.curState.context.tagName)) {
|
||||
state.curMode = cssMode;
|
||||
state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
|
||||
state.curClose = /^<\/\s*style\s*>/i;
|
||||
state.mode = "css";
|
||||
}
|
||||
}
|
||||
return style;
|
||||
} else if ((!isPHP || state.php.tokenize == null) &&
|
||||
stream.match(state.curClose, isPHP)) {
|
||||
state.curMode = htmlMode;
|
||||
state.curState = state.html;
|
||||
state.curClose = null;
|
||||
state.mode = "html";
|
||||
if (isPHP) return "meta";
|
||||
else return dispatch(stream, state);
|
||||
} else {
|
||||
return state.curMode.token(stream, state.curState);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
var html = htmlMode.startState();
|
||||
return {html: html,
|
||||
php: phpMode.startState(),
|
||||
curMode: parserConfig.startOpen ? phpMode : htmlMode,
|
||||
curState: parserConfig.startOpen ? phpMode.startState() : html,
|
||||
curClose: parserConfig.startOpen ? /^\?>/ : null,
|
||||
mode: parserConfig.startOpen ? "php" : "html",
|
||||
pending: null}
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
|
||||
php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
|
||||
if (state.curState == html) cur = htmlNew;
|
||||
else if (state.curState == php) cur = phpNew;
|
||||
else cur = CodeMirror.copyState(state.curMode, state.curState);
|
||||
return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
|
||||
curClose: state.curClose, mode: state.mode,
|
||||
pending: state.pending};
|
||||
},
|
||||
|
||||
token: dispatch,
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
|
||||
(state.curMode == phpMode && /^\?>/.test(textAfter)))
|
||||
return htmlMode.indent(state.html, textAfter);
|
||||
return state.curMode.indent(state.curState, textAfter);
|
||||
},
|
||||
|
||||
electricChars: "/{}:"
|
||||
}
|
||||
});
|
||||
CodeMirror.defineMIME("application/x-httpd-php", "php");
|
||||
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
|
||||
CodeMirror.defineMIME("text/x-php", phpConfig);
|
||||
})();
|
@ -1,62 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Oracle PL/SQL mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="plsql.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style>.CodeMirror {border: 2px inset #dee;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Oracle PL/SQL mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
-- Oracle PL/SQL Code Demo
|
||||
/*
|
||||
based on c-like mode, adapted to PL/SQL by Peter Raganitsch ( http://www.oracle-and-apex.com/ )
|
||||
April 2011
|
||||
*/
|
||||
DECLARE
|
||||
vIdx NUMBER;
|
||||
vString VARCHAR2(100);
|
||||
cText CONSTANT VARCHAR2(100) := 'That''s it! Have fun with CodeMirror 2';
|
||||
BEGIN
|
||||
vIdx := 0;
|
||||
--
|
||||
FOR rDATA IN
|
||||
( SELECT *
|
||||
FROM EMP
|
||||
ORDER BY EMPNO
|
||||
)
|
||||
LOOP
|
||||
vIdx := vIdx + 1;
|
||||
vString := rDATA.EMPNO || ' - ' || rDATA.ENAME;
|
||||
--
|
||||
UPDATE EMP
|
||||
SET SAL = SAL * 101/100
|
||||
WHERE EMPNO = rDATA.EMPNO
|
||||
;
|
||||
END LOOP;
|
||||
--
|
||||
SYS.DBMS_OUTPUT.Put_Line (cText);
|
||||
END;
|
||||
--
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
indentUnit: 4,
|
||||
mode: "text/x-plsql"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>
|
||||
Simple mode that handles Oracle PL/SQL language (and Oracle SQL, of course).
|
||||
</p>
|
||||
|
||||
<p><strong>MIME type defined:</strong> <code>text/x-plsql</code>
|
||||
(PLSQL code)
|
||||
</html>
|
@ -1,217 +0,0 @@
|
||||
CodeMirror.defineMode("plsql", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit,
|
||||
keywords = parserConfig.keywords,
|
||||
functions = parserConfig.functions,
|
||||
types = parserConfig.types,
|
||||
sqlplus = parserConfig.sqlplus,
|
||||
multiLineStrings = parserConfig.multiLineStrings;
|
||||
var isOperatorChar = /[+\-*&%=<>!?:\/|]/;
|
||||
function chain(stream, state, f) {
|
||||
state.tokenize = f;
|
||||
return f(stream, state);
|
||||
}
|
||||
|
||||
var type;
|
||||
function ret(tp, style) {
|
||||
type = tp;
|
||||
return style;
|
||||
}
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
// start of string?
|
||||
if (ch == '"' || ch == "'")
|
||||
return chain(stream, state, tokenString(ch));
|
||||
// is it one of the special signs []{}().,;? Seperator?
|
||||
else if (/[\[\]{}\(\),;\.]/.test(ch))
|
||||
return ret(ch);
|
||||
// start of a number value?
|
||||
else if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
return ret("number", "number");
|
||||
}
|
||||
// multi line comment or simple operator?
|
||||
else if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
return chain(stream, state, tokenComment);
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return ret("operator", "operator");
|
||||
}
|
||||
}
|
||||
// single line comment or simple operator?
|
||||
else if (ch == "-") {
|
||||
if (stream.eat("-")) {
|
||||
stream.skipToEnd();
|
||||
return ret("comment", "comment");
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return ret("operator", "operator");
|
||||
}
|
||||
}
|
||||
// pl/sql variable?
|
||||
else if (ch == "@" || ch == "$") {
|
||||
stream.eatWhile(/[\w\d\$_]/);
|
||||
return ret("word", "variable");
|
||||
}
|
||||
// is it a operator?
|
||||
else if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return ret("operator", "operator");
|
||||
}
|
||||
else {
|
||||
// get the whole word
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
// is it one of the listed keywords?
|
||||
if (keywords && keywords.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "keyword");
|
||||
// is it one of the listed functions?
|
||||
if (functions && functions.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "builtin");
|
||||
// is it one of the listed types?
|
||||
if (types && types.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "variable-2");
|
||||
// is it one of the listed sqlplus keywords?
|
||||
if (sqlplus && sqlplus.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "variable-3");
|
||||
// default: just a "word"
|
||||
return ret("word", "plsql-word");
|
||||
}
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {end = true; break;}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !(escaped || multiLineStrings))
|
||||
state.tokenize = tokenBase;
|
||||
return ret("string", "plsql-string");
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return ret("comment", "plsql-comment");
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: tokenBase,
|
||||
startOfLine: true
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
return style;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
(function() {
|
||||
function keywords(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
var cKeywords = "abort accept access add all alter and any array arraylen as asc assert assign at attributes audit " +
|
||||
"authorization avg " +
|
||||
"base_table begin between binary_integer body boolean by " +
|
||||
"case cast char char_base check close cluster clusters colauth column comment commit compress connect " +
|
||||
"connected constant constraint crash create current currval cursor " +
|
||||
"data_base database date dba deallocate debugoff debugon decimal declare default definition delay delete " +
|
||||
"desc digits dispose distinct do drop " +
|
||||
"else elsif enable end entry escape exception exception_init exchange exclusive exists exit external " +
|
||||
"fast fetch file for force form from function " +
|
||||
"generic goto grant group " +
|
||||
"having " +
|
||||
"identified if immediate in increment index indexes indicator initial initrans insert interface intersect " +
|
||||
"into is " +
|
||||
"key " +
|
||||
"level library like limited local lock log logging long loop " +
|
||||
"master maxextents maxtrans member minextents minus mislabel mode modify multiset " +
|
||||
"new next no noaudit nocompress nologging noparallel not nowait number_base " +
|
||||
"object of off offline on online only open option or order out " +
|
||||
"package parallel partition pctfree pctincrease pctused pls_integer positive positiven pragma primary prior " +
|
||||
"private privileges procedure public " +
|
||||
"raise range raw read rebuild record ref references refresh release rename replace resource restrict return " +
|
||||
"returning reverse revoke rollback row rowid rowlabel rownum rows run " +
|
||||
"savepoint schema segment select separate session set share snapshot some space split sql start statement " +
|
||||
"storage subtype successful synonym " +
|
||||
"tabauth table tables tablespace task terminate then to trigger truncate type " +
|
||||
"union unique unlimited unrecoverable unusable update use using " +
|
||||
"validate value values variable view views " +
|
||||
"when whenever where while with work";
|
||||
|
||||
var cFunctions = "abs acos add_months ascii asin atan atan2 average " +
|
||||
"bfilename " +
|
||||
"ceil chartorowid chr concat convert cos cosh count " +
|
||||
"decode deref dual dump dup_val_on_index " +
|
||||
"empty error exp " +
|
||||
"false floor found " +
|
||||
"glb greatest " +
|
||||
"hextoraw " +
|
||||
"initcap instr instrb isopen " +
|
||||
"last_day least lenght lenghtb ln lower lpad ltrim lub " +
|
||||
"make_ref max min mod months_between " +
|
||||
"new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower " +
|
||||
"nls_sort nls_upper nlssort no_data_found notfound null nvl " +
|
||||
"others " +
|
||||
"power " +
|
||||
"rawtohex reftohex round rowcount rowidtochar rpad rtrim " +
|
||||
"sign sin sinh soundex sqlcode sqlerrm sqrt stddev substr substrb sum sysdate " +
|
||||
"tan tanh to_char to_date to_label to_multi_byte to_number to_single_byte translate true trunc " +
|
||||
"uid upper user userenv " +
|
||||
"variance vsize";
|
||||
|
||||
var cTypes = "bfile blob " +
|
||||
"character clob " +
|
||||
"dec " +
|
||||
"float " +
|
||||
"int integer " +
|
||||
"mlslabel " +
|
||||
"natural naturaln nchar nclob number numeric nvarchar2 " +
|
||||
"real rowtype " +
|
||||
"signtype smallint string " +
|
||||
"varchar varchar2";
|
||||
|
||||
var cSqlplus = "appinfo arraysize autocommit autoprint autorecovery autotrace " +
|
||||
"blockterminator break btitle " +
|
||||
"cmdsep colsep compatibility compute concat copycommit copytypecheck " +
|
||||
"define describe " +
|
||||
"echo editfile embedded escape exec execute " +
|
||||
"feedback flagger flush " +
|
||||
"heading headsep " +
|
||||
"instance " +
|
||||
"linesize lno loboffset logsource long longchunksize " +
|
||||
"markup " +
|
||||
"native newpage numformat numwidth " +
|
||||
"pagesize pause pno " +
|
||||
"recsep recsepchar release repfooter repheader " +
|
||||
"serveroutput shiftinout show showmode size spool sqlblanklines sqlcase sqlcode sqlcontinue sqlnumber " +
|
||||
"sqlpluscompatibility sqlprefix sqlprompt sqlterminator suffix " +
|
||||
"tab term termout time timing trimout trimspool ttitle " +
|
||||
"underline " +
|
||||
"verify version " +
|
||||
"wrap";
|
||||
|
||||
CodeMirror.defineMIME("text/x-plsql", {
|
||||
name: "plsql",
|
||||
keywords: keywords(cKeywords),
|
||||
functions: keywords(cFunctions),
|
||||
types: keywords(cTypes),
|
||||
sqlplus: keywords(cSqlplus)
|
||||
});
|
||||
}());
|
@ -1,40 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Properties files mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="properties.js"></script>
|
||||
<style>.CodeMirror {border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Properties files mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
# This is a properties file
|
||||
a.key = A value
|
||||
another.key = http://example.com
|
||||
! Exclamation mark as comment
|
||||
but.not=Within ! A value # indeed
|
||||
# Spaces at the beginning of a line
|
||||
spaces.before.key=value
|
||||
backslash=Used for multi\
|
||||
line entries,\
|
||||
that's convenient.
|
||||
# Unicode sequences
|
||||
unicode.key=This is \u0020 Unicode
|
||||
no.multiline=here
|
||||
# Colons
|
||||
colons : can be used too
|
||||
# Spaces
|
||||
spaces\ in\ keys=Not very common...
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-properties</code>,
|
||||
<code>text/x-ini</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,63 +0,0 @@
|
||||
CodeMirror.defineMode("properties", function() {
|
||||
return {
|
||||
token: function(stream, state) {
|
||||
var sol = stream.sol() || state.afterSection;
|
||||
var eol = stream.eol();
|
||||
|
||||
state.afterSection = false;
|
||||
|
||||
if (sol) {
|
||||
if (state.nextMultiline) {
|
||||
state.inMultiline = true;
|
||||
state.nextMultiline = false;
|
||||
} else {
|
||||
state.position = "def";
|
||||
}
|
||||
}
|
||||
|
||||
if (eol && ! state.nextMultiline) {
|
||||
state.inMultiline = false;
|
||||
state.position = "def";
|
||||
}
|
||||
|
||||
if (sol) {
|
||||
while(stream.eatSpace());
|
||||
}
|
||||
|
||||
var ch = stream.next();
|
||||
|
||||
if (sol && (ch === "#" || ch === "!" || ch === ";")) {
|
||||
state.position = "comment";
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
} else if (sol && ch === "[") {
|
||||
state.afterSection = true;
|
||||
stream.skipTo("]"); stream.eat("]");
|
||||
return "header";
|
||||
} else if (ch === "=" || ch === ":") {
|
||||
state.position = "quote";
|
||||
return null;
|
||||
} else if (ch === "\\" && state.position === "quote") {
|
||||
if (stream.next() !== "u") { // u = Unicode sequence \u1234
|
||||
// Multiline value
|
||||
state.nextMultiline = true;
|
||||
}
|
||||
}
|
||||
|
||||
return state.position;
|
||||
},
|
||||
|
||||
startState: function() {
|
||||
return {
|
||||
position : "def", // Current position, "def", "quote" or "comment"
|
||||
nextMultiline : false, // Is the next line multiline value
|
||||
inMultiline : false, // Is the current line a multiline value
|
||||
afterSection : false // Did we just open a section
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-properties", "properties");
|
||||
CodeMirror.defineMIME("text/x-ini", "properties");
|
@ -1,21 +0,0 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2010 Timothy Farrell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -1,122 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Python mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="python.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Python mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
# Literals
|
||||
1234
|
||||
0.0e101
|
||||
.123
|
||||
0b01010011100
|
||||
0o01234567
|
||||
0x0987654321abcdef
|
||||
7
|
||||
2147483647
|
||||
3L
|
||||
79228162514264337593543950336L
|
||||
0x100000000L
|
||||
79228162514264337593543950336
|
||||
0xdeadbeef
|
||||
3.14j
|
||||
10.j
|
||||
10j
|
||||
.001j
|
||||
1e100j
|
||||
3.14e-10j
|
||||
|
||||
|
||||
# String Literals
|
||||
'For\''
|
||||
"God\""
|
||||
"""so loved
|
||||
the world"""
|
||||
'''that he gave
|
||||
his only begotten\' '''
|
||||
'that whosoever believeth \
|
||||
in him'
|
||||
''
|
||||
|
||||
# Identifiers
|
||||
__a__
|
||||
a.b
|
||||
a.b.c
|
||||
|
||||
# Operators
|
||||
+ - * / % & | ^ ~ < >
|
||||
== != <= >= <> << >> // **
|
||||
and or not in is
|
||||
|
||||
# Delimiters
|
||||
() [] {} , : ` = ; @ . # Note that @ and . require the proper context.
|
||||
+= -= *= /= %= &= |= ^=
|
||||
//= >>= <<= **=
|
||||
|
||||
# Keywords
|
||||
as assert break class continue def del elif else except
|
||||
finally for from global if import lambda pass raise
|
||||
return try while with yield
|
||||
|
||||
# Python 2 Keywords (otherwise Identifiers)
|
||||
exec print
|
||||
|
||||
# Python 3 Keywords (otherwise Identifiers)
|
||||
nonlocal
|
||||
|
||||
# Types
|
||||
bool classmethod complex dict enumerate float frozenset int list object
|
||||
property reversed set slice staticmethod str super tuple type
|
||||
|
||||
# Python 2 Types (otherwise Identifiers)
|
||||
basestring buffer file long unicode xrange
|
||||
|
||||
# Python 3 Types (otherwise Identifiers)
|
||||
bytearray bytes filter map memoryview open range zip
|
||||
|
||||
# Some Example code
|
||||
import os
|
||||
from package import ParentClass
|
||||
|
||||
@nonsenseDecorator
|
||||
def doesNothing():
|
||||
pass
|
||||
|
||||
class ExampleClass(ParentClass):
|
||||
@staticmethod
|
||||
def example(inputStr):
|
||||
a = list(inputStr)
|
||||
a.reverse()
|
||||
return ''.join(a)
|
||||
|
||||
def __init__(self, mixin = 'Hello'):
|
||||
self.mixin = mixin
|
||||
|
||||
</textarea></div>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: {name: "python",
|
||||
version: 2,
|
||||
singleLineStringErrors: false},
|
||||
lineNumbers: true,
|
||||
indentUnit: 4,
|
||||
tabMode: "shift",
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
<h2>Configuration Options:</h2>
|
||||
<ul>
|
||||
<li>version - 2/3 - The version of Python to recognize. Default is 2.</li>
|
||||
<li>singleLineStringErrors - true/false - If you have a single-line string that is not terminated at the end of the line, this will show subsequent lines as errors if true, otherwise it will consider the newline as the end of the string. Default is false.</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-python</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,340 +0,0 @@
|
||||
CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
var ERRORCLASS = 'error';
|
||||
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
||||
}
|
||||
|
||||
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
|
||||
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
|
||||
var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
|
||||
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
||||
var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
|
||||
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
||||
|
||||
var wordOperators = wordRegexp(['and', 'or', 'not', 'is', 'in']);
|
||||
var commonkeywords = ['as', 'assert', 'break', 'class', 'continue',
|
||||
'def', 'del', 'elif', 'else', 'except', 'finally',
|
||||
'for', 'from', 'global', 'if', 'import',
|
||||
'lambda', 'pass', 'raise', 'return',
|
||||
'try', 'while', 'with', 'yield'];
|
||||
var commonBuiltins = ['abs', 'all', 'any', 'bin', 'bool', 'bytearray', 'callable', 'chr',
|
||||
'classmethod', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod',
|
||||
'enumerate', 'eval', 'filter', 'float', 'format', 'frozenset',
|
||||
'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id',
|
||||
'input', 'int', 'isinstance', 'issubclass', 'iter', 'len',
|
||||
'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next',
|
||||
'object', 'oct', 'open', 'ord', 'pow', 'property', 'range',
|
||||
'repr', 'reversed', 'round', 'set', 'setattr', 'slice',
|
||||
'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple',
|
||||
'type', 'vars', 'zip', '__import__', 'NotImplemented',
|
||||
'Ellipsis', '__debug__'];
|
||||
var py2 = {'builtins': ['apply', 'basestring', 'buffer', 'cmp', 'coerce', 'execfile',
|
||||
'file', 'intern', 'long', 'raw_input', 'reduce', 'reload',
|
||||
'unichr', 'unicode', 'xrange', 'False', 'True', 'None'],
|
||||
'keywords': ['exec', 'print']};
|
||||
var py3 = {'builtins': ['ascii', 'bytes', 'exec', 'print'],
|
||||
'keywords': ['nonlocal', 'False', 'True', 'None']};
|
||||
|
||||
if (!!parserConf.version && parseInt(parserConf.version, 10) === 3) {
|
||||
commonkeywords = commonkeywords.concat(py3.keywords);
|
||||
commonBuiltins = commonBuiltins.concat(py3.builtins);
|
||||
var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
|
||||
} else {
|
||||
commonkeywords = commonkeywords.concat(py2.keywords);
|
||||
commonBuiltins = commonBuiltins.concat(py2.builtins);
|
||||
var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
|
||||
}
|
||||
var keywords = wordRegexp(commonkeywords);
|
||||
var builtins = wordRegexp(commonBuiltins);
|
||||
|
||||
var indentInfo = null;
|
||||
|
||||
// tokenizers
|
||||
function tokenBase(stream, state) {
|
||||
// Handle scope changes
|
||||
if (stream.sol()) {
|
||||
var scopeOffset = state.scopes[0].offset;
|
||||
if (stream.eatSpace()) {
|
||||
var lineOffset = stream.indentation();
|
||||
if (lineOffset > scopeOffset) {
|
||||
indentInfo = 'indent';
|
||||
} else if (lineOffset < scopeOffset) {
|
||||
indentInfo = 'dedent';
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
if (scopeOffset > 0) {
|
||||
dedent(stream, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stream.eatSpace()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ch = stream.peek();
|
||||
|
||||
// Handle Comments
|
||||
if (ch === '#') {
|
||||
stream.skipToEnd();
|
||||
return 'comment';
|
||||
}
|
||||
|
||||
// Handle Number Literals
|
||||
if (stream.match(/^[0-9\.]/, false)) {
|
||||
var floatLiteral = false;
|
||||
// Floats
|
||||
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
|
||||
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
|
||||
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
|
||||
if (floatLiteral) {
|
||||
// Float literals may be "imaginary"
|
||||
stream.eat(/J/i);
|
||||
return 'number';
|
||||
}
|
||||
// Integers
|
||||
var intLiteral = false;
|
||||
// Hex
|
||||
if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
|
||||
// Binary
|
||||
if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
|
||||
// Octal
|
||||
if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
|
||||
// Decimal
|
||||
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
|
||||
// Decimal literals may be "imaginary"
|
||||
stream.eat(/J/i);
|
||||
// TODO - Can you have imaginary longs?
|
||||
intLiteral = true;
|
||||
}
|
||||
// Zero by itself with no other piece of number.
|
||||
if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
|
||||
if (intLiteral) {
|
||||
// Integer literals may be "long"
|
||||
stream.eat(/L/i);
|
||||
return 'number';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Strings
|
||||
if (stream.match(stringPrefixes)) {
|
||||
state.tokenize = tokenStringFactory(stream.current());
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
|
||||
// Handle operators and Delimiters
|
||||
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
|
||||
return null;
|
||||
}
|
||||
if (stream.match(doubleOperators)
|
||||
|| stream.match(singleOperators)
|
||||
|| stream.match(wordOperators)) {
|
||||
return 'operator';
|
||||
}
|
||||
if (stream.match(singleDelimiters)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (stream.match(keywords)) {
|
||||
return 'keyword';
|
||||
}
|
||||
|
||||
if (stream.match(builtins)) {
|
||||
return 'builtin';
|
||||
}
|
||||
|
||||
if (stream.match(identifiers)) {
|
||||
return 'variable';
|
||||
}
|
||||
|
||||
// Handle non-detected items
|
||||
stream.next();
|
||||
return ERRORCLASS;
|
||||
}
|
||||
|
||||
function tokenStringFactory(delimiter) {
|
||||
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
|
||||
delimiter = delimiter.substr(1);
|
||||
}
|
||||
var singleline = delimiter.length == 1;
|
||||
var OUTCLASS = 'string';
|
||||
|
||||
return function tokenString(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
stream.eatWhile(/[^'"\\]/);
|
||||
if (stream.eat('\\')) {
|
||||
stream.next();
|
||||
if (singleline && stream.eol()) {
|
||||
return OUTCLASS;
|
||||
}
|
||||
} else if (stream.match(delimiter)) {
|
||||
state.tokenize = tokenBase;
|
||||
return OUTCLASS;
|
||||
} else {
|
||||
stream.eat(/['"]/);
|
||||
}
|
||||
}
|
||||
if (singleline) {
|
||||
if (parserConf.singleLineStringErrors) {
|
||||
return ERRORCLASS;
|
||||
} else {
|
||||
state.tokenize = tokenBase;
|
||||
}
|
||||
}
|
||||
return OUTCLASS;
|
||||
};
|
||||
}
|
||||
|
||||
function indent(stream, state, type) {
|
||||
type = type || 'py';
|
||||
var indentUnit = 0;
|
||||
if (type === 'py') {
|
||||
if (state.scopes[0].type !== 'py') {
|
||||
state.scopes[0].offset = stream.indentation();
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < state.scopes.length; ++i) {
|
||||
if (state.scopes[i].type === 'py') {
|
||||
indentUnit = state.scopes[i].offset + conf.indentUnit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
indentUnit = stream.column() + stream.current().length;
|
||||
}
|
||||
state.scopes.unshift({
|
||||
offset: indentUnit,
|
||||
type: type
|
||||
});
|
||||
}
|
||||
|
||||
function dedent(stream, state, type) {
|
||||
type = type || 'py';
|
||||
if (state.scopes.length == 1) return;
|
||||
if (state.scopes[0].type === 'py') {
|
||||
var _indent = stream.indentation();
|
||||
var _indent_index = -1;
|
||||
for (var i = 0; i < state.scopes.length; ++i) {
|
||||
if (_indent === state.scopes[i].offset) {
|
||||
_indent_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_indent_index === -1) {
|
||||
return true;
|
||||
}
|
||||
while (state.scopes[0].offset !== _indent) {
|
||||
state.scopes.shift();
|
||||
}
|
||||
return false
|
||||
} else {
|
||||
if (type === 'py') {
|
||||
state.scopes[0].offset = stream.indentation();
|
||||
return false;
|
||||
} else {
|
||||
if (state.scopes[0].type != type) {
|
||||
return true;
|
||||
}
|
||||
state.scopes.shift();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tokenLexer(stream, state) {
|
||||
indentInfo = null;
|
||||
var style = state.tokenize(stream, state);
|
||||
var current = stream.current();
|
||||
|
||||
// Handle '.' connected identifiers
|
||||
if (current === '.') {
|
||||
style = state.tokenize(stream, state);
|
||||
current = stream.current();
|
||||
if (style === 'variable' || style === 'builtin') {
|
||||
return 'variable';
|
||||
} else {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle decorators
|
||||
if (current === '@') {
|
||||
style = state.tokenize(stream, state);
|
||||
current = stream.current();
|
||||
if (style === 'variable'
|
||||
|| current === '@staticmethod'
|
||||
|| current === '@classmethod') {
|
||||
return 'meta';
|
||||
} else {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle scope changes.
|
||||
if (current === 'pass' || current === 'return') {
|
||||
state.dedent += 1;
|
||||
}
|
||||
if ((current === ':' && !state.lambda && state.scopes[0].type == 'py')
|
||||
|| indentInfo === 'indent') {
|
||||
indent(stream, state);
|
||||
}
|
||||
var delimiter_index = '[({'.indexOf(current);
|
||||
if (delimiter_index !== -1) {
|
||||
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
|
||||
}
|
||||
if (indentInfo === 'dedent') {
|
||||
if (dedent(stream, state)) {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
delimiter_index = '])}'.indexOf(current);
|
||||
if (delimiter_index !== -1) {
|
||||
if (dedent(stream, state, current)) {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'py') {
|
||||
if (state.scopes.length > 1) state.scopes.shift();
|
||||
state.dedent -= 1;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
var external = {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: tokenBase,
|
||||
scopes: [{offset:basecolumn || 0, type:'py'}],
|
||||
lastToken: null,
|
||||
lambda: false,
|
||||
dedent: 0
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var style = tokenLexer(stream, state);
|
||||
|
||||
state.lastToken = {style:style, content: stream.current()};
|
||||
|
||||
if (stream.eol() && stream.lambda) {
|
||||
state.lambda = false;
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return state.scopes[0].offset;
|
||||
}
|
||||
|
||||
};
|
||||
return external;
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-python", "python");
|
@ -1,24 +0,0 @@
|
||||
Copyright (c) 2011, Ubalo, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Ubalo, Inc nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL UBALO, INC BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -1,73 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: R mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="r.js"></script>
|
||||
<style>
|
||||
.CodeMirror { border-top: 1px solid silver; border-bottom: 1px solid silver; }
|
||||
.cm-s-default span.cm-semi { color: blue; font-weight: bold; }
|
||||
.cm-s-default span.cm-dollar { color: orange; font-weight: bold; }
|
||||
.cm-s-default span.cm-arrow { color: brown; }
|
||||
.cm-s-default span.cm-arg-is { color: brown; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: R mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
# Code from http://www.mayin.org/ajayshah/KB/R/
|
||||
|
||||
# FIRST LEARN ABOUT LISTS --
|
||||
X = list(height=5.4, weight=54)
|
||||
print("Use default printing --")
|
||||
print(X)
|
||||
print("Accessing individual elements --")
|
||||
cat("Your height is ", X$height, " and your weight is ", X$weight, "\n")
|
||||
|
||||
# FUNCTIONS --
|
||||
square <- function(x) {
|
||||
return(x*x)
|
||||
}
|
||||
cat("The square of 3 is ", square(3), "\n")
|
||||
|
||||
# default value of the arg is set to 5.
|
||||
cube <- function(x=5) {
|
||||
return(x*x*x);
|
||||
}
|
||||
cat("Calling cube with 2 : ", cube(2), "\n") # will give 2^3
|
||||
cat("Calling cube : ", cube(), "\n") # will default to 5^3.
|
||||
|
||||
# LEARN ABOUT FUNCTIONS THAT RETURN MULTIPLE OBJECTS --
|
||||
powers <- function(x) {
|
||||
parcel = list(x2=x*x, x3=x*x*x, x4=x*x*x*x);
|
||||
return(parcel);
|
||||
}
|
||||
|
||||
X = powers(3);
|
||||
print("Showing powers of 3 --"); print(X);
|
||||
|
||||
# WRITING THIS COMPACTLY (4 lines instead of 7)
|
||||
|
||||
powerful <- function(x) {
|
||||
return(list(x2=x*x, x3=x*x*x, x4=x*x*x*x));
|
||||
}
|
||||
print("Showing powers of 3 --"); print(powerful(3));
|
||||
|
||||
# In R, the last expression in a function is, by default, what is
|
||||
# returned. So you could equally just say:
|
||||
powerful <- function(x) {list(x2=x*x, x3=x*x*x, x4=x*x*x*x)}
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-rsrc</code>.</p>
|
||||
|
||||
<p>Development of the CodeMirror R mode was kindly sponsored
|
||||
by <a href="http://ubalo.com/">Ubalo</a>, who hold
|
||||
the <a href="LICENSE">license</a>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,141 +0,0 @@
|
||||
CodeMirror.defineMode("r", function(config) {
|
||||
function wordObj(str) {
|
||||
var words = str.split(" "), res = {};
|
||||
for (var i = 0; i < words.length; ++i) res[words[i]] = true;
|
||||
return res;
|
||||
}
|
||||
var atoms = wordObj("NULL NA Inf NaN NA_integer_ NA_real_ NA_complex_ NA_character_");
|
||||
var builtins = wordObj("list quote bquote eval return call parse deparse");
|
||||
var keywords = wordObj("if else repeat while function for in next break");
|
||||
var blockkeywords = wordObj("if else repeat while function for");
|
||||
var opChars = /[+\-*\/^<>=!&|~$:]/;
|
||||
var curPunc;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
curPunc = null;
|
||||
var ch = stream.next();
|
||||
if (ch == "#") {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
} else if (ch == "0" && stream.eat("x")) {
|
||||
stream.eatWhile(/[\da-f]/i);
|
||||
return "number";
|
||||
} else if (ch == "." && stream.eat(/\d/)) {
|
||||
stream.match(/\d*(?:e[+\-]?\d+)?/);
|
||||
return "number";
|
||||
} else if (/\d/.test(ch)) {
|
||||
stream.match(/\d*(?:\.\d+)?(?:e[+\-]\d+)?L?/);
|
||||
return "number";
|
||||
} else if (ch == "'" || ch == '"') {
|
||||
state.tokenize = tokenString(ch);
|
||||
return "string";
|
||||
} else if (ch == "." && stream.match(/.[.\d]+/)) {
|
||||
return "keyword";
|
||||
} else if (/[\w\.]/.test(ch) && ch != "_") {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
var word = stream.current();
|
||||
if (atoms.propertyIsEnumerable(word)) return "atom";
|
||||
if (keywords.propertyIsEnumerable(word)) {
|
||||
if (blockkeywords.propertyIsEnumerable(word)) curPunc = "block";
|
||||
return "keyword";
|
||||
}
|
||||
if (builtins.propertyIsEnumerable(word)) return "builtin";
|
||||
return "variable";
|
||||
} else if (ch == "%") {
|
||||
if (stream.skipTo("%")) stream.next();
|
||||
return "variable-2";
|
||||
} else if (ch == "<" && stream.eat("-")) {
|
||||
return "arrow";
|
||||
} else if (ch == "=" && state.ctx.argList) {
|
||||
return "arg-is";
|
||||
} else if (opChars.test(ch)) {
|
||||
if (ch == "$") return "dollar";
|
||||
stream.eatWhile(opChars);
|
||||
return "operator";
|
||||
} else if (/[\(\){}\[\];]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
if (ch == ";") return "semi";
|
||||
return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
if (stream.eat("\\")) {
|
||||
var ch = stream.next();
|
||||
if (ch == "x") stream.match(/^[a-f0-9]{2}/i);
|
||||
else if ((ch == "u" || ch == "U") && stream.eat("{") && stream.skipTo("}")) stream.next();
|
||||
else if (ch == "u") stream.match(/^[a-f0-9]{4}/i);
|
||||
else if (ch == "U") stream.match(/^[a-f0-9]{8}/i);
|
||||
else if (/[0-7]/.test(ch)) stream.match(/^[0-7]{1,2}/);
|
||||
return "string-2";
|
||||
} else {
|
||||
var next;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote) { state.tokenize = tokenBase; break; }
|
||||
if (next == "\\") { stream.backUp(1); break; }
|
||||
}
|
||||
return "string";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function push(state, type, stream) {
|
||||
state.ctx = {type: type,
|
||||
indent: state.indent,
|
||||
align: null,
|
||||
column: stream.column(),
|
||||
prev: state.ctx};
|
||||
}
|
||||
function pop(state) {
|
||||
state.indent = state.ctx.indent;
|
||||
state.ctx = state.ctx.prev;
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function(base) {
|
||||
return {tokenize: tokenBase,
|
||||
ctx: {type: "top",
|
||||
indent: -config.indentUnit,
|
||||
align: false},
|
||||
indent: 0,
|
||||
afterIdent: false};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) {
|
||||
if (state.ctx.align == null) state.ctx.align = false;
|
||||
state.indent = stream.indentation();
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
if (style != "comment" && state.ctx.align == null) state.ctx.align = true;
|
||||
|
||||
var ctype = state.ctx.type;
|
||||
if ((curPunc == ";" || curPunc == "{" || curPunc == "}") && ctype == "block") pop(state);
|
||||
if (curPunc == "{") push(state, "}", stream);
|
||||
else if (curPunc == "(") {
|
||||
push(state, ")", stream);
|
||||
if (state.afterIdent) state.ctx.argList = true;
|
||||
}
|
||||
else if (curPunc == "[") push(state, "]", stream);
|
||||
else if (curPunc == "block") push(state, "block", stream);
|
||||
else if (curPunc == ctype) pop(state);
|
||||
state.afterIdent = style == "variable" || style == "keyword";
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), ctx = state.ctx,
|
||||
closing = firstChar == ctx.type;
|
||||
if (ctx.type == "block") return ctx.indent + (firstChar == "{" ? 0 : config.indentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indent + (closing ? 0 : config.indentUnit);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rsrc", "r");
|
@ -1,19 +0,0 @@
|
||||
CodeMirror.defineMode("changes", function(config, modeConfig) {
|
||||
var headerSeperator = /^-+$/;
|
||||
var headerLine = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ?\d{1,2} \d{2}:\d{2}(:\d{2})? [A-Z]{3,4} \d{4} - /;
|
||||
var simpleEmail = /^[\w+.-]+@[\w.-]+/;
|
||||
|
||||
return {
|
||||
token: function(stream) {
|
||||
if (stream.sol()) {
|
||||
if (stream.match(headerSeperator)) { return 'tag'; }
|
||||
if (stream.match(headerLine)) { return 'tag'; }
|
||||
}
|
||||
if (stream.match(simpleEmail)) { return 'string'; }
|
||||
stream.next();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rpm-changes", "changes");
|
@ -1,53 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: RPM changes mode</title>
|
||||
<link rel="stylesheet" href="../../../lib/codemirror.css">
|
||||
<script src="../../../lib/codemirror.js"></script>
|
||||
<script src="changes.js"></script>
|
||||
<link rel="stylesheet" href="../../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: RPM changes mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
-------------------------------------------------------------------
|
||||
Tue Oct 18 13:58:40 UTC 2011 - misterx@example.com
|
||||
|
||||
- Update to r60.3
|
||||
- Fixes bug in the reflect package
|
||||
* disallow Interface method on Value obtained via unexported name
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Oct 6 08:14:24 UTC 2011 - misterx@example.com
|
||||
|
||||
- Update to r60.2
|
||||
- Fixes memory leak in certain map types
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed Oct 5 14:34:10 UTC 2011 - misterx@example.com
|
||||
|
||||
- Tweaks for gdb debugging
|
||||
- go.spec changes:
|
||||
- move %go_arch definition to %prep section
|
||||
- pass correct location of go specific gdb pretty printer and
|
||||
functions to cpp as HOST_EXTRA_CFLAGS macro
|
||||
- install go gdb functions & printer
|
||||
- gdb-printer.patch
|
||||
- patch linker (src/cmd/ld/dwarf.c) to emit correct location of go
|
||||
gdb functions and pretty printer
|
||||
</textarea></div>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: {name: "changes"},
|
||||
lineNumbers: true,
|
||||
indentUnit: 4,
|
||||
tabMode: "shift",
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-rpm-changes</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,99 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: RPM spec mode</title>
|
||||
<link rel="stylesheet" href="../../../lib/codemirror.css">
|
||||
<script src="../../../lib/codemirror.js"></script>
|
||||
<script src="spec.js"></script>
|
||||
<link rel="stylesheet" href="spec.css">
|
||||
<link rel="stylesheet" href="../../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: RPM spec mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
#
|
||||
# spec file for package minidlna
|
||||
#
|
||||
# Copyright (c) 2011, Sascha Peilicke <saschpe@gmx.de>
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
# upon. The license for this file, and modifications and additions to the
|
||||
# file, is the same license as for the pristine package itself (unless the
|
||||
# license for the pristine package is not an Open Source License, in which
|
||||
# case the license is the MIT License). An "Open Source License" is a
|
||||
# license that conforms to the Open Source Definition (Version 1.9)
|
||||
# published by the Open Source Initiative.
|
||||
|
||||
|
||||
Name: libupnp6
|
||||
Version: 1.6.13
|
||||
Release: 0
|
||||
Summary: Portable Universal Plug and Play (UPnP) SDK
|
||||
Group: System/Libraries
|
||||
License: BSD-3-Clause
|
||||
Url: http://sourceforge.net/projects/pupnp/
|
||||
Source0: http://downloads.sourceforge.net/pupnp/libupnp-%{version}.tar.bz2
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||
|
||||
%description
|
||||
The portable Universal Plug and Play (UPnP) SDK provides support for building
|
||||
UPnP-compliant control points, devices, and bridges on several operating
|
||||
systems.
|
||||
|
||||
%package -n libupnp-devel
|
||||
Summary: Portable Universal Plug and Play (UPnP) SDK
|
||||
Group: Development/Libraries/C and C++
|
||||
Provides: pkgconfig(libupnp)
|
||||
Requires: %{name} = %{version}
|
||||
|
||||
%description -n libupnp-devel
|
||||
The portable Universal Plug and Play (UPnP) SDK provides support for building
|
||||
UPnP-compliant control points, devices, and bridges on several operating
|
||||
systems.
|
||||
|
||||
%prep
|
||||
%setup -n libupnp-%{version}
|
||||
|
||||
%build
|
||||
%configure --disable-static
|
||||
make %{?_smp_mflags}
|
||||
|
||||
%install
|
||||
%makeinstall
|
||||
find %{buildroot} -type f -name '*.la' -exec rm -f {} ';'
|
||||
|
||||
%post -p /sbin/ldconfig
|
||||
|
||||
%postun -p /sbin/ldconfig
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%doc ChangeLog NEWS README TODO
|
||||
%{_libdir}/libixml.so.*
|
||||
%{_libdir}/libthreadutil.so.*
|
||||
%{_libdir}/libupnp.so.*
|
||||
|
||||
%files -n libupnp-devel
|
||||
%defattr(-,root,root,-)
|
||||
%{_libdir}/pkgconfig/libupnp.pc
|
||||
%{_libdir}/libixml.so
|
||||
%{_libdir}/libthreadutil.so
|
||||
%{_libdir}/libupnp.so
|
||||
%{_includedir}/upnp/
|
||||
|
||||
%changelog</textarea></div>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: {name: "spec"},
|
||||
lineNumbers: true,
|
||||
indentUnit: 4,
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-rpm-spec</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,5 +0,0 @@
|
||||
.cm-s-default span.cm-preamble {color: #b26818; font-weight: bold;}
|
||||
.cm-s-default span.cm-macro {color: #b218b2;}
|
||||
.cm-s-default span.cm-section {color: green; font-weight: bold;}
|
||||
.cm-s-default span.cm-script {color: red;}
|
||||
.cm-s-default span.cm-issue {color: yellow;}
|
@ -1,66 +0,0 @@
|
||||
// Quick and dirty spec file highlighting
|
||||
|
||||
CodeMirror.defineMode("spec", function(config, modeConfig) {
|
||||
var arch = /^(i386|i586|i686|x86_64|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
|
||||
|
||||
var preamble = /^(Name|Version|Release|License|Summary|Url|Group|Source|BuildArch|BuildRequires|BuildRoot|AutoReqProv|Provides|Requires(\(\w+\))?|Obsoletes|Conflicts|Recommends|Source\d*|Patch\d*|ExclusiveArch|NoSource|Supplements):/;
|
||||
var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preun|postun|pre|post|triggerin|triggerun|pretrans|posttrans|verifyscript|check|triggerpostun|triggerprein|trigger)/;
|
||||
var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros
|
||||
var control_flow_simple = /^%(else|endif)/; // rpm control flow macros
|
||||
var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros
|
||||
|
||||
return {
|
||||
startState: function () {
|
||||
return {
|
||||
controlFlow: false,
|
||||
macroParameters: false,
|
||||
section: false
|
||||
};
|
||||
},
|
||||
token: function (stream, state) {
|
||||
var ch = stream.peek();
|
||||
if (ch == "#") { stream.skipToEnd(); return "comment"; }
|
||||
|
||||
if (stream.sol()) {
|
||||
if (stream.match(preamble)) { return "preamble"; }
|
||||
if (stream.match(section)) { return "section"; }
|
||||
}
|
||||
|
||||
if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
|
||||
if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
|
||||
|
||||
if (stream.match(control_flow_simple)) { return "keyword"; }
|
||||
if (stream.match(control_flow_complex)) {
|
||||
state.controlFlow = true;
|
||||
return "keyword";
|
||||
}
|
||||
if (state.controlFlow) {
|
||||
if (stream.match(operators)) { return "operator"; }
|
||||
if (stream.match(/^(\d+)/)) { return "number"; }
|
||||
if (stream.eol()) { state.controlFlow = false; }
|
||||
}
|
||||
|
||||
if (stream.match(arch)) { return "number"; }
|
||||
|
||||
// Macros like '%make_install' or '%attr(0775,root,root)'
|
||||
if (stream.match(/^%[\w]+/)) {
|
||||
if (stream.match(/^\(/)) { state.macroParameters = true; }
|
||||
return "macro";
|
||||
}
|
||||
if (state.macroParameters) {
|
||||
if (stream.match(/^\d+/)) { return "number";}
|
||||
if (stream.match(/^\)/)) {
|
||||
state.macroParameters = false;
|
||||
return "macro";
|
||||
}
|
||||
}
|
||||
if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}'
|
||||
|
||||
//TODO: Include bash script sub-parser (CodeMirror supports that)
|
||||
stream.next();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rpm-spec", "spec");
|
@ -1,525 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: reStructuredText mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="rst.js"></script>
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: reStructuredText mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
.. This is an excerpt from Sphinx documentation: http://sphinx.pocoo.org/_sources/rest.txt
|
||||
|
||||
.. highlightlang:: rest
|
||||
|
||||
.. _rst-primer:
|
||||
|
||||
reStructuredText Primer
|
||||
=======================
|
||||
|
||||
This section is a brief introduction to reStructuredText (reST) concepts and
|
||||
syntax, intended to provide authors with enough information to author documents
|
||||
productively. Since reST was designed to be a simple, unobtrusive markup
|
||||
language, this will not take too long.
|
||||
|
||||
.. seealso::
|
||||
|
||||
The authoritative `reStructuredText User Documentation
|
||||
<http://docutils.sourceforge.net/rst.html>`_. The "ref" links in this
|
||||
document link to the description of the individual constructs in the reST
|
||||
reference.
|
||||
|
||||
|
||||
Paragraphs
|
||||
----------
|
||||
|
||||
The paragraph (:duref:`ref <paragraphs>`) is the most basic block in a reST
|
||||
document. Paragraphs are simply chunks of text separated by one or more blank
|
||||
lines. As in Python, indentation is significant in reST, so all lines of the
|
||||
same paragraph must be left-aligned to the same level of indentation.
|
||||
|
||||
|
||||
.. _inlinemarkup:
|
||||
|
||||
Inline markup
|
||||
-------------
|
||||
|
||||
The standard reST inline markup is quite simple: use
|
||||
|
||||
* one asterisk: ``*text*`` for emphasis (italics),
|
||||
* two asterisks: ``**text**`` for strong emphasis (boldface), and
|
||||
* backquotes: ````text```` for code samples.
|
||||
|
||||
If asterisks or backquotes appear in running text and could be confused with
|
||||
inline markup delimiters, they have to be escaped with a backslash.
|
||||
|
||||
Be aware of some restrictions of this markup:
|
||||
|
||||
* it may not be nested,
|
||||
* content may not start or end with whitespace: ``* text*`` is wrong,
|
||||
* it must be separated from surrounding text by non-word characters. Use a
|
||||
backslash escaped space to work around that: ``thisis\ *one*\ word``.
|
||||
|
||||
These restrictions may be lifted in future versions of the docutils.
|
||||
|
||||
reST also allows for custom "interpreted text roles"', which signify that the
|
||||
enclosed text should be interpreted in a specific way. Sphinx uses this to
|
||||
provide semantic markup and cross-referencing of identifiers, as described in
|
||||
the appropriate section. The general syntax is ``:rolename:`content```.
|
||||
|
||||
Standard reST provides the following roles:
|
||||
|
||||
* :durole:`emphasis` -- alternate spelling for ``*emphasis*``
|
||||
* :durole:`strong` -- alternate spelling for ``**strong**``
|
||||
* :durole:`literal` -- alternate spelling for ````literal````
|
||||
* :durole:`subscript` -- subscript text
|
||||
* :durole:`superscript` -- superscript text
|
||||
* :durole:`title-reference` -- for titles of books, periodicals, and other
|
||||
materials
|
||||
|
||||
See :ref:`inline-markup` for roles added by Sphinx.
|
||||
|
||||
|
||||
Lists and Quote-like blocks
|
||||
---------------------------
|
||||
|
||||
List markup (:duref:`ref <bullet-lists>`) is natural: just place an asterisk at
|
||||
the start of a paragraph and indent properly. The same goes for numbered lists;
|
||||
they can also be autonumbered using a ``#`` sign::
|
||||
|
||||
* This is a bulleted list.
|
||||
* It has two items, the second
|
||||
item uses two lines.
|
||||
|
||||
1. This is a numbered list.
|
||||
2. It has two items too.
|
||||
|
||||
#. This is a numbered list.
|
||||
#. It has two items too.
|
||||
|
||||
|
||||
Nested lists are possible, but be aware that they must be separated from the
|
||||
parent list items by blank lines::
|
||||
|
||||
* this is
|
||||
* a list
|
||||
|
||||
* with a nested list
|
||||
* and some subitems
|
||||
|
||||
* and here the parent list continues
|
||||
|
||||
Definition lists (:duref:`ref <definition-lists>`) are created as follows::
|
||||
|
||||
term (up to a line of text)
|
||||
Definition of the term, which must be indented
|
||||
|
||||
and can even consist of multiple paragraphs
|
||||
|
||||
next term
|
||||
Description.
|
||||
|
||||
Note that the term cannot have more than one line of text.
|
||||
|
||||
Quoted paragraphs (:duref:`ref <block-quotes>`) are created by just indenting
|
||||
them more than the surrounding paragraphs.
|
||||
|
||||
Line blocks (:duref:`ref <line-blocks>`) are a way of preserving line breaks::
|
||||
|
||||
| These lines are
|
||||
| broken exactly like in
|
||||
| the source file.
|
||||
|
||||
There are also several more special blocks available:
|
||||
|
||||
* field lists (:duref:`ref <field-lists>`)
|
||||
* option lists (:duref:`ref <option-lists>`)
|
||||
* quoted literal blocks (:duref:`ref <quoted-literal-blocks>`)
|
||||
* doctest blocks (:duref:`ref <doctest-blocks>`)
|
||||
|
||||
|
||||
Source Code
|
||||
-----------
|
||||
|
||||
Literal code blocks (:duref:`ref <literal-blocks>`) are introduced by ending a
|
||||
paragraph with the special marker ``::``. The literal block must be indented
|
||||
(and, like all paragraphs, separated from the surrounding ones by blank lines)::
|
||||
|
||||
This is a normal text paragraph. The next paragraph is a code sample::
|
||||
|
||||
It is not processed in any way, except
|
||||
that the indentation is removed.
|
||||
|
||||
It can span multiple lines.
|
||||
|
||||
This is a normal text paragraph again.
|
||||
|
||||
The handling of the ``::`` marker is smart:
|
||||
|
||||
* If it occurs as a paragraph of its own, that paragraph is completely left
|
||||
out of the document.
|
||||
* If it is preceded by whitespace, the marker is removed.
|
||||
* If it is preceded by non-whitespace, the marker is replaced by a single
|
||||
colon.
|
||||
|
||||
That way, the second sentence in the above example's first paragraph would be
|
||||
rendered as "The next paragraph is a code sample:".
|
||||
|
||||
|
||||
.. _rst-tables:
|
||||
|
||||
Tables
|
||||
------
|
||||
|
||||
Two forms of tables are supported. For *grid tables* (:duref:`ref
|
||||
<grid-tables>`), you have to "paint" the cell grid yourself. They look like
|
||||
this::
|
||||
|
||||
+------------------------+------------+----------+----------+
|
||||
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
|
||||
| (header rows optional) | | | |
|
||||
+========================+============+==========+==========+
|
||||
| body row 1, column 1 | column 2 | column 3 | column 4 |
|
||||
+------------------------+------------+----------+----------+
|
||||
| body row 2 | ... | ... | |
|
||||
+------------------------+------------+----------+----------+
|
||||
|
||||
*Simple tables* (:duref:`ref <simple-tables>`) are easier to write, but
|
||||
limited: they must contain more than one row, and the first column cannot
|
||||
contain multiple lines. They look like this::
|
||||
|
||||
===== ===== =======
|
||||
A B A and B
|
||||
===== ===== =======
|
||||
False False False
|
||||
True False False
|
||||
False True False
|
||||
True True True
|
||||
===== ===== =======
|
||||
|
||||
|
||||
Hyperlinks
|
||||
----------
|
||||
|
||||
External links
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
Use ```Link text <http://example.com/>`_`` for inline web links. If the link
|
||||
text should be the web address, you don't need special markup at all, the parser
|
||||
finds links and mail addresses in ordinary text.
|
||||
|
||||
You can also separate the link and the target definition (:duref:`ref
|
||||
<hyperlink-targets>`), like this::
|
||||
|
||||
This is a paragraph that contains `a link`_.
|
||||
|
||||
.. _a link: http://example.com/
|
||||
|
||||
|
||||
Internal links
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
Internal linking is done via a special reST role provided by Sphinx, see the
|
||||
section on specific markup, :ref:`ref-role`.
|
||||
|
||||
|
||||
Sections
|
||||
--------
|
||||
|
||||
Section headers (:duref:`ref <sections>`) are created by underlining (and
|
||||
optionally overlining) the section title with a punctuation character, at least
|
||||
as long as the text::
|
||||
|
||||
=================
|
||||
This is a heading
|
||||
=================
|
||||
|
||||
Normally, there are no heading levels assigned to certain characters as the
|
||||
structure is determined from the succession of headings. However, for the
|
||||
Python documentation, this convention is used which you may follow:
|
||||
|
||||
* ``#`` with overline, for parts
|
||||
* ``*`` with overline, for chapters
|
||||
* ``=``, for sections
|
||||
* ``-``, for subsections
|
||||
* ``^``, for subsubsections
|
||||
* ``"``, for paragraphs
|
||||
|
||||
Of course, you are free to use your own marker characters (see the reST
|
||||
documentation), and use a deeper nesting level, but keep in mind that most
|
||||
target formats (HTML, LaTeX) have a limited supported nesting depth.
|
||||
|
||||
|
||||
Explicit Markup
|
||||
---------------
|
||||
|
||||
"Explicit markup" (:duref:`ref <explicit-markup-blocks>`) is used in reST for
|
||||
most constructs that need special handling, such as footnotes,
|
||||
specially-highlighted paragraphs, comments, and generic directives.
|
||||
|
||||
An explicit markup block begins with a line starting with ``..`` followed by
|
||||
whitespace and is terminated by the next paragraph at the same level of
|
||||
indentation. (There needs to be a blank line between explicit markup and normal
|
||||
paragraphs. This may all sound a bit complicated, but it is intuitive enough
|
||||
when you write it.)
|
||||
|
||||
|
||||
.. _directives:
|
||||
|
||||
Directives
|
||||
----------
|
||||
|
||||
A directive (:duref:`ref <directives>`) is a generic block of explicit markup.
|
||||
Besides roles, it is one of the extension mechanisms of reST, and Sphinx makes
|
||||
heavy use of it.
|
||||
|
||||
Docutils supports the following directives:
|
||||
|
||||
* Admonitions: :dudir:`attention`, :dudir:`caution`, :dudir:`danger`,
|
||||
:dudir:`error`, :dudir:`hint`, :dudir:`important`, :dudir:`note`,
|
||||
:dudir:`tip`, :dudir:`warning` and the generic :dudir:`admonition`.
|
||||
(Most themes style only "note" and "warning" specially.)
|
||||
|
||||
* Images:
|
||||
|
||||
- :dudir:`image` (see also Images_ below)
|
||||
- :dudir:`figure` (an image with caption and optional legend)
|
||||
|
||||
* Additional body elements:
|
||||
|
||||
- :dudir:`contents` (a local, i.e. for the current file only, table of
|
||||
contents)
|
||||
- :dudir:`container` (a container with a custom class, useful to generate an
|
||||
outer ``<div>`` in HTML)
|
||||
- :dudir:`rubric` (a heading without relation to the document sectioning)
|
||||
- :dudir:`topic`, :dudir:`sidebar` (special highlighted body elements)
|
||||
- :dudir:`parsed-literal` (literal block that supports inline markup)
|
||||
- :dudir:`epigraph` (a block quote with optional attribution line)
|
||||
- :dudir:`highlights`, :dudir:`pull-quote` (block quotes with their own
|
||||
class attribute)
|
||||
- :dudir:`compound` (a compound paragraph)
|
||||
|
||||
* Special tables:
|
||||
|
||||
- :dudir:`table` (a table with title)
|
||||
- :dudir:`csv-table` (a table generated from comma-separated values)
|
||||
- :dudir:`list-table` (a table generated from a list of lists)
|
||||
|
||||
* Special directives:
|
||||
|
||||
- :dudir:`raw` (include raw target-format markup)
|
||||
- :dudir:`include` (include reStructuredText from another file)
|
||||
-- in Sphinx, when given an absolute include file path, this directive takes
|
||||
it as relative to the source directory
|
||||
- :dudir:`class` (assign a class attribute to the next element) [1]_
|
||||
|
||||
* HTML specifics:
|
||||
|
||||
- :dudir:`meta` (generation of HTML ``<meta>`` tags)
|
||||
- :dudir:`title` (override document title)
|
||||
|
||||
* Influencing markup:
|
||||
|
||||
- :dudir:`default-role` (set a new default role)
|
||||
- :dudir:`role` (create a new role)
|
||||
|
||||
Since these are only per-file, better use Sphinx' facilities for setting the
|
||||
:confval:`default_role`.
|
||||
|
||||
Do *not* use the directives :dudir:`sectnum`, :dudir:`header` and
|
||||
:dudir:`footer`.
|
||||
|
||||
Directives added by Sphinx are described in :ref:`sphinxmarkup`.
|
||||
|
||||
Basically, a directive consists of a name, arguments, options and content. (Keep
|
||||
this terminology in mind, it is used in the next chapter describing custom
|
||||
directives.) Looking at this example, ::
|
||||
|
||||
.. function:: foo(x)
|
||||
foo(y, z)
|
||||
:module: some.module.name
|
||||
|
||||
Return a line of text input from the user.
|
||||
|
||||
``function`` is the directive name. It is given two arguments here, the
|
||||
remainder of the first line and the second line, as well as one option
|
||||
``module`` (as you can see, options are given in the lines immediately following
|
||||
the arguments and indicated by the colons). Options must be indented to the
|
||||
same level as the directive content.
|
||||
|
||||
The directive content follows after a blank line and is indented relative to the
|
||||
directive start.
|
||||
|
||||
|
||||
Images
|
||||
------
|
||||
|
||||
reST supports an image directive (:dudir:`ref <image>`), used like so::
|
||||
|
||||
.. image:: gnu.png
|
||||
(options)
|
||||
|
||||
When used within Sphinx, the file name given (here ``gnu.png``) must either be
|
||||
relative to the source file, or absolute which means that they are relative to
|
||||
the top source directory. For example, the file ``sketch/spam.rst`` could refer
|
||||
to the image ``images/spam.png`` as ``../images/spam.png`` or
|
||||
``/images/spam.png``.
|
||||
|
||||
Sphinx will automatically copy image files over to a subdirectory of the output
|
||||
directory on building (e.g. the ``_static`` directory for HTML output.)
|
||||
|
||||
Interpretation of image size options (``width`` and ``height``) is as follows:
|
||||
if the size has no unit or the unit is pixels, the given size will only be
|
||||
respected for output channels that support pixels (i.e. not in LaTeX output).
|
||||
Other units (like ``pt`` for points) will be used for HTML and LaTeX output.
|
||||
|
||||
Sphinx extends the standard docutils behavior by allowing an asterisk for the
|
||||
extension::
|
||||
|
||||
.. image:: gnu.*
|
||||
|
||||
Sphinx then searches for all images matching the provided pattern and determines
|
||||
their type. Each builder then chooses the best image out of these candidates.
|
||||
For instance, if the file name ``gnu.*`` was given and two files :file:`gnu.pdf`
|
||||
and :file:`gnu.png` existed in the source tree, the LaTeX builder would choose
|
||||
the former, while the HTML builder would prefer the latter.
|
||||
|
||||
.. versionchanged:: 0.4
|
||||
Added the support for file names ending in an asterisk.
|
||||
|
||||
.. versionchanged:: 0.6
|
||||
Image paths can now be absolute.
|
||||
|
||||
|
||||
Footnotes
|
||||
---------
|
||||
|
||||
For footnotes (:duref:`ref <footnotes>`), use ``[#name]_`` to mark the footnote
|
||||
location, and add the footnote body at the bottom of the document after a
|
||||
"Footnotes" rubric heading, like so::
|
||||
|
||||
Lorem ipsum [#f1]_ dolor sit amet ... [#f2]_
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
.. [#f1] Text of the first footnote.
|
||||
.. [#f2] Text of the second footnote.
|
||||
|
||||
You can also explicitly number the footnotes (``[1]_``) or use auto-numbered
|
||||
footnotes without names (``[#]_``).
|
||||
|
||||
|
||||
Citations
|
||||
---------
|
||||
|
||||
Standard reST citations (:duref:`ref <citations>`) are supported, with the
|
||||
additional feature that they are "global", i.e. all citations can be referenced
|
||||
from all files. Use them like so::
|
||||
|
||||
Lorem ipsum [Ref]_ dolor sit amet.
|
||||
|
||||
.. [Ref] Book or article reference, URL or whatever.
|
||||
|
||||
Citation usage is similar to footnote usage, but with a label that is not
|
||||
numeric or begins with ``#``.
|
||||
|
||||
|
||||
Substitutions
|
||||
-------------
|
||||
|
||||
reST supports "substitutions" (:duref:`ref <substitution-definitions>`), which
|
||||
are pieces of text and/or markup referred to in the text by ``|name|``. They
|
||||
are defined like footnotes with explicit markup blocks, like this::
|
||||
|
||||
.. |name| replace:: replacement *text*
|
||||
|
||||
or this::
|
||||
|
||||
.. |caution| image:: warning.png
|
||||
:alt: Warning!
|
||||
|
||||
See the :duref:`reST reference for substitutions <substitution-definitions>`
|
||||
for details.
|
||||
|
||||
If you want to use some substitutions for all documents, put them into
|
||||
:confval:`rst_prolog` or put them into a separate file and include it into all
|
||||
documents you want to use them in, using the :rst:dir:`include` directive. (Be
|
||||
sure to give the include file a file name extension differing from that of other
|
||||
source files, to avoid Sphinx finding it as a standalone document.)
|
||||
|
||||
Sphinx defines some default substitutions, see :ref:`default-substitutions`.
|
||||
|
||||
|
||||
Comments
|
||||
--------
|
||||
|
||||
Every explicit markup block which isn't a valid markup construct (like the
|
||||
footnotes above) is regarded as a comment (:duref:`ref <comments>`). For
|
||||
example::
|
||||
|
||||
.. This is a comment.
|
||||
|
||||
You can indent text after a comment start to form multiline comments::
|
||||
|
||||
..
|
||||
This whole indented block
|
||||
is a comment.
|
||||
|
||||
Still in the comment.
|
||||
|
||||
|
||||
Source encoding
|
||||
---------------
|
||||
|
||||
Since the easiest way to include special characters like em dashes or copyright
|
||||
signs in reST is to directly write them as Unicode characters, one has to
|
||||
specify an encoding. Sphinx assumes source files to be encoded in UTF-8 by
|
||||
default; you can change this with the :confval:`source_encoding` config value.
|
||||
|
||||
|
||||
Gotchas
|
||||
-------
|
||||
|
||||
There are some problems one commonly runs into while authoring reST documents:
|
||||
|
||||
* **Separation of inline markup:** As said above, inline markup spans must be
|
||||
separated from the surrounding text by non-word characters, you have to use a
|
||||
backslash-escaped space to get around that. See `the reference
|
||||
<http://docutils.sf.net/docs/ref/rst/restructuredtext.html#inline-markup>`_
|
||||
for the details.
|
||||
|
||||
* **No nested inline markup:** Something like ``*see :func:`foo`*`` is not
|
||||
possible.
|
||||
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
.. [1] When the default domain contains a :rst:dir:`class` directive, this directive
|
||||
will be shadowed. Therefore, Sphinx re-exports it as :rst:dir:`rst-class`.
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
});
|
||||
</script>
|
||||
<p>The reStructuredText mode supports one configuration parameter:</p>
|
||||
<dl>
|
||||
<dt><code>verbatim (string)</code></dt>
|
||||
<dd>A name or MIME type of a mode that will be used for highlighting
|
||||
verbatim blocks. By default, reStructuredText mode uses uniform color
|
||||
for whole block of verbatim text if no mode is given.</dd>
|
||||
</dl>
|
||||
<p>If <code>python</code> mode is available,
|
||||
it will be used for highlighting blocks containing Python/IPython terminal
|
||||
sessions (blocks starting with <code>>>></code> (for Python) or
|
||||
<code>In [num]:</code> (for IPython).
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-rst</code>.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,326 +0,0 @@
|
||||
CodeMirror.defineMode('rst', function(config, options) {
|
||||
function setState(state, fn, ctx) {
|
||||
state.fn = fn;
|
||||
setCtx(state, ctx);
|
||||
}
|
||||
|
||||
function setCtx(state, ctx) {
|
||||
state.ctx = ctx || {};
|
||||
}
|
||||
|
||||
function setNormal(state, ch) {
|
||||
if (ch && (typeof ch !== 'string')) {
|
||||
var str = ch.current();
|
||||
ch = str[str.length-1];
|
||||
}
|
||||
|
||||
setState(state, normal, {back: ch});
|
||||
}
|
||||
|
||||
function hasMode(mode) {
|
||||
if (mode) {
|
||||
var modes = CodeMirror.listModes();
|
||||
|
||||
for (var i in modes) {
|
||||
if (modes[i] == mode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getMode(mode) {
|
||||
if (hasMode(mode)) {
|
||||
return CodeMirror.getMode(config, mode);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var verbatimMode = getMode(options.verbatim);
|
||||
var pythonMode = getMode('python');
|
||||
|
||||
var reSection = /^[!"#$%&'()*+,-./:;<=>?@[\\\]^_`{|}~]/;
|
||||
var reDirective = /^\s*\w([-:.\w]*\w)?::(\s|$)/;
|
||||
var reHyperlink = /^\s*_[\w-]+:(\s|$)/;
|
||||
var reFootnote = /^\s*\[(\d+|#)\](\s|$)/;
|
||||
var reCitation = /^\s*\[[A-Za-z][\w-]*\](\s|$)/;
|
||||
var reFootnoteRef = /^\[(\d+|#)\]_/;
|
||||
var reCitationRef = /^\[[A-Za-z][\w-]*\]_/;
|
||||
var reDirectiveMarker = /^\.\.(\s|$)/;
|
||||
var reVerbatimMarker = /^::\s*$/;
|
||||
var rePreInline = /^[-\s"([{</:]/;
|
||||
var rePostInline = /^[-\s`'")\]}>/:.,;!?\\_]/;
|
||||
var reEnumeratedList = /^\s*((\d+|[A-Za-z#])[.)]|\((\d+|[A-Z-a-z#])\))\s/;
|
||||
var reBulletedList = /^\s*[-\+\*]\s/;
|
||||
var reExamples = /^\s+(>>>|In \[\d+\]:)\s/;
|
||||
|
||||
function normal(stream, state) {
|
||||
var ch, sol, i;
|
||||
|
||||
if (stream.eat(/\\/)) {
|
||||
ch = stream.next();
|
||||
setNormal(state, ch);
|
||||
return null;
|
||||
}
|
||||
|
||||
sol = stream.sol();
|
||||
|
||||
if (sol && (ch = stream.eat(reSection))) {
|
||||
for (i = 0; stream.eat(ch); i++);
|
||||
|
||||
if (i >= 3 && stream.match(/^\s*$/)) {
|
||||
setNormal(state, null);
|
||||
return 'header';
|
||||
} else {
|
||||
stream.backUp(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (sol && stream.match(reDirectiveMarker)) {
|
||||
if (!stream.eol()) {
|
||||
setState(state, directive);
|
||||
}
|
||||
return 'meta';
|
||||
}
|
||||
|
||||
if (stream.match(reVerbatimMarker)) {
|
||||
if (!verbatimMode) {
|
||||
setState(state, verbatim);
|
||||
} else {
|
||||
var mode = verbatimMode;
|
||||
|
||||
setState(state, verbatim, {
|
||||
mode: mode,
|
||||
local: mode.startState()
|
||||
});
|
||||
}
|
||||
return 'meta';
|
||||
}
|
||||
|
||||
if (sol && stream.match(reExamples, false)) {
|
||||
if (!pythonMode) {
|
||||
setState(state, verbatim);
|
||||
return 'meta';
|
||||
} else {
|
||||
var mode = pythonMode;
|
||||
|
||||
setState(state, verbatim, {
|
||||
mode: mode,
|
||||
local: mode.startState()
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function testBackward(re) {
|
||||
return sol || !state.ctx.back || re.test(state.ctx.back);
|
||||
}
|
||||
|
||||
function testForward(re) {
|
||||
return stream.eol() || stream.match(re, false);
|
||||
}
|
||||
|
||||
function testInline(re) {
|
||||
return stream.match(re) && testBackward(/\W/) && testForward(/\W/);
|
||||
}
|
||||
|
||||
if (testInline(reFootnoteRef)) {
|
||||
setNormal(state, stream);
|
||||
return 'footnote';
|
||||
}
|
||||
|
||||
if (testInline(reCitationRef)) {
|
||||
setNormal(state, stream);
|
||||
return 'citation';
|
||||
}
|
||||
|
||||
ch = stream.next();
|
||||
|
||||
if (testBackward(rePreInline)) {
|
||||
if ((ch === ':' || ch === '|') && stream.eat(/\S/)) {
|
||||
var token;
|
||||
|
||||
if (ch === ':') {
|
||||
token = 'builtin';
|
||||
} else {
|
||||
token = 'atom';
|
||||
}
|
||||
|
||||
setState(state, inline, {
|
||||
ch: ch,
|
||||
wide: false,
|
||||
prev: null,
|
||||
token: token
|
||||
});
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
if (ch === '*' || ch === '`') {
|
||||
var orig = ch,
|
||||
wide = false;
|
||||
|
||||
ch = stream.next();
|
||||
|
||||
if (ch == orig) {
|
||||
wide = true;
|
||||
ch = stream.next();
|
||||
}
|
||||
|
||||
if (ch && !/\s/.test(ch)) {
|
||||
var token;
|
||||
|
||||
if (orig === '*') {
|
||||
token = wide ? 'strong' : 'em';
|
||||
} else {
|
||||
token = wide ? 'string' : 'string-2';
|
||||
}
|
||||
|
||||
setState(state, inline, {
|
||||
ch: orig, // inline() has to know what to search for
|
||||
wide: wide, // are we looking for `ch` or `chch`
|
||||
prev: null, // terminator must not be preceeded with whitespace
|
||||
token: token // I don't want to recompute this all the time
|
||||
});
|
||||
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setNormal(state, ch);
|
||||
return null;
|
||||
}
|
||||
|
||||
function inline(stream, state) {
|
||||
var ch = stream.next(),
|
||||
token = state.ctx.token;
|
||||
|
||||
function finish(ch) {
|
||||
state.ctx.prev = ch;
|
||||
return token;
|
||||
}
|
||||
|
||||
if (ch != state.ctx.ch) {
|
||||
return finish(ch);
|
||||
}
|
||||
|
||||
if (/\s/.test(state.ctx.prev)) {
|
||||
return finish(ch);
|
||||
}
|
||||
|
||||
if (state.ctx.wide) {
|
||||
ch = stream.next();
|
||||
|
||||
if (ch != state.ctx.ch) {
|
||||
return finish(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (!stream.eol() && !rePostInline.test(stream.peek())) {
|
||||
if (state.ctx.wide) {
|
||||
stream.backUp(1);
|
||||
}
|
||||
|
||||
return finish(ch);
|
||||
}
|
||||
|
||||
setState(state, normal);
|
||||
setNormal(state, ch);
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
function directive(stream, state) {
|
||||
var token = null;
|
||||
|
||||
if (stream.match(reDirective)) {
|
||||
token = 'attribute';
|
||||
} else if (stream.match(reHyperlink)) {
|
||||
token = 'link';
|
||||
} else if (stream.match(reFootnote)) {
|
||||
token = 'quote';
|
||||
} else if (stream.match(reCitation)) {
|
||||
token = 'quote';
|
||||
} else {
|
||||
stream.eatSpace();
|
||||
|
||||
if (stream.eol()) {
|
||||
setNormal(state, stream);
|
||||
return null;
|
||||
} else {
|
||||
stream.skipToEnd();
|
||||
setState(state, comment);
|
||||
return 'comment';
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME this is unreachable
|
||||
setState(state, body, {start: true});
|
||||
return token;
|
||||
}
|
||||
|
||||
function body(stream, state) {
|
||||
var token = 'body';
|
||||
|
||||
if (!state.ctx.start || stream.sol()) {
|
||||
return block(stream, state, token);
|
||||
}
|
||||
|
||||
stream.skipToEnd();
|
||||
setCtx(state);
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
function comment(stream, state) {
|
||||
return block(stream, state, 'comment');
|
||||
}
|
||||
|
||||
function verbatim(stream, state) {
|
||||
if (!verbatimMode) {
|
||||
return block(stream, state, 'meta');
|
||||
} else {
|
||||
if (stream.sol()) {
|
||||
if (!stream.eatSpace()) {
|
||||
setNormal(state, stream);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return verbatimMode.token(stream, state.ctx.local);
|
||||
}
|
||||
}
|
||||
|
||||
function block(stream, state, token) {
|
||||
if (stream.eol() || stream.eatSpace()) {
|
||||
stream.skipToEnd();
|
||||
return token;
|
||||
} else {
|
||||
setNormal(state, stream);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return {fn: normal, ctx: {}};
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
return {fn: state.fn, ctx: state.ctx};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var token = state.fn(stream, state);
|
||||
return token;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rst", "rst");
|
@ -1,24 +0,0 @@
|
||||
Copyright (c) 2011, Ubalo, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Ubalo, Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL UBALO, INC BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -1,171 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Ruby mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="ruby.js"></script>
|
||||
<style>
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
.cm-s-default span.cm-arrow { color: red; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Ruby mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
# Code from http://sandbox.mc.edu/~bennet/ruby/code/poly_rb.html
|
||||
#
|
||||
# This program evaluates polynomials. It first asks for the coefficients
|
||||
# of a polynomial, which must be entered on one line, highest-order first.
|
||||
# It then requests values of x and will compute the value of the poly for
|
||||
# each x. It will repeatly ask for x values, unless you the user enters
|
||||
# a blank line. It that case, it will ask for another polynomial. If the
|
||||
# user types quit for either input, the program immediately exits.
|
||||
#
|
||||
|
||||
#
|
||||
# Function to evaluate a polynomial at x. The polynomial is given
|
||||
# as a list of coefficients, from the greatest to the least.
|
||||
def polyval(x, coef)
|
||||
sum = 0
|
||||
coef = coef.clone # Don't want to destroy the original
|
||||
while true
|
||||
sum += coef.shift # Add and remove the next coef
|
||||
break if coef.empty? # If no more, done entirely.
|
||||
sum *= x # This happens the right number of times.
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
#
|
||||
# Function to read a line containing a list of integers and return
|
||||
# them as an array of integers. If the string conversion fails, it
|
||||
# throws TypeError. If the input line is the word 'quit', then it
|
||||
# converts it to an end-of-file exception
|
||||
def readints(prompt)
|
||||
# Read a line
|
||||
print prompt
|
||||
line = readline.chomp
|
||||
raise EOFError.new if line == 'quit' # You can also use a real EOF.
|
||||
|
||||
# Go through each item on the line, converting each one and adding it
|
||||
# to retval.
|
||||
retval = [ ]
|
||||
for str in line.split(/\s+/)
|
||||
if str =~ /^\-?\d+$/
|
||||
retval.push(str.to_i)
|
||||
else
|
||||
raise TypeError.new
|
||||
end
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
#
|
||||
# Take a coeff and an exponent and return the string representation, ignoring
|
||||
# the sign of the coefficient.
|
||||
def term_to_str(coef, exp)
|
||||
ret = ""
|
||||
|
||||
# Show coeff, unless it's 1 or at the right
|
||||
coef = coef.abs
|
||||
ret = coef.to_s unless coef == 1 && exp > 0
|
||||
ret += "x" if exp > 0 # x if exponent not 0
|
||||
ret += "^" + exp.to_s if exp > 1 # ^exponent, if > 1.
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
#
|
||||
# Create a string of the polynomial in sort-of-readable form.
|
||||
def polystr(p)
|
||||
# Get the exponent of first coefficient, plus 1.
|
||||
exp = p.length
|
||||
|
||||
# Assign exponents to each term, making pairs of coeff and exponent,
|
||||
# Then get rid of the zero terms.
|
||||
p = (p.map { |c| exp -= 1; [ c, exp ] }).select { |p| p[0] != 0 }
|
||||
|
||||
# If there's nothing left, it's a zero
|
||||
return "0" if p.empty?
|
||||
|
||||
# *** Now p is a non-empty list of [ coef, exponent ] pairs. ***
|
||||
|
||||
# Convert the first term, preceded by a "-" if it's negative.
|
||||
result = (if p[0][0] < 0 then "-" else "" end) + term_to_str(*p[0])
|
||||
|
||||
# Convert the rest of the terms, in each case adding the appropriate
|
||||
# + or - separating them.
|
||||
for term in p[1...p.length]
|
||||
# Add the separator then the rep. of the term.
|
||||
result += (if term[0] < 0 then " - " else " + " end) +
|
||||
term_to_str(*term)
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
#
|
||||
# Run until some kind of endfile.
|
||||
begin
|
||||
# Repeat until an exception or quit gets us out.
|
||||
while true
|
||||
# Read a poly until it works. An EOF will except out of the
|
||||
# program.
|
||||
print "\n"
|
||||
begin
|
||||
poly = readints("Enter a polynomial coefficients: ")
|
||||
rescue TypeError
|
||||
print "Try again.\n"
|
||||
retry
|
||||
end
|
||||
break if poly.empty?
|
||||
|
||||
# Read and evaluate x values until the user types a blank line.
|
||||
# Again, an EOF will except out of the pgm.
|
||||
while true
|
||||
# Request an integer.
|
||||
print "Enter x value or blank line: "
|
||||
x = readline.chomp
|
||||
break if x == ''
|
||||
raise EOFError.new if x == 'quit'
|
||||
|
||||
# If it looks bad, let's try again.
|
||||
if x !~ /^\-?\d+$/
|
||||
print "That doesn't look like an integer. Please try again.\n"
|
||||
next
|
||||
end
|
||||
|
||||
# Convert to an integer and print the result.
|
||||
x = x.to_i
|
||||
print "p(x) = ", polystr(poly), "\n"
|
||||
print "p(", x, ") = ", polyval(x, poly), "\n"
|
||||
end
|
||||
end
|
||||
rescue EOFError
|
||||
print "\n=== EOF ===\n"
|
||||
rescue Interrupt, SignalException
|
||||
print "\n=== Interrupted ===\n"
|
||||
else
|
||||
print "--- Bye ---\n"
|
||||
end
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "text/x-ruby",
|
||||
tabMode: "indent",
|
||||
matchBrackets: true,
|
||||
indentUnit: 4
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-ruby</code>.</p>
|
||||
|
||||
<p>Development of the CodeMirror Ruby mode was kindly sponsored
|
||||
by <a href="http://ubalo.com/">Ubalo</a>, who hold
|
||||
the <a href="LICENSE">license</a>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,200 +0,0 @@
|
||||
CodeMirror.defineMode("ruby", function(config, parserConfig) {
|
||||
function wordObj(words) {
|
||||
var o = {};
|
||||
for (var i = 0, e = words.length; i < e; ++i) o[words[i]] = true;
|
||||
return o;
|
||||
}
|
||||
var keywords = wordObj([
|
||||
"alias", "and", "BEGIN", "begin", "break", "case", "class", "def", "defined?", "do", "else",
|
||||
"elsif", "END", "end", "ensure", "false", "for", "if", "in", "module", "next", "not", "or",
|
||||
"redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless",
|
||||
"until", "when", "while", "yield", "nil", "raise", "throw", "catch", "fail", "loop", "callcc",
|
||||
"caller", "lambda", "proc", "public", "protected", "private", "require", "load",
|
||||
"require_relative", "extend", "autoload"
|
||||
]);
|
||||
var indentWords = wordObj(["def", "class", "case", "for", "while", "do", "module", "then",
|
||||
"catch", "loop", "proc", "begin"]);
|
||||
var dedentWords = wordObj(["end", "until"]);
|
||||
var matching = {"[": "]", "{": "}", "(": ")"};
|
||||
var curPunc;
|
||||
|
||||
function chain(newtok, stream, state) {
|
||||
state.tokenize.push(newtok);
|
||||
return newtok(stream, state);
|
||||
}
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
curPunc = null;
|
||||
if (stream.sol() && stream.match("=begin") && stream.eol()) {
|
||||
state.tokenize.push(readBlockComment);
|
||||
return "comment";
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
var ch = stream.next();
|
||||
if (ch == "`" || ch == "'" || ch == '"' ||
|
||||
(ch == "/" && !stream.eol() && stream.peek() != " ")) {
|
||||
return chain(readQuoted(ch, "string", ch == '"' || ch == "`"), stream, state);
|
||||
} else if (ch == "%") {
|
||||
var style, embed = false;
|
||||
if (stream.eat("s")) style = "atom";
|
||||
else if (stream.eat(/[WQ]/)) { style = "string"; embed = true; }
|
||||
else if (stream.eat(/[wxqr]/)) style = "string";
|
||||
var delim = stream.eat(/[^\w\s]/);
|
||||
if (!delim) return "operator";
|
||||
if (matching.propertyIsEnumerable(delim)) delim = matching[delim];
|
||||
return chain(readQuoted(delim, style, embed, true), stream, state);
|
||||
} else if (ch == "#") {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
} else if (ch == "<" && stream.eat("<")) {
|
||||
stream.eat("-");
|
||||
stream.eat(/[\'\"\`]/);
|
||||
var match = stream.match(/^\w+/);
|
||||
stream.eat(/[\'\"\`]/);
|
||||
if (match) return chain(readHereDoc(match[0]), stream, state);
|
||||
return null;
|
||||
} else if (ch == "0") {
|
||||
if (stream.eat("x")) stream.eatWhile(/[\da-fA-F]/);
|
||||
else if (stream.eat("b")) stream.eatWhile(/[01]/);
|
||||
else stream.eatWhile(/[0-7]/);
|
||||
return "number";
|
||||
} else if (/\d/.test(ch)) {
|
||||
stream.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/);
|
||||
return "number";
|
||||
} else if (ch == "?") {
|
||||
while (stream.match(/^\\[CM]-/)) {}
|
||||
if (stream.eat("\\")) stream.eatWhile(/\w/);
|
||||
else stream.next();
|
||||
return "string";
|
||||
} else if (ch == ":") {
|
||||
if (stream.eat("'")) return chain(readQuoted("'", "atom", false), stream, state);
|
||||
if (stream.eat('"')) return chain(readQuoted('"', "atom", true), stream, state);
|
||||
stream.eatWhile(/[\w\?]/);
|
||||
return "atom";
|
||||
} else if (ch == "@") {
|
||||
stream.eat("@");
|
||||
stream.eatWhile(/[\w\?]/);
|
||||
return "variable-2";
|
||||
} else if (ch == "$") {
|
||||
stream.next();
|
||||
stream.eatWhile(/[\w\?]/);
|
||||
return "variable-3";
|
||||
} else if (/\w/.test(ch)) {
|
||||
stream.eatWhile(/[\w\?]/);
|
||||
if (stream.eat(":")) return "atom";
|
||||
return "ident";
|
||||
} else if (ch == "|" && (state.varList || state.lastTok == "{" || state.lastTok == "do")) {
|
||||
curPunc = "|";
|
||||
return null;
|
||||
} else if (/[\(\)\[\]{}\\;]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null;
|
||||
} else if (ch == "-" && stream.eat(">")) {
|
||||
return "arrow";
|
||||
} else if (/[=+\-\/*:\.^%<>~|]/.test(ch)) {
|
||||
stream.eatWhile(/[=+\-\/*:\.^%<>~|]/);
|
||||
return "operator";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function tokenBaseUntilBrace() {
|
||||
var depth = 1;
|
||||
return function(stream, state) {
|
||||
if (stream.peek() == "}") {
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
state.tokenize.pop();
|
||||
return state.tokenize[state.tokenize.length-1](stream, state);
|
||||
}
|
||||
} else if (stream.peek() == "{") {
|
||||
depth++;
|
||||
}
|
||||
return tokenBase(stream, state);
|
||||
};
|
||||
}
|
||||
function readQuoted(quote, style, embed, unescaped) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == quote && (unescaped || !escaped)) {
|
||||
state.tokenize.pop();
|
||||
break;
|
||||
}
|
||||
if (embed && ch == "#" && !escaped && stream.eat("{")) {
|
||||
state.tokenize.push(tokenBaseUntilBrace(arguments.callee));
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
function readHereDoc(phrase) {
|
||||
return function(stream, state) {
|
||||
if (stream.match(phrase)) state.tokenize.pop();
|
||||
else stream.skipToEnd();
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
function readBlockComment(stream, state) {
|
||||
if (stream.sol() && stream.match("=end") && stream.eol())
|
||||
state.tokenize.pop();
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return {tokenize: [tokenBase],
|
||||
indented: 0,
|
||||
context: {type: "top", indented: -config.indentUnit},
|
||||
continuedLine: false,
|
||||
lastTok: null,
|
||||
varList: false};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) state.indented = stream.indentation();
|
||||
var style = state.tokenize[state.tokenize.length-1](stream, state), kwtype;
|
||||
if (style == "ident") {
|
||||
var word = stream.current();
|
||||
style = keywords.propertyIsEnumerable(stream.current()) ? "keyword"
|
||||
: /^[A-Z]/.test(word) ? "tag"
|
||||
: (state.lastTok == "def" || state.lastTok == "class" || state.varList) ? "def"
|
||||
: "variable";
|
||||
if (indentWords.propertyIsEnumerable(word)) kwtype = "indent";
|
||||
else if (dedentWords.propertyIsEnumerable(word)) kwtype = "dedent";
|
||||
else if ((word == "if" || word == "unless") && stream.column() == stream.indentation())
|
||||
kwtype = "indent";
|
||||
}
|
||||
if (curPunc || (style && style != "comment")) state.lastTok = word || curPunc || style;
|
||||
if (curPunc == "|") state.varList = !state.varList;
|
||||
|
||||
if (kwtype == "indent" || /[\(\[\{]/.test(curPunc))
|
||||
state.context = {prev: state.context, type: curPunc || style, indented: state.indented};
|
||||
else if ((kwtype == "dedent" || /[\)\]\}]/.test(curPunc)) && state.context.prev)
|
||||
state.context = state.context.prev;
|
||||
|
||||
if (stream.eol())
|
||||
state.continuedLine = (curPunc == "\\" || style == "operator");
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize[state.tokenize.length-1] != tokenBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0);
|
||||
var ct = state.context;
|
||||
var closing = ct.type == matching[firstChar] ||
|
||||
ct.type == "keyword" && /^(?:end|until|else|elsif|when|rescue)\b/.test(textAfter);
|
||||
return ct.indented + (closing ? 0 : config.indentUnit) +
|
||||
(state.continuedLine ? config.indentUnit : 0);
|
||||
},
|
||||
electricChars: "}de" // enD and rescuE
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-ruby", "ruby");
|
||||
|
@ -1,48 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Rust mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="rust.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Rust mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
// Demo code.
|
||||
|
||||
type foo<T> = int;
|
||||
enum bar {
|
||||
some(int, foo<float>),
|
||||
none
|
||||
}
|
||||
|
||||
fn check_crate(x: int) {
|
||||
let v = 10;
|
||||
alt foo {
|
||||
1 to 3 {
|
||||
print_foo();
|
||||
if x {
|
||||
blah() + 10;
|
||||
}
|
||||
}
|
||||
(x, y) { "bye" }
|
||||
_ { "hi" }
|
||||
}
|
||||
}
|
||||
</textarea></div>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
tabMode: "indent"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-rustsrc</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,432 +0,0 @@
|
||||
CodeMirror.defineMode("rust", function() {
|
||||
var indentUnit = 4, altIndentUnit = 2;
|
||||
var valKeywords = {
|
||||
"if": "if-style", "while": "if-style", "else": "else-style",
|
||||
"do": "else-style", "ret": "else-style", "fail": "else-style",
|
||||
"break": "atom", "cont": "atom", "const": "let", "resource": "fn",
|
||||
"let": "let", "fn": "fn", "for": "for", "alt": "alt", "iface": "iface",
|
||||
"impl": "impl", "type": "type", "enum": "enum", "mod": "mod",
|
||||
"as": "op", "true": "atom", "false": "atom", "assert": "op", "check": "op",
|
||||
"claim": "op", "native": "ignore", "unsafe": "ignore", "import": "else-style",
|
||||
"export": "else-style", "copy": "op", "log": "op", "log_err": "op",
|
||||
"use": "op", "bind": "op", "self": "atom"
|
||||
};
|
||||
var typeKeywords = function() {
|
||||
var keywords = {"fn": "fn", "block": "fn", "obj": "obj"};
|
||||
var atoms = "bool uint int i8 i16 i32 i64 u8 u16 u32 u64 float f32 f64 str char".split(" ");
|
||||
for (var i = 0, e = atoms.length; i < e; ++i) keywords[atoms[i]] = "atom";
|
||||
return keywords;
|
||||
}();
|
||||
var operatorChar = /[+\-*&%=<>!?|\.@]/;
|
||||
|
||||
// Tokenizer
|
||||
|
||||
// Used as scratch variable to communicate multiple values without
|
||||
// consing up tons of objects.
|
||||
var tcat, content;
|
||||
function r(tc, style) {
|
||||
tcat = tc;
|
||||
return style;
|
||||
}
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == '"') {
|
||||
state.tokenize = tokenString;
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
if (ch == "'") {
|
||||
tcat = "atom";
|
||||
if (stream.eat("\\")) {
|
||||
if (stream.skipTo("'")) { stream.next(); return "string"; }
|
||||
else { return "error"; }
|
||||
} else {
|
||||
stream.next();
|
||||
return stream.eat("'") ? "string" : "error";
|
||||
}
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("/")) { stream.skipToEnd(); return "comment"; }
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize = tokenComment(1);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
}
|
||||
if (ch == "#") {
|
||||
if (stream.eat("[")) { tcat = "open-attr"; return null; }
|
||||
stream.eatWhile(/\w/);
|
||||
return r("macro", "meta");
|
||||
}
|
||||
if (ch == ":" && stream.match(":<")) {
|
||||
return r("op", null);
|
||||
}
|
||||
if (ch.match(/\d/) || (ch == "." && stream.eat(/\d/))) {
|
||||
var flp = false;
|
||||
if (!stream.match(/^x[\da-f]+/i) && !stream.match(/^b[01]+/)) {
|
||||
stream.eatWhile(/\d/);
|
||||
if (stream.eat(".")) { flp = true; stream.eatWhile(/\d/); }
|
||||
if (stream.match(/^e[+\-]?\d+/i)) { flp = true; }
|
||||
}
|
||||
if (flp) stream.match(/^f(?:32|64)/);
|
||||
else stream.match(/^[ui](?:8|16|32|64)/);
|
||||
return r("atom", "number");
|
||||
}
|
||||
if (ch.match(/[()\[\]{}:;,]/)) return r(ch, null);
|
||||
if (ch == "-" && stream.eat(">")) return r("->", null);
|
||||
if (ch.match(operatorChar)) {
|
||||
stream.eatWhile(operatorChar);
|
||||
return r("op", null);
|
||||
}
|
||||
stream.eatWhile(/\w/);
|
||||
content = stream.current();
|
||||
if (stream.match(/^::\w/)) {
|
||||
stream.backUp(1);
|
||||
return r("prefix", "variable-2");
|
||||
}
|
||||
if (state.keywords.propertyIsEnumerable(content))
|
||||
return r(state.keywords[content], content.match(/true|false/) ? "atom" : "keyword");
|
||||
return r("name", "variable");
|
||||
}
|
||||
|
||||
function tokenString(stream, state) {
|
||||
var ch, escaped = false;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == '"' && !escaped) {
|
||||
state.tokenize = tokenBase;
|
||||
return r("atom", "string");
|
||||
}
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
// Hack to not confuse the parser when a string is split in
|
||||
// pieces.
|
||||
return r("op", "string");
|
||||
}
|
||||
|
||||
function tokenComment(depth) {
|
||||
return function(stream, state) {
|
||||
var lastCh = null, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && lastCh == "*") {
|
||||
if (depth == 1) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
} else {
|
||||
state.tokenize = tokenComment(depth - 1);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
}
|
||||
if (ch == "*" && lastCh == "/") {
|
||||
state.tokenize = tokenComment(depth + 1);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
lastCh = ch;
|
||||
}
|
||||
return "comment";
|
||||
};
|
||||
}
|
||||
|
||||
// Parser
|
||||
|
||||
var cx = {state: null, stream: null, marked: null, cc: null};
|
||||
function pass() {
|
||||
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
||||
}
|
||||
function cont() {
|
||||
pass.apply(null, arguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
function pushlex(type, info) {
|
||||
var result = function() {
|
||||
var state = cx.state;
|
||||
state.lexical = {indented: state.indented, column: cx.stream.column(),
|
||||
type: type, prev: state.lexical, info: info};
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
function poplex() {
|
||||
var state = cx.state;
|
||||
if (state.lexical.prev) {
|
||||
if (state.lexical.type == ")")
|
||||
state.indented = state.lexical.indented;
|
||||
state.lexical = state.lexical.prev;
|
||||
}
|
||||
}
|
||||
function typecx() { cx.state.keywords = typeKeywords; }
|
||||
function valcx() { cx.state.keywords = valKeywords; }
|
||||
poplex.lex = typecx.lex = valcx.lex = true;
|
||||
|
||||
function commasep(comb, end) {
|
||||
function more(type) {
|
||||
if (type == ",") return cont(comb, more);
|
||||
if (type == end) return cont();
|
||||
return cont(more);
|
||||
}
|
||||
return function(type) {
|
||||
if (type == end) return cont();
|
||||
return pass(comb, more);
|
||||
};
|
||||
}
|
||||
|
||||
function stat_of(comb, tag) {
|
||||
return cont(pushlex("stat", tag), comb, poplex, block);
|
||||
}
|
||||
function block(type) {
|
||||
if (type == "}") return cont();
|
||||
if (type == "let") return stat_of(letdef1, "let");
|
||||
if (type == "fn") return stat_of(fndef);
|
||||
if (type == "type") return cont(pushlex("stat"), tydef, endstatement, poplex, block);
|
||||
if (type == "enum") return stat_of(enumdef);
|
||||
if (type == "mod") return stat_of(mod);
|
||||
if (type == "iface") return stat_of(iface);
|
||||
if (type == "impl") return stat_of(impl);
|
||||
if (type == "open-attr") return cont(pushlex("]"), commasep(expression, "]"), poplex);
|
||||
if (type == "ignore" || type.match(/[\]\);,]/)) return cont(block);
|
||||
return pass(pushlex("stat"), expression, poplex, endstatement, block);
|
||||
}
|
||||
function endstatement(type) {
|
||||
if (type == ";") return cont();
|
||||
return pass();
|
||||
}
|
||||
function expression(type) {
|
||||
if (type == "atom" || type == "name") return cont(maybeop);
|
||||
if (type == "{") return cont(pushlex("}"), exprbrace, poplex);
|
||||
if (type.match(/[\[\(]/)) return matchBrackets(type, expression);
|
||||
if (type.match(/[\]\)\};,]/)) return pass();
|
||||
if (type == "if-style") return cont(expression, expression);
|
||||
if (type == "else-style" || type == "op") return cont(expression);
|
||||
if (type == "for") return cont(pattern, maybetype, inop, expression, expression);
|
||||
if (type == "alt") return cont(expression, altbody);
|
||||
if (type == "fn") return cont(fndef);
|
||||
if (type == "macro") return cont(macro);
|
||||
return cont();
|
||||
}
|
||||
function maybeop(type) {
|
||||
if (content == ".") return cont(maybeprop);
|
||||
if (content == "::<"){return cont(typarams, maybeop);}
|
||||
if (type == "op" || content == ":") return cont(expression);
|
||||
if (type == "(" || type == "[") return matchBrackets(type, expression);
|
||||
return pass();
|
||||
}
|
||||
function maybeprop(type) {
|
||||
if (content.match(/^\w+$/)) {cx.marked = "variable"; return cont(maybeop);}
|
||||
return pass(expression);
|
||||
}
|
||||
function exprbrace(type) {
|
||||
if (type == "op") {
|
||||
if (content == "|") return cont(blockvars, poplex, pushlex("}", "block"), block);
|
||||
if (content == "||") return cont(poplex, pushlex("}", "block"), block);
|
||||
}
|
||||
if (content == "mutable" || (content.match(/^\w+$/) && cx.stream.peek() == ":"
|
||||
&& !cx.stream.match("::", false)))
|
||||
return pass(record_of(expression));
|
||||
return pass(block);
|
||||
}
|
||||
function record_of(comb) {
|
||||
function ro(type) {
|
||||
if (content == "mutable" || content == "with") {cx.marked = "keyword"; return cont(ro);}
|
||||
if (content.match(/^\w*$/)) {cx.marked = "variable"; return cont(ro);}
|
||||
if (type == ":") return cont(comb, ro);
|
||||
if (type == "}") return cont();
|
||||
return cont(ro);
|
||||
}
|
||||
return ro;
|
||||
}
|
||||
function blockvars(type) {
|
||||
if (type == "name") {cx.marked = "def"; return cont(blockvars);}
|
||||
if (type == "op" && content == "|") return cont();
|
||||
return cont(blockvars);
|
||||
}
|
||||
|
||||
function letdef1(type) {
|
||||
if (type.match(/[\]\)\};]/)) return cont();
|
||||
if (content == "=") return cont(expression, letdef2);
|
||||
if (type == ",") return cont(letdef1);
|
||||
return pass(pattern, maybetype, letdef1);
|
||||
}
|
||||
function letdef2(type) {
|
||||
if (type.match(/[\]\)\};,]/)) return pass(letdef1);
|
||||
else return pass(expression, letdef2);
|
||||
}
|
||||
function maybetype(type) {
|
||||
if (type == ":") return cont(typecx, rtype, valcx);
|
||||
return pass();
|
||||
}
|
||||
function inop(type) {
|
||||
if (type == "name" && content == "in") {cx.marked = "keyword"; return cont();}
|
||||
return pass();
|
||||
}
|
||||
function fndef(type) {
|
||||
if (content == "@" || content == "~") {cx.marked = "keyword"; return cont(fndef);}
|
||||
if (type == "name") {cx.marked = "def"; return cont(fndef);}
|
||||
if (content == "<") return cont(typarams, fndef);
|
||||
if (type == "{") return pass(expression);
|
||||
if (type == "(") return cont(pushlex(")"), commasep(argdef, ")"), poplex, fndef);
|
||||
if (type == "->") return cont(typecx, rtype, valcx, fndef);
|
||||
if (type == ";") return cont();
|
||||
return cont(fndef);
|
||||
}
|
||||
function tydef(type) {
|
||||
if (type == "name") {cx.marked = "def"; return cont(tydef);}
|
||||
if (content == "<") return cont(typarams, tydef);
|
||||
if (content == "=") return cont(typecx, rtype, valcx);
|
||||
return cont(tydef);
|
||||
}
|
||||
function enumdef(type) {
|
||||
if (type == "name") {cx.marked = "def"; return cont(enumdef);}
|
||||
if (content == "<") return cont(typarams, enumdef);
|
||||
if (content == "=") return cont(typecx, rtype, valcx, endstatement);
|
||||
if (type == "{") return cont(pushlex("}"), typecx, enumblock, valcx, poplex);
|
||||
return cont(enumdef);
|
||||
}
|
||||
function enumblock(type) {
|
||||
if (type == "}") return cont();
|
||||
if (type == "(") return cont(pushlex(")"), commasep(rtype, ")"), poplex, enumblock);
|
||||
if (content.match(/^\w+$/)) cx.marked = "def";
|
||||
return cont(enumblock);
|
||||
}
|
||||
function mod(type) {
|
||||
if (type == "name") {cx.marked = "def"; return cont(mod);}
|
||||
if (type == "{") return cont(pushlex("}"), block, poplex);
|
||||
return pass();
|
||||
}
|
||||
function iface(type) {
|
||||
if (type == "name") {cx.marked = "def"; return cont(iface);}
|
||||
if (content == "<") return cont(typarams, iface);
|
||||
if (type == "{") return cont(pushlex("}"), block, poplex);
|
||||
return pass();
|
||||
}
|
||||
function impl(type) {
|
||||
if (content == "<") return cont(typarams, impl);
|
||||
if (content == "of" || content == "for") {cx.marked = "keyword"; return cont(rtype, impl);}
|
||||
if (type == "name") {cx.marked = "def"; return cont(impl);}
|
||||
if (type == "{") return cont(pushlex("}"), block, poplex);
|
||||
return pass();
|
||||
}
|
||||
function typarams(type) {
|
||||
if (content == ">") return cont();
|
||||
if (content == ",") return cont(typarams);
|
||||
if (content == ":") return cont(rtype, typarams);
|
||||
return pass(rtype, typarams);
|
||||
}
|
||||
function argdef(type) {
|
||||
if (type == "name") {cx.marked = "def"; return cont(argdef);}
|
||||
if (type == ":") return cont(typecx, rtype, valcx);
|
||||
return pass();
|
||||
}
|
||||
function rtype(type) {
|
||||
if (type == "name") {cx.marked = "variable-3"; return cont(rtypemaybeparam); }
|
||||
if (content == "mutable") {cx.marked = "keyword"; return cont(rtype);}
|
||||
if (type == "atom") return cont(rtypemaybeparam);
|
||||
if (type == "op" || type == "obj") return cont(rtype);
|
||||
if (type == "fn") return cont(fntype);
|
||||
if (type == "{") return cont(pushlex("{"), record_of(rtype), poplex);
|
||||
return matchBrackets(type, rtype);
|
||||
}
|
||||
function rtypemaybeparam(type) {
|
||||
if (content == "<") return cont(typarams);
|
||||
return pass();
|
||||
}
|
||||
function fntype(type) {
|
||||
if (type == "(") return cont(pushlex("("), commasep(rtype, ")"), poplex, fntype);
|
||||
if (type == "->") return cont(rtype);
|
||||
return pass();
|
||||
}
|
||||
function pattern(type) {
|
||||
if (type == "name") {cx.marked = "def"; return cont(patternmaybeop);}
|
||||
if (type == "atom") return cont(patternmaybeop);
|
||||
if (type == "op") return cont(pattern);
|
||||
if (type.match(/[\]\)\};,]/)) return pass();
|
||||
return matchBrackets(type, pattern);
|
||||
}
|
||||
function patternmaybeop(type) {
|
||||
if (type == "op" && content == ".") return cont();
|
||||
if (content == "to") {cx.marked = "keyword"; return cont(pattern);}
|
||||
else return pass();
|
||||
}
|
||||
function altbody(type) {
|
||||
if (type == "{") return cont(pushlex("}", "alt"), altblock1, poplex);
|
||||
return pass();
|
||||
}
|
||||
function altblock1(type) {
|
||||
if (type == "}") return cont();
|
||||
if (type == "|") return cont(altblock1);
|
||||
if (content == "when") {cx.marked = "keyword"; return cont(expression, altblock2);}
|
||||
if (type.match(/[\]\);,]/)) return cont(altblock1);
|
||||
return pass(pattern, altblock2);
|
||||
}
|
||||
function altblock2(type) {
|
||||
if (type == "{") return cont(pushlex("}", "alt"), block, poplex, altblock1);
|
||||
else return pass(altblock1);
|
||||
}
|
||||
|
||||
function macro(type) {
|
||||
if (type.match(/[\[\(\{]/)) return matchBrackets(type, expression);
|
||||
return pass();
|
||||
}
|
||||
function matchBrackets(type, comb) {
|
||||
if (type == "[") return cont(pushlex("]"), commasep(comb, "]"), poplex);
|
||||
if (type == "(") return cont(pushlex(")"), commasep(comb, ")"), poplex);
|
||||
if (type == "{") return cont(pushlex("}"), commasep(comb, "}"), poplex);
|
||||
return cont();
|
||||
}
|
||||
|
||||
function parse(state, stream, style) {
|
||||
var cc = state.cc;
|
||||
// Communicate our context to the combinators.
|
||||
// (Less wasteful than consing up a hundred closures on every call.)
|
||||
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
|
||||
|
||||
while (true) {
|
||||
var combinator = cc.length ? cc.pop() : block;
|
||||
if (combinator(tcat)) {
|
||||
while(cc.length && cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
return cx.marked || style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return {
|
||||
tokenize: tokenBase,
|
||||
cc: [],
|
||||
lexical: {indented: -indentUnit, column: 0, type: "top", align: false},
|
||||
keywords: valKeywords,
|
||||
indented: 0
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) {
|
||||
if (!state.lexical.hasOwnProperty("align"))
|
||||
state.lexical.align = false;
|
||||
state.indented = stream.indentation();
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
tcat = content = null;
|
||||
var style = state.tokenize(stream, state);
|
||||
if (style == "comment") return style;
|
||||
if (!state.lexical.hasOwnProperty("align"))
|
||||
state.lexical.align = true;
|
||||
if (tcat == "prefix") return style;
|
||||
if (!content) content = stream.current();
|
||||
return parse(state, stream, style);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
|
||||
type = lexical.type, closing = firstChar == type;
|
||||
if (type == "stat") return lexical.indented + indentUnit;
|
||||
if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
||||
return lexical.indented + (closing ? 0 : (lexical.info == "alt" ? altIndentUnit : indentUnit));
|
||||
},
|
||||
|
||||
electricChars: "{}"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rustsrc", "rust");
|
@ -1,64 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Scheme mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="scheme.js"></script>
|
||||
<style>.CodeMirror {background: #f8f8f8;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Scheme mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
; See if the input starts with a given symbol.
|
||||
(define (match-symbol input pattern)
|
||||
(cond ((null? (remain input)) #f)
|
||||
((eqv? (car (remain input)) pattern) (r-cdr input))
|
||||
(else #f)))
|
||||
|
||||
; Allow the input to start with one of a list of patterns.
|
||||
(define (match-or input pattern)
|
||||
(cond ((null? pattern) #f)
|
||||
((match-pattern input (car pattern)))
|
||||
(else (match-or input (cdr pattern)))))
|
||||
|
||||
; Allow a sequence of patterns.
|
||||
(define (match-seq input pattern)
|
||||
(if (null? pattern)
|
||||
input
|
||||
(let ((match (match-pattern input (car pattern))))
|
||||
(if match (match-seq match (cdr pattern)) #f))))
|
||||
|
||||
; Match with the pattern but no problem if it does not match.
|
||||
(define (match-opt input pattern)
|
||||
(let ((match (match-pattern input (car pattern))))
|
||||
(if match match input)))
|
||||
|
||||
; Match anything (other than '()), until pattern is found. The rather
|
||||
; clumsy form of requiring an ending pattern is needed to decide where
|
||||
; the end of the match is. If none is given, this will match the rest
|
||||
; of the sentence.
|
||||
(define (match-any input pattern)
|
||||
(cond ((null? (remain input)) #f)
|
||||
((null? pattern) (f-cons (remain input) (clear-remain input)))
|
||||
(else
|
||||
(let ((accum-any (collector)))
|
||||
(define (match-pattern-any input pattern)
|
||||
(cond ((null? (remain input)) #f)
|
||||
(else (accum-any (car (remain input)))
|
||||
(cond ((match-pattern (r-cdr input) pattern))
|
||||
(else (match-pattern-any (r-cdr input) pattern))))))
|
||||
(let ((retval (match-pattern-any input (car pattern))))
|
||||
(if retval
|
||||
(f-cons (accum-any) retval)
|
||||
#f))))))
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-scheme</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,202 +0,0 @@
|
||||
/**
|
||||
* Author: Koh Zi Han, based on implementation by Koh Zi Chun
|
||||
*/
|
||||
CodeMirror.defineMode("scheme", function (config, mode) {
|
||||
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
|
||||
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword";
|
||||
var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
|
||||
|
||||
function makeKeywords(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
|
||||
var indentKeys = makeKeywords("define let letrec let* lambda");
|
||||
|
||||
|
||||
function stateStack(indent, type, prev) { // represents a state stack object
|
||||
this.indent = indent;
|
||||
this.type = type;
|
||||
this.prev = prev;
|
||||
}
|
||||
|
||||
function pushStack(state, indent, type) {
|
||||
state.indentStack = new stateStack(indent, type, state.indentStack);
|
||||
}
|
||||
|
||||
function popStack(state) {
|
||||
state.indentStack = state.indentStack.prev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scheme numbers are complicated unfortunately.
|
||||
* Checks if we're looking at a number, which might be possibly a fraction.
|
||||
* Also checks that it is not part of a longer identifier. Returns true/false accordingly.
|
||||
*/
|
||||
function isNumber(ch, stream){
|
||||
if(/[0-9]/.exec(ch) != null){
|
||||
stream.eatWhile(/[0-9]/);
|
||||
stream.eat(/\//);
|
||||
stream.eatWhile(/[0-9]/);
|
||||
if (stream.eol() || !(/[a-zA-Z\-\_\/]/.exec(stream.peek()))) return true;
|
||||
stream.backUp(stream.current().length - 1); // undo all the eating
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function () {
|
||||
return {
|
||||
indentStack: null,
|
||||
indentation: 0,
|
||||
mode: false,
|
||||
sExprComment: false
|
||||
};
|
||||
},
|
||||
|
||||
token: function (stream, state) {
|
||||
if (state.indentStack == null && stream.sol()) {
|
||||
// update indentation, but only if indentStack is empty
|
||||
state.indentation = stream.indentation();
|
||||
}
|
||||
|
||||
// skip spaces
|
||||
if (stream.eatSpace()) {
|
||||
return null;
|
||||
}
|
||||
var returnType = null;
|
||||
|
||||
switch(state.mode){
|
||||
case "string": // multi-line string parsing mode
|
||||
var next, escaped = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == "\"" && !escaped) {
|
||||
|
||||
state.mode = false;
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
returnType = STRING; // continue on in scheme-string mode
|
||||
break;
|
||||
case "comment": // comment parsing mode
|
||||
var next, maybeEnd = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == "#" && maybeEnd) {
|
||||
|
||||
state.mode = false;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "|");
|
||||
}
|
||||
returnType = COMMENT;
|
||||
break;
|
||||
case "s-expr-comment": // s-expr commenting mode
|
||||
state.mode = false;
|
||||
if(stream.peek() == "(" || stream.peek() == "["){
|
||||
// actually start scheme s-expr commenting mode
|
||||
state.sExprComment = 0;
|
||||
}else{
|
||||
// if not we just comment the entire of the next token
|
||||
stream.eatWhile(/[^/s]/); // eat non spaces
|
||||
returnType = COMMENT;
|
||||
break;
|
||||
}
|
||||
default: // default parsing mode
|
||||
var ch = stream.next();
|
||||
|
||||
if (ch == "\"") {
|
||||
state.mode = "string";
|
||||
returnType = STRING;
|
||||
|
||||
} else if (ch == "'") {
|
||||
returnType = ATOM;
|
||||
} else if (ch == '#') {
|
||||
if (stream.eat("|")) { // Multi-line comment
|
||||
state.mode = "comment"; // toggle to comment mode
|
||||
returnType = COMMENT;
|
||||
} else if (stream.eat(/[tf]/)) { // #t/#f (atom)
|
||||
returnType = ATOM;
|
||||
} else if (stream.eat(';')) { // S-Expr comment
|
||||
state.mode = "s-expr-comment";
|
||||
returnType = COMMENT;
|
||||
}
|
||||
|
||||
} else if (ch == ";") { // comment
|
||||
stream.skipToEnd(); // rest of the line is a comment
|
||||
returnType = COMMENT;
|
||||
} else if (ch == "-"){
|
||||
|
||||
if(!isNaN(parseInt(stream.peek()))){
|
||||
stream.eatWhile(/[\/0-9]/);
|
||||
returnType = NUMBER;
|
||||
}else{
|
||||
returnType = null;
|
||||
}
|
||||
} else if (isNumber(ch,stream)){
|
||||
returnType = NUMBER;
|
||||
} else if (ch == "(" || ch == "[") {
|
||||
var keyWord = ''; var indentTemp = stream.column();
|
||||
/**
|
||||
Either
|
||||
(indent-word ..
|
||||
(non-indent-word ..
|
||||
(;something else, bracket, etc.
|
||||
*/
|
||||
|
||||
while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) {
|
||||
keyWord += letter;
|
||||
}
|
||||
|
||||
if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
|
||||
|
||||
pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
|
||||
} else { // non-indent word
|
||||
// we continue eating the spaces
|
||||
stream.eatSpace();
|
||||
if (stream.eol() || stream.peek() == ";") {
|
||||
// nothing significant after
|
||||
// we restart indentation 1 space after
|
||||
pushStack(state, indentTemp + 1, ch);
|
||||
} else {
|
||||
pushStack(state, indentTemp + stream.current().length, ch); // else we match
|
||||
}
|
||||
}
|
||||
stream.backUp(stream.current().length - 1); // undo all the eating
|
||||
|
||||
if(typeof state.sExprComment == "number") state.sExprComment++;
|
||||
|
||||
returnType = BRACKET;
|
||||
} else if (ch == ")" || ch == "]") {
|
||||
returnType = BRACKET;
|
||||
if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
|
||||
popStack(state);
|
||||
|
||||
if(typeof state.sExprComment == "number"){
|
||||
if(--state.sExprComment == 0){
|
||||
returnType = COMMENT; // final closing bracket
|
||||
state.sExprComment = false; // turn off s-expr commenting mode
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stream.eatWhile(/[\w\$_\-]/);
|
||||
|
||||
if (keywords && keywords.propertyIsEnumerable(stream.current())) {
|
||||
returnType = BUILTIN;
|
||||
}else returnType = null;
|
||||
}
|
||||
}
|
||||
return (typeof state.sExprComment == "number") ? COMMENT : returnType;
|
||||
},
|
||||
|
||||
indent: function (state, textAfter) {
|
||||
if (state.indentStack == null) return state.indentation;
|
||||
return state.indentStack.indent;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-scheme", "scheme");
|
@ -1,55 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Smalltalk mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="smalltalk.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style>
|
||||
.CodeMirror {border: 2px solid #dee; border-right-width: 10px;}
|
||||
.CodeMirror-gutter {border: none; background: #dee;}
|
||||
.CodeMirror-gutter pre {color: white; font-weight: bold;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Smalltalk mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
"
|
||||
This is a test of the Smalltalk code
|
||||
"
|
||||
Seaside.WAComponent subclass: #MyCounter [
|
||||
| count |
|
||||
MyCounter class >> canBeRoot [ ^true ]
|
||||
|
||||
initialize [
|
||||
super initialize.
|
||||
count := 0.
|
||||
]
|
||||
states [ ^{ self } ]
|
||||
renderContentOn: html [
|
||||
html heading: count.
|
||||
html anchor callback: [ count := count + 1 ]; with: '++'.
|
||||
html space.
|
||||
html anchor callback: [ count := count - 1 ]; with: '--'.
|
||||
]
|
||||
]
|
||||
|
||||
MyCounter registerAsApplication: 'mycounter'
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "text/x-stsrc",
|
||||
indentUnit: 4
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Simple Smalltalk mode.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-stsrc</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,139 +0,0 @@
|
||||
CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
|
||||
|
||||
var specialChars = /[+\-/\\*~<>=@%|&?!.:;^]/;
|
||||
var keywords = /true|false|nil|self|super|thisContext/;
|
||||
|
||||
var Context = function(tokenizer, parent) {
|
||||
this.next = tokenizer;
|
||||
this.parent = parent;
|
||||
};
|
||||
|
||||
var Token = function(name, context, eos) {
|
||||
this.name = name;
|
||||
this.context = context;
|
||||
this.eos = eos;
|
||||
};
|
||||
|
||||
var State = function() {
|
||||
this.context = new Context(next, null);
|
||||
this.expectVariable = true;
|
||||
this.indentation = 0;
|
||||
this.userIndentationDelta = 0;
|
||||
};
|
||||
|
||||
State.prototype.userIndent = function(indentation) {
|
||||
this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;
|
||||
};
|
||||
|
||||
var next = function(stream, context, state) {
|
||||
var token = new Token(null, context, false);
|
||||
var aChar = stream.next();
|
||||
|
||||
if (aChar === '"') {
|
||||
token = nextComment(stream, new Context(nextComment, context));
|
||||
|
||||
} else if (aChar === '\'') {
|
||||
token = nextString(stream, new Context(nextString, context));
|
||||
|
||||
} else if (aChar === '#') {
|
||||
stream.eatWhile(/[^ .]/);
|
||||
token.name = 'string-2';
|
||||
|
||||
} else if (aChar === '$') {
|
||||
stream.eatWhile(/[^ ]/);
|
||||
token.name = 'string-2';
|
||||
|
||||
} else if (aChar === '|' && state.expectVariable) {
|
||||
token.context = new Context(nextTemporaries, context);
|
||||
|
||||
} else if (/[\[\]{}()]/.test(aChar)) {
|
||||
token.name = 'bracket';
|
||||
token.eos = /[\[{(]/.test(aChar);
|
||||
|
||||
if (aChar === '[') {
|
||||
state.indentation++;
|
||||
} else if (aChar === ']') {
|
||||
state.indentation = Math.max(0, state.indentation - 1);
|
||||
}
|
||||
|
||||
} else if (specialChars.test(aChar)) {
|
||||
stream.eatWhile(specialChars);
|
||||
token.name = 'operator';
|
||||
token.eos = aChar !== ';'; // ; cascaded message expression
|
||||
|
||||
} else if (/\d/.test(aChar)) {
|
||||
stream.eatWhile(/[\w\d]/);
|
||||
token.name = 'number'
|
||||
|
||||
} else if (/[\w_]/.test(aChar)) {
|
||||
stream.eatWhile(/[\w\d_]/);
|
||||
token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;
|
||||
|
||||
} else {
|
||||
token.eos = state.expectVariable;
|
||||
}
|
||||
|
||||
return token;
|
||||
};
|
||||
|
||||
var nextComment = function(stream, context) {
|
||||
stream.eatWhile(/[^"]/);
|
||||
return new Token('comment', stream.eat('"') ? context.parent : context, true);
|
||||
};
|
||||
|
||||
var nextString = function(stream, context) {
|
||||
stream.eatWhile(/[^']/);
|
||||
return new Token('string', stream.eat('\'') ? context.parent : context, false);
|
||||
};
|
||||
|
||||
var nextTemporaries = function(stream, context, state) {
|
||||
var token = new Token(null, context, false);
|
||||
var aChar = stream.next();
|
||||
|
||||
if (aChar === '|') {
|
||||
token.context = context.parent;
|
||||
token.eos = true;
|
||||
|
||||
} else {
|
||||
stream.eatWhile(/[^|]/);
|
||||
token.name = 'variable';
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return new State;
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
state.userIndent(stream.indentation());
|
||||
|
||||
if (stream.eatSpace()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var token = state.context.next(stream, state.context, state);
|
||||
state.context = token.context;
|
||||
state.expectVariable = token.eos;
|
||||
|
||||
state.lastToken = token;
|
||||
return token.name;
|
||||
},
|
||||
|
||||
blankLine: function(state) {
|
||||
state.userIndent(0);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
|
||||
return (state.indentation + i) * config.indentUnit;
|
||||
},
|
||||
|
||||
electricChars: ']'
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
|
@ -1,82 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: Smarty mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="smarty.js"></script>
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: Smarty mode</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
{extends file="parent.tpl"}
|
||||
{include file="template.tpl"}
|
||||
|
||||
{* some example Smarty content *}
|
||||
{if isset($name) && $name == 'Blog'}
|
||||
This is a {$var}.
|
||||
{$integer = 451}, {$array[] = "a"}, {$stringvar = "string"}
|
||||
{assign var='bob' value=$var.prop}
|
||||
{elseif $name == $foo}
|
||||
{function name=menu level=0}
|
||||
{foreach $data as $entry}
|
||||
{if is_array($entry)}
|
||||
- {$entry@key}
|
||||
{menu data=$entry level=$level+1}
|
||||
{else}
|
||||
{$entry}
|
||||
{/if}
|
||||
{/foreach}
|
||||
{/function}
|
||||
{/if}</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
mode: "smarty"
|
||||
});
|
||||
</script>
|
||||
|
||||
<br />
|
||||
|
||||
<form><textarea id="code2" name="code2">
|
||||
{--extends file="parent.tpl"--}
|
||||
{--include file="template.tpl"--}
|
||||
|
||||
{--* some example Smarty content *--}
|
||||
{--if isset($name) && $name == 'Blog'--}
|
||||
This is a {--$var--}.
|
||||
{--$integer = 451--}, {--$array[] = "a"--}, {--$stringvar = "string"--}
|
||||
{--assign var='bob' value=$var.prop--}
|
||||
{--elseif $name == $foo--}
|
||||
{--function name=menu level=0--}
|
||||
{--foreach $data as $entry--}
|
||||
{--if is_array($entry)--}
|
||||
- {--$entry@key--}
|
||||
{--menu data=$entry level=$level+1--}
|
||||
{--else--}
|
||||
{--$entry--}
|
||||
{--/if--}
|
||||
{--/foreach--}
|
||||
{--/function--}
|
||||
{--/if--}</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code2"), {
|
||||
lineNumbers: true,
|
||||
mode: {
|
||||
name: "smarty",
|
||||
leftDelimiter: "{--",
|
||||
rightDelimiter: "--}"
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>A plain text/Smarty mode which allows for custom delimiter tags (defaults to <b>{</b> and <b>}</b>).</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-smarty</code></p>
|
||||
</body>
|
||||
</html>
|
@ -1,148 +0,0 @@
|
||||
CodeMirror.defineMode("smarty", function(config, parserConfig) {
|
||||
var keyFuncs = ["debug", "extends", "function", "include", "literal"];
|
||||
var last;
|
||||
var regs = {
|
||||
operatorChars: /[+\-*&%=<>!?]/,
|
||||
validIdentifier: /[a-zA-Z0-9\_]/,
|
||||
stringChar: /[\'\"]/
|
||||
}
|
||||
var leftDelim = (typeof config.mode.leftDelimiter != 'undefined') ? config.mode.leftDelimiter : "{";
|
||||
var rightDelim = (typeof config.mode.rightDelimiter != 'undefined') ? config.mode.rightDelimiter : "}";
|
||||
function ret(style, lst) { last = lst; return style; }
|
||||
|
||||
|
||||
function tokenizer(stream, state) {
|
||||
function chain(parser) {
|
||||
state.tokenize = parser;
|
||||
return parser(stream, state);
|
||||
}
|
||||
|
||||
if (stream.match(leftDelim, true)) {
|
||||
if (stream.eat("*")) {
|
||||
return chain(inBlock("comment", "*" + rightDelim));
|
||||
}
|
||||
else {
|
||||
state.tokenize = inSmarty;
|
||||
return "tag";
|
||||
}
|
||||
}
|
||||
else {
|
||||
// I'd like to do an eatWhile() here, but I can't get it to eat only up to the rightDelim string/char
|
||||
stream.next();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function inSmarty(stream, state) {
|
||||
if (stream.match(rightDelim, true)) {
|
||||
state.tokenize = tokenizer;
|
||||
return ret("tag", null);
|
||||
}
|
||||
|
||||
var ch = stream.next();
|
||||
if (ch == "$") {
|
||||
stream.eatWhile(regs.validIdentifier);
|
||||
return ret("variable-2", "variable");
|
||||
}
|
||||
else if (ch == ".") {
|
||||
return ret("operator", "property");
|
||||
}
|
||||
else if (regs.stringChar.test(ch)) {
|
||||
state.tokenize = inAttribute(ch);
|
||||
return ret("string", "string");
|
||||
}
|
||||
else if (regs.operatorChars.test(ch)) {
|
||||
stream.eatWhile(regs.operatorChars);
|
||||
return ret("operator", "operator");
|
||||
}
|
||||
else if (ch == "[" || ch == "]") {
|
||||
return ret("bracket", "bracket");
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/\d/);
|
||||
return ret("number", "number");
|
||||
}
|
||||
else {
|
||||
if (state.last == "variable") {
|
||||
if (ch == "@") {
|
||||
stream.eatWhile(regs.validIdentifier);
|
||||
return ret("property", "property");
|
||||
}
|
||||
else if (ch == "|") {
|
||||
stream.eatWhile(regs.validIdentifier);
|
||||
return ret("qualifier", "modifier");
|
||||
}
|
||||
}
|
||||
else if (state.last == "whitespace") {
|
||||
stream.eatWhile(regs.validIdentifier);
|
||||
return ret("attribute", "modifier");
|
||||
}
|
||||
else if (state.last == "property") {
|
||||
stream.eatWhile(regs.validIdentifier);
|
||||
return ret("property", null);
|
||||
}
|
||||
else if (/\s/.test(ch)) {
|
||||
last = "whitespace";
|
||||
return null;
|
||||
}
|
||||
|
||||
var str = "";
|
||||
if (ch != "/") {
|
||||
str += ch;
|
||||
}
|
||||
var c = "";
|
||||
while ((c = stream.eat(regs.validIdentifier))) {
|
||||
str += c;
|
||||
}
|
||||
var i, j;
|
||||
for (i=0, j=keyFuncs.length; i<j; i++) {
|
||||
if (keyFuncs[i] == str) {
|
||||
return ret("keyword", "keyword");
|
||||
}
|
||||
}
|
||||
if (/\s/.test(ch)) {
|
||||
return null;
|
||||
}
|
||||
return ret("tag", "tag");
|
||||
}
|
||||
}
|
||||
|
||||
function inAttribute(quote) {
|
||||
return function(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
if (stream.next() == quote) {
|
||||
state.tokenize = inSmarty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function inBlock(style, terminator) {
|
||||
return function(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
if (stream.match(terminator)) {
|
||||
state.tokenize = tokenizer;
|
||||
break;
|
||||
}
|
||||
stream.next();
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return { tokenize: tokenizer, mode: "smarty", last: null };
|
||||
},
|
||||
token: function(stream, state) {
|
||||
var style = state.tokenize(stream, state);
|
||||
state.last = last;
|
||||
return style;
|
||||
},
|
||||
electricChars: ""
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-smarty", "smarty");
|
@ -1,40 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: SPARQL mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="sparql.js"></script>
|
||||
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: SPARQL mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
PREFIX a: <http://www.w3.org/2000/10/annotation-ns#>
|
||||
PREFIX dc: <http://purl.org/dc/elements/1.1/>
|
||||
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
||||
|
||||
# Comment!
|
||||
|
||||
SELECT ?given ?family
|
||||
WHERE {
|
||||
?annot a:annotates <http://www.w3.org/TR/rdf-sparql-query/> .
|
||||
?annot dc:creator ?c .
|
||||
OPTIONAL {?c foaf:given ?given ;
|
||||
foaf:family ?family } .
|
||||
FILTER isBlank(?c)
|
||||
}
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "application/x-sparql-query",
|
||||
tabMode: "indent",
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>application/x-sparql-query</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,143 +0,0 @@
|
||||
CodeMirror.defineMode("sparql", function(config) {
|
||||
var indentUnit = config.indentUnit;
|
||||
var curPunc;
|
||||
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
|
||||
"isblank", "isliteral", "union", "a"]);
|
||||
var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
|
||||
"ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
|
||||
"graph", "by", "asc", "desc"]);
|
||||
var operatorChars = /[*+\-<>=&|]/;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
curPunc = null;
|
||||
if (ch == "$" || ch == "?") {
|
||||
stream.match(/^[\w\d]*/);
|
||||
return "variable-2";
|
||||
}
|
||||
else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
|
||||
stream.match(/^[^\s\u00a0>]*>?/);
|
||||
return "atom";
|
||||
}
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
state.tokenize = tokenLiteral(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
else if (/[{}\(\),\.;\[\]]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null;
|
||||
}
|
||||
else if (ch == "#") {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
else if (operatorChars.test(ch)) {
|
||||
stream.eatWhile(operatorChars);
|
||||
return null;
|
||||
}
|
||||
else if (ch == ":") {
|
||||
stream.eatWhile(/[\w\d\._\-]/);
|
||||
return "atom";
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(/[_\w\d]/);
|
||||
if (stream.eat(":")) {
|
||||
stream.eatWhile(/[\w\d_\-]/);
|
||||
return "atom";
|
||||
}
|
||||
var word = stream.current(), type;
|
||||
if (ops.test(word))
|
||||
return null;
|
||||
else if (keywords.test(word))
|
||||
return "keyword";
|
||||
else
|
||||
return "variable";
|
||||
}
|
||||
}
|
||||
|
||||
function tokenLiteral(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == quote && !escaped) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function pushContext(state, type, col) {
|
||||
state.context = {prev: state.context, indent: state.indent, col: col, type: type};
|
||||
}
|
||||
function popContext(state) {
|
||||
state.indent = state.context.indent;
|
||||
state.context = state.context.prev;
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function(base) {
|
||||
return {tokenize: tokenBase,
|
||||
context: null,
|
||||
indent: 0,
|
||||
col: 0};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.sol()) {
|
||||
if (state.context && state.context.align == null) state.context.align = false;
|
||||
state.indent = stream.indentation();
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
|
||||
if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
|
||||
state.context.align = true;
|
||||
}
|
||||
|
||||
if (curPunc == "(") pushContext(state, ")", stream.column());
|
||||
else if (curPunc == "[") pushContext(state, "]", stream.column());
|
||||
else if (curPunc == "{") pushContext(state, "}", stream.column());
|
||||
else if (/[\]\}\)]/.test(curPunc)) {
|
||||
while (state.context && state.context.type == "pattern") popContext(state);
|
||||
if (state.context && curPunc == state.context.type) popContext(state);
|
||||
}
|
||||
else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
|
||||
else if (/atom|string|variable/.test(style) && state.context) {
|
||||
if (/[\}\]]/.test(state.context.type))
|
||||
pushContext(state, "pattern", stream.column());
|
||||
else if (state.context.type == "pattern" && !state.context.align) {
|
||||
state.context.align = true;
|
||||
state.context.col = stream.column();
|
||||
}
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var firstChar = textAfter && textAfter.charAt(0);
|
||||
var context = state.context;
|
||||
if (/[\]\}]/.test(firstChar))
|
||||
while (context && context.type == "pattern") context = context.prev;
|
||||
|
||||
var closing = context && firstChar == context.type;
|
||||
if (!context)
|
||||
return 0;
|
||||
else if (context.type == "pattern")
|
||||
return context.col;
|
||||
else if (context.align)
|
||||
return context.col + (closing ? 0 : 1);
|
||||
else
|
||||
return context.indent + (closing ? 0 : indentUnit);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("application/x-sparql-query", "sparql");
|
@ -1,95 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: sTeX mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="stex.js"></script>
|
||||
<style>.CodeMirror {background: #f8f8f8;}</style>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: sTeX mode</h1>
|
||||
<form><textarea id="code" name="code">
|
||||
\begin{module}[id=bbt-size]
|
||||
\importmodule[balanced-binary-trees]{balanced-binary-trees}
|
||||
\importmodule[\KWARCslides{dmath/en/cardinality}]{cardinality}
|
||||
|
||||
\begin{frame}
|
||||
\frametitle{Size Lemma for Balanced Trees}
|
||||
\begin{itemize}
|
||||
\item
|
||||
\begin{assertion}[id=size-lemma,type=lemma]
|
||||
Let $G=\tup{V,E}$ be a \termref[cd=binary-trees]{balanced binary tree}
|
||||
of \termref[cd=graph-depth,name=vertex-depth]{depth}$n>i$, then the set
|
||||
$\defeq{\livar{V}i}{\setst{\inset{v}{V}}{\gdepth{v} = i}}$ of
|
||||
\termref[cd=graphs-intro,name=node]{nodes} at
|
||||
\termref[cd=graph-depth,name=vertex-depth]{depth} $i$ has
|
||||
\termref[cd=cardinality,name=cardinality]{cardinality} $\power2i$.
|
||||
\end{assertion}
|
||||
\item
|
||||
\begin{sproof}[id=size-lemma-pf,proofend=,for=size-lemma]{via induction over the depth $i$.}
|
||||
\begin{spfcases}{We have to consider two cases}
|
||||
\begin{spfcase}{$i=0$}
|
||||
\begin{spfstep}[display=flow]
|
||||
then $\livar{V}i=\set{\livar{v}r}$, where $\livar{v}r$ is the root, so
|
||||
$\eq{\card{\livar{V}0},\card{\set{\livar{v}r}},1,\power20}$.
|
||||
\end{spfstep}
|
||||
\end{spfcase}
|
||||
\begin{spfcase}{$i>0$}
|
||||
\begin{spfstep}[display=flow]
|
||||
then $\livar{V}{i-1}$ contains $\power2{i-1}$ vertexes
|
||||
\begin{justification}[method=byIH](IH)\end{justification}
|
||||
\end{spfstep}
|
||||
\begin{spfstep}
|
||||
By the \begin{justification}[method=byDef]definition of a binary
|
||||
tree\end{justification}, each $\inset{v}{\livar{V}{i-1}}$ is a leaf or has
|
||||
two children that are at depth $i$.
|
||||
\end{spfstep}
|
||||
\begin{spfstep}
|
||||
As $G$ is \termref[cd=balanced-binary-trees,name=balanced-binary-tree]{balanced} and $\gdepth{G}=n>i$, $\livar{V}{i-1}$ cannot contain
|
||||
leaves.
|
||||
\end{spfstep}
|
||||
\begin{spfstep}[type=conclusion]
|
||||
Thus $\eq{\card{\livar{V}i},{\atimes[cdot]{2,\card{\livar{V}{i-1}}}},{\atimes[cdot]{2,\power2{i-1}}},\power2i}$.
|
||||
\end{spfstep}
|
||||
\end{spfcase}
|
||||
\end{spfcases}
|
||||
\end{sproof}
|
||||
\item
|
||||
\begin{assertion}[id=fbbt,type=corollary]
|
||||
A fully balanced tree of depth $d$ has $\power2{d+1}-1$ nodes.
|
||||
\end{assertion}
|
||||
\item
|
||||
\begin{sproof}[for=fbbt,id=fbbt-pf]{}
|
||||
\begin{spfstep}
|
||||
Let $\defeq{G}{\tup{V,E}}$ be a fully balanced tree
|
||||
\end{spfstep}
|
||||
\begin{spfstep}
|
||||
Then $\card{V}=\Sumfromto{i}1d{\power2i}= \power2{d+1}-1$.
|
||||
\end{spfstep}
|
||||
\end{sproof}
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
\begin{note}
|
||||
\begin{omtext}[type=conclusion,for=binary-tree]
|
||||
This shows that balanced binary trees grow in breadth very quickly, a consequence of
|
||||
this is that they are very shallow (and this compute very fast), which is the essence of
|
||||
the next result.
|
||||
\end{omtext}
|
||||
\end{note}
|
||||
\end{module}
|
||||
|
||||
%%% Local Variables:
|
||||
%%% mode: LaTeX
|
||||
%%% TeX-master: "all"
|
||||
%%% End: \end{document}
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-stex</code>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,180 +0,0 @@
|
||||
/*
|
||||
* Author: Constantin Jucovschi (c.jucovschi@jacobs-university.de)
|
||||
* Licence: MIT
|
||||
*/
|
||||
|
||||
CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
|
||||
{
|
||||
function pushCommand(state, command) {
|
||||
state.cmdState.push(command);
|
||||
}
|
||||
|
||||
function peekCommand(state) {
|
||||
if (state.cmdState.length>0)
|
||||
return state.cmdState[state.cmdState.length-1];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
function popCommand(state) {
|
||||
if (state.cmdState.length>0) {
|
||||
var plug = state.cmdState.pop();
|
||||
plug.closeBracket();
|
||||
}
|
||||
}
|
||||
|
||||
function applyMostPowerful(state) {
|
||||
var context = state.cmdState;
|
||||
for (var i = context.length - 1; i >= 0; i--) {
|
||||
var plug = context[i];
|
||||
if (plug.name=="DEFAULT")
|
||||
continue;
|
||||
return plug.styleIdentifier();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function addPluginPattern(pluginName, cmdStyle, brackets, styles) {
|
||||
return function () {
|
||||
this.name=pluginName;
|
||||
this.bracketNo = 0;
|
||||
this.style=cmdStyle;
|
||||
this.styles = styles;
|
||||
this.brackets = brackets;
|
||||
|
||||
this.styleIdentifier = function(content) {
|
||||
if (this.bracketNo<=this.styles.length)
|
||||
return this.styles[this.bracketNo-1];
|
||||
else
|
||||
return null;
|
||||
};
|
||||
this.openBracket = function(content) {
|
||||
this.bracketNo++;
|
||||
return "bracket";
|
||||
};
|
||||
this.closeBracket = function(content) {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var plugins = new Array();
|
||||
|
||||
plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]);
|
||||
plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]);
|
||||
plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
|
||||
plugins["begin"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
|
||||
plugins["end"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
|
||||
|
||||
plugins["DEFAULT"] = function () {
|
||||
this.name="DEFAULT";
|
||||
this.style="tag";
|
||||
|
||||
this.styleIdentifier = function(content) {
|
||||
};
|
||||
this.openBracket = function(content) {
|
||||
};
|
||||
this.closeBracket = function(content) {
|
||||
};
|
||||
};
|
||||
|
||||
function setState(state, f) {
|
||||
state.f = f;
|
||||
}
|
||||
|
||||
function normal(source, state) {
|
||||
if (source.match(/^\\[a-zA-Z@]+/)) {
|
||||
var cmdName = source.current();
|
||||
cmdName = cmdName.substr(1, cmdName.length-1);
|
||||
var plug = plugins[cmdName];
|
||||
if (typeof(plug) == 'undefined') {
|
||||
plug = plugins["DEFAULT"];
|
||||
}
|
||||
plug = new plug();
|
||||
pushCommand(state, plug);
|
||||
setState(state, beginParams);
|
||||
return plug.style;
|
||||
}
|
||||
|
||||
// escape characters
|
||||
if (source.match(/^\\[$&%#{}_]/)) {
|
||||
return "tag";
|
||||
}
|
||||
|
||||
// white space control characters
|
||||
if (source.match(/^\\[,;!\/]/)) {
|
||||
return "tag";
|
||||
}
|
||||
|
||||
var ch = source.next();
|
||||
if (ch == "%") {
|
||||
// special case: % at end of its own line; stay in same state
|
||||
if (!source.eol()) {
|
||||
setState(state, inCComment);
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
else if (ch=='}' || ch==']') {
|
||||
plug = peekCommand(state);
|
||||
if (plug) {
|
||||
plug.closeBracket(ch);
|
||||
setState(state, beginParams);
|
||||
} else
|
||||
return "error";
|
||||
return "bracket";
|
||||
} else if (ch=='{' || ch=='[') {
|
||||
plug = plugins["DEFAULT"];
|
||||
plug = new plug();
|
||||
pushCommand(state, plug);
|
||||
return "bracket";
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
source.eatWhile(/[\w.%]/);
|
||||
return "atom";
|
||||
}
|
||||
else {
|
||||
source.eatWhile(/[\w-_]/);
|
||||
return applyMostPowerful(state);
|
||||
}
|
||||
}
|
||||
|
||||
function inCComment(source, state) {
|
||||
source.skipToEnd();
|
||||
setState(state, normal);
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function beginParams(source, state) {
|
||||
var ch = source.peek();
|
||||
if (ch == '{' || ch == '[') {
|
||||
var lastPlug = peekCommand(state);
|
||||
var style = lastPlug.openBracket(ch);
|
||||
source.eat(ch);
|
||||
setState(state, normal);
|
||||
return "bracket";
|
||||
}
|
||||
if (/[ \t\r]/.test(ch)) {
|
||||
source.eat(ch);
|
||||
return null;
|
||||
}
|
||||
setState(state, normal);
|
||||
lastPlug = peekCommand(state);
|
||||
if (lastPlug) {
|
||||
popCommand(state);
|
||||
}
|
||||
return normal(source, state);
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() { return { f:normal, cmdState:[] }; },
|
||||
copyState: function(s) { return { f: s.f, cmdState: s.cmdState.slice(0, s.cmdState.length) }; },
|
||||
|
||||
token: function(stream, state) {
|
||||
var t = state.f(stream, state);
|
||||
var w = stream.current();
|
||||
return t;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
CodeMirror.defineMIME("text/x-stex", "stex");
|
@ -1,251 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: sTeX mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="stex.js"></script>
|
||||
<link rel="stylesheet" href="../../test/mode_test.css">
|
||||
<script src="../../test/mode_test.js"></script>
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Tests for the sTeX Mode</h1>
|
||||
<h2>Basics</h2>
|
||||
<script language="javascript">
|
||||
MT = ModeTest;
|
||||
|
||||
MT.test('foo',
|
||||
null, 'foo');
|
||||
|
||||
MT.test('foo bar',
|
||||
null, 'foo',
|
||||
null, ' bar');
|
||||
</script>
|
||||
|
||||
<h2>Tags</h2>
|
||||
<script language="javascript">
|
||||
MT.test('\\begin{document}\n\\end{document}',
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'document',
|
||||
'bracket', '}',
|
||||
'tag', '\\end',
|
||||
'bracket', '{',
|
||||
'atom', 'document',
|
||||
'bracket', '}');
|
||||
|
||||
MT.test('\\begin{equation}\n E=mc^2\n\\end{equation}',
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'equation',
|
||||
'bracket', '}',
|
||||
null, ' ',
|
||||
null, ' ',
|
||||
null, 'E',
|
||||
null, '=mc',
|
||||
null, '^2',
|
||||
'tag', '\\end',
|
||||
'bracket', '{',
|
||||
'atom', 'equation',
|
||||
'bracket', '}');
|
||||
|
||||
MT.test('\\begin{module}[]',
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'module',
|
||||
'bracket', '}',
|
||||
'bracket', '[',
|
||||
'bracket', ']');
|
||||
|
||||
MT.test('\\begin{module}[id=bbt-size]',
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'module',
|
||||
'bracket', '}',
|
||||
'bracket', '[',
|
||||
null, 'id',
|
||||
null, '=bbt-size',
|
||||
'bracket', ']');
|
||||
|
||||
MT.test('\\importmodule[b-b-t]{b-b-t}',
|
||||
'tag', '\\importmodule',
|
||||
'bracket', '[',
|
||||
'string', 'b-b-t',
|
||||
'bracket', ']',
|
||||
'bracket', '{',
|
||||
'builtin', 'b-b-t',
|
||||
'bracket', '}');
|
||||
|
||||
MT.test('\\importmodule[\\KWARCslides{dmath/en/cardinality}]{card}',
|
||||
'tag', '\\importmodule',
|
||||
'bracket', '[',
|
||||
'tag', '\\KWARCslides',
|
||||
'bracket', '{',
|
||||
'string', 'dmath',
|
||||
'string', '/en',
|
||||
'string', '/cardinality',
|
||||
'bracket', '}',
|
||||
'bracket', ']',
|
||||
'bracket', '{',
|
||||
'builtin', 'card',
|
||||
'bracket', '}');
|
||||
|
||||
MT.test('\\PSforPDF[1]{#1}', // could treat #1 specially
|
||||
'tag', '\\PSforPDF',
|
||||
'bracket', '[',
|
||||
'atom', '1',
|
||||
'bracket', ']',
|
||||
'bracket', '{',
|
||||
null, '#1',
|
||||
'bracket', '}');
|
||||
</script>
|
||||
|
||||
<h2>Comments</h2>
|
||||
<script language="javascript">
|
||||
MT.test('% foo',
|
||||
'comment', '%',
|
||||
'comment', ' foo');
|
||||
|
||||
MT.test('\\item% bar',
|
||||
'tag', '\\item',
|
||||
'comment', '%',
|
||||
'comment', ' bar');
|
||||
|
||||
MT.test(' % \\item',
|
||||
null, ' ',
|
||||
'comment', '%',
|
||||
'comment', ' \\item');
|
||||
|
||||
MT.test('%\nfoo',
|
||||
'comment', '%',
|
||||
null, 'foo');
|
||||
</script>
|
||||
|
||||
<h2>Errors</h2>
|
||||
<script language="javascript">
|
||||
MT.test('\\begin}{',
|
||||
'tag', '\\begin',
|
||||
'error', '}',
|
||||
'bracket', '{');
|
||||
|
||||
MT.test('\\item]{',
|
||||
'tag', '\\item',
|
||||
'error', ']',
|
||||
'bracket', '{');
|
||||
|
||||
MT.test('% }',
|
||||
'comment', '%',
|
||||
'comment', ' }');
|
||||
</script>
|
||||
|
||||
<h2>Character Escapes</h2>
|
||||
<script language="javascript">
|
||||
MT.test('the \\# key',
|
||||
null, 'the',
|
||||
null, ' ',
|
||||
'tag', '\\#',
|
||||
null, ' key');
|
||||
|
||||
MT.test('a \\$5 stetson',
|
||||
null, 'a',
|
||||
null, ' ',
|
||||
'tag', '\\$',
|
||||
'atom', 5,
|
||||
null, ' stetson');
|
||||
|
||||
MT.test('100\\% beef',
|
||||
'atom', '100',
|
||||
'tag', '\\%',
|
||||
null, ' beef');
|
||||
|
||||
MT.test('L \\& N',
|
||||
null, 'L',
|
||||
null, ' ',
|
||||
'tag', '\\&',
|
||||
null, ' N');
|
||||
|
||||
MT.test('foo\\_bar',
|
||||
null, 'foo',
|
||||
'tag', '\\_',
|
||||
null, 'bar');
|
||||
|
||||
MT.test('\\emph{\\{}',
|
||||
'tag', '\\emph',
|
||||
'bracket','{',
|
||||
'tag', '\\{',
|
||||
'bracket','}');
|
||||
|
||||
MT.test('\\emph{\\}}',
|
||||
'tag', '\\emph',
|
||||
'bracket','{',
|
||||
'tag', '\\}',
|
||||
'bracket','}');
|
||||
|
||||
MT.test('section \\S1',
|
||||
null, 'section',
|
||||
null, ' ',
|
||||
'tag', '\\S',
|
||||
'atom', '1');
|
||||
|
||||
MT.test('para \\P2',
|
||||
null, 'para',
|
||||
null, ' ',
|
||||
'tag', '\\P',
|
||||
'atom', '2');
|
||||
|
||||
</script>
|
||||
|
||||
<h2>Spacing control</h2>
|
||||
|
||||
<script language="javascript">
|
||||
MT.test('x\\,y', // thinspace
|
||||
null, 'x',
|
||||
'tag', '\\,',
|
||||
null, 'y');
|
||||
|
||||
MT.test('x\\;y', // thickspace
|
||||
null, 'x',
|
||||
'tag', '\\;',
|
||||
null, 'y');
|
||||
|
||||
MT.test('x\\!y', // negative thinspace
|
||||
null, 'x',
|
||||
'tag', '\\!',
|
||||
null, 'y');
|
||||
|
||||
MT.test('J.\\ L.\\ is', // period not ending a sentence
|
||||
null, 'J',
|
||||
null, '.',
|
||||
null, '\\',
|
||||
null, ' L',
|
||||
null, '.',
|
||||
null, '\\',
|
||||
null, ' is'); // maybe could be better
|
||||
|
||||
MT.test('X\\@. The', // period ending a sentence
|
||||
null, 'X',
|
||||
'tag', '\\@',
|
||||
null, '.',
|
||||
null, ' The');
|
||||
|
||||
MT.test('{\\em If\\/} I', // italic correction
|
||||
'bracket', '{',
|
||||
'tag', '\\em',
|
||||
null, ' ',
|
||||
null, 'If',
|
||||
'tag', '\\/',
|
||||
'bracket', '}',
|
||||
null, ' ',
|
||||
null, 'I');
|
||||
|
||||
</script>
|
||||
|
||||
<h2>Summary</h2>
|
||||
<script language="javascript">
|
||||
MT.printSummary();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,140 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror: TiddlyWiki mode</title>
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="tiddlywiki.js"></script>
|
||||
<link rel="stylesheet" href="tiddlywiki.css">
|
||||
<link rel="stylesheet" href="../../doc/docs.css">
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror: TiddlyWiki mode</h1>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
!TiddlyWiki Formatting
|
||||
* Rendered versions can be found at: http://www.tiddlywiki.com/#Reference
|
||||
|
||||
|!Option | !Syntax |
|
||||
|bold font | ''bold'' |
|
||||
|italic type | //italic// |
|
||||
|underlined text | __underlined__ |
|
||||
|strikethrough text | --strikethrough-- |
|
||||
|superscript text | super^^script^^ |
|
||||
|subscript text | sub~~script~~ |
|
||||
|highlighted text | @@highlighted@@ |
|
||||
|preformatted text | {{{preformatted}}} |
|
||||
|
||||
!Block Elements
|
||||
<<<
|
||||
!Heading 1
|
||||
|
||||
!!Heading 2
|
||||
|
||||
!!!Heading 3
|
||||
|
||||
!!!!Heading 4
|
||||
|
||||
!!!!!Heading 5
|
||||
<<<
|
||||
|
||||
!!Lists
|
||||
<<<
|
||||
* unordered list, level 1
|
||||
** unordered list, level 2
|
||||
*** unordered list, level 3
|
||||
|
||||
# ordered list, level 1
|
||||
## ordered list, level 2
|
||||
### unordered list, level 3
|
||||
|
||||
; definition list, term
|
||||
: definition list, description
|
||||
<<<
|
||||
|
||||
!!Blockquotes
|
||||
<<<
|
||||
> blockquote, level 1
|
||||
>> blockquote, level 2
|
||||
>>> blockquote, level 3
|
||||
|
||||
> blockquote
|
||||
<<<
|
||||
|
||||
!!Preformatted Text
|
||||
<<<
|
||||
{{{
|
||||
preformatted (e.g. code)
|
||||
}}}
|
||||
<<<
|
||||
|
||||
!!Code Sections
|
||||
<<<
|
||||
{{{
|
||||
Text style code
|
||||
}}}
|
||||
|
||||
//{{{
|
||||
JS styled code. TiddlyWiki mixed mode should support highlighter switching in the future.
|
||||
//}}}
|
||||
|
||||
<!--{{{-->
|
||||
XML styled code. TiddlyWiki mixed mode should support highlighter switching in the future.
|
||||
<!--}}}-->
|
||||
<<<
|
||||
|
||||
!!Tables
|
||||
<<<
|
||||
|CssClass|k
|
||||
|!heading column 1|!heading column 2|
|
||||
|row 1, column 1|row 1, column 2|
|
||||
|row 2, column 1|row 2, column 2|
|
||||
|>|COLSPAN|
|
||||
|ROWSPAN| ... |
|
||||
|~| ... |
|
||||
|CssProperty:value;...| ... |
|
||||
|caption|c
|
||||
|
||||
''Annotation:''
|
||||
* The {{{>}}} marker creates a "colspan", causing the current cell to merge with the one to the right.
|
||||
* The {{{~}}} marker creates a "rowspan", causing the current cell to merge with the one above.
|
||||
<<<
|
||||
!!Images /% TODO %/
|
||||
cf. [[TiddlyWiki.com|http://www.tiddlywiki.com/#EmbeddedImages]]
|
||||
|
||||
!Hyperlinks
|
||||
* [[WikiWords|WikiWord]] are automatically transformed to hyperlinks to the respective tiddler
|
||||
** the automatic transformation can be suppressed by preceding the respective WikiWord with a tilde ({{{~}}}): {{{~WikiWord}}}
|
||||
* [[PrettyLinks]] are enclosed in square brackets and contain the desired tiddler name: {{{[[tiddler name]]}}}
|
||||
** optionally, a custom title or description can be added, separated by a pipe character ({{{|}}}): {{{[[title|target]]}}}<br>'''N.B.:''' In this case, the target can also be any website (i.e. URL).
|
||||
|
||||
!Custom Styling
|
||||
* {{{@@CssProperty:value;CssProperty:value;...@@}}}<br>''N.B.:'' CSS color definitions should use lowercase letters to prevent the inadvertent creation of WikiWords.
|
||||
* <html><code>{{customCssClass{...}}}</code></html>
|
||||
* raw HTML can be inserted by enclosing the respective code in HTML tags: {{{<html> ... </html>}}}
|
||||
|
||||
!Special Markers
|
||||
* {{{<br>}}} forces a manual line break
|
||||
* {{{----}}} creates a horizontal ruler
|
||||
* [[HTML entities|http://www.tiddlywiki.com/#HtmlEntities]]
|
||||
* [[HTML entities local|HtmlEntities]]
|
||||
* {{{<<macroName>>}}} calls the respective [[macro|Macros]]
|
||||
* To hide text within a tiddler so that it is not displayed, it can be wrapped in {{{/%}}} and {{{%/}}}.<br/>This can be a useful trick for hiding drafts or annotating complex markup.
|
||||
* To prevent wiki markup from taking effect for a particular section, that section can be enclosed in three double quotes: e.g. {{{"""WikiWord"""}}}.
|
||||
</textarea></div>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: 'tiddlywiki',
|
||||
lineNumbers: true,
|
||||
enterMode: 'keep',
|
||||
matchBrackets: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>TiddlyWiki mode supports a single configuration.</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-tiddlywiki</code>.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,21 +0,0 @@
|
||||
.cm-s-default span.cm-header {color: blue; font-weight:bold;}
|
||||
.cm-s-default span.cm-code {color: #a50;}
|
||||
.cm-s-default span.cm-code-inline {color: #660;}
|
||||
|
||||
.cm-s-default span.cm-quote {color: #555;}
|
||||
.cm-s-default span.cm-list {color: #c60;}
|
||||
.cm-s-default span.cm-hr {color: #999;}
|
||||
.cm-s-default span.cm-em {font-style: italic;}
|
||||
.cm-s-default span.cm-strong {font-weight: bold;}
|
||||
|
||||
.cm-s-default span.cm-link-external {color: blue;}
|
||||
.cm-s-default span.cm-brace {color: #170; font-weight: bold;}
|
||||
.cm-s-default span.cm-macro {color: #9E3825;}
|
||||
.cm-s-default span.cm-table {color: blue; font-weight: bold;}
|
||||
.cm-s-default span.cm-warning {color: red; font-weight: bold;}
|
||||
|
||||
.cm-s-default span.cm-underlined {text-decoration: underline;}
|
||||
.cm-s-default span.cm-line-through {text-decoration: line-through;}
|
||||
|
||||
.cm-s-default span.cm-comment {color: #666;}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue