Changeset cb9fc3d121e39e788a2874d98bcb25256263d7ff

Show
Ignore:
Timestamp:
06/30/2008 02:18:05 AM (2 months ago)
Author:
Fedor Korsakov <fedorkorsakov@fedor-korsakovs-computer.local>
git-committer:
Fedor Korsakov <fedorkorsakov@fedor-korsakovs-computer.local> 1214817485 -0500
git-parent:

[bbea41e6bfa5ff11ea5ffe165bab8bd107d215db]

git-author:
Fedor Korsakov <fedorkorsakov@fedor-korsakovs-computer.local> 1214817485 -0500
Message:

Merged with Mitchell's branch and resolved conflicts. Haml support remains rudimentary.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ext/ohcount_native/ragel_parser.c

    r676dc44 rcb9fc3d  
    1414#include "boo_parser.h" 
    1515#include "c_parser.h" 
     16#include "classic_basic_parser.h" 
    1617#include "clearsilver_parser.h" 
    1718#include "clearsilverhtml_parser.h" 
     
    2122#include "dylan_parser.h" 
    2223#include "ebuild_parser.h" 
     24#include "eiffel_parser.h" 
    2325#include "erlang_parser.h" 
    2426#include "exheres_parser.h" 
     
    2729#include "groovy_parser.h" 
    2830#include "haskell_parser.h" 
     31#include "haml_parser.h" 
    2932#include "html_parser.h" 
    3033#include "java_parser.h" 
     
    4043#include "mxml_parser.h" 
    4144#include "objective_c_parser.h" 
     45#include "ocaml_parser.h" 
    4246#include "pascal_parser.h" 
    4347#include "perl_parser.h" 
     
    5155#include "shell_parser.h" 
    5256#include "smalltalk_parser.h" 
     57#include "structured_basic_parser.h" 
    5358#include "sql_parser.h" 
    5459#include "tcl_parser.h" 
     
    8287  { "boo", parse_boo }, 
    8388  { "c", parse_c }, 
     89  { "classic_basic", parse_classic_basic }, 
    8490  { "clearsilver", parse_clearsilver }, 
    8591  { "clearsilver_template", parse_cshtml }, 
     
    9197  { "dylan", parse_dylan }, 
    9298  { "ebuild", parse_ebuild }, 
     99  { "eiffel", parse_eiffel }, 
    93100  { "erlang", parse_erlang }, 
    94101  { "exheres", parse_exheres }, 
     
    98105  { "groovy", parse_groovy }, 
    99106  { "haskell", parse_haskell }, 
     107  { "haml", parse_haml }, 
    100108  { "html", parse_html }, 
    101109  { "java", parse_java }, 
     
    111119  { "mxml", parse_mxml }, 
    112120  { "objective_c", parse_objective_c }, 
     121  { "ocaml", parse_ocaml }, 
    113122  { "pascal", parse_pascal }, 
    114123  { "perl", parse_perl }, 
     
    123132  { "shell", parse_shell }, 
    124133  { "smalltalk", parse_smalltalk }, 
     134  { "structured_basic", parse_structured_basic }, 
    125135  { "sql", parse_sql }, 
    126136  { "tcl", parse_tcl }, 
  • ext/ohcount_native/ragel_parsers/haskell.rl

    r0b4bd62 rcb9fc3d  
    4545  } 
    4646 
     47  action haskell_comment_nc_res { nest_count = 0; } 
     48  action haskell_comment_nc_inc { nest_count++; } 
     49  action haskell_comment_nc_dec { nest_count--; } 
     50 
    4751  # TODO: |-- is not a comment 
    4852  haskell_line_comment = '--' [^>] @{ fhold; } @comment nonnewline*; 
    49   haskell_block_comment = 
    50     '{-' @comment ( 
     53  haskell_nested_block_comment = 
     54    '{-' >haskell_comment_nc_res @comment ( 
    5155      newline %{ entity = INTERNAL_NL; } %haskell_ccallback 
    5256      | 
    5357      ws 
     58      | 
     59      '{-' @haskell_comment_nc_inc @comment 
     60      | 
     61      '-}' @haskell_comment_nc_dec @comment 
    5462      | 
    5563      (nonnewline - ws) @comment 
    56     )* :>> '-}'
    57   haskell_comment = haskell_line_comment | haskell_block_comment; 
     64    )* :>> ('-}' when { nest_count == 0 }) @comment
     65  haskell_comment = haskell_line_comment | haskell_nested_block_comment; 
    5866 
    5967  haskell_char = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline) '\''; 
     
    105113  init 
    106114 
     115  int nest_count = 0; 
     116 
    107117  %% write init; 
    108118  cs = (count) ? haskell_en_haskell_line : haskell_en_haskell_entity; 
  • ext/ohcount_native/ragel_parsers/visual_basic.rl

    r242cbc6 rcb9fc3d  
    4545  } 
    4646 
    47   vb_comment = '\'' @comment nonnewline*; 
     47  vb_comment = ('\'' | /rem/i) @comment nonnewline*; 
    4848 
    4949  vb_string = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"'; 
  • lib/ohcount/detector.rb

    r1fabcc0 rcb9fc3d  
    2727    # is stored here to avoid checking twice. 
    2828    attr_accessor :contains_pike_or_pmod 
     29  end 
     30 
     31  module ContainsVB 
     32    # A performance hack -- once we've checked for the presence of *.frx, *.frm and *.vbp files, the result 
     33    # is stored here to avoid checking twice. 
     34    attr_accessor :contains_vb 
    2935  end 
    3036 
     
    110116    '.asm'  => "assembler", 
    111117    '.awk'  => "awk", 
    112     '.bas'  => "visualbasic", 
     118    '.b'    => :disambiguate_non_visual_basic, 
     119    '.bas'  => :disambiguate_basic, 
    113120    '.bat'  => "bat", 
     121    '.bi'   => :disambiguate_non_visual_basic, 
    114122    '.boo'  => "boo", 
    115123    '.c'    => "c", 
     
    126134    '.cs'   => :disambiguate_cs, 
    127135    '.dylan'=> "dylan", 
     136    '.e'    => "eiffel", 
    128137    '.ebuild'=> "ebuild", 
    129138    '.eclass'=> "ebuild", 
     
    147156    '.h'    => :disambiguate_h_header, 
    148157    '.H'    => "cpp", 
     158    '.haml' => "haml", 
    149159    '.hpp'  => "cpp", 
    150160    '.h++'  => "cpp", 
     
    166176    '.mf'   => 'metafont', 
    167177    '.mk'   => 'make', 
     178    '.ml'   => "ocaml", 
     179    '.mli'  => "ocaml", 
    168180    '.mm'   => "objective_c", 
    169181    '.mp'   => 'metapost_with_tex', 
     
    492504  end 
    493505 
     506  # Attempts to tell apart VB, classic BASIC and structured BASIC. 
     507  # First, checks if it is classic BASIC based on syntax. 
     508  # If not checks for .vb, .vbp, .frx and .frm files (associated with VB) 
     509  # in file context 
     510  # 
     511  # If these files are absent, assumes structured BASIC 
     512  # 
     513  def self.disambiguate_basic(file_context) 
     514    classic_basic_line = /^\d+\s+\w+.*$/ 
     515    vb_filename = /\.fr[mx]$|\.vb([aps]?)$/ 
     516    buffer = file_context.contents 
     517    if lines_matching(buffer,classic_basic_line) > 0 
     518      return 'classic_basic' 
     519    else 
     520      unless defined?(file_context.filenames.contains_vb) 
     521        file_context.filenames.extend(ContainsVB) 
     522        file_context.filenames.contains_vb = file_context.filenames.select { |a| a =~ vb_filename }.any? 
     523      end 
     524      if file_context.filenames.contains_vb 
     525        return 'visualbasic' 
     526      else 
     527        return 'structured_basic' 
     528      end 
     529    end 
     530  end 
     531 
     532  def self.disambiguate_non_visual_basic(file_context) 
     533    classic_basic_line = /^\d+\s+\w+.*$/ 
     534    buffer = file_context.contents 
     535 
     536    if lines_matching(buffer,classic_basic_line) > 0 
     537      return 'classic_basic' 
     538    else 
     539      return 'structured_basic' 
     540    end 
     541  end 
     542 
    494543  # Attempts to determine the Polyglot for files that do not have a 
    495544  # filename extension. 
  • lib/ohcount/sloc_info.rb

    r5bdc29e rcb9fc3d  
    4949      'boo'           => {:nice_name => 'Boo'              , :category => 0}, 
    5050      'c'             => {:nice_name => 'C'                , :category => 0}, 
     51      'classic_basic'   => {:nice_name => 'Classic Basic'     , :category => 0}, 
    5152      'cpp'           => {:nice_name => 'C++'              , :category => 0}, 
    5253      'clearsilver'   => {:nice_name => 'ClearSilver'      , :category => 0}, 
     
    5657      'dylan'         => {:nice_name => 'Dylan'            , :category => 0}, 
    5758      'ebuild'        => {:nice_name => 'Ebuild'           , :category => 0}, 
     59      'eiffel'        => {:nice_name => 'Eiffel'           , :category => 0}, 
    5860      'emacslisp'     => {:nice_name => 'Emacs Lisp'       , :category => 0}, 
    5961      'erlang'        => {:nice_name => 'Erlang'           , :category => 0}, 
     
    7375      'mxml'          => {:nice_name => 'Flex'             , :category => 1}, 
    7476      'objective_c'   => {:nice_name => 'Objective C'      , :category => 0}, 
     77      'ocaml'         => {:nice_name => 'Objective Caml'   , :category => 0}, 
    7578      'pascal'        => {:nice_name => 'Pascal'           , :category => 0}, 
    7679      'perl'          => {:nice_name => 'Perl'             , :category => 0}, 
     
    8487      'shell'         => {:nice_name => 'shell script'     , :category => 0}, 
    8588      'smalltalk'     => {:nice_name => 'Smalltalk'        , :category => 0}, 
     89      'structured_basic'   => {:nice_name => 'Structured Basic'     , :category => 0}, 
    8690      'sql'           => {:nice_name => 'SQL'              , :category => 0}, 
    8791      'tcl'           => {:nice_name => 'Tcl'              , :category => 0}, 
  • test/unit/detector_test.rb

    r53b5981 rcb9fc3d  
    2323  def do_detect(filename, filenames = []) 
    2424    file_location = File.dirname(__FILE__) + "/../detect_files/" + filename 
     25    sfc = Ohcount::SimpleFileContext.new(filename, filenames, nil, file_location) 
     26    Ohcount::Detector.detect(sfc) 
     27  end 
     28 
     29  # Nonrecursively adds files from the file's directory to the context 
     30  def do_detect_with_siblings(filename) 
     31    file_location = File.dirname(__FILE__) + "/../detect_files/" + filename 
     32    filenames = Dir.entries(File.dirname(__FILE__) + File.dirname("/../detect_files/" + filename)) - [filename] 
    2533    sfc = Ohcount::SimpleFileContext.new(filename, filenames, nil, file_location) 
    2634    Ohcount::Detector.detect(sfc) 
     
    6169    assert_equal "exheres", do_detect("foo.exheres-0") 
    6270    assert_equal "exheres", do_detect("foo.exlib") 
     71    assert_equal "eiffel", do_detect("eiffel.e") 
     72    assert_equal "ocaml", do_detect("ocaml.ml") 
    6373  end 
    6474 
     
    8999  end 
    90100 
     101  def test_basic 
     102    assert_equal "structured_basic", do_detect("visual_basic.bas") 
     103    assert_equal "visualbasic", do_detect("visual_basic.bas", ["frx1.frx"]) 
     104    assert_equal "classic_basic", do_detect("classic_basic.b") 
     105    assert_equal "structured_basic", do_detect("structured_basic.b")     
     106  end 
     107 
    91108end 
    92109 
  • test/unit/haskell_test.rb

    r5a0bfaf rcb9fc3d  
    1717                verify_parse("haskell2.hs") 
    1818        end 
     19         
     20        def test_comprehensive_with_nested_comments 
     21                verify_parse("haskell3.hs") 
     22        end 
    1923end 
    2024