diff options
| author | Seba Gamboa <[email protected]> | 2015-09-28 18:29:41 -0300 |
|---|---|---|
| committer | Seba Gamboa <[email protected]> | 2015-09-28 18:29:41 -0300 |
| commit | 73326c64a5e720f7d31b1e52ef9fda341895e800 (patch) | |
| tree | 065b8ed13fa31c8a910433fe41be8f1bbd213aac /lib/yard/mruby/parser | |
| parent | 2c3c127806e64ecc32b995913778252a2212c6a9 (diff) | |
| download | yard-mruby-73326c64a5e720f7d31b1e52ef9fda341895e800.tar.gz yard-mruby-73326c64a5e720f7d31b1e52ef9fda341895e800.zip | |
Handle #define directives
Diffstat (limited to 'lib/yard/mruby/parser')
| -rw-r--r-- | lib/yard/mruby/parser/c.rb | 1 | ||||
| -rw-r--r-- | lib/yard/mruby/parser/c/directive_statement.rb | 6 | ||||
| -rw-r--r-- | lib/yard/mruby/parser/c/header_parser.rb | 41 |
3 files changed, 48 insertions, 0 deletions
diff --git a/lib/yard/mruby/parser/c.rb b/lib/yard/mruby/parser/c.rb index 4d95fa1..13f5ef7 100644 --- a/lib/yard/mruby/parser/c.rb +++ b/lib/yard/mruby/parser/c.rb @@ -1,3 +1,4 @@ require_relative 'c/parser' require_relative 'c/source_parser' require_relative 'c/header_parser' +require_relative 'c/directive_statement' diff --git a/lib/yard/mruby/parser/c/directive_statement.rb b/lib/yard/mruby/parser/c/directive_statement.rb new file mode 100644 index 0000000..b146d17 --- /dev/null +++ b/lib/yard/mruby/parser/c/directive_statement.rb @@ -0,0 +1,6 @@ +module YARD::MRuby::Parser::C + class DirectiveStatement < YARD::Parser::C::Statement + attr_accessor :declaration + attr_accessor :comments + end +end diff --git a/lib/yard/mruby/parser/c/header_parser.rb b/lib/yard/mruby/parser/c/header_parser.rb index 598fe21..2b2dea7 100644 --- a/lib/yard/mruby/parser/c/header_parser.rb +++ b/lib/yard/mruby/parser/c/header_parser.rb @@ -1,5 +1,46 @@ module YARD::MRuby::Parser::C class HeaderParser < Parser + + # Consumes a directive and generates a DirectiveStatement + def consume_directive + super if @in_body_statements + + @newline = false + start = @index + line = @line + statement = DirectiveStatement.new(nil, @file, line) + @statements << statement + attach_comment(statement) + + multiline = false + advance_loop do + chr = char + case chr + when '\\'; multiline=true; advance + when /\s/; consume_whitespace + else advance + end + + if @newline + if multiline + multiline = false + else + break + end + end + end + + decl = @content[start...@index] + + statement.declaration = decl + end + + def consume_body_statements + @in_body_statements = true + result = super + @in_body_statements = false + result + end end # |
