From fc016f1716aa8b556ed7955306c61ac6b4806740 Mon Sep 17 00:00:00 2001 From: moculus Date: Wed, 1 Apr 2009 03:24:28 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- application.py | 2 +- code_examples/wiki.ebnf | 16 ++++++++++++++++ mode/ebnf.py | 35 +++++++++++++++++++++++++++++++++++ mode/nasm.py | 4 ++-- 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 code_examples/wiki.ebnf create mode 100644 mode/ebnf.py diff --git a/application.py b/application.py index 0ad9ad2..c9fdf06 100755 --- a/application.py +++ b/application.py @@ -117,7 +117,7 @@ class Application(object): 'latex', 'insertmini', 'conf', 'haskell', 'erlang', 'iperl', 'iperlmini', 'ipython', 'ipythonmini', 'awk', 'shell', 'shellmini', 'fstab', 'yacc', 'pipe', - 'mbox', 'error', 'lua', 'lily', 'forth', + 'mbox', 'error', 'lua', 'lily', 'forth', 'ebnf', ) for name in names: exec("import mode.%s; mode.%s.install(self)" % (name, name)) diff --git a/code_examples/wiki.ebnf b/code_examples/wiki.ebnf new file mode 100644 index 0000000..e8dfdf4 --- /dev/null +++ b/code_examples/wiki.ebnf @@ -0,0 +1,16 @@ +(* a simple program in EBNF - Wikipedia *) +program = 'PROGRAM' , white space , identifier , white space , + 'BEGIN' , white space , + { assignment , ";" , white space } , + 'END.' ; +identifier = alphabetic character , { alphabetic character | digit } ; +number = [ "-" ] , digit , { digit } ; +string = '"' , { all characters - '"' } , '"' ; +assignment = identifier , ":=" , ( number | identifier | string ) ; +alphabetic character = "A" | "B" | "C" | "D" | "E" | "F" | "G" + | "H" | "I" | "J" | "K" | "L" | "M" | "N" + | "O" | "P" | "Q" | "R" | "S" | "T" | "U" + | "V" | "W" | "X" | "Y" | "Z" ; +digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; +white space = ? white space characters ? ; +all characters = ? all visible characters ? ; diff --git a/mode/ebnf.py b/mode/ebnf.py new file mode 100644 index 0000000..0033732 --- /dev/null +++ b/mode/ebnf.py @@ -0,0 +1,35 @@ +from mode import Fundamental +from lex import Grammar, PatternRule, RegionRule, PatternMatchRule +from mode.python import StringGrammar1, StringGrammar2, StringGrammar3, StringGrammar4 + +class CommentGrammar(Grammar): + rules = [PatternRule('data', r'(?:[^\*]|\*(?!\)))+')] +class SequenceGrammar(Grammar): + rules = [PatternRule('data', r'(?:\\.|[^?])+')] + +class EbnfGrammar(Grammar): + rules = [ + PatternRule('spaces', ' +'), + PatternRule('eol', r'\n'), + RegionRule('string', "'", StringGrammar1, "'"), + RegionRule('string', '"', StringGrammar2, '"'), + RegionRule('ebnf_sequence', r'\?', SequenceGrammar, r'\?'), + RegionRule('comment', r'\(\*', CommentGrammar, r'\*\)'), + PatternRule('delimiter', '[=,;|\[\]{}\(\)-]'), + PatternRule('ebnf_nonterminal', r'[a-zA-Z_][-a-zA-Z0-9_ ]*[a-zA-Z0-9_]'), + PatternRule('ebnf_nonterminal', r'[a-zA-Z_]'), + ] + +class Ebnf(Fundamental): + name = 'ebnf' + extensions = ['.ebnf'] + grammar = EbnfGrammar + colors = { + 'ebnf_sequence.start': ('magenta', 'default', 'bold'), + 'ebnf_sequence.data': ('magenta', 'default', 'bold'), + 'ebnf_sequence.null': ('magenta', 'default', 'bold'), + 'ebnf_sequence.end': ('magenta', 'default', 'bold'), + 'ebnf_nonterminal': ('cyan', 'default', 'bold'), + } + +install = Ebnf.install diff --git a/mode/nasm.py b/mode/nasm.py index 81a7f2c..ba1e064 100644 --- a/mode/nasm.py +++ b/mode/nasm.py @@ -1,4 +1,4 @@ -import color, mode +from mode import Fundamental from lex import Grammar, PatternRule, RegionRule, PatternMatchRule from mode.python import StringGrammar1, StringGrammar2, StringGrammar3, StringGrammar4 @@ -26,7 +26,7 @@ class NasmGrammar(Grammar): PatternRule('comment', ';.*$'), ] -class Nasm(mode.Fundamental): +class Nasm(Fundamental): name = 'nasm' extensions = ['.s'] grammar = NasmGrammar