Skip to content

Commit

Permalink
Add Genie samples and improve heuristics (github-linguist#5021)
Browse files Browse the repository at this point in the history
Samples:

* Genie/web.gs
  * Source: https://github.com/korylprince/WebKiosk/blob/22c6c656ba8080451167c4d52d950fc75b9844df/web.gs
  * License: Public Domain
* Genie/IDataLoader.gs
  * Source: https://github.com/darkoverlordofdata/liboverlap2d/blob/53f66d46e3d992bdb303f356b919d3c1ef66d0ea/src/resources/IDataLoader.gs
  * License: Apache 2

Improve Gosu heuristic and add Genie heuristic for the common
`[indent=\d+\]` construct.

Co-authored-by: Colin Seymour <[email protected]>
  • Loading branch information
smola and lildude authored Oct 16, 2020
1 parent b3664e4 commit 5d876c1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ disambiguations:
- language: GLSL
pattern: '^#version\s+[0-9]+\b'
- language: Gosu
pattern: '^uses java\.'
pattern: '^uses (java|gw)\.'
- language: Genie
pattern: '^\[indent=[0-9]+\]'
- extensions: ['.h']
rules:
- language: Objective-C
Expand Down
18 changes: 18 additions & 0 deletions samples/Genie/IDataLoader.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* IDataLoader.gs
*
*
*
*/
[indent=4]
uses Gee
uses sdx
uses sdx.math
uses sdx.graphics.s2d
uses o2d.data

namespace o2d.resources

interface IDataLoader : Object
def abstract loadSceneVO(sceneName: string): SceneVO
def abstract loadProjectVO(): ProjectInfoVO
76 changes: 76 additions & 0 deletions samples/Genie/web.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[indent=4]
// valac --pkg gtk+-3.0 --pkg webkitgtk-3.0 web.gs

uses
Gtk
WebKit

class ValaBrowser : Window

webview: WebView
button: ToolButton
spinner: Spinner

init
window_position = WindowPosition.CENTER
set_default_size(1024, 768)
create_widgets()
connect_signals ()
webview.grab_focus ()
var settings = new WebSettings()
settings.set("enable-default-context-menu",false)
webview.set_settings(settings)

def create_widgets () : void
var toolbar = new Toolbar ()
toolbar.set_style(ToolbarStyle.BOTH)
toolbar.get_style_context().add_class(STYLE_CLASS_PRIMARY_TOOLBAR)
this.button = new ToolButton(null,"Refresh")
toolbar.add (this.button)
this.webview = new WebView ()
this.spinner = new Spinner()
this.spinner.set_margin_left(5)
this.spinner.set_margin_right(5)
this.spinner.set_margin_bottom(5)
this.spinner.set_margin_top(5)
this.spinner.start()
var fixed = new Fixed()
fixed.add(this.spinner)
fixed.set_halign(Align.START)
fixed.set_valign(Align.END)
var overlay = new Overlay()
overlay.add(this.webview)
overlay.add_overlay(fixed)
var vbox = new Box (Orientation.VERTICAL, 0)
vbox.pack_start (toolbar, false, true, 0)
vbox.pack_start(overlay,true,true,0)
add (vbox)


def connect_signals () : void
this.destroy.connect (Gtk.main_quit)
this.button.clicked.connect (this.start)
this.webview.document_load_finished.connect(this.loaded)
this.webview.load_started.connect(this.started)


def start () : void
show_all ()
//URL to show
this.webview.open ("https://google.com")


def loaded () : void
this.spinner.hide()
//Use the next command to run some javascript on page load
//this.webview.execute_script("$('body').show()")

def started () : void
show_all()

def main (arg: array of string[]) : int
Gtk.init (ref arg)
var browser = new ValaBrowser ()
browser.start ()
Gtk.main ()
return 0
8 changes: 6 additions & 2 deletions test/test_heuristics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,18 @@ def test_gml_by_heuristics
})
end

# Candidate languages = ["Genie", "GLSL", "Gosu", "JavaScript"]
def test_gs_by_heuristics
ambiguous = [
"#{samples_path}/Genie/Class.gs",
"#{samples_path}/Genie/Hello.gs",
]
assert_heuristics({
"GLSL" => all_fixtures("GLSL", "*.gs"),
"Genie" => all_fixtures("Genie", "*.gs") - ambiguous,
"Gosu" => all_fixtures("Gosu", "*.gs"),
})
assert_heuristics({
nil => all_fixtures("Genie", "*.gs") + all_fixtures("JavaScript")
nil => all_fixtures("JavaScript")
}, alt_name="test.gs")
end

Expand Down

0 comments on commit 5d876c1

Please sign in to comment.