Class: IndentCode::IndentCPP
- Inherits:
-
Object
- Object
- IndentCode::IndentCPP
- Includes:
- IndentCode
- Defined in:
- lib/indent_code/indent_cpp.rb
Constant Summary
Constants included from IndentCode
Instance Method Summary collapse
-
#indent(c) ⇒ Object
indent method for this language.
-
#initialize ⇒ IndentCPP
constructor
A new instance of IndentCPP.
Methods included from IndentCode
Constructor Details
#initialize ⇒ IndentCPP
Returns a new instance of IndentCPP.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/indent_code/indent_cpp.rb', line 8 def initialize @parser = Iparser::Machine.new @st_cline = Iparser::State.new('comment-line') @st_cblock = Iparser::State.new('comment-block') @st_char = Iparser::State.new('char') @st_string = Iparser::State.new('string') @st_screen = Iparser::State.new('screen') @st_scope = Iparser::State.new('scope') @parser.addstate @st_scope @parser.addstate @st_cline @parser.addstate @st_cblock @parser.addstate @st_char @parser.addstate @st_string @parser.addstate @st_screen # Setting comment-line state. @st_cline.entry << '/' @st_cline.entry << '/' @st_cline.leave << /[\n\r]/ # Setting comment-block state. @st_cblock.entry << '/' @st_cblock.entry << '*' @st_cblock.leave << '*' @st_cblock.leave << '/' @st_cblock.handler( method( :cblock_handler ) ) @st_cblock.fini( method( :cblock_fini ) ) # Setting char state. @st_char.entry << "'" @st_char.leave << "'" @st_char.branches << @parser.state_index( @st_screen ) # Setting string state. @st_string.entry << '"' @st_string.leave << '"' @st_string.branches << @parser.state_index( @st_screen ) # Setting screen state. @st_screen.entry << '\\' @st_screen.leave << /./ # Setting open state. @st_scope.entry << '{' @st_scope.leave << '}' @st_scope.branches << @parser.state_index( @st_scope ) @st_scope.branches << @parser.state_index( @st_cline ) @st_scope.branches << @parser.state_index( @st_cblock ) @st_scope.branches << @parser.state_index( @st_string ) @st_scope.branches << @parser.state_index( @st_char ) @st_scope.init( method( :scope_init ) ) @st_scope.fini( method( :scope_fini ) ) @parser.prestart end |
Instance Method Details
#indent(c) ⇒ Object
indent method for this language.
99 100 101 |
# File 'lib/indent_code/indent_cpp.rb', line 99 def indent ( c ) return @parser.parse( c ) end |