parent
c3d14ee686
commit
c53d9e4584
|
@ -177,7 +177,7 @@ class Application(object):
|
|||
'haskell', 'erlang', 'iperl', 'iperlmini', 'ipython', 'ipythonmini',
|
||||
'awk', 'shell', 'shellmini', 'fstab', 'yacc', 'pipe', 'mbox',
|
||||
'error', 'lua', 'lily', 'forth', 'ebnf', 'colortest', 'go',
|
||||
'inform6', 'scala', 'markdown', 'roy',
|
||||
'inform6', 'scala', 'markdown', 'roy', 'twine',
|
||||
)
|
||||
for name in names:
|
||||
exec("import mode.%s; mode.%s.install(self)" % (name, name))
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
from lex import Grammar, PatternRule, RegionRule, OverrideRegionRule, PatternMatchRule
|
||||
from mode import Fundamental
|
||||
from method import Method, WrapParagraph
|
||||
from mode.text import TextInsertSpace
|
||||
|
||||
from mode.c import CGrammar
|
||||
from mode.html import HTMLGrammar
|
||||
from mode.java import JavaGrammar
|
||||
from mode.javascript import JavascriptGrammar
|
||||
from mode.python import PythonGrammar
|
||||
from mode.scala import ScalaGrammar
|
||||
from mode.sql import SqlGrammar
|
||||
from mode.xml import XMLGrammar
|
||||
|
||||
class LineGrammar(Grammar): pass
|
||||
LineGrammar.rules = [
|
||||
PatternRule('line', r'.+'),
|
||||
PatternRule('eol', r'\n'),
|
||||
]
|
||||
|
||||
class WordGrammar(Grammar): pass
|
||||
WordGrammar.rules = [
|
||||
PatternRule('word', r'[A-Za-z0-9_]+'),
|
||||
]
|
||||
|
||||
class CmdGrammar(Grammar): pass
|
||||
CmdGrammar.rules = [
|
||||
PatternRule('tw.var', r'\$[a-zA-Z0-9_]+'),
|
||||
PatternRule('tw.keyword', '(?<=<<)[a-zA-Z0-9_]+'),
|
||||
PatternRule('tw.op', r'(?:eq|neq|gte|gt|lte|lt|and|or|not)'),
|
||||
PatternRule('arg', r'"(?:[^\\"]|\.)*"'),
|
||||
PatternRule('arg', r"'(?:[^\\']|\.)*'"),
|
||||
PatternRule('spaces', r' +'),
|
||||
]
|
||||
|
||||
class TwineGrammar(Grammar): pass
|
||||
TwineGrammar.rules = [
|
||||
#PatternRule('md.head1', r'^#.+'),
|
||||
#PatternRule('md.head2', r'^##.+'),
|
||||
#PatternRule('md.head3', r'^###.+'),
|
||||
#PatternRule('md.head4', r'^####.+'),
|
||||
#PatternRule('md.head5', r'^#####.+'),
|
||||
#PatternRule('md.head6', r'^######.+'),
|
||||
#
|
||||
#RegionRule('md.tag', r'^<(?P<tag>[a-zA-Z_][a-zA-Z0-9_]*)>$', HTMLGrammar, r'^</%(tag)s>$'),
|
||||
#
|
||||
#PatternRule('md.bullet', r'^\s*[\*\-\*] '),
|
||||
#
|
||||
#PatternMatchRule('', r'(\[.+?\])(\(.+?\))', 'md.linkname', 'md.linkurl'),
|
||||
#
|
||||
#PatternRule('md.block3', r'^(?:>\s*>\s*>\s*)*>\s*>\s*>(?:[^>].*)?\n$'),
|
||||
#PatternRule('md.block2', r'^(?:>\s*>\s*>\s*)*>\s*>(?:[^>].*)?\n$'),
|
||||
#PatternRule('md.block1', r'^(?:>\s*>\s*>\s*)*>(?:[^>].*)?\n$'),
|
||||
#
|
||||
#PatternRule('md.code', r'^(?: |\t).*$'),
|
||||
#
|
||||
#PatternRule('md.inlinelink', r'http://[^`*\t(){}\[\] ]+'),
|
||||
#
|
||||
#RegionRule('md.lang', r'^```c$', CGrammar, r'^```'),
|
||||
#RegionRule('md.lang', r'^```html$', HTMLGrammar, r'^```'),
|
||||
#RegionRule('md.lang', r'^```(?:javascript|js)$', JavascriptGrammar, r'^```'),
|
||||
#RegionRule('md.lang', r'^```java$', JavaGrammar, r'^```'),
|
||||
#RegionRule('md.lang', r'^```python$', PythonGrammar, r'^```'),
|
||||
#RegionRule('md.lang', r'^```scala$', ScalaGrammar, r'^```'),
|
||||
#RegionRule('md.lang', r'^```sql$', SqlGrammar, r'^```'),
|
||||
#RegionRule('md.lang', r'^```xml$', XMLGrammar, r'^```'),
|
||||
#
|
||||
#RegionRule('md.code', r'^```.+$', LineGrammar, r'^```'),
|
||||
#
|
||||
#RegionRule('md.bold', r'\*\*', TwineGrammar, r'\*\*'),
|
||||
#RegionRule('md.tt', r'``', TwineGrammar, r'``'),
|
||||
#
|
||||
#RegionRule('md.bold', r'\*', TwineGrammar, r'\*'),
|
||||
#RegionRule('md.tt', r'`', WordGrammar, r'`'),
|
||||
|
||||
#PatternRule('md.escaped', r'\\.'),
|
||||
|
||||
PatternRule('tw.passage', r'::.+'),
|
||||
|
||||
PatternMatchRule('', '(\[\[)([^\[\]|]*)(\|)([^\[\]|]*)(\]\])',
|
||||
'tw.passage', 'tw.link', 'tw.passage', 'tw.passage', 'tw.passage'),
|
||||
PatternMatchRule('', r'(\[\[)([^\[\]|]*)(\]\])',
|
||||
'tw.passage', 'tw.link', 'tw.passage'),
|
||||
|
||||
PatternRule('tw.keyword', '(?<=<<)[a-zA-Z0-9_]+'),
|
||||
|
||||
#RegionRule('tw.cmd', r'<<', None, r'>>'),
|
||||
RegionRule('tw.cmd', r'<<', CmdGrammar, r'>>'),
|
||||
|
||||
#PatternMatchRule('', r'(<<choice +\")(.+?)(\" +\")(.+?)(\" *>>)',
|
||||
# 'tw.choice', 'tw.passage', 'tw.choice', 'tw.link', 'tw.choice'),
|
||||
#PatternMatchRule('', r'(<<choice +\")(.+?)(\" *>>)',
|
||||
# 'tw.choice', 'tw.link', 'tw.choice'),
|
||||
|
||||
PatternRule('tw.var', r'\$[a-zA-Z0-9_]+'),
|
||||
RegionRule('tw.html', r'<html>', Grammar, r'</html>'),
|
||||
|
||||
#PatternRule('tw.link', r'[[a-zA-Z\'"\-]+'),
|
||||
PatternRule('tw.word', r'[a-zA-Z\'"\-]+'),
|
||||
#RegionRule('tw.html', r'<html>', HTMLGrammar, r'</html>'),
|
||||
|
||||
PatternRule('spaces', '\s+'),
|
||||
PatternRule('eol', r'\n'),
|
||||
PatternRule('null', r'.'),
|
||||
]
|
||||
|
||||
|
||||
class TwWrapParagraph(WrapParagraph):
|
||||
limit = 75
|
||||
#class TwInsertSpace(TextInsertSpace):
|
||||
# limit = 75
|
||||
# wrapper = TwWrapParagraph
|
||||
|
||||
# white is for delimiters, operators, numbers
|
||||
default = ('default', 'default')
|
||||
|
||||
# magenta is for keywords/builtins
|
||||
lo_magenta = ('magenta202', 'default')
|
||||
hi_magenta = ('magenta414', 'default')
|
||||
|
||||
# red is for comments
|
||||
lo_red = ('red300', 'default')
|
||||
hi_red = ('red511', 'default')
|
||||
|
||||
# orange is for macro definitions, headers and constants
|
||||
hi_orange = ('yellow531', 'default')
|
||||
lo_orange = ('yellow520', 'default')
|
||||
|
||||
# yellow is for parts of macros
|
||||
hi_yellow = ('yellow551', 'default')
|
||||
lo_yellow = ('yellow330', 'default')
|
||||
|
||||
# green is for strings and characters
|
||||
lo_green = ('green030', 'default')
|
||||
hi_green = ('green050', 'default')
|
||||
|
||||
# cyan is for types
|
||||
lo_cyan = ('cyan033', 'default')
|
||||
hi_cyan = ('cyan155', 'default')
|
||||
|
||||
# blue is definitions, functions and some macros
|
||||
lo_blue = ('blue113', 'default')
|
||||
hi_blue = ('blue225', 'default')
|
||||
|
||||
class Twine(Fundamental):
|
||||
name = 'Twine'
|
||||
extensions = ['.tw']
|
||||
grammar = TwineGrammar
|
||||
colors = {
|
||||
'tw.passage': hi_magenta,
|
||||
'tw.delim': hi_magenta,
|
||||
'tw.link': hi_cyan,
|
||||
'tw.var': hi_yellow,
|
||||
#'tw.choice': hi_orange,
|
||||
'tw.cmd.start': hi_orange,
|
||||
'tw.keyword': hi_orange,
|
||||
'tw.op': hi_magenta,
|
||||
'tw.cmd.arg': hi_yellow,
|
||||
'tw.cmd.end': hi_orange,
|
||||
|
||||
'tw.html.start': hi_green,
|
||||
'tw.html.null': hi_green,
|
||||
'tw.html.end': hi_green,
|
||||
|
||||
'tw.word': default,
|
||||
}
|
||||
actions = [TwWrapParagraph]
|
||||
config = {
|
||||
'tw.margin': 75,
|
||||
}
|
||||
_bindings = {
|
||||
'tw-wrap-paragraph': ('M-q',),
|
||||
}
|
||||
|
||||
install = Twine.install
|
Loading…
Reference in New Issue