pmacs3/mode/ebnf.py

36 lines
1.3 KiB
Python
Raw Permalink Normal View History

2009-03-31 23:24:28 -04:00
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