From 4dcdb0c79c041e59b2f1d810816e0b823bb83f65 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 13 Jul 2015 10:32:08 +0200 Subject: [PATCH 1/2] xBase: add .ch extension + sample --- lib/linguist/languages.yml | 1 + samples/xBase/sample.ch | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 samples/xBase/sample.ch diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 03a6c6df..85261f69 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3783,5 +3783,6 @@ xBase: color: "#403a40" extensions: - .prg + - .ch tm_scope: none ace_mode: text diff --git a/samples/xBase/sample.ch b/samples/xBase/sample.ch new file mode 100644 index 00000000..308f1e1c --- /dev/null +++ b/samples/xBase/sample.ch @@ -0,0 +1,30 @@ +#ifndef __HARBOUR__ + #ifndef __XPP__ + #ifndef __CLIP__ + #ifndef FlagShip + #define __CLIPPER__ + #endif + #endif + #endif +#endif + +/* File create flags */ +#define FC_NORMAL 0 /* No file attributes are set */ +#define FC_READONLY 1 +#define FC_HIDDEN 2 +#define FC_SYSTEM 4 + +// New-style comment +#command SET DELETED => Set( _SET_DELETED, <(x)> ) +#command SET DELETED () => Set( _SET_DELETED, ) +#command @ , SAY [PICTURE ] [COLOR ] => ; + DevPos( , ) ; DevOutPict( , [, ] ) + +#command ENDIF <*x*> => endif + +#ifdef __CLIPPER__ + #xtranslate hb_MemoWrit( [] ) => MemoWrit( ) + #xtranslate hb_dbExists( ) => File( ) + #xtranslate hb_dbPack() => __dbPack() + #xtranslate hb_default( @, ) => iif( StrTran( ValType( ), "M", "C" ) == StrTran( ValType( ), "M", "C" ),, := , ) +#endif From 6b747f7d65711dbc5816de644356c29450bc5d3a Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 21 Jul 2015 14:59:47 +0100 Subject: [PATCH 2/2] Adding Charity and heuristic for xBase .ch files --- lib/linguist/heuristics.rb | 6 ++++++ lib/linguist/languages.yml | 7 +++++++ samples/Charity/example.ch | 6 ++++++ test/test_heuristics.rb | 28 +++++++++++++++++----------- 4 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 samples/Charity/example.ch diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 23de1b02..d5b92457 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -333,5 +333,11 @@ module Linguist Language["GAS"] end end + + disambiguate "xBase", "Charity" do |data| + if /^\s*#\s*(if|ifdef|ifndef|define|command|xcommand|translate|xtranslate|include|pragma|undef)\b/i.match(data) + Language["xBase"] + end + end end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 9b48cc23..a734d452 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -501,6 +501,13 @@ Chapel: - .chpl ace_mode: text +Charity: + type: programming + extensions: + - .ch + tm_scope: none + ace_mode: text + ChucK: type: programming extensions: diff --git a/samples/Charity/example.ch b/samples/Charity/example.ch new file mode 100644 index 00000000..d3ee289b --- /dev/null +++ b/samples/Charity/example.ch @@ -0,0 +1,6 @@ +% +% Some very badly written Charity +% + +data LA(A) -> D = ss: A -> D + | ff: -> D. diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 010bf587..8914e4c2 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -22,6 +22,17 @@ class TestHeuristcs < Minitest::Test assert_equal [], results end + def assert_heuristics(hash) + candidates = hash.keys.map { |l| Language[l] } + + hash.each do |language, blobs| + Array(blobs).each do |blob| + result = Heuristics.call(file_blob(blob), candidates) + assert_equal [Language[language]], result, "Failed for #{blob}" + end + end + end + # Candidate languages = ["C++", "Objective-C"] def test_obj_c_by_heuristics # Only calling out '.h' filenames as these are the ones causing issues @@ -147,17 +158,6 @@ class TestHeuristcs < Minitest::Test }) end - def assert_heuristics(hash) - candidates = hash.keys.map { |l| Language[l] } - - hash.each do |language, blobs| - Array(blobs).each do |blob| - result = Heuristics.call(file_blob(blob), candidates) - assert_equal [Language[language]], result, "Failed for #{blob}" - end - end - end - def test_ls_by_heuristics assert_heuristics({ "LiveScript" => "LiveScript/hello.ls", @@ -171,4 +171,10 @@ class TestHeuristcs < Minitest::Test "XML" => all_fixtures("XML", "*.ts") }) end + + def test_ch_by_heuristics + assert_heuristics({ + "xBase" => all_fixtures("xBase") + }) + end end