parent
0aaa84c894
commit
f9e78c8c11
|
@ -1,21 +1,44 @@
|
||||||
import color, mode, tab
|
import color, mode, tab
|
||||||
from lex import Grammar, PatternRule, RegionRule
|
from lex import Grammar, PatternRule, RegionRule, PatternGroupRule
|
||||||
from point import Point
|
from point import Point
|
||||||
from mode.python import StringGrammar
|
|
||||||
|
class StringGrammar1(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
||||||
|
PatternRule(r'hex', r'\\x[0-9a-fA-F]{2}'),
|
||||||
|
PatternRule(r'escaped', r'\\.'),
|
||||||
|
PatternRule(r'data', r'[^\\\']+'),
|
||||||
|
]
|
||||||
|
class StringGrammar2(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
||||||
|
PatternRule(r'hex', r'\\x[0-9a-fA-F]{2}'),
|
||||||
|
PatternRule(r'escaped', r'\\.'),
|
||||||
|
PatternRule(r'data', r'[^\\\"]+'),
|
||||||
|
]
|
||||||
|
class RegexGrammar(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
||||||
|
PatternRule(r'hex', r'\\x[0-9a-fA-F]{2}'),
|
||||||
|
PatternRule(r'escaped', r'\\.'),
|
||||||
|
PatternRule(r'data', r'[^/\\]+'),
|
||||||
|
]
|
||||||
|
|
||||||
class JavascriptGrammar(Grammar):
|
class JavascriptGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'comment', r'//.*$'),
|
PatternRule(r'comment', r'//.*$'),
|
||||||
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
||||||
PatternRule(r'continuation', r'\\(?= *$)'),
|
PatternRule(r'continuation', r'\\(?= *$)'),
|
||||||
PatternRule(r'js_function', r"(?<=function )[a-zA-Z_][a-zA-Z0-9_]*"),
|
|
||||||
PatternRule(r'js_class', r"(?<=class )[a-zA-Z_][a-zA-Z0-9_]*"),
|
|
||||||
|
|
||||||
PatternRule(r'js_reserved', 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(r'js_reserved', r'(?:abstract|debugger|enum|goto|implements|interface|native|protected|synchronized|throws|transient|volatile)(?![a-zA-Z0-9_])'),
|
|
||||||
PatternRule(r'js_nonreserved', r'(?:get|include|set)(?![a-zA-Z0-9_])'),
|
|
||||||
|
|
||||||
PatternRule(r"method", r"(?<=\.)[a-zA-Z_][a-zA-Z0-9_]*(?= *\()"),
|
PatternGroupRule(r'func_def', 'js_reserved', r'function', r'spaces', r' +', r'js_function', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
|
PatternGroupRule(r'class_def', 'js_reserved', r'class', r'spaces', r' +', r'js_class', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
|
PatternGroupRule(r'class_new', r'js_reserved', r'new', r'spaces', r' +', r'js_class', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
|
|
||||||
|
PatternRule(r'js_reserved', r'(?:abstract|as|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|get|goto|if|import|implements|include|instanceof|interface|in|is|namespace|native|new|null|package|private|protected|public|return|set|super|switch|synchronized|this|throws|throw|transient|true|try|typeof|use|var|void|volatile|while|with)(?![a-zA-Z0-9_])'),
|
||||||
|
|
||||||
|
PatternGroupRule(r'func_use', r"js_function", r"[a-zA-Z_][a-zA-Z0-9_]", r'spaces', ' +',
|
||||||
|
r'delimiter', r"\("),
|
||||||
|
PatternRule(r"js_function", r"[a-zA-Z_][a-zA-Z0-9_]*(?= *\()"),
|
||||||
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
||||||
|
|
||||||
PatternRule(r'integer', r"(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
PatternRule(r'integer', r"(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
||||||
|
@ -31,9 +54,9 @@ class JavascriptGrammar(Grammar):
|
||||||
PatternRule(r'delimiter', r'%=|&&=|&=|\(|\)|\*=|\+=|,|-=|\.{3}|\.|/=(?= |$)|::|:|;|<<=|>>=|>>>=|\?|\[|\]|^=|^^=|\{|\}|\|=|\|\|='),
|
PatternRule(r'delimiter', r'%=|&&=|&=|\(|\)|\*=|\+=|,|-=|\.{3}|\.|/=(?= |$)|::|:|;|<<=|>>=|>>>=|\?|\[|\]|^=|^^=|\{|\}|\|=|\|\|='),
|
||||||
PatternRule(r'operator', r'!==|!=|!|%|&&|&|\*|\+\+|\+|--|-|/(?= |$)|<<=|<<|<=|<|===|==|=|>>>=|>>>|>>=|>>|>=|>|\\|\|\|'),
|
PatternRule(r'operator', r'!==|!=|!|%|&&|&|\*|\+\+|\+|--|-|/(?= |$)|<<=|<<|<=|<|===|==|=|>>>=|>>>|>>=|>>|>=|>|\\|\|\|'),
|
||||||
|
|
||||||
RegionRule('js_regex', "/", StringGrammar, "/"),
|
RegionRule('js_regex', "/", RegexGrammar, "/[a-z]*"),
|
||||||
RegionRule('string', "'", StringGrammar, "'"),
|
RegionRule('string', "'", StringGrammar1, "'"),
|
||||||
RegionRule('string', '"', StringGrammar, '"'),
|
RegionRule('string', '"', StringGrammar2, '"'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class JavascriptTabber(tab.StackTabber):
|
class JavascriptTabber(tab.StackTabber):
|
||||||
|
@ -66,10 +89,10 @@ class Javascript(mode.Fundamental):
|
||||||
closetags = {')': '(', ']': '[', '}': '{'}
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
colors = {
|
colors = {
|
||||||
'js_function': ('blue', 'default', 'bold'),
|
'js_function': ('blue', 'default', 'bold'),
|
||||||
'js_class': ('green', 'default', 'bold'),
|
'js_class': ('magenta', 'default', 'bold'),
|
||||||
'js_reserved': ('cyan', 'default', 'bold'),
|
'js_reserved': ('cyan', 'default', 'bold'),
|
||||||
'js_nonreserved': ('cyan', 'default', 'bold'),
|
|
||||||
'js_regex.start': ('cyan', 'default', 'bold'),
|
'js_regex.start': ('cyan', 'default', 'bold'),
|
||||||
|
'js_regex.data': ('cyan', 'default', 'bold'),
|
||||||
'js_regex.null': ('cyan', 'default', 'bold'),
|
'js_regex.null': ('cyan', 'default', 'bold'),
|
||||||
'js_regex.octal': ('magenta', 'default', 'bold'),
|
'js_regex.octal': ('magenta', 'default', 'bold'),
|
||||||
'js_regex.escaped': ('magenta', 'default', 'bold'),
|
'js_regex.escaped': ('magenta', 'default', 'bold'),
|
||||||
|
|
Loading…
Reference in New Issue