Class: VER::Syntax
- Inherits:
-
Object
- Object
- VER::Syntax
- Defined in:
- lib/ver/syntax.rb,
lib/ver/syntax/detector.rb,
lib/ver/syntax/processor.rb
Defined Under Namespace
Modules: Detector Classes: Processor
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#theme ⇒ Object
Returns the value of attribute theme.
Class Method Summary collapse
- .find(syntax_name) ⇒ Object
- .find_and_load(syntax_name) ⇒ Object
- .from_filename(filename) ⇒ Object
- .list ⇒ Object
- .load(file) ⇒ Object
Instance Method Summary collapse
- #highlight(textarea, code, lineno = nil, from = '1.0', to = 'end') ⇒ Object
-
#initialize(name, theme = nil) ⇒ Syntax
constructor
A new instance of Syntax.
Constructor Details
#initialize(name, theme = nil) ⇒ Syntax
Returns a new instance of Syntax.
34 35 36 37 38 39 40 41 |
# File 'lib/ver/syntax.rb', line 34 def initialize(name, theme = nil) @name = name @first_highlight = true @old_theme = nil @parser = self.class.find_and_load(name) @theme = theme || Theme.find_and_load(VER.[:theme]) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
31 32 33 |
# File 'lib/ver/syntax.rb', line 31 def name @name end |
#parser ⇒ Object
Returns the value of attribute parser.
31 32 33 |
# File 'lib/ver/syntax.rb', line 31 def parser @parser end |
#theme ⇒ Object
Returns the value of attribute theme.
32 33 34 |
# File 'lib/ver/syntax.rb', line 32 def theme @theme end |
Class Method Details
.find(syntax_name) ⇒ Object
18 19 20 |
# File 'lib/ver/syntax.rb', line 18 def self.find(syntax_name) VER.find_in_loadpath("syntax/#{syntax_name}.json") end |
.find_and_load(syntax_name) ⇒ Object
27 28 29 |
# File 'lib/ver/syntax.rb', line 27 def self.find_and_load(syntax_name) load(find(syntax_name)) end |
.from_filename(filename) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/ver/syntax.rb', line 10 def self.from_filename(filename) if syntax_name = Detector.detect(filename) return new(syntax_name) else new(VER..filetype) end end |
.list ⇒ Object
6 7 8 |
# File 'lib/ver/syntax.rb', line 6 def self.list VER.loadpath.map{|path| Dir[(path/'syntax/*.json').to_s] }.flatten end |
.load(file) ⇒ Object
22 23 24 25 |
# File 'lib/ver/syntax.rb', line 22 def self.load(file) raise(ArgumentError, "No path to syntax file given") unless file Textpow::SyntaxNode.load(file) end |
Instance Method Details
#highlight(textarea, code, lineno = nil, from = '1.0', to = 'end') ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ver/syntax.rb', line 43 def highlight(textarea, code, lineno = nil, from = '1.0', to = 'end') if @old_theme @old_theme.(textarea) @old_theme = nil end if @first_highlight @theme.(textarea) @theme.apply_default_on(textarea) @first_highlight = false else @theme.(textarea, from, to) end pr = Processor.new(textarea, @theme, lineno || 0) if lineno pr.start_parsing(parser.scopeName) stack = [[parser, nil]] parser.parse_line(stack, code, pr) pr.end_parsing(parser.scopeName) else @theme.(textarea, from, to) parser.parse(code, pr) end end |