parent
57966e6420
commit
178420f3fc
|
@ -7,12 +7,12 @@ import util, window2
|
|||
from point2 import Point
|
||||
|
||||
# modes
|
||||
# TODO: mode_sql mode_javascript mode_tt
|
||||
# TODO: mode_sql mode_tt
|
||||
import mode2
|
||||
import mode_mini, mode_search, mode_replace, mode_which
|
||||
import mode_console, mode_consolemini
|
||||
import mode_blame, mode_diff
|
||||
import mode_c, mode_python, mode_perl, mode_xml, mode_nasm, mode_sh
|
||||
import mode_c, mode_python, mode_perl, mode_xml, mode_nasm, mode_sh, mode_javascript
|
||||
import mode_life, mode_text, mode_mutt
|
||||
|
||||
def run(buffers, jump_to_line=None, init_mode=None):
|
||||
|
@ -99,8 +99,8 @@ class Application(object):
|
|||
'xml': mode_xml.XML,
|
||||
'life': mode_life.Life,
|
||||
'mutt': mode_mutt.Mutt,
|
||||
'javascript': mode_javascript.Javascript,
|
||||
#'sql': mode_sql.Sql,
|
||||
# 'javascript': mode_javascript.Javascript,
|
||||
#'template': mode_tt.Template,
|
||||
}
|
||||
|
||||
|
@ -128,8 +128,8 @@ class Application(object):
|
|||
'.xml.in': 'xml',
|
||||
'.html': 'xml',
|
||||
'.htm': 'xml',
|
||||
'.js': 'javascript',
|
||||
#'.sql': 'sql',
|
||||
# '.js': 'javascript',
|
||||
#'.tt': 'template'
|
||||
}
|
||||
self.mode_detection = {
|
||||
|
|
|
@ -1,43 +1,80 @@
|
|||
import re, sets, string, sys
|
||||
import color, commands, default, lex, lex_javascript, method, mode, point, regex, tab_javascript
|
||||
import color, mode2
|
||||
from lex2 import Grammar, PatternRule, RegionRule
|
||||
from point2 import Point
|
||||
|
||||
class Javascript(mode.Fundamental):
|
||||
class StringGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(name=r'octal', pattern=r'\\[0-7]{3}'),
|
||||
PatternRule(name=r'escaped', pattern=r'\\.'),
|
||||
]
|
||||
|
||||
class JavascriptGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(name=r'comment', pattern=r'//.*$'),
|
||||
RegionRule(name=r'comment', start='/\*', grammar=Grammar(), end='\*/'),
|
||||
PatternRule(name=r'continuation', pattern=r'\\(?= *$)'),
|
||||
PatternRule(name=r'function', pattern=r"(?<=function )[a-zA-Z_][a-zA-Z0-9_]*"),
|
||||
PatternRule(name=r'class', pattern=r"(?<=class )[a-zA-Z_][a-zA-Z0-9_]*"),
|
||||
|
||||
PatternRule(name=r'reserved1', pattern=r'(?:as|break|case|catch|class|const|continue|default|delete|do|else|export|extends|false|finally|for|function|if|import|in|instanceof|is|namespace|new|null|package|private|public|return|super|switch|this|throw|true|try|typeof|use|var|void|while|with)(?![a-zA-Z0-9_])'),
|
||||
PatternRule(name=r'reserved2', pattern=r'(?:abstract|debugger|enum|goto|implements|interface|native|protected|synchronized|throws|transient|volatile)(?![a-zA-Z0-9_])'),
|
||||
PatternRule(name=r'nonreserved', pattern=r'(?:get|include|set)(?![a-zA-Z0-9_])'),
|
||||
|
||||
PatternRule(name=r"method", pattern=r"(?<=\.)[a-zA-Z_][a-zA-Z0-9_]*(?= *\()"),
|
||||
PatternRule(name=r'identifier', pattern=r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
||||
|
||||
PatternRule(name=r'integer', pattern=r"(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
||||
PatternRule(name=r'float', pattern=r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
||||
|
||||
# fucking javascript!
|
||||
# their lexer grammar requires one-token look-behind in order to know
|
||||
# whether a "/" starts a literal regex, or is part of a mathematical
|
||||
# expression/assignment. so for now we will require either a space or $
|
||||
# after / in order to *not* treat it as a regex. dammit!
|
||||
PatternRule(name=r'delimiter', pattern=r'%=|&&=|&=|\(|\)|\*=|\+=|,|-=|\.{3}|\.|/=(?= |$)|::|:|;|<<=|>>=|>>>=|\?|\[|\]|^=|^^=|\{|\}|\|=|\|\|='),
|
||||
PatternRule(name=r'operator', pattern=r'!==|!=|!|%|&&|&|\*|\+\+|\+|--|-|/(?= |$)|<<=|<<|<=|<|===|==|=|>>>=|>>>|>>=|>>|>=|>|\\'),
|
||||
|
||||
RegionRule(name='regex', start="/", grammar=StringGrammar(), end="/"),
|
||||
RegionRule(name='string', start="'", grammar=StringGrammar(), end="'"),
|
||||
RegionRule(name='string', start='"', grammar=StringGrammar(), end='"'),
|
||||
]
|
||||
|
||||
class Javascript(mode2.Fundamental):
|
||||
grammar = JavascriptGrammar()
|
||||
def __init__(self, w):
|
||||
mode.Fundamental.__init__(self, w)
|
||||
|
||||
self.tag_matching = True
|
||||
self.grammar = lex_javascript.JavascriptGrammar()
|
||||
self.lexer = lex.Lexer(self.grammar)
|
||||
|
||||
mode2.Fundamental.__init__(self, w)
|
||||
self.add_bindings('close-paren', (')',))
|
||||
self.add_bindings('close-brace', ('}',))
|
||||
self.add_bindings('close-bracket', (']',))
|
||||
|
||||
self.default_color = color.build_attr(color.pairs('default', 'default'))
|
||||
self.colors = {
|
||||
'keyword' : color.build('cyan', 'default', 'bold'),
|
||||
'pseudo-keyword' : color.build('cyan', 'default', 'bold'),
|
||||
'built-in method' : color.build('cyan', 'default', 'bold'),
|
||||
'function declaration' : color.build('blue', 'default', 'bold'),
|
||||
'class declaration' : color.build('green', 'default'),
|
||||
'string4' : color.build('green', 'default'),
|
||||
'string3' : color.build('green', 'default'),
|
||||
'string2' : color.build('green', 'default'),
|
||||
'string1' : color.build('green', 'default'),
|
||||
'comment': color.build('red', 'default'),
|
||||
'comment.start': color.build('red', 'default'),
|
||||
'comment.null': color.build('red', 'default'),
|
||||
'comment.end': color.build('red', 'default'),
|
||||
'continuation': color.build('red', 'default'),
|
||||
#'operator' : color.build('yellow', 'default'),
|
||||
#'delimiter' : color.build('magenta', 'default'),
|
||||
'system_identifier' : color.build('cyan', 'default', 'bold'),
|
||||
#'bound method' : color.build('yellow', 'default'),
|
||||
'import statement' : color.build('magenta', 'green'),
|
||||
'bizzaro' : color.build('magenta', 'green'),
|
||||
'function': color.build('blue', 'default'),
|
||||
'class': color.build('green', 'default'),
|
||||
|
||||
'reserved1': color.build('cyan', 'default'),
|
||||
'reserved2': color.build('cyan', 'default'),
|
||||
'nonreserved': color.build('cyan', 'default'),
|
||||
|
||||
'delimiter': color.build('default', 'default'),
|
||||
'operator': color.build('default', 'default'),
|
||||
'integer': color.build('default', 'default'),
|
||||
'float': color.build('default', 'default'),
|
||||
|
||||
'string.start': color.build('green', 'default'),
|
||||
'string.null': color.build('green', 'default'),
|
||||
'string.octal': color.build('magenta', 'default'),
|
||||
'string.escaped': color.build('magenta', 'default'),
|
||||
'string.end': color.build('green', 'default'),
|
||||
|
||||
'regex.start': color.build('cyan', 'default'),
|
||||
'regex.null': color.build('cyan', 'default'),
|
||||
'regex.octal': color.build('magenta', 'default'),
|
||||
'regex.escaped': color.build('magenta', 'default'),
|
||||
'regex.end': color.build('cyan', 'default'),
|
||||
}
|
||||
|
||||
#self.highlighter.lex_buffer()
|
||||
#self.get_regions()
|
||||
self.tabber = tab_javascript.JavascriptTabber(self)
|
||||
|
||||
def name(self):
|
||||
return "Javascript"
|
||||
|
||||
|
|
Loading…
Reference in New Issue