Compare commits

...

222 Commits

Author SHA1 Message Date
Rick Bradley
0c6f4383a7 Merge pull request #1075 from github/release-2.10.12
cut a 2.10.12 release
2014-04-17 13:26:12 -07:00
Rick Bradley
97908204a3 2.10.12 2014-04-17 11:28:15 -05:00
Brandon Keepers
b6d0a41718 Merge pull request #1063 from lucaswerkmeister/patch-1
Add .osm extension for XML
2014-04-16 09:57:21 -04:00
Lucas Werkmeister
3f96bcc32b Add .osm extension for XML
The OpenStreetMap project (openstreetmap.org) uses the .osm extension for the OSM XML format (http://wiki.openstreetmap.org/wiki/OSM_XML).
2014-04-14 10:07:15 +02:00
Ted Nyman
f39456ee47 Merge pull request #991 from waywardmonkeys/improve-dylan-support
Add .lid and .intr extensions for Dylan.
2014-03-15 18:13:41 -07:00
Bruce Mitchener
957dd15d5b Add .lid and .intr extensions for Dylan. 2014-03-14 22:03:31 +07:00
Ted Nyman
2e731a1084 Merge pull request #978 from cronycle/master
added VCR Cassette to the 'generated' list so they get suppressed
2014-03-13 14:37:25 -07:00
Ted Nyman
38bd07a113 Merge pull request #832 from dasmithii/patch-2
Updated language list to include HOW, and fixed the lack of lexer proble...
2014-03-11 20:24:07 -07:00
Douglas Adam Smith II
645411e256 Testing... 2014-03-11 14:23:28 -04:00
Douglas Adam Smith II
29510b26e0 Fix 2014-03-11 14:00:49 -04:00
Douglas Adam Smith II
e4c1cc572b Fixed order of languages. Forgot how ASCI works.
This will (hopefully) fix the build.
2014-03-11 13:51:16 -04:00
Douglas Adam Smith II
7c85c11944 Updated How language to FLUX (name change) 2014-03-11 13:38:10 -04:00
Ted Nyman
5318402be5 Merge pull request #981 from cjxgm/patch-1
add extension .cc for c++
2014-03-09 04:21:02 -07:00
eXerigumo Clanjor (哆啦比猫/兰威举)
8323450958 add extension .cc for c++ 2014-03-09 16:12:30 +08:00
Nayeem Syed
68793b1f0f added check for extension and line count on vcr_cassette? in generated 2014-03-08 08:12:18 +00:00
Ted Nyman
c6e3c8fab8 Merge pull request #963 from mbezjak/vendor-gradle
Add gradle wrapper files to vendor.yml
2014-03-07 20:46:46 -08:00
Nayeem Syed
210ca9a86f added VCR Cassette to the 'generated' list so they get suppressed 2014-03-06 12:00:54 +00:00
Ted Nyman
ff9e0aedd6 Merge pull request #854 from cndreisbach/patch-1
Adding support for Hoplon files
2014-03-05 18:31:54 -08:00
Ted Nyman
115ac6b999 Merge pull request #938 from tenbits/master
Add Mask markup language
2014-03-03 15:10:34 -08:00
Ted Nyman
5715802999 Merge pull request #971 from veganstraightedge/master
Added Gemfile.lock to the list of Ruby filenames
2014-02-26 14:48:44 -08:00
Shane Becker
8b00872d36 Added Gemfile.lock to the list of Ruby filenames 2014-02-26 02:15:08 -08:00
Ted Nyman
c67c8a7482 Merge pull request #967 from jaaso/master
Added Shen programming language
2014-02-25 13:18:46 -08:00
saarin
78217e1cee Add shen language in linguist 2014-02-23 05:22:39 +01:00
Ted Nyman
86364da07e Regenerate samples 2014-02-21 13:50:54 -08:00
Miro Bezjak
92e1b1eb40 Add gradle wrapper files to vendor.yml 2014-02-21 11:27:47 +01:00
Ted Nyman
a34398eb92 Merge pull request #935 from pchaigno/sld
Support of the .sld file extension for Scheme.
2014-02-20 15:32:52 -08:00
Ted Nyman
2f6035cd1e Merge pull request #957 from github/adding-jsonld
Adding support for JSONLD: http://json-ld.org/
2014-02-19 22:01:34 -08:00
Arfon Smith
e437cf749d Adding support for JSONLD: http://json-ld.org/ 2014-02-18 15:28:22 -06:00
Ted Nyman
5218b60681 Merge pull request #952 from github/applescript-interpreter
Add interpreter for AppleScript
2014-02-17 11:51:54 -08:00
Ivan Zuzak
8afe123084 add interpreter for applescript 2014-02-17 17:08:51 +01:00
Ted Nyman
69bfe73165 Not yet on the additional binary check 2014-02-16 19:43:33 -08:00
Ted Nyman
3429ddeaa1 Standard regex 2014-02-16 19:41:45 -08:00
Ted Nyman
9242a2f83b Merge pull request #923 from kasoki/master
add haxelib run.n neko bytecode file to vendor list
2014-02-16 19:40:24 -08:00
Ted Nyman
b0894e20ef Merge pull request #301 from andyli/binary
Do not detect language if it is a binary file.
2014-02-16 14:55:07 -08:00
Ted Nyman
0cc47dd47d Merge pull request #944 from midraed/patch-1
added .rsx extension to R languge
2014-02-14 18:45:23 -08:00
Guillermo Federico Olmedo
fdbfd8b806 Added sample of R qgis script 2014-02-14 14:53:14 -02:00
Guillermo Federico Olmedo
9f3ee8dff6 added .rsx extension to R.
When we write R extensions for QGIS we have to end the files in .rsx [1]. But the code its pure R. It would be great if github acknowledge those scripts as R scripts.

[1] http://www.qgis.org/es/docs/user_manual/processing/3rdParty.html#r-creating-r-scripts
2014-02-14 13:42:18 -02:00
Ted Nyman
166012dcf0 Merge pull request #911 from bbarker/master
Added ATS to language list and several samples (try #2).
2014-02-13 15:18:33 -08:00
Alex Kit
bb754d8849 .mask support for Mask 2014-02-13 03:47:56 +01:00
Paul Chaignon
0eaaa2bacc Support of the .sld file extension for Scheme. 2014-02-11 13:39:50 +01:00
Ted Nyman
a1eab2a439 Merge pull request #916 from pchaigno/ecl
Support of the .ecl file extension for Prolog.
2014-02-09 15:34:07 -08:00
Ted Nyman
0cfcb6917b Minor README 2014-02-06 13:18:02 -08:00
Christopher Kaster
03ce24221e add haxelib run.n neko bytecode file to vendor list 2014-02-04 19:00:33 +01:00
Paul Chaignon
f78ce5389e Support of the .ecl file extension for Prolog. 2014-02-01 15:47:51 +01:00
Ted Nyman
dd32b8f441 Merge pull request #913 from larsbrinkhoff/cl
Add heuristics for .cl
2014-01-28 19:06:10 -08:00
Lars Brinkhoff
39a9c768c8 Add heuristics for '.cl'. 2014-01-28 09:20:26 +01:00
Ted Nyman
ff257175ac Merge pull request #909 from github/coffescript-interpreters
Add interpreter for CoffeeScript
2014-01-26 10:06:18 -08:00
Brandon
877ee775a3 adding more varied examples, including an .atxt file 2014-01-25 17:55:28 -05:00
Ted Nyman
19e151390e Merge pull request #910 from abuiles/es6
Add .es6 as JavaScript extension.
2014-01-25 14:09:47 -08:00
Brandon
7da9038e79 fixed extension order in languages.yml 2014-01-25 15:17:52 -05:00
Brandon
1f8ef83657 Merge remote-tracking branch 'upstream/master' 2014-01-25 12:09:11 -05:00
Brandon
2770e4e111 adding ATS and several sample files 2014-01-25 12:09:00 -05:00
Adolfo Builes
96dfbc71eb Add .es6 as JavaScript extension. 2014-01-25 14:26:24 -02:00
Ivan Zuzak
9076086d9b add interpreter for coffescript 2014-01-24 20:46:51 +01:00
Ted Nyman
dc76ca7e37 Travis settings 2014-01-24 08:49:17 -08:00
Ted Nyman
7ee2b60762 Merge pull request #906 from Cirru/master
add Cirru with some samples
2014-01-24 08:47:53 -08:00
Ted Nyman
e3a9395b4c Merge pull request #907 from github/groovy-interpreters
Add interpreter for Groovy language
2014-01-24 08:44:29 -08:00
Ivan Zuzak
83513977a4 add interpreter for groovy language 2014-01-24 11:42:55 +01:00
jiyinyiyong
42912141c5 add Cirru with some samples 2014-01-23 19:52:58 +08:00
Ted Nyman
8561ece4d7 Minor README 2014-01-20 23:33:04 -08:00
Ted Nyman
b91738721b Remove travis fix 2014-01-15 23:56:21 -08:00
Ted Nyman
123f4c26c3 Typescript vendor fixup 2014-01-15 16:15:30 -08:00
Ted Nyman
1bbf75b5ab Merge pull request #896 from sigurdsvela/master
Ignore typescript definition files.
2014-01-15 16:14:52 -08:00
sigurdsvela
70e56303ab Ignore typescript definition files. 2014-01-15 15:57:06 +01:00
Ted Nyman
ec2e3428ec 2.10.11 2014-01-14 15:33:35 -08:00
Ted Nyman
f8601dd663 Merge pull request #892 from edechter/master
Add .pl as prolog extension. Test sample already exists.
2014-01-14 15:30:41 -08:00
Eyal Dechter
df5faa0f21 Whitespace. 2014-01-14 10:09:40 -05:00
Eyal Dechter
8341992a38 Add .pl as extension for prolog. This is the standard prolog file extension. No one actually uses .prolog. 2014-01-14 10:07:27 -05:00
Ted Nyman
6a8d54e983 Merge pull request #890 from mihneadb/patch-1
Add foundation css to vendor.yml
2014-01-13 13:53:49 -08:00
Mihnea Dobrescu-Balaur
a18155da49 Add foundation css to vendor.yml 2014-01-13 23:28:33 +02:00
Ted Nyman
2a1e850924 Merge pull request #759 from vszakats/patch-3
recognize Harbour sources
2014-01-12 20:15:29 -08:00
Ted Nyman
528adc1a04 Minor documentation 2014-01-11 14:19:46 -08:00
Ted Nyman
9e7b1bf3cb Merge pull request #888 from rognierbenoit/patch-1
adds .ml4 extension for ocaml
2014-01-09 15:11:03 -08:00
Benoit Rognier
a517de8168 moves .ml4 ocaml extension before .mli
This should fix non reg tests
2014-01-09 14:54:15 +01:00
Benoit Rognier
a4ab7555e2 adds ml4 as ocaml extension 2014-01-08 14:40:41 +01:00
Ted Nyman
b666123f8e Version 2.10.10 2014-01-06 12:02:39 -08:00
Ted Nyman
8e36ddbafe Regenerate samples 2014-01-06 12:01:53 -08:00
Ted Nyman
abd0c47838 More C samples 2014-01-06 12:00:58 -08:00
Ted Nyman
8625f91b1b Merge pull request #886 from ruben2020/master
Fix for *.ts conflict between TypeScript and Qt Translation files
2014-01-04 13:51:42 -08:00
Ted Nyman
6c6b07fc68 Merge pull request #885 from GiampaoloFalqui/master
Add PAWN language
2014-01-04 13:50:37 -08:00
ruben2020
f5a6f20af0 renamed Qt translation ts file to have XML ext and updated test_heuristics.rb 2014-01-04 23:14:58 +08:00
ruben2020
76ee294c29 Removing second ts from languages.yml, but adding to test code for heuristics 2014-01-04 23:01:17 +08:00
ruben2020
77bff8fd6a *.ts conflict between TypeScript and Qt translation files: attempting roll back of samples.json 2014-01-04 22:04:53 +08:00
ruben2020
40b2e19310 Fix for *.ts conflict between TypeScript and Qt Translation files 2014-01-04 21:32:16 +08:00
Giampaolo Falqui
aaf281ec0e PAWN .inc extension & sample removed 2014-01-04 13:24:38 +01:00
Giampaolo Falqui
82bc320843 Add PAWN language 2014-01-04 01:39:49 +01:00
Arfon Smith
1f38db61df Merge pull request #884 from jmromer/add-tex-cls-extension
Add tex cls extension
2014-01-03 14:38:13 -08:00
Arfon Smith
db20462481 Merge pull request #834 from berkerpeksag/add-hy
Add Hy language.
2014-01-03 14:35:50 -08:00
Jake Romer
79be60bf8f adds cls file sample 2014-01-03 16:30:15 -05:00
Jake Romer
d57ff3abd6 adds latex cls extension 2014-01-03 16:29:20 -05:00
Ted Nyman
cd6c315fc8 Merge pull request #783 from jimhester/master
Add r alias
2014-01-02 18:55:10 -08:00
Ted Nyman
60bc772d48 New year 2014-01-02 12:17:28 -08:00
Jim Hester
7ad99baf32 Add check for R alias 2014-01-02 13:39:19 -05:00
Ted Nyman
252ae63854 Merge pull request #880 from emma-burrows/VBnet-samples
VB.net samples
2014-01-01 12:06:58 -08:00
Emma Burrows
7e3a9434ef Updated sample.json to include VB.Net samples 2014-01-01 17:35:45 +00:00
Emma Burrows
f388daab39 Added Visual Basic .NET sample files (a console code file and a Razor vbhtml file) 2013-12-31 19:20:21 +00:00
Berker Peksag
89f4885b62 Add Hy language.
Hy is a dialect of Lisp that’s embedded in Python.
2013-12-31 14:43:29 +02:00
Ted Nyman
23a1ae5085 Merge pull request #878 from kevmoo/master
updated Dart sample to align with best practices
2013-12-30 19:20:28 -08:00
Kevin Moore
9cd6d6f001 updated Dart sample to align with best practices 2013-12-30 16:39:25 -08:00
Ted Nyman
a15ed48377 Regenerate samples 2013-12-30 14:41:28 -08:00
Ted Nyman
f5e8671481 Merge pull request #877 from emma-burrows/Csharp-samples
Csharp samples, including ASP.Net MVC view file
2013-12-30 14:40:50 -08:00
Emma Burrows
614f4f31ed Merge branch 'Csharp-samples' of https://github.com/emma-burrows/linguist into Csharp-samples 2013-12-30 22:32:57 +00:00
Emma Burrows
95c8405e0c Corrected order of C# file extentions 2013-12-30 22:31:52 +00:00
Emma Burrows
e6baa1d690 Updated sample.json to include C# samples 2013-12-30 22:06:16 +00:00
Emma Burrows
928409a355 Added cshtml extention for C# ASP.Net MVC Views. 2013-12-30 21:46:30 +00:00
Emma Burrows
86c9c9f6f3 Added a C# console file and cshtml Razor MVC View file. 2013-12-30 21:24:14 +00:00
Ted Nyman
49f29a53c0 Nicer breakdown output 2013-12-29 23:56:13 -08:00
Arfon Smith
40c04c8f6f travis/bundler fix 2013-12-29 19:27:20 -08:00
Arfon Smith
800d26cdad Adding Perl heuristic (and fixing up Prolog) 2013-12-29 19:22:31 -08:00
Ted Nyman
016f9852d6 Update prolog samples 2013-12-29 12:24:02 -08:00
Ted Nyman
fbcad41813 2.10.9 2013-12-29 12:15:44 -08:00
Ted Nyman
cdf6fb4a22 Initialize breakdown hash 2013-12-29 02:55:17 -08:00
Ted Nyman
9dc7329601 Merge pull request #873 from github/debug
fix refactoring from #836
2013-12-29 02:51:37 -08:00
Patrick Reynolds
bd4204b89e fix refactoring from #836 2013-12-29 01:32:56 -06:00
Ted Nyman
bbf0e65c74 No need for the extra check 2013-12-28 20:09:54 -08:00
Ted Nyman
b7e2f7cff9 Clearer naming 2013-12-28 20:00:11 -08:00
Ted Nyman
f9e50f4826 Minor README 2013-12-28 19:58:36 -08:00
Ted Nyman
184095cc02 Clarify README for new options 2013-12-28 19:57:39 -08:00
Ted Nyman
6a78ac61a7 Add --breakdown option for linguist binary 2013-12-28 19:56:41 -08:00
Ted Nyman
b498d51889 Add another breakdown_by_file assertion 2013-12-28 19:45:40 -08:00
Ted Nyman
7fb16b7abe More README 2013-12-28 19:42:03 -08:00
Ted Nyman
7bfdd4086e Update README for new output 2013-12-28 19:41:06 -08:00
Ted Nyman
dd27ddda17 Fixup output 2013-12-28 19:40:02 -08:00
Ted Nyman
b5181488a0 Merge pull request #872 from github/file-breakdown
Add support for stats breakdown by file per repo
2013-12-28 19:32:54 -08:00
Ted Nyman
001068ec75 Add test for language breakdown 2013-12-28 19:29:55 -08:00
Ted Nyman
e660442e2e Add support for stats breakdown by file per repo 2013-12-28 19:22:13 -08:00
Ted Nyman
f7b7a89709 Start towards pl heuristics 2013-12-28 18:06:04 -08:00
Ted Nyman
f46a895ae3 Merge pull request #870 from joshterrell805/patch-1
Add .njs as a Javascript extension
2013-12-28 13:06:20 -08:00
Josh Terrell
da396d4c28 Add .njs as a Javascript extension
.njs is an extension used to denote node javascript files.

Fixes https://github.com/github/linguist/issues/865
2013-12-27 14:20:37 -08:00
Ted Nyman
93556449c9 Merge pull request #868 from ktdreyer/gemspec
update gemspec metadata
2013-12-27 13:54:19 -08:00
Ken Dreyer
813c150918 add description metadata to gemspec 2013-12-27 14:14:04 -07:00
Ken Dreyer
3ced5ec784 add MIT license metadata to gemspec 2013-12-27 13:21:44 -07:00
Ted Nyman
cdde9096da More test_markup 2013-12-26 19:36:27 -08:00
Ted Nyman
2cb2194686 Add test_prose 2013-12-26 19:35:19 -08:00
Ted Nyman
6ae12cd0be Merge pull request #864 from natebrennand/master
add AngularJS to the vendored list
2013-12-24 13:43:13 -08:00
Nate Brennand
a3e1420476 add AngularJS to the vendored list 2013-12-24 02:05:10 -08:00
Ted Nyman
66a2d5fa2e Merge pull request #862 from wadetandy/master
Add vendor patterns for bower_components files
2013-12-23 20:55:19 -08:00
Wade Tandy
582daf273a Add vendor patterns for bower_components files
Adds Bower Component files to the vendored files list.  This
uses the `bower_components` directory, which is the standard set by the
Bower package manager.
2013-12-23 21:36:55 -05:00
Ted Nyman
310a804507 Add lua interpreter 2013-12-23 18:11:02 -08:00
Ted Nyman
5e4b860fb7 2.10.8 2013-12-23 17:38:54 -08:00
Ted Nyman
86f78792c4 Regenerate samples 2013-12-23 17:37:57 -08:00
Ted Nyman
064c62b587 Remove extra gosu sample 2013-12-23 17:37:05 -08:00
Ted Nyman
7f34de90c6 More ignored files 2013-12-23 17:31:52 -08:00
Ted Nyman
7fb389fda3 Just use primary extension here 2013-12-23 17:24:32 -08:00
Ted Nyman
85e4c58aeb Merge pull request #861 from github/add_crystal
Add crystal
2013-12-23 13:02:55 -08:00
Arfon Smith
de47a28ca0 Merge pull request #860 from github/extending_standard_ml
Extending standard ml
2013-12-23 13:02:18 -08:00
Arfon Smith
0f42d35f29 Merge branch 'pr/678' into add_crystal
Conflicts:
	lib/linguist/languages.yml
2013-12-23 14:58:35 -06:00
Arfon Smith
d51df2aef3 Adding .fun extension to Standard ML definition and adding some sample files 2013-12-23 14:50:39 -06:00
Arfon Smith
0c02bd18db Merge branch 'pr/520' into standard_ml 2013-12-23 14:39:37 -06:00
Arfon Smith
75276c8380 Regenerating samples.json 2013-12-23 14:37:25 -06:00
Ted Nyman
442aa4ed33 Merge pull request #859 from github/postscript_support
Postscript support
2013-12-23 12:33:51 -08:00
Arfon Smith
1ab8c8da53 Merge branch 'pr/804' into postscript_support
Conflicts:
	lib/linguist/generated.rb
2013-12-23 14:25:33 -06:00
Ted Nyman
f03201209f Merge pull request #858 from github/perl_6
Perl 6
2013-12-23 11:58:12 -08:00
Arfon Smith
d79d535182 Merge branch 'master' into perl_6
Conflicts:
	lib/linguist/samples.json
2013-12-23 13:52:37 -06:00
Arfon Smith
01dc7e2294 Removing non-Perl 6 specific extensions 2013-12-23 13:50:22 -06:00
Arfon Smith
b2d1917fa0 Merge branch 'pr/750' into perl_6
Conflicts:
	lib/linguist/samples.json
2013-12-23 13:49:20 -06:00
Ted Nyman
ca9ca29cc9 Merge pull request #857 from github/idl_support
Idl support
2013-12-23 11:47:33 -08:00
Arfon Smith
1ea21fbb8d Removing .pro extension for prolog 2013-12-23 13:37:21 -06:00
Arfon Smith
46274496d6 Merge branch 'master' into idl_support
Conflicts:
	lib/linguist/samples.json
2013-12-23 13:10:34 -06:00
Arfon Smith
16f1f87a8e Updating samples to include IDL 2013-12-23 13:09:00 -06:00
Ted Nyman
7847e17735 Merge pull request #856 from ChimeraCoder/master
Ignore non-minified bootstrap files
2013-12-23 11:06:03 -08:00
Ted Nyman
8cacd10210 Regenerate samples 2013-12-23 11:05:10 -08:00
Aditya Mukerjee
9a6446bae3 Fix typo 2013-12-23 14:04:39 -05:00
Ted Nyman
f6034b85fb Remove prolog samples for now and rely on .prolog extension 2013-12-23 11:04:26 -08:00
Arfon Smith
55c24a30df Merge branch 'pr/425' into idl_support 2013-12-23 13:01:11 -06:00
Aditya Mukerjee
88afdac5d2 Ignore non-minified bootstrap files
* bootstrap.min.js is already excluded, but bootstrap.js is not.
2013-12-23 13:30:03 -05:00
Ted Nyman
c5e9023762 Merge pull request #850 from github/cpp_heuristic
A C++ shibboleth?
2013-12-23 10:20:36 -08:00
Ted Nyman
b7d23efc1b Include SCSS as detectable markup 2013-12-23 10:05:36 -08:00
Arfon Smith
300d47b36b Regenerating samples.json and bringing C++ heuristic test up to date 2013-12-22 19:27:14 -06:00
Arfon Smith
e4d381d81c Merge branch 'master' into cpp_heuristic
Conflicts:
	lib/linguist/samples.json
2013-12-22 19:25:01 -06:00
Ted Nyman
3ece15b398 Update samples, version bump to 2.10.7 2013-12-22 15:46:54 -08:00
Ted Nyman
c8761d39d7 Narrow test and set ACTIVE flag for heuristics 2013-12-22 15:25:56 -08:00
Ted Nyman
51195290b8 Remove .pas sample 2013-12-22 15:18:54 -08:00
Clinton N. Dreisbach
63cb5aac20 Adding support for Hoplon files
See https://github.com/tailrecursion/hoplon-demos/blob/master/todoFRP/src/index.cljs.hl for an example and https://github.com/tailrecursion/hoplon for the full project.
2013-12-22 11:54:14 -05:00
Ted Nyman
11be3f3f08 Merge pull request #851 from github/append--applescript-extension
Include .scpt as a valid Applescript extension
2013-12-21 19:03:14 -08:00
Garen Torikian
91dd8d4950 Include .scpt as a valid Applescript extension 2013-12-21 19:59:00 -06:00
Ted Nyman
9c26488f29 Merge pull request #849 from github/even_moar_cpp
Adding a few more problematic C++ .h files to samples.
2013-12-21 12:26:59 -08:00
Arfon Smith
b2a5c30a44 A C++ shibboleth? 2013-12-20 22:28:25 -06:00
Arfon Smith
e3d520dba8 Adding a few more problematic C++ .h files to samples. 2013-12-20 22:01:23 -06:00
Ted Nyman
715680bc36 Minor README 2013-12-20 15:34:40 -08:00
Ted Nyman
b5df71950d Minor formatting 2013-12-20 14:55:47 -08:00
Ted Nyman
ed6bcfddef Merge pull request #848 from rlidwka/json5
adding JSON5 support
2013-12-19 10:01:20 -08:00
Alex Kocharin
a633dd8c79 adding JSON5 support 2013-12-19 14:13:23 +04:00
Ted Nyman
0974586d5c Merge pull request #847 from zhemao/master
Get scons files recognized as python
2013-12-17 14:10:08 -08:00
Howard Mao
774f658f67 get scons files recognized as python 2013-12-17 16:47:31 -05:00
Ted Nyman
37ef402a1f Formatting 2013-12-16 21:01:39 -08:00
Ted Nyman
99ad32511e Minor README updates 2013-12-16 20:59:28 -08:00
Ted Nyman
a282b56f46 Fix debug method 2013-12-16 20:55:00 -08:00
Ted Nyman
9845eba9df Merge pull request #844 from github/cpp-extra-samples
Cpp extra samples
2013-12-16 18:23:33 -08:00
Arfon Smith
a49303c93f Expanding TestHeuristcs to include all Objective C header files 2013-12-16 15:27:48 -08:00
Rob Hunter
4adbbc3fcc Add a few samples of misclassified C++ headers
Several people mentioned in #467 that they were seeing their C++ projects
erroneously showing up as containing Objective C.

I've added a file from each of the problematic repositories:

  - https://github.com/mp13on11/dwarf_mine
  - https://github.com/miguelishawt/anax
  - https://github.com/mholt/cppcsv
  - https://github.com/coder543/libcanister

They all seem to be triggering on different aspects, since adding one sample
wasn't sufficient to correctly classify the others.

The discussion in #467 makes me think that perhaps Linuist might need to take
the rest of the repository into account when classifying ambiguous files.
2013-12-16 14:38:56 -08:00
Ted Nyman
03cadf22fa 2.10.6 2013-12-15 20:31:34 -08:00
Ted Nyman
89c8d1e64c Docs 2013-12-15 20:30:55 -08:00
Ted Nyman
56ebfae598 Fix test 2013-12-15 20:27:56 -08:00
Ted Nyman
b1bb1a7345 Update RMarkdown type 2013-12-15 20:24:32 -08:00
Ted Nyman
4510bf1007 Merge pull request #839 from github/heuristics
Introduce heuristics
2013-12-15 20:20:50 -08:00
Ted Nyman
dd8b368f76 Merge branch 'master' into heuristics 2013-12-15 20:20:19 -08:00
Ted Nyman
17d0b1e02f More documentation 2013-12-15 20:17:30 -08:00
Ted Nyman
0626def699 Start with Objective-C 2013-12-15 20:15:19 -08:00
Ted Nyman
b3c6c85387 Start on basic heuristics tests 2013-12-15 20:06:59 -08:00
Ted Nyman
455266f27d Merge pull request #838 from github/rmd-sample
Adding rmd example
2013-12-15 20:01:51 -08:00
Arfon Smith
567408bc5e Adding rmd example 2013-12-15 19:52:15 -08:00
Ted Nyman
0c668ee179 Some README updates 2013-12-15 12:25:47 -08:00
Ted Nyman
3bc17e822d Start on basic heuristic approach 2013-12-14 23:33:21 -08:00
Ted Nyman
6bd97c7fc7 Bit of docs 2013-12-14 18:51:34 -08:00
Douglas Adam Smith II
00de2b011d Updated language list to include HOW, and fixed the lack of lexer problem.
Because HOW does not yet have a standardized lexer, I left the "lexer" field as "Text only".
2013-12-13 01:24:34 -05:00
Rob Hoelz
f1ffc9e581 Remove duplicate extensions for Perl 6 2013-12-04 11:22:17 +01:00
Rob Hoelz
ec6ef033a1 Update samples file 2013-12-04 08:18:17 +01:00
Rob Hoelz
a375a063d5 Add sample Perl 6 files 2013-12-04 08:10:58 +01:00
Rob Hoelz
d66147a277 Add Perl6 to languages.yml 2013-12-04 08:10:58 +01:00
Aaron Puchert
86329a0758 Forgot parantheses 2013-12-03 17:21:43 +01:00
Aaron Puchert
53f29344f8 Changed PostScript type to 'markup' 2013-11-24 18:04:44 +01:00
Aaron Puchert
0436973fb7 Add detection for generated PostScript files. 2013-11-24 18:04:20 +01:00
Jim Hester
c2ca9f40ac Add r alias 2013-11-18 13:45:11 -05:00
Viktor Szakáts
7f9142a41d recognize Harbour sources
[Harbour language: https://github.com/harbour/core]

Reopened PR 593 with the two language additions split off.
2013-11-05 11:27:04 +01:00
kethomassen
fb3e59c6f5 Fix Crystal Lexer
"ruby" => "Ruby"
2013-09-10 16:52:12 +10:00
kethomassen
c0c0252bab Add Crystal test 2013-09-09 17:52:11 +10:00
kethomassen
02953ac3ef Add Crystal
http://crystal-lang.org/
2013-09-09 17:47:16 +10:00
Aaron Puchert
fab34da3e7 Added PostScript to languages.yml and a sample file. 2013-05-31 20:10:54 +02:00
Matthew Fluet
a9a28ce58d The .fun extension is commonly used for Standard ML. 2013-05-30 20:54:36 -04:00
Michael Galloy
a8b2b0a86b Adding Interactive Data Language (IDL) support. 2013-03-07 18:48:27 -07:00
Andy Li
7c9e973082 Do not detect language if it is a binary file. 2012-11-26 21:54:43 +08:00
90 changed files with 12618 additions and 1544 deletions

View File

@@ -1,4 +1,6 @@
before_install: sudo apt-get install libicu-dev -y
before_install:
- sudo apt-get install libicu-dev -y
- gem update --system 2.1.11
rvm:
- 1.8.7
- 1.9.2

View File

@@ -1,4 +1,4 @@
Copyright (c) 2011-2013 GitHub, Inc.
Copyright (c) 2011-2014 GitHub, Inc.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation

View File

@@ -1,18 +1,17 @@
# Linguist
We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs and generate language breakdown graphs.
We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs, and generate language breakdown graphs.
## Features
### Language detection
Linguist defines the list of all languages known to GitHub in a [yaml file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). In order for a file to be highlighted, a language and lexer must be defined there.
Linguist defines a list of all languages known to GitHub in a [yaml file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). In order for a file to be highlighted, a language and a lexer must be defined there.
Most languages are detected by their file extension. This is the fastest and most common situation.
For disambiguating between files with common extensions, we use a [Bayesian classifier](https://github.com/github/linguist/blob/master/lib/linguist/classifier.rb). For an example, this helps us tell the difference between `.h` files which could be either C, C++, or Obj-C.
In the actual GitHub app we deal with `Grit::Blob` objects. For testing, there is a simple `FileBlob` API.
Most languages are detected by their file extension. For disambiguating between files with common extensions, we first apply some common-sense heuristics to pick out obvious languages. After that, we use a
[statistical
classifier](https://github.com/github/linguist/blob/master/lib/linguist/classifier.rb).
This process can help us tell the difference between, for example, `.h` files which could be either C, C++, or Obj-C.
```ruby
@@ -27,12 +26,9 @@ See [lib/linguist/language.rb](https://github.com/github/linguist/blob/master/li
The actual syntax highlighting is handled by our Pygments wrapper, [pygments.rb](https://github.com/tmm1/pygments.rb). It also provides a [Lexer abstraction](https://github.com/tmm1/pygments.rb/blob/master/lib/pygments/lexer.rb) that determines which highlighter should be used on a file.
We typically run on a pre-release version of Pygments, [pygments.rb](https://github.com/tmm1/pygments.rb), to get early access to new lexers. The [languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) file is a dump of the lexers we have available on our server.
### Stats
The Language Graph you see on every repository is built by aggregating the languages of each file in that repository.
The top language in the graph determines the project's primary language. Collectively, these stats make up the [Top Languages](https://github.com/languages) page.
The Language stats bar that you see on every repository is built by aggregating the languages of each file in that repository. The top language in the graph determines the project's primary language.
The repository stats API, accessed through `#languages`, can be used on a directory:
@@ -42,10 +38,27 @@ project.language.name #=> "Ruby"
project.languages #=> { "Ruby" => 0.98, "Shell" => 0.02 }
```
These stats are also printed out by the `linguist` binary. Try running `linguist` on itself:
These stats are also printed out by the `linguist` binary. You can use the
`--breakdown` flag, and the binary will also output the breakdown of files by language.
$ bundle exec linguist lib/
100% Ruby
You can try running `linguist` on the `lib/` directory in this repository itself:
$ bundle exec linguist lib/ --breakdown
100.00% Ruby
Ruby:
linguist/blob_helper.rb
linguist/classifier.rb
linguist/file_blob.rb
linguist/generated.rb
linguist/heuristics.rb
linguist/language.rb
linguist/md5.rb
linguist/repository.rb
linguist/samples.rb
linguist/tokenizer.rb
linguist.rb
#### Ignore vendored files

View File

@@ -1,7 +1,7 @@
require 'json'
require 'rake/clean'
require 'rake/testtask'
require 'yaml'
require 'json'
task :default => :test

View File

@@ -1,14 +1,22 @@
#!/usr/bin/env ruby
# linguist — detect language type for a file, or, given a directory, determine language breakdown
#
# usage: linguist <path>
# usage: linguist <path> [<--breakdown>]
require 'linguist/file_blob'
require 'linguist/repository'
path = ARGV[0] || Dir.pwd
# special case if not given a directory but still given the --breakdown option
if path == "--breakdown"
path = Dir.pwd
breakdown = true
end
ARGV.shift
breakdown = true if ARGV[0] == "--breakdown"
if File.directory?(path)
repo = Linguist::Repository.from_directory(path)
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
@@ -16,6 +24,17 @@ if File.directory?(path)
percentage = sprintf '%.2f' % percentage
puts "%-7s %s" % ["#{percentage}%", language]
end
if breakdown
puts
file_breakdown = repo.breakdown_by_file
file_breakdown.each do |lang, files|
puts "#{lang}:"
files.each do |file|
puts file
end
puts
end
end
elsif File.file?(path)
blob = Linguist::FileBlob.new(path, Dir.pwd)
type = if blob.text?

View File

@@ -1,10 +1,12 @@
Gem::Specification.new do |s|
s.name = 'github-linguist'
s.version = '2.10.5'
s.version = '2.10.12'
s.summary = "GitHub Language detection"
s.description = 'We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs, and generate language breakdown graphs.'
s.authors = "GitHub"
s.homepage = "https://github.com/github/linguist"
s.license = "MIT"
s.files = Dir['lib/**/*']
s.executables << 'linguist'

View File

@@ -1,5 +1,6 @@
require 'linguist/blob_helper'
require 'linguist/generated'
require 'linguist/heuristics'
require 'linguist/language'
require 'linguist/repository'
require 'linguist/samples'

View File

@@ -83,8 +83,8 @@ module Linguist
debug_dump_all_tokens(tokens, languages) if verbosity >= 2
languages.each do |language|
debug_dump_probabilities(tokens, language) if verbosity >= 1
scores[language] = tokens_probability(tokens, language) + language_probability(language)
debug_dump_probabilities(tokens, language, scores[language]) if verbosity >= 1
end
scores.sort { |a, b| b[1] <=> a[1] }.map { |score| [score[0], score[1]] }
@@ -130,9 +130,9 @@ module Linguist
@verbosity ||= (ENV['LINGUIST_DEBUG'] || 0).to_i
end
def debug_dump_probabilities
def debug_dump_probabilities(tokens, language, score)
printf("%10s = %10.3f + %7.3f = %10.3f\n",
language, tokens_probability(tokens, language), language_probability(language), scores[language])
language, tokens_probability(tokens, language), language_probability(language), score)
end
# Internal: show a table of probabilities for each <token,language> pair.

View File

@@ -58,10 +58,12 @@ module Linguist
generated_parser? ||
generated_net_docfile? ||
generated_net_designer_file? ||
generated_postscript? ||
generated_protocol_buffer? ||
generated_jni_header? ||
composer_lock? ||
node_modules?
node_modules? ||
vcr_cassette?
end
# Internal: Is the blob an XCode project file?
@@ -176,6 +178,29 @@ module Linguist
false
end
# Internal: Is the blob of PostScript generated?
#
# PostScript files are often generated by other programs. If they tell us so,
# we can detect them.
#
# Returns true or false.
def generated_postscript?
return false unless ['.ps', '.eps'].include? extname
# We analyze the "%%Creator:" comment, which contains the author/generator
# of the file. If there is one, it should be in one of the first few lines.
creator = lines[0..9].find {|line| line =~ /^%%Creator: /}
return false if creator.nil?
# Most generators write their version number, while human authors' or companies'
# names don't contain numbers. So look if the line contains digits. Also
# look for some special cases without version numbers.
return creator =~ /[0-9]/ ||
creator.include?("mpage") ||
creator.include?("draw") ||
creator.include?("ImageMagick")
end
# Internal: Is the blob a C++, Java or Python source file generated by the
# Protocol Buffer compiler?
#
@@ -198,20 +223,28 @@ module Linguist
lines[1].include?("#include <jni.h>")
end
# node_modules/ can contain large amounts of files, in general not meant
# for humans in pull requests.
# Internal: Is the blob part of node_modules/, which are not meant for humans in pull requests.
#
# Returns true or false.
def node_modules?
!!name.match(/node_modules\//)
end
# the php composer tool generates a lock file to represent a specific dependency state.
# In general not meant for humans in pull requests.
# Internal: Is the blob a generated php composer lock file?
#
# Returns true or false.
def composer_lock?
!!name.match(/composer.lock/)
end
# Is the blob a VCR Cassette file?
#
# Returns true or false
def vcr_cassette?
return false unless extname == '.yml'
return false unless lines.count > 2
# VCR Cassettes have "recorded_with: VCR" in the second last line.
return lines[-2].include?("recorded_with: VCR")
end
end
end

View File

@@ -0,0 +1,80 @@
module Linguist
# A collection of simple heuristics that can be used to better analyze languages.
class Heuristics
ACTIVE = false
# Public: Given an array of String language names,
# apply heuristics against the given data and return an array
# of matching languages, or nil.
#
# data - Array of tokens or String data to analyze.
# languages - Array of language name Strings to restrict to.
#
# Returns an array of Languages or []
def self.find_by_heuristics(data, languages)
if active?
if languages.all? { |l| ["Objective-C", "C++"].include?(l) }
disambiguate_c(data, languages)
end
if languages.all? { |l| ["Perl", "Prolog"].include?(l) }
disambiguate_pl(data, languages)
end
if languages.all? { |l| ["ECL", "Prolog"].include?(l) }
disambiguate_ecl(data, languages)
end
if languages.all? { |l| ["TypeScript", "XML"].include?(l) }
disambiguate_ts(data, languages)
end
if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) }
disambiguate_cl(data, languages)
end
end
end
# .h extensions are ambigious between C, C++, and Objective-C.
# We want to shortcut look for Objective-C _and_ now C++ too!
#
# Returns an array of Languages or []
def self.disambiguate_c(data, languages)
matches = []
matches << Language["Objective-C"] if data.include?("@interface")
matches << Language["C++"] if data.include?("#include <cstdint>")
matches
end
def self.disambiguate_pl(data, languages)
matches = []
matches << Language["Prolog"] if data.include?(":-")
matches << Language["Perl"] if data.include?("use strict")
matches
end
def self.disambiguate_ecl(data, languages)
matches = []
matches << Language["Prolog"] if data.include?(":-")
matches << Language["ECL"] if data.include?(":=")
matches
end
def self.disambiguate_ts(data, languages)
matches = []
if (data.include?("</translation>"))
matches << Language["XML"]
else
matches << Language["TypeScript"]
end
matches
end
def self.disambiguate_cl(data, languages)
matches = []
matches << Language["Common Lisp"] if data.include?("(defun ")
matches << Language["OpenCL"] if /\/\* |\/\/ |^\}/.match(data)
matches
end
def self.active?
!!ACTIVE
end
end
end

View File

@@ -7,6 +7,7 @@ rescue LoadError
end
require 'linguist/classifier'
require 'linguist/heuristics'
require 'linguist/samples'
module Linguist
@@ -32,7 +33,7 @@ module Linguist
#
# Returns an array
def self.detectable_markup
["CSS", "Less", "Sass", "Stylus", "TeX"]
["CSS", "Less", "Sass", "SCSS", "Stylus", "TeX"]
end
# Detect languages by a specific type
@@ -113,19 +114,32 @@ module Linguist
name += ".script!"
end
# First try to find languages that match based on filename.
possible_languages = find_by_filename(name)
# If there is more than one possible language with that extension (or no
# extension at all, in the case of extensionless scripts), we need to continue
# our detection work
if possible_languages.length > 1
data = data.call() if data.respond_to?(:call)
possible_language_names = possible_languages.map(&:name)
# Don't bother with emptiness
if data.nil? || data == ""
nil
# Check if there's a shebang line and use that as authoritative
elsif (result = find_by_shebang(data)) && !result.empty?
result.first
elsif classified = Classifier.classify(Samples::DATA, data, possible_languages.map(&:name)).first
# No shebang. Still more work to do. Try to find it with our heuristics.
elsif (determined = Heuristics.find_by_heuristics(data, possible_language_names)) && !determined.empty?
determined.first
# Lastly, fall back to the probablistic classifier.
elsif classified = Classifier.classify(Samples::DATA, data, possible_language_names ).first
# Return the actual Language object based of the string language name (i.e., first element of `#classify`)
Language[classified[0]]
end
else
# Simplest and most common case, we can just return the one match based on extension
possible_languages.first
end
end

View File

@@ -53,6 +53,18 @@ ASP:
- .aspx
- .axd
ATS:
type: programming
color: "#1ac620"
primary_extension: .dats
lexer: OCaml
aliases:
- ats2
extensions:
- .atxt
- .hats
- .sats
ActionScript:
type: programming
lexer: ActionScript 3
@@ -90,6 +102,10 @@ AppleScript:
aliases:
- osascript
primary_extension: .applescript
extensions:
- .scpt
interpreters:
- osascript
Arc:
type: programming
@@ -212,6 +228,7 @@ C:
color: "#555"
primary_extension: .c
extensions:
- .cats
- .w
C#:
@@ -223,6 +240,7 @@ C#:
- csharp
primary_extension: .cs
extensions:
- .cshtml
- .csx
C++:
@@ -236,6 +254,7 @@ C++:
extensions:
- .C
- .c++
- .cc
- .cxx
- .H
- .h++
@@ -293,6 +312,16 @@ ChucK:
lexer: Java
primary_extension: .ck
Cirru:
type: programming
color: "#aaaaff"
primary_extension: .cirru
# ace_mode: cirru
# lexer: Cirru
lexer: Text only
extensions:
- .cr
Clean:
type: programming
color: "#3a81ad"
@@ -313,6 +342,7 @@ Clojure:
- .cljscm
- .cljx
- .hic
- .cljs.hl
filenames:
- riemann.config
@@ -330,6 +360,8 @@ CoffeeScript:
- .iced
filenames:
- Cakefile
interpreters:
- coffee
ColdFusion:
type: programming
@@ -380,6 +412,12 @@ Creole:
wrap: true
primary_extension: .creole
Crystal:
type: programming
lexer: Ruby
primary_extension: .cr
ace_mode: ruby
Cucumber:
lexer: Gherkin
primary_extension: .feature
@@ -454,6 +492,9 @@ Dylan:
type: programming
color: "#3ebc27"
primary_extension: .dylan
extensions:
- .intr
- .lid
Ecere Projects:
type: data
@@ -519,6 +560,14 @@ F#:
- .fsi
- .fsx
FLUX:
type: programming
color: "#33CCFF"
primary_extension: .fx
lexer: Text only
extensions:
- .flux
FORTRAN:
type: programming
lexer: Fortran
@@ -557,7 +606,7 @@ Fancy:
- .fancypack
filenames:
- Fakefile
Fantom:
type: programming
color: "#dbded5"
@@ -644,6 +693,8 @@ Groovy:
ace_mode: groovy
color: "#e69f56"
primary_extension: .groovy
interpreters:
- groovy
Groovy Server Pages:
group: Groovy
@@ -661,6 +712,7 @@ HTML:
extensions:
- .htm
- .xhtml
- .html.hl
HTML+Django:
type: markup
@@ -709,6 +761,12 @@ Handlebars:
- .html.handlebars
- .html.hbs
Harbour:
type: programming
lexer: Text only
color: "#0e60e3"
primary_extension: .hb
Haskell:
type: programming
color: "#29b544"
@@ -724,6 +782,19 @@ Haxe:
extensions:
- .hxsl
Hy:
type: programming
lexer: Clojure
ace_mode: clojure
color: "#7891b1"
primary_extension: .hy
IDL:
type: programming
lexer: Text only
color: "#e3592c"
primary_extension: .pro
INI:
type: data
extensions:
@@ -785,6 +856,18 @@ JSON:
- .jshintrc
- composer.lock
JSON5:
type: data
lexer: JavaScript
primary_extension: .json5
JSONLD:
type: data
group: JavaScript
ace_mode: json
lexer: JavaScript
primary_extension: .jsonld
Jade:
group: HTML
type: markup
@@ -815,11 +898,13 @@ JavaScript:
extensions:
- ._js
- .bones
- .es6
- .jake
- .jsfl
- .jsm
- .jss
- .jsx
- .njs
- .pac
- .sjs
- .ssjs
@@ -913,10 +998,6 @@ LiveScript:
Logos:
type: programming
primary_extension: .xm
extensions:
- .x
- .xi
- .xmi
Logtalk:
type: programming
@@ -932,6 +1013,8 @@ Lua:
extensions:
- .nse
- .rbxs
interpreters:
- lua
M:
type: programming
@@ -973,6 +1056,13 @@ Markdown:
- .mkdown
- .ron
Mask:
type: markup
lexer: SCSS
color: "#f97732"
ace_mode: scss
primary_extension: .mask
Matlab:
type: programming
color: "#bb92ac"
@@ -1080,6 +1170,7 @@ OCaml:
primary_extension: .ml
extensions:
- .eliomi
- .ml4
- .mli
- .mll
- .mly
@@ -1146,6 +1237,12 @@ Oxygene:
color: "#5a63a3"
primary_extension: .oxygene
PAWN:
type: programming
lexer: C++
color: "#dbb284"
primary_extension: .pwn
PHP:
type: programming
ace_mode: php
@@ -1199,16 +1296,28 @@ Perl:
primary_extension: .pl
extensions:
- .PL
- .nqp
- .perl
- .ph
- .plx
- .pm6
- .pm
- .pod
- .psgi
interpreters:
- perl
Perl6:
type: programming
color: "#0298c3"
primary_extension: .p6
extensions:
- .6pl
- .6pm
- .nqp
- .p6l
- .p6m
- .pl6
- .pm6
Pike:
type: programming
color: "#066ab2"
@@ -1230,6 +1339,12 @@ PogoScript:
lexer: Text only
primary_extension: .pogo
PostScript:
type: markup
primary_extension: .ps
extensions:
- .eps
PowerShell:
type: programming
ace_mode: powershell
@@ -1251,7 +1366,8 @@ Prolog:
color: "#74283c"
primary_extension: .prolog
extensions:
- .pro
- .ecl
- .pl
Protocol Buffer:
type: markup
@@ -1289,6 +1405,8 @@ Python:
- .xpy
filenames:
- wscript
- SConstruct
- SConscript
interpreters:
- python
@@ -1308,9 +1426,12 @@ R:
type: programming
color: "#198ce7"
lexer: S
aliases:
- R
primary_extension: .r
extensions:
- .R
- .rsx
filenames:
- .Rprofile
interpreters:
@@ -1340,7 +1461,7 @@ RHTML:
primary_extension: .rhtml
RMarkdown:
type: markup
type: prose
lexer: Text only
wrap: true
ace_mode: markdown
@@ -1424,6 +1545,7 @@ Ruby:
- Appraisals
- Berksfile
- Gemfile
- Gemfile.lock
- Guardfile
- Podfile
- Thorfile
@@ -1475,6 +1597,7 @@ Scheme:
color: "#1e4aec"
primary_extension: .scm
extensions:
- .sld
- .sls
- .ss
interpreters:
@@ -1513,6 +1636,12 @@ Shell:
filenames:
- Dockerfile
Shen:
type: programming
color: "#120F14"
lexer: Text only
primary_extension: .shen
Slash:
type: programming
color: "#007eff"
@@ -1537,6 +1666,8 @@ Standard ML:
aliases:
- sml
primary_extension: .sml
extensions:
- .fun
Stylus:
type: markup
@@ -1584,6 +1715,7 @@ TeX:
extensions:
- .aux
- .bib
- .cls
- .dtx
- .ins
- .ltx
@@ -1690,6 +1822,7 @@ Visual Basic:
- .frm
- .frx
- .vba
- .vbhtml
- .vbs
Volt:
@@ -1725,6 +1858,7 @@ XML:
- .kml
- .launch
- .mxml
- .osm
- .plist
- .pluginspec
- .ps1xml

View File

@@ -29,6 +29,7 @@ module Linguist
@computed_stats = false
@language = @size = nil
@sizes = Hash.new { 0 }
@file_breakdown = Hash.new { |h,k| h[k] = Array.new }
end
# Public: Returns a breakdown of language stats.
@@ -60,6 +61,12 @@ module Linguist
@size
end
# Public: Return the language breakdown of this repository by file
def breakdown_by_file
compute_stats
@file_breakdown
end
# Internal: Compute language breakdown for each blob in the Repository.
#
# Returns nothing
@@ -75,6 +82,10 @@ module Linguist
# Only include programming languages and acceptable markup languages
if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
# Build up the per-file breakdown stats
@file_breakdown[blob.language.group.name] << blob.name
@sizes[blob.language.group] += blob.size
end
end

File diff suppressed because it is too large Load Diff

View File

@@ -27,11 +27,18 @@
# Node dependencies
- node_modules/
# Bower Components
- bower_components/
# Erlang bundles
- ^rebar$
# Bootstrap minified css and js
- (^|/)bootstrap([^.]*)(\.min)\.(js|css)$
- (^|/)bootstrap([^.]*)(\.min)?\.(js|css)$
# Foundation css
- foundation.min.css
- foundation.css
# Vendored dependencies
- thirdparty/
@@ -40,6 +47,9 @@
# Debian packaging
- ^debian/
# Haxelib projects often contain a neko bytecode file named run.n
- run.n$
## Commonly Bundled JavaScript frameworks ##
# jQuery
@@ -56,6 +66,9 @@
- (^|/)controls\.js$
- (^|/)dragdrop\.js$
# Typescript definition files
- (.*?)\.d\.ts$
# MooTools
- (^|/)mootools([^.]*)\d+\.\d+.\d+([^.]*)\.js$
@@ -82,6 +95,9 @@
- (^|/)shCore\.js$
- (^|/)shLegacy\.js$
# AngularJS
- (^|/)angular([^.]*)(\.min)?\.js$
## Python ##
# django
@@ -101,6 +117,13 @@
# Sparkle
- (^|/)Sparkle/
## Groovy ##
# Gradle
- (^|/)gradlew$
- (^|/)gradlew\.bat$
- (^|/)gradle/wrapper/
## .NET ##
# Visual Studio IntelliSense
@@ -140,6 +163,7 @@
# LICENSE, README, git config files
- ^COPYING$
- LICENSE$
- License$
- gitattributes$
- gitignore$
- gitmodules$

View File

@@ -0,0 +1,110 @@
(* ****** ****** *)
//
// HX-2014-01
// CoYoneda Lemma:
//
(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
staload
"libats/ML/SATS/basis.sats"
staload
"libats/ML/SATS/list0.sats"
(* ****** ****** *)
staload _ = "libats/ML/DATS/list0.dats"
(* ****** ****** *)
sortdef ftype = type -> type
(* ****** ****** *)
infixr (->) ->>
typedef ->> (a:type, b:type) = a -<cloref1> b
(* ****** ****** *)
typedef
functor(F:ftype) =
{a,b:type} (a ->> b) ->> F(a) ->> F(b)
(* ****** ****** *)
typedef
list0 (a:type) = list0 (a)
extern
val functor_list0 : functor (list0)
(* ****** ****** *)
implement
functor_list0{a,b}
(f) = lam xs => list0_map<a><b> (xs, f)
(* ****** ****** *)
datatype
CoYoneda
(F:ftype, r:type) = {a:type} CoYoneda of (a ->> r, F(a))
// end of [CoYoneda]
(* ****** ****** *)
//
extern
fun CoYoneda_phi
: {F:ftype}functor(F) -> {r:type} (F (r) ->> CoYoneda (F, r))
extern
fun CoYoneda_psi
: {F:ftype}functor(F) -> {r:type} (CoYoneda (F, r) ->> F (r))
//
(* ****** ****** *)
implement
CoYoneda_phi(ftor) = lam (fx) => CoYoneda (lam x => x, fx)
implement
CoYoneda_psi(ftor) = lam (CoYoneda(f, fx)) => ftor (f) (fx)
(* ****** ****** *)
datatype int0 = I of (int)
datatype bool = True | False // boxed boolean
(* ****** ****** *)
//
fun bool2string
(x:bool): string =
(
case+ x of True() => "True" | False() => "False"
)
//
implement
fprint_val<bool> (out, x) = fprint (out, bool2string(x))
//
(* ****** ****** *)
fun int2bool (i: int0): bool =
let val+I(i) = i in if i > 0 then True else False end
(* ****** ****** *)
val myintlist0 = g0ofg1($list{int0}((I)1, (I)0, (I)1, (I)0, (I)0))
val myboolist0 = CoYoneda{list0,bool}{int0}(lam (i) => int2bool(i), myintlist0)
val myboolist0 = CoYoneda_psi{list0}(functor_list0){bool}(myboolist0)
(* ****** ****** *)
val ((*void*)) = fprintln! (stdout_ref, "myboolist0 = ", myboolist0)
(* ****** ****** *)
implement main0 () = ()
(* ****** ****** *)
(* end of [CoYonedaLemma.dats] *)

View File

@@ -0,0 +1,178 @@
(* ****** ****** *)
//
// HX-2013-11
//
// Implementing a variant of
// the problem of Dining Philosophers
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
staload
UN = "prelude/SATS/unsafe.sats"
(* ****** ****** *)
staload "libc/SATS/stdlib.sats"
staload "libc/SATS/unistd.sats"
(* ****** ****** *)
staload "{$LIBATSHWXI}/teaching/mythread/SATS/channel.sats"
(* ****** ****** *)
staload _ = "libats/DATS/deqarray.dats"
staload _ = "{$LIBATSHWXI}/teaching/mythread/DATS/channel.dats"
(* ****** ****** *)
staload "./DiningPhil2.sats"
(* ****** ****** *)
implement phil_left (n) = n
implement phil_right (n) = (n+1) \nmod NPHIL
(* ****** ****** *)
//
extern
fun randsleep (n: intGte(1)): void
//
implement
randsleep (n) =
ignoret (sleep($UN.cast{uInt}(rand() mod n + 1)))
// end of [randsleep]
//
(* ****** ****** *)
implement
phil_think (n) =
{
val () = println! ("phil_think(", n, ") starts")
val () = randsleep (6)
val () = println! ("phil_think(", n, ") finishes")
}
(* ****** ****** *)
implement
phil_dine (n, lf, rf) =
{
val () = println! ("phil_dine(", n, ") starts")
val () = randsleep (3)
val () = println! ("phil_dine(", n, ") finishes")
}
(* ****** ****** *)
implement
phil_loop (n) = let
//
val () = phil_think (n)
//
val nl = phil_left (n)
val nr = phil_right (n)
//
val ch_lfork = fork_changet (nl)
val ch_rfork = fork_changet (nr)
//
val lf = channel_takeout (ch_lfork)
val () = println! ("phil_loop(", n, ") picks left fork")
//
val () = randsleep (2) // HX: try to actively induce deadlock
//
val rf = channel_takeout (ch_rfork)
val () = println! ("phil_loop(", n, ") picks right fork")
//
val () = phil_dine (n, lf, rf)
//
val ch_forktray = forktray_changet ()
val () = channel_insert (ch_forktray, lf)
val () = channel_insert (ch_forktray, rf)
//
in
phil_loop (n)
end // end of [phil_loop]
(* ****** ****** *)
implement
cleaner_wash (f) =
{
val f = fork_get_num (f)
val () = println! ("cleaner_wash(", f, ") starts")
val () = randsleep (1)
val () = println! ("cleaner_wash(", f, ") finishes")
}
(* ****** ****** *)
implement
cleaner_return (f) =
{
val n = fork_get_num (f)
val ch = fork_changet (n)
val () = channel_insert (ch, f)
}
(* ****** ****** *)
implement
cleaner_loop () = let
//
val ch = forktray_changet ()
val f0 = channel_takeout (ch)
//
val () = cleaner_wash (f0)
val () = cleaner_return (f0)
//
in
cleaner_loop ()
end // end of [cleaner_loop]
(* ****** ****** *)
dynload "DiningPhil2.sats"
dynload "DiningPhil2_fork.dats"
dynload "DiningPhil2_thread.dats"
(* ****** ****** *)
local
//
staload
"{$LIBATSHWXI}/teaching/mythread/SATS/mythread.sats"
//
in (* in of [local] *)
//
val () = mythread_create_cloptr (llam () => phil_loop (0))
val () = mythread_create_cloptr (llam () => phil_loop (1))
val () = mythread_create_cloptr (llam () => phil_loop (2))
val () = mythread_create_cloptr (llam () => phil_loop (3))
val () = mythread_create_cloptr (llam () => phil_loop (4))
//
val () = mythread_create_cloptr (llam () => cleaner_loop ())
//
end // end of [local]
(* ****** ****** *)
implement
main0 () =
{
//
val () = println! ("DiningPhil2: starting")
val ((*void*)) = while (true) ignoret (sleep(1))
//
} (* end of [main0] *)
(* ****** ****** *)
(* end of [DiningPhil2.dats] *)

View File

@@ -0,0 +1,71 @@
(* ****** ****** *)
//
// HX-2013-11
//
// Implementing a variant of
// the problem of Dining Philosophers
//
(* ****** ****** *)
#include
"share/atspre_define.hats"
(* ****** ****** *)
staload "{$LIBATSHWXI}/teaching/mythread/SATS/channel.sats"
(* ****** ****** *)
%{#
#define NPHIL 5
%} // end of [%{#]
#define NPHIL 5
(* ****** ****** *)
typedef nphil = natLt(NPHIL)
(* ****** ****** *)
fun phil_left (n: nphil): nphil
fun phil_right (n: nphil): nphil
(* ****** ****** *)
//
fun phil_loop (n: nphil): void
//
(* ****** ****** *)
fun cleaner_loop ((*void*)): void
(* ****** ****** *)
absvtype fork_vtype = ptr
vtypedef fork = fork_vtype
(* ****** ****** *)
fun fork_get_num (!fork): nphil
(* ****** ****** *)
fun phil_dine
(n: nphil, lf: !fork, rf: !fork): void
// end of [phil_dine]
fun phil_think (n: nphil): void
(* ****** ****** *)
fun cleaner_wash (f: !fork): void
fun cleaner_return (f: fork): void
(* ****** ****** *)
//
fun fork_changet (n: nphil): channel(fork)
//
fun forktray_changet ((*void*)): channel(fork)
//
(* ****** ****** *)
(* end of [DiningPhil2.sats] *)

View File

@@ -0,0 +1,89 @@
(* ****** ****** *)
//
// HX-2013-11
//
// Implementing a variant of
// the problem of Dining Philosophers
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
staload
UN = "prelude/SATS/unsafe.sats"
(* ****** ****** *)
staload "{$LIBATSHWXI}/teaching/mythread/SATS/channel.sats"
(* ****** ****** *)
staload _ = "libats/DATS/deqarray.dats"
staload _ = "{$LIBATSHWXI}/teaching/mythread/DATS/channel.dats"
(* ****** ****** *)
staload "./DiningPhil2.sats"
(* ****** ****** *)
datavtype fork = FORK of (nphil)
(* ****** ****** *)
assume fork_vtype = fork
(* ****** ****** *)
implement
fork_get_num (f) = let val FORK(n) = f in n end
(* ****** ****** *)
local
val
the_forkarray = let
//
typedef t = channel(fork)
//
implement
array_tabulate$fopr<t>
(n) = ch where
{
val n = $UN.cast{nphil}(n)
val ch = channel_create_exn<fork> (i2sz(2))
val () = channel_insert (ch, FORK (n))
}
//
in
arrayref_tabulate<t> (i2sz(NPHIL))
end // end of [val]
in (* in of [local] *)
implement fork_changet (n) = the_forkarray[n]
end // end of [local]
(* ****** ****** *)
local
val the_forktray =
channel_create_exn<fork> (i2sz(NPHIL+1))
in (* in of [local] *)
implement forktray_changet () = the_forktray
end // end of [local]
(* ****** ****** *)
(* end of [DiningPhil2_fork.dats] *)

View File

@@ -0,0 +1,43 @@
(* ****** ****** *)
//
// HX-2013-11
//
// Implementing a variant of
// the problem of Dining Philosophers
//
(* ****** ****** *)
//
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
//
(* ****** ****** *)
staload "{$LIBATSHWXI}/teaching/mythread/SATS/mythread.sats"
(* ****** ****** *)
local
//
#include "{$LIBATSHWXI}/teaching/mythread/DATS/mythread.dats"
//
in (* in of [local] *)
//
// HX: it is intentionally left to be empty
//
end // end of [local]
(* ****** ****** *)
local
//
#include "{$LIBATSHWXI}/teaching/mythread/DATS/mythread_posix.dats"
//
in (* in of [local] *)
//
// HX: it is intentionally left to be empty
//
end // end of [local]
(* ****** ****** *)
(* end of [DiningPhil2_thread.dats] *)

View File

@@ -0,0 +1,178 @@
(* ****** ****** *)
//
// HX-2014-01
// Yoneda Lemma:
// The hardest "trivial" theorem :)
//
(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
staload
"libats/ML/SATS/basis.sats"
staload
"libats/ML/SATS/list0.sats"
staload
"libats/ML/SATS/option0.sats"
(* ****** ****** *)
staload _ = "libats/ML/DATS/list0.dats"
staload _ = "libats/ML/DATS/option0.dats"
(* ****** ****** *)
sortdef ftype = type -> type
(* ****** ****** *)
infixr (->) ->>
typedef ->> (a:type, b:type) = a -<cloref1> b
(* ****** ****** *)
typedef
functor(F:ftype) =
{a,b:type} (a ->> b) ->> F(a) ->> F(b)
(* ****** ****** *)
typedef
list0 (a:type) = list0 (a)
extern
val functor_list0 : functor (list0)
(* ****** ****** *)
implement
functor_list0{a,b}
(f) = lam xs => list0_map<a><b> (xs, f)
(* ****** ****** *)
typedef
option0 (a:type) = option0 (a)
extern
val functor_option0 : functor (option0)
(* ****** ****** *)
implement
functor_option0{a,b}
(f) = lam opt => option0_map<a><b> (opt, f)
(* ****** ****** *)
extern
val functor_homres
: {c:type} functor (lam(r:type) => c ->> r)
(* ****** ****** *)
implement
functor_homres{c}{a,b} (f) = lam (r) => lam (x) => f (r(x))
(* ****** ****** *)
//
extern
fun Yoneda_phi : {F:ftype}functor(F) ->
{a:type}F(a) ->> ({r:type}(a ->> r) ->> F(r))
extern
fun Yoneda_psi : {F:ftype}functor(F) ->
{a:type}({r:type}(a ->> r) ->> F(r)) ->> F(a)
//
(* ****** ****** *)
//
implement
Yoneda_phi
(ftor) = lam(fx) => lam (m) => ftor(m)(fx)
//
implement
Yoneda_psi (ftor) = lam(mf) => mf(lam x => x)
//
(* ****** ****** *)
(*
(* ****** ****** *)
//
// HX-2014-01-05:
// Another version based on Natural Transformation
//
(* ****** ****** *)
typedef
natrans(F:ftype, G:ftype) = {x:type} (F(x) ->> G(x))
(* ****** ****** *)
//
extern
fun Yoneda_phi_nat : {F:ftype}functor(F) ->
{a:type} F(a) ->> natrans(lam (r:type) => (a ->> r), F)
extern
fun Yoneda_psi_nat : {F:ftype}functor(F) ->
{a:type} natrans(lam (r:type) => (a ->> r), F) ->> F(a)
//
(* ****** ****** *)
//
implement
Yoneda_phi_nat
(ftor) = lam(fx) => lam (m) => ftor(m)(fx)
//
implement
Yoneda_psi_nat (ftor) = lam(mf) => mf(lam x => x)
//
(* ****** ****** *)
*)
(* ****** ****** *)
datatype bool = True | False // boxed boolean
(* ****** ****** *)
//
fun bool2string
(x:bool): string =
(
case+ x of True() => "True" | False() => "False"
)
//
implement
fprint_val<bool> (out, x) = fprint (out, bool2string(x))
//
(* ****** ****** *)
//
val myboolist0 =
$list_t{bool}(True, False, True, False, False)
val myboolist0 = g0ofg1_list (myboolist0)
//
(* ****** ****** *)
//
extern
val Yoneda_bool_list0 : {r:type} (bool ->> r) ->> list0(r)
//
implement
Yoneda_bool_list0 =
Yoneda_phi(functor_list0){bool}(myboolist0)
//
(* ****** ****** *)
//
val myboolist1 =
Yoneda_psi(functor_list0){bool}(Yoneda_bool_list0)
//
(* ****** ****** *)
val () = fprintln! (stdout_ref, "myboolist0 = ", myboolist0)
val () = fprintln! (stdout_ref, "myboolist1 = ", myboolist1)
(* ****** ****** *)
implement main0 () = ()
(* ****** ****** *)
(* end of [YonedaLemma.dats] *)

187
samples/ATS/linset.hats Normal file
View File

@@ -0,0 +1,187 @@
(***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(***********************************************************************)
(*
** ATS/Postiats - Unleashing the Potential of Types!
** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
(* Author: Hongwei Xi *)
(* Authoremail: hwxi AT cs DOT bu DOT edu *)
(* Start time: December, 2012 *)
(* ****** ****** *)
//
// HX: shared by linset_listord (* ordered list *)
// HX: shared by linset_avltree (* AVL-tree-based *)
//
(* ****** ****** *)
//
// HX-2013-02:
// for sets of nonlinear elements
//
absvtype set_vtype (a:t@ype+) = ptr
//
(* ****** ****** *)
vtypedef set (a:t0p) = set_vtype (a)
(* ****** ****** *)
fun{a:t0p}
compare_elt_elt (x1: a, x2: a):<> int
(* ****** ****** *)
fun{} linset_nil{a:t0p} ():<> set(a)
fun{} linset_make_nil{a:t0p} ():<> set(a)
(* ****** ****** *)
fun{a:t0p} linset_sing (x: a):<!wrt> set(a)
fun{a:t0p} linset_make_sing (x: a):<!wrt> set(a)
(* ****** ****** *)
fun{a:t0p}
linset_make_list (xs: List(INV(a))):<!wrt> set(a)
(* ****** ****** *)
fun{}
linset_is_nil {a:t0p} (xs: !set(INV(a))):<> bool
fun{}
linset_isnot_nil {a:t0p} (xs: !set(INV(a))):<> bool
(* ****** ****** *)
fun{a:t0p} linset_size (!set(INV(a))): size_t
(* ****** ****** *)
fun{a:t0p}
linset_is_member (xs: !set(INV(a)), x0: a):<> bool
fun{a:t0p}
linset_isnot_member (xs: !set(INV(a)), x0: a):<> bool
(* ****** ****** *)
fun{a:t0p}
linset_copy (!set(INV(a))):<!wrt> set(a)
fun{a:t0p}
linset_free (xs: set(INV(a))):<!wrt> void
(* ****** ****** *)
//
fun{a:t0p}
linset_insert
(xs: &set(INV(a)) >> _, x0: a):<!wrt> bool
//
(* ****** ****** *)
//
fun{a:t0p}
linset_takeout
(
&set(INV(a)) >> _, a, res: &(a?) >> opt(a, b)
) :<!wrt> #[b:bool] bool(b) // endfun
fun{a:t0p}
linset_takeout_opt (&set(INV(a)) >> _, a):<!wrt> Option_vt(a)
//
(* ****** ****** *)
//
fun{a:t0p}
linset_remove
(xs: &set(INV(a)) >> _, x0: a):<!wrt> bool
//
(* ****** ****** *)
//
// HX: choosing an element in an unspecified manner
//
fun{a:t0p}
linset_choose
(
xs: !set(INV(a)), x: &a? >> opt (a, b)
) :<!wrt> #[b:bool] bool(b)
//
fun{a:t0p}
linset_choose_opt (xs: !set(INV(a))):<!wrt> Option_vt(a)
//
(* ****** ****** *)
fun{a:t0p}
linset_takeoutmax
(
xs: &set(INV(a)) >> _, res: &a? >> opt(a, b)
) :<!wrt> #[b:bool] bool (b)
fun{a:t0p}
linset_takeoutmax_opt (xs: &set(INV(a)) >> _):<!wrt> Option_vt(a)
(* ****** ****** *)
fun{a:t0p}
linset_takeoutmin
(
xs: &set(INV(a)) >> _, res: &a? >> opt(a, b)
) :<!wrt> #[b:bool] bool (b)
fun{a:t0p}
linset_takeoutmin_opt (xs: &set(INV(a)) >> _):<!wrt> Option_vt(a)
(* ****** ****** *)
//
fun{}
fprint_linset$sep (FILEref): void // ", "
//
fun{a:t0p}
fprint_linset (out: FILEref, xs: !set(INV(a))): void
//
overload fprint with fprint_linset
//
(* ****** ****** *)
//
fun{
a:t0p}{env:vt0p
} linset_foreach$fwork
(x: a, env: &(env) >> _): void
//
fun{a:t0p}
linset_foreach (set: !set(INV(a))): void
fun{
a:t0p}{env:vt0p
} linset_foreach_env
(set: !set(INV(a)), env: &(env) >> _): void
// end of [linset_foreach_env]
//
(* ****** ****** *)
fun{a:t0p}
linset_listize (xs: set(INV(a))): List0_vt (a)
(* ****** ****** *)
fun{a:t0p}
linset_listize1 (xs: !set(INV(a))): List0_vt (a)
(* ****** ****** *)
(* end of [linset.hats] *)

View File

@@ -0,0 +1,504 @@
(***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(***********************************************************************)
(*
** ATS/Postiats - Unleashing the Potential of Types!
** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
(* Author: Hongwei Xi *)
(* Authoremail: hwxi AT cs DOT bu DOT edu *)
(* Start time: February, 2013 *)
(* ****** ****** *)
//
// HX-2013-08:
// a set is represented as a sorted list in descending order;
// note that descending order is chosen to faciliate set comparison
//
(* ****** ****** *)
staload
UN = "prelude/SATS/unsafe.sats"
(* ****** ****** *)
staload "libats/SATS/linset_listord.sats"
(* ****** ****** *)
#include "./SHARE/linset.hats" // code reuse
#include "./SHARE/linset_node.hats" // code reuse
(* ****** ****** *)
assume
set_vtype (elt:t@ype) = List0_vt (elt)
(* ****** ****** *)
implement{}
linset_nil () = list_vt_nil ()
implement{}
linset_make_nil () = list_vt_nil ()
(* ****** ****** *)
implement
{a}(*tmp*)
linset_sing
(x) = list_vt_cons{a}(x, list_vt_nil)
// end of [linset_sing]
implement{a}
linset_make_sing
(x) = list_vt_cons{a}(x, list_vt_nil)
// end of [linset_make_sing]
(* ****** ****** *)
implement{}
linset_is_nil (xs) = list_vt_is_nil (xs)
implement{}
linset_isnot_nil (xs) = list_vt_is_cons (xs)
(* ****** ****** *)
implement{a}
linset_size (xs) =
let val n = list_vt_length(xs) in i2sz(n) end
// end of [linset_size]
(* ****** ****** *)
implement{a}
linset_is_member
(xs, x0) = let
//
fun aux
{n:nat} .<n>.
(
xs: !list_vt (a, n)
) :<> bool = let
in
//
case+ xs of
| list_vt_cons (x, xs) => let
val sgn = compare_elt_elt<a> (x0, x) in
if sgn > 0 then false else (if sgn < 0 then aux (xs) else true)
end // end of [list_vt_cons]
| list_vt_nil ((*void*)) => false
//
end // end of [aux]
//
in
aux (xs)
end // end of [linset_is_member]
(* ****** ****** *)
implement{a}
linset_copy (xs) = list_vt_copy<a> (xs)
implement{a}
linset_free (xs) = list_vt_free<a> (xs)
(* ****** ****** *)
implement{a}
linset_insert
(xs, x0) = let
//
fun
mynode_cons
{n:nat} .<>.
(
nx: mynode1 (a), xs: list_vt (a, n)
) : list_vt (a, n+1) = let
//
val xs1 =
$UN.castvwtp0{List1_vt(a)}(nx)
val+@list_vt_cons (_, xs2) = xs1
prval () = $UN.cast2void (xs2); val () = (xs2 := xs)
//
in
fold@ (xs1); xs1
end // end of [mynode_cons]
//
fun ins
{n:nat} .<n>. // tail-recursive
(
xs: &list_vt (a, n) >> list_vt (a, n1)
) : #[n1:nat | n <= n1; n1 <= n+1] bool =
(
case+ xs of
| @list_vt_cons
(x, xs1) => let
val sgn =
compare_elt_elt<a> (x0, x)
// end of [val]
in
if sgn > 0 then let
prval () = fold@ (xs)
val nx = mynode_make_elt<a> (x0)
val ((*void*)) = xs := mynode_cons (nx, xs)
in
false
end else if sgn < 0 then let
val ans = ins (xs1)
prval () = fold@ (xs)
in
ans
end else let // [x0] is found
prval () = fold@ (xs)
in
true (* [x0] in [xs] *)
end (* end of [if] *)
end // end of [list_vt_cons]
| list_vt_nil () => let
val nx = mynode_make_elt<a> (x0)
val ((*void*)) = xs := mynode_cons (nx, xs)
in
false
end // end of [list_vt_nil]
) (* end of [ins] *)
//
in
$effmask_all (ins (xs))
end // end of [linset_insert]
(* ****** ****** *)
(*
//
HX-2013-08:
[linset_remove] moved up
//
implement{a}
linset_remove
(xs, x0) = let
//
fun rem
{n:nat} .<n>. // tail-recursive
(
xs: &list_vt (a, n) >> list_vt (a, n1)
) : #[n1:nat | n1 <= n; n <= n1+1] bool =
(
case+ xs of
| @list_vt_cons
(x, xs1) => let
val sgn =
compare_elt_elt<a> (x0, x)
// end of [val]
in
if sgn > 0 then let
prval () = fold@ (xs)
in
false
end else if sgn < 0 then let
val ans = rem (xs1)
prval () = fold@ (xs)
in
ans
end else let // x0 = x
val xs1_ = xs1
val ((*void*)) = free@{a}{0}(xs)
val () = xs := xs1_
in
true // [x0] in [xs]
end (* end of [if] *)
end // end of [list_vt_cons]
| list_vt_nil () => false
) (* end of [rem] *)
//
in
$effmask_all (rem (xs))
end // end of [linset_remove]
*)
(* ****** ****** *)
(*
** By Brandon Barker
*)
implement
{a}(*tmp*)
linset_choose
(xs, x0) = let
in
//
case+ xs of
| list_vt_cons
(x, xs1) => let
val () = x0 := x
prval () = opt_some{a}(x0)
in
true
end // end of [list_vt_cons]
| list_vt_nil () => let
prval () = opt_none{a}(x0)
in
false
end // end of [list_vt_nil]
//
end // end of [linset_choose]
(* ****** ****** *)
implement
{a}{env}
linset_foreach_env (xs, env) = let
//
implement
list_vt_foreach$fwork<a><env>
(x, env) = linset_foreach$fwork<a><env> (x, env)
//
in
list_vt_foreach_env<a><env> (xs, env)
end // end of [linset_foreach_env]
(* ****** ****** *)
implement{a}
linset_listize (xs) = xs
(* ****** ****** *)
implement{a}
linset_listize1 (xs) = list_vt_copy (xs)
(* ****** ****** *)
//
// HX: functions for processing mynodes
//
(* ****** ****** *)
implement{
} mynode_null{a} () =
$UN.castvwtp0{mynode(a,null)}(the_null_ptr)
// end of [mynode_null]
(* ****** ****** *)
implement
{a}(*tmp*)
mynode_make_elt
(x) = let
//
val nx = list_vt_cons{a}{0}(x, _ )
//
in
$UN.castvwtp0{mynode1(a)}(nx)
end // end of [mynode_make_elt]
(* ****** ****** *)
implement{
} mynode_free
{a}(nx) = () where {
val nx =
$UN.castvwtp0{List1_vt(a)}(nx)
//
val+~list_vt_cons (_, nx2) = nx
//
prval ((*void*)) = $UN.cast2void (nx2)
//
} (* end of [mynode_free] *)
(* ****** ****** *)
implement
{a}(*tmp*)
mynode_get_elt
(nx) = (x) where {
//
val nx1 =
$UN.castvwtp1{List1_vt(a)}(nx)
//
val+list_vt_cons (x, _) = nx1
//
prval ((*void*)) = $UN.cast2void (nx1)
//
} (* end of [mynode_get_elt] *)
(* ****** ****** *)
implement
{a}(*tmp*)
mynode_set_elt
{l} (nx, x0) =
{
//
val nx1 =
$UN.castvwtp1{List1_vt(a)}(nx)
//
val+@list_vt_cons (x, _) = nx1
//
val () = x := x0
//
prval () = fold@ (nx1)
prval () = $UN.cast2void (nx1)
//
prval () = __assert (nx) where
{
extern praxi __assert (nx: !mynode(a?, l) >> mynode (a, l)): void
} (* end of [prval] *)
//
} (* end of [mynode_set_elt] *)
(* ****** ****** *)
implement
{a}(*tmp*)
mynode_getfree_elt
(nx) = (x) where {
//
val nx =
$UN.castvwtp0{List1_vt(a)}(nx)
//
val+~list_vt_cons (x, nx2) = nx
//
prval ((*void*)) = $UN.cast2void (nx2)
//
} (* end of [mynode_getfree_elt] *)
(* ****** ****** *)
(*
fun{a:t0p}
linset_takeout_ngc
(set: &set(INV(a)) >> _, x0: a):<!wrt> mynode0 (a)
// end of [linset_takeout_ngc]
*)
implement
{a}(*tmp*)
linset_takeout_ngc
(set, x0) = let
//
fun takeout
(
xs: &List0_vt (a) >> _
) : mynode0(a) = let
in
//
case+ xs of
| @list_vt_cons
(x, xs1) => let
prval pf_x = view@x
prval pf_xs1 = view@xs1
val sgn =
compare_elt_elt<a> (x0, x)
// end of [val]
in
if sgn > 0 then let
prval () = fold@ (xs)
in
mynode_null{a}((*void*))
end else if sgn < 0 then let
val res = takeout (xs1)
prval ((*void*)) = fold@ (xs)
in
res
end else let // x0 = x
val xs1_ = xs1
val res = $UN.castvwtp0{mynode1(a)}((pf_x, pf_xs1 | xs))
val () = xs := xs1_
in
res // [x0] in [xs]
end (* end of [if] *)
end // end of [list_vt_cons]
| list_vt_nil () => mynode_null{a}((*void*))
//
end (* end of [takeout] *)
//
in
$effmask_all (takeout (set))
end // end of [linset_takeout_ngc]
(* ****** ****** *)
implement
{a}(*tmp*)
linset_takeoutmax_ngc
(xs) = let
in
//
case+ xs of
| @list_vt_cons
(x, xs1) => let
prval pf_x = view@x
prval pf_xs1 = view@xs1
val xs_ = xs
val () = xs := xs1
in
$UN.castvwtp0{mynode1(a)}((pf_x, pf_xs1 | xs_))
end // end of [list_vt_cons]
| @list_vt_nil () => let
prval () = fold@ (xs)
in
mynode_null{a}((*void*))
end // end of [list_vt_nil]
//
end // end of [linset_takeoutmax_ngc]
(* ****** ****** *)
implement
{a}(*tmp*)
linset_takeoutmin_ngc
(xs) = let
//
fun unsnoc
{n:pos} .<n>.
(
xs: &list_vt (a, n) >> list_vt (a, n-1)
) :<!wrt> mynode1 (a) = let
//
val+@list_vt_cons (x, xs1) = xs
//
prval pf_x = view@x and pf_xs1 = view@xs1
//
in
//
case+ xs1 of
| list_vt_cons _ =>
let val res = unsnoc(xs1) in fold@xs; res end
// end of [list_vt_cons]
| list_vt_nil () => let
val xs_ = xs
val () = xs := list_vt_nil{a}()
in
$UN.castvwtp0{mynode1(a)}((pf_x, pf_xs1 | xs_))
end // end of [list_vt_nil]
//
end // end of [unsnoc]
//
in
//
case+ xs of
| list_vt_cons _ => unsnoc (xs)
| list_vt_nil () => mynode_null{a}((*void*))
//
end // end of [linset_takeoutmin_ngc]
(* ****** ****** *)
(* end of [linset_listord.dats] *)

View File

@@ -0,0 +1,51 @@
(***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(***********************************************************************)
(*
** ATS/Postiats - Unleashing the Potential of Types!
** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: hwxiATcsDOTbuDOTedu
// Time: October, 2010
//
(* ****** ****** *)
#define ATS_PACKNAME "ATSLIB.libats.linset_listord"
#define ATS_STALOADFLAG 0 // no static loading at run-time
(* ****** ****** *)
#include "./SHARE/linset.hats"
#include "./SHARE/linset_node.hats"
(* ****** ****** *)
castfn
linset2list {a:t0p} (xs: set (INV(a))):<> List0_vt (a)
(* ****** ****** *)
(* end of [linset_listord.sats] *)

215
samples/ATS/main.atxt Normal file
View File

@@ -0,0 +1,215 @@
%{
#include "./../ATEXT/atextfun.hats"
%}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>EFFECTIVATS-DiningPhil2</title>
#patscode_style()
</head>
<body>
<h1>
Effective ATS: Dining Philosophers
</h1>
In this article, I present an implementation of a slight variant of the
famous problem of 5-Dining-Philosophers by Dijkstra that makes simple but
convincing use of linear types.
<h2>
The Original Problem
</h2>
There are five philosophers sitting around a table and there are also 5
forks placed on the table such that each fork is located between the left
hand of a philosopher and the right hand of another philosopher. Each
philosopher does the following routine repeatedly: thinking and dining. In
order to dine, a philosopher needs to first acquire two forks: one located
on his left-hand side and the other on his right-hand side. After
finishing dining, a philosopher puts the two acquired forks onto the table:
one on his left-hand side and the other on his right-hand side.
<h2>
A Variant of the Original Problem
</h2>
The following twist is added to the original version:
<p>
After a fork is used, it becomes a "dirty" fork and needs to be put in a
tray for dirty forks. There is a cleaner who cleans dirty forks and then
puts them back on the table.
<h2>
Channels for Communication
</h2>
A channel is just a shared queue of fixed capacity. The following two
functions are for inserting an element into and taking an element out of a
given channel:
<pre
class="patsyntax">
#pats2xhtml_sats("\
fun{a:vt0p} channel_insert (channel (a), a): void
fun{a:vt0p} channel_takeout (chan: channel (a)): (a)
")</pre>
If [channel_insert] is called on a channel that is full, then the caller is
blocked until an element is taken out of the channel. If [channel_takeout]
is called on a channel that is empty, then the caller is blocked until an
element is inserted into the channel.
<h2>
A Channel for Each Fork
</h2>
Forks are resources given a linear type. Each fork is initially stored in a
channel, which can be obtained by calling the following function:
<pre
class="patsyntax">
#pats2xhtml_sats("\
fun fork_changet (n: nphil): channel(fork)
")</pre>
where the type [nphil] is defined to be [natLt(5)] (for natural numbers
less than 5). The channels for storing forks are chosen to be of capacity
2. The reason that channels of capacity 2 are chosen to store at most one
element (in each of them) is to guarantee that these channels can never be
full (so that there is no attempt made to send signals to awake callers
supposedly being blocked due to channels being full).
<h2>
A Channel for the Fork Tray
</h2>
A tray for storing "dirty" forks is also a channel, which can be obtained
by calling the following function:
<pre
class="patsyntax">
#pats2xhtml_sats("\
fun forktray_changet ((*void*)): channel(fork)
")</pre>
The capacity chosen for the channel is 6 (instead of 5) so that it can
never become full (as there are only 5 forks in total).
<h2>
Philosopher Loop
</h2>
Each philosopher is implemented as a loop:
<pre
class="patsyntax">
#pats2xhtml_dats('\
implement
phil_loop (n) = let
//
val () = phil_think (n)
//
val nl = phil_left (n) // = n
val nr = phil_right (n) // = (n+1) % 5
//
val ch_lfork = fork_changet (nl)
val ch_rfork = fork_changet (nr)
//
val lf = channel_takeout (ch_lfork)
val () = println! ("phil_loop(", n, ") picks left fork")
//
val () = randsleep (2) // sleep up to 2 seconds
//
val rf = channel_takeout (ch_rfork)
val () = println! ("phil_loop(", n, ") picks right fork")
//
val () = phil_dine (n, lf, rf)
//
val ch_forktray = forktray_changet ()
val () = channel_insert (ch_forktray, lf) // left fork to dirty tray
val () = channel_insert (ch_forktray, rf) // right fork to dirty tray
//
in
phil_loop (n)
end // end of [phil_loop]
')</pre>
It should be straighforward to follow the code for [phil_loop].
<h2>
Fork Cleaner Loop
</h2>
A cleaner is implemented as a loop:
<pre
class="patsyntax">
#pats2xhtml_dats('\
implement
cleaner_loop () = let
//
val ch = forktray_changet ()
val f0 = channel_takeout (ch) // [f0] is dirty
//
val () = cleaner_wash (f0) // washes dirty [f0]
val () = cleaner_return (f0) // puts back cleaned [f0]
//
in
cleaner_loop ()
end // end of [cleaner_loop]
')</pre>
The function [cleaner_return] first finds out the number of a given fork
and then uses the number to locate the channel for storing the fork. Its
actual implementation is given as follows:
<pre
class="patsyntax">
#pats2xhtml_dats('\
implement
cleaner_return (f) =
{
val n = fork_get_num (f)
val ch = fork_changet (n)
val () = channel_insert (ch, f)
}
')</pre>
It should now be straighforward to follow the code for [cleaner_loop].
<h2>
Testing
</h2>
The entire code of this implementation is stored in the following files:
<pre>
DiningPhil2.sats
DiningPhil2.dats
DiningPhil2_fork.dats
DiningPhil2_thread.dats
</pre>
There is also a Makefile available for compiling the ATS source code into
an excutable for testing. One should be able to encounter a deadlock after
running the simulation for a while.
<hr size="2">
This article is written by <a href="http://www.cs.bu.edu/~hwxi/">Hongwei Xi</a>.
</body>
</html>
%{
implement main () = fprint_filsub (stdout_ref, "main_atxt.txt")
%}

45
samples/C#/Index.cshtml Normal file
View File

@@ -0,0 +1,45 @@
@{
ViewBag.Title = "Home Page";
}
@section featured {
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>@ViewBag.Message</h2>
</hgroup>
<p>
To learn more about ASP.NET MVC visit
<a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET MVC.
If you have any questions about ASP.NET MVC visit
<a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET MVC Forum">our forums</a>.
</p>
</div>
</section>
}
<h3>We suggest the following:</h3>
<ol class="round">
<li class="one">
<h5>Getting Started</h5>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
enables a clean separation of concerns and that gives you full control over markup
for enjoyable, agile development. ASP.NET MVC includes many features that enable
fast, TDD-friendly development for creating sophisticated applications that use
the latest web standards.
<a href="http://go.microsoft.com/fwlink/?LinkId=245151">Learn more…</a>
</li>
<li class="two">
<h5>Add NuGet packages and jump-start your coding</h5>
NuGet makes it easy to install and update free libraries and tools.
<a href="http://go.microsoft.com/fwlink/?LinkId=245153">Learn more…</a>
</li>
<li class="three">
<h5>Find Web Hosting</h5>
You can easily find a web hosting company that offers the right mix of features
and price for your applications.
<a href="http://go.microsoft.com/fwlink/?LinkId=245157">Learn more…</a>
</li>
</ol>

21
samples/C#/Program.cs Normal file
View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LittleSampleApp
{
/// <summary>
/// Just what it says on the tin. A little sample application for Linguist to try out.
///
/// </summary>
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, I am a little sample application to test GitHub's Linguist module.");
Console.WriteLine("I also include a Razor MVC file just to prove it handles cshtml files now.");
}
}
}

42
samples/C++/CsvStreamer.h Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include <string>
#include <vector>
#include <fstream>
#include "util.h"
using namespace std;
#define DEFAULT_DELIMITER ','
class CsvStreamer
{
private:
ofstream file; // File output stream
vector<string> row_buffer; // Buffer which stores a row's data before being flushed/written
int fields; // Number of fields (columns)
long rows; // Number of rows (records) including header row
char delimiter; // Delimiter character; comma by default
string sanitize(string); // Returns a string ready for output into the file
public:
CsvStreamer(); // Empty CSV streamer... be sure to open the file before writing!
CsvStreamer(string, char); // Same as open(string, char)...
CsvStreamer(string); // Opens an output CSV file given a file path/name
~CsvStreamer(); // Ensures the output file is closed and saved
void open(string); // Opens an output CSV file given a file path/name (default delimiter)
void open(string, char); // Opens an output CSV file given a file path/name and a delimiting character (default comma)
void add_field(string); // If still on first line, adds a new field to the header row
void save_fields(); // Call this to save the header row; all new writes should be through append()
void append(string); // Appends the current row with this data for the next field; quoted only if needed (leading/trailing spaces are trimmed)
void append(string, bool); // Like append(string) but can specify whether to trim spaces at either end of the data (false to keep spaces)
void append(float); // Appends the current row with this number
void append(double); // Appends the current row with this number
void append(long); // Appends the current row with this number
void append(int); // Appends the current row with this number
void writeln(); // Flushes what was in the row buffer into the file (writes the row)
void close(); // Saves and closes the file
int field_count(); // Gets the number of fields (columns)
long row_count(); // Gets the number of records (rows) -- NOT including the header row
};

32
samples/C++/Field.h Normal file
View File

@@ -0,0 +1,32 @@
/*****************************************************************************
* Dwarf Mine - The 13-11 Benchmark
*
* Copyright (c) 2013 Bünger, Thomas; Kieschnick, Christian; Kusber,
* Michael; Lohse, Henning; Wuttke, Nikolai; Xylander, Oliver; Yao, Gary;
* Zimmermann, Florian
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#pragma once
enum Field { Free, Black, White, Illegal };
typedef Field Player;

32
samples/C++/Types.h Normal file
View File

@@ -0,0 +1,32 @@
/*****************************************************************************
* Dwarf Mine - The 13-11 Benchmark
*
* Copyright (c) 2013 Bünger, Thomas; Kieschnick, Christian; Kusber,
* Michael; Lohse, Henning; Wuttke, Nikolai; Xylander, Oliver; Yao, Gary;
* Zimmermann, Florian
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#pragma once
#include <cstdint>
typedef uint32_t smallPrime_t;

1129
samples/C++/bcm2835.h Normal file

File diff suppressed because it is too large Load Diff

138
samples/C++/libcanister.h Normal file
View File

@@ -0,0 +1,138 @@
#ifndef LIBCANIH
#define LIBCANIH
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <cstring>
#define int64 unsigned long long
//#define DEBUG
#ifdef DEBUG
#define dout cout
#else
#define dout if (0) cerr
#endif
using namespace std;
namespace libcanister
{
//the canmem object is a generic memory container used commonly
//throughout the canister framework to hold memory of uncertain
//length which may or may not contain null bytes.
class canmem
{
public:
char* data; //the raw memory block
int size; //the absolute length of the block
canmem(); //creates an unallocated canmem
canmem(int allocsize); //creates an allocated, blank canmem of size
canmem(char* strdata); //automates the creation of zero-limited canmems
~canmem(); //cleans up the canmem
void zeromem(); //overwrites this canmem
void fragmem(); //overwrites this canmem with fragment notation
void countlen(); //counts length of zero-limited strings and stores it in size
void trim(); //removes any nulls from the end of the string
static canmem null(); //returns a singleton null canmem
};
//contains information about the canister
class caninfo
{
public:
canmem path; //physical path
canmem internalname; //a name for the canister
int numfiles; //the number of files in the canister
};
//necessary for the use of this class as a type in canfile
class canister;
//this object holds the definition of a 'file' within the
//canister 'filesystem.'
class canfile
{
public:
libcanister::canister* parent; //the canister that holds this file
canmem path; //internal path ('filename')
canmem data; //the file's decompressed contents
int isfrag; //0 = probably not fragment, 1 = definitely a fragment (ignore)
int cfid; //'canfile id' -- a unique ID for this file
int64 dsize; //ondisk size (compressed form size)
int cachestate; //0 = not in memory, 1 = in memory, 2 = in memory and needs flush
//-1 = error, check the data for the message
void cache(); //pull the file from disk and cache it in memory
void cachedump(); //deletes the contents of this file from the memory cache after assuring the on disk copy is up to date
void cachedumpfinal(fstream& infile); //same as cachedump, but more efficient during closing procedures
void flush(); //updates the on disk copy, but retains the memory cache
};
//the primary class
//this defines and controls a single canister
class canister
{
//table of contents
//absolutely worthless to the control code in the canister
//but quite useful to programs using the API, as they may
//desire to enumerate the files in a canister for a user's
//use or for their own.
//contains a newline-delimited list of files in the container.
canfile TOC;
public:
caninfo info; //the general info about this canister
//the raw canfiles -- recommended that programs do not modify
//these files directly, but not enforced.
canfile* files;
bool readonly; //if true then no write routines will do anything
//maximum number of files to have in memory at any given
//time, change this to whatever suits your application.
int cachemax;
int cachecnt; //number of files in the cache (should not be modified)
//both initialize the canister from a physical location
canister (canmem fspath);
canister (char* fspath);
//destroys the canister (after flushing the modded buffers, of course)
~canister();
//open the fspath
//does it exist?
// | --- yes --- opening it (return 1)
// | --- yes --- file is corrupted, halting (return -1)
// | --- no --- making a new one (return 0)
int open();
//close the canister, flush all buffers, clean up
int close();
//deletes the file at path inside this canister
int delFile(canmem path);
//pulls the contents of the file from disk or memory and returns it as a file
canfile getFile(canmem path);
//creates a file if it does not exist, otherwise overwrites
//returns whether operation succeeded
bool writeFile(canmem path, canmem data);
bool writeFile(canfile file);
//get the 'table of contents', a file containing a newline delimited
//list of the file paths in the container which have contents
canfile getTOC();
//brings the cache back within the cachemax limit
//important: sCFID is the safe CFID
//(the CFID of the file we want to avoid uncaching)
//really just used internally, but it can't do any harm.
void cacheclean(int sCFID, bool dFlush = false);
};
}
#endif

92
samples/C++/metrics.h Normal file
View File

@@ -0,0 +1,92 @@
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef NINJA_METRICS_H_
#define NINJA_METRICS_H_
#include <string>
#include <vector>
using namespace std;
#include "util.h" // For int64_t.
/// The Metrics module is used for the debug mode that dumps timing stats of
/// various actions. To use, see METRIC_RECORD below.
/// A single metrics we're tracking, like "depfile load time".
struct Metric {
string name;
/// Number of times we've hit the code path.
int count;
/// Total time (in micros) we've spent on the code path.
int64_t sum;
};
/// A scoped object for recording a metric across the body of a function.
/// Used by the METRIC_RECORD macro.
struct ScopedMetric {
explicit ScopedMetric(Metric* metric);
~ScopedMetric();
private:
Metric* metric_;
/// Timestamp when the measurement started.
/// Value is platform-dependent.
int64_t start_;
};
/// The singleton that stores metrics and prints the report.
struct Metrics {
Metric* NewMetric(const string& name);
/// Print a summary report to stdout.
void Report();
private:
vector<Metric*> metrics_;
};
/// Get the current time as relative to some epoch.
/// Epoch varies between platforms; only useful for measuring elapsed time.
int64_t GetTimeMillis();
/// A simple stopwatch which returns the time
/// in seconds since Restart() was called.
struct Stopwatch {
public:
Stopwatch() : started_(0) {}
/// Seconds since Restart() call.
double Elapsed() const {
return 1e-6 * static_cast<double>(Now() - started_);
}
void Restart() { started_ = Now(); }
private:
uint64_t started_;
uint64_t Now() const;
};
/// The primary interface to metrics. Use METRIC_RECORD("foobar") at the top
/// of a function to get timing stats recorded for each call of the function.
#define METRIC_RECORD(name) \
static Metric* metrics_h_metric = \
g_metrics ? g_metrics->NewMetric(name) : NULL; \
ScopedMetric metrics_h_scoped(metrics_h_metric);
extern Metrics* g_metrics;
#endif // NINJA_METRICS_H_

View File

@@ -0,0 +1,6 @@
#include <cstdint>
namespace Gui
{
}

26
samples/C++/rpc.h Normal file
View File

@@ -0,0 +1,26 @@
// Copyright (C) 2013 Simon Que
//
// This file is part of DuinoCube.
//
// DuinoCube is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DuinoCube is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DuinoCube. If not, see <http://www.gnu.org/licenses/>.
// DuinoCube remote procedure call functions.
#include <stdint.h>
// Initializes RPC system.
void rpc_init();
// Runs the RPC server loop forever.
void rpc_server_loop();

102
samples/C/bootstrap.h Normal file
View File

@@ -0,0 +1,102 @@
#ifndef BOOTSTRAP_H
#define BOOTSTRAP_H
#include <stdio.h>
#include "cxrs.h"
/* If we're not using GNU C, elide __attribute__ */
#ifndef __GNUC__
# define __attribute__(x) /*NOTHING*/
#endif
typedef struct object object;
object *true;
object *false;
object *eof;
object *empty_list;
object *global_enviroment;
enum obj_type {
scm_bool,
scm_empty_list,
scm_eof,
scm_char,
scm_int,
scm_pair,
scm_symbol,
scm_prim_fun,
scm_lambda,
scm_str,
scm_file
};
typedef object *(*prim_proc)(object *args);
object *read(FILE *in);
object *eval(object *code, object *env);
void print(FILE *out, object *obj, int display);
int check_type(enum obj_type type, object *obj, int err_on_false);
static inline int is_true(object *obj)
{
return obj != false;
}
object *make_int(int value);
int obj2int(object *i);
object *make_bool(int value);
int obj2bool(object *b);
object *make_char(char c);
char obj2char(object *ch);
object *make_str(char *str);
char *obj2str(object *str);
object *cons(object *car, object *cdr);
object *car(object *pair);
object *cdr(object *pair);
void set_car(object *pair, object *new);
void set_cdr(object *pair, object *new);
object *make_symbol(char *name);
char *sym2str(object *sym);
object *get_symbol(char *name) __attribute__((pure));
object *make_prim_fun(prim_proc fun);
prim_proc obj2prim_proc(object *proc);
object *make_lambda(object *args, object *code, object *env);
object *lambda_code(object *lambda);
object *lambda_args(object *lambda);
object *make_port(FILE *handle, int direction);
int port_direction(object *port);
FILE *port_handle(object *port);
void set_port_handle_to_null(object *port);
/*both of these should never be called*/
object *apply_proc(object *);
object *eval_proc(object *);
object *maybe_add_begin(object *code);
void init_enviroment(object *env);
void eval_err(char *msg, object *code) __attribute__((noreturn));
void define_var(object *var, object *val, object *env);
void set_var(object *var, object *val, object *env);
object *get_var(object *var, object *env);
object *cond2nested_if(object *cond);
object *let2lambda(object *let);
object *and2nested_if(object *and);
object *or2nested_if(object *or);
#endif /*include guard*/

56
samples/C/dynarray.cats Normal file
View File

@@ -0,0 +1,56 @@
/* ******************************************************************* */
/* */
/* Applied Type System */
/* */
/* ******************************************************************* */
/*
** ATS/Postiats - Unleashing the Potential of Types!
** Copyright (C) 2011-20?? Hongwei Xi, ATS Trustful Software, Inc.
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*/
/* ****** ****** */
/*
(* Author: Hongwei Xi *)
(* Authoremail: hwxi AT cs DOT bu DOT edu *)
(* Start time: March, 2013 *)
*/
/* ****** ****** */
#ifndef ATSHOME_LIBATS_DYNARRAY_CATS
#define ATSHOME_LIBATS_DYNARRAY_CATS
/* ****** ****** */
#include <string.h>
/* ****** ****** */
#define atslib_dynarray_memcpy memcpy
#define atslib_dynarray_memmove memmove
/* ****** ****** */
#endif // ifndef ATSHOME_LIBATS_DYNARRAY_CATS
/* ****** ****** */
/* end of [dynarray.cats] */

47
samples/C/readline.cats Normal file
View File

@@ -0,0 +1,47 @@
/*
** API in ATS for GNU-readline
*/
/* ****** ****** */
/*
** Permission to use, copy, modify, and distribute this software for any
** purpose with or without fee is hereby granted, provided that the above
** copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
** ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* ****** ****** */
#ifndef READLINE_READLINE_CATS
#define READLINE_READLINE_CATS
/* ****** ****** */
#include <readline/readline.h>
/* ****** ****** */
//
#define \
atscntrb_readline_rl_library_version() ((char*)rl_library_version)
//
#define atscntrb_readline_rl_readline_version() (rl_readline_version)
//
/* ****** ****** */
#define atscntrb_readline_readline readline
/* ****** ****** */
#endif // ifndef READLINE_READLINE_CATS
/* ****** ****** */
/* end of [readline.cats] */

12
samples/Cirru/array.cirru Normal file
View File

@@ -0,0 +1,12 @@
print $ array
int 1
string 2
print $ array
int 1
array
int 2
string 3
array
string 4

View File

@@ -0,0 +1,7 @@
set f $ block (a b c)
print a b c
call f (int 1) (int 2) (int 3)
f (int 1) (int 2) (int 3)

7
samples/Cirru/bool.cirru Normal file
View File

@@ -0,0 +1,7 @@
print $ bool true
print $ bool false
print $ bool yes
print $ bool no
print $ bool 1
print $ bool 0

14
samples/Cirru/map.cirru Normal file
View File

@@ -0,0 +1,14 @@
print $ map
a $ int 5
b $ array (int 1) (int 2)
c $ map
int 1
array (int 4)
set m $ map
a $ int 1
set m b $ int 2
print m

View File

@@ -0,0 +1,3 @@
print $ int 1
print $ float 1.2

View File

@@ -0,0 +1,2 @@
require ./stdio.cr

23
samples/Cirru/scope.cirru Normal file
View File

@@ -0,0 +1,23 @@
set a (int 2)
print (self)
set c (child)
under c
under parent
print a
print $ get c a
set c x (int 3)
print $ get c x
set just-print $ code
print a
print just-print
eval (self) just-print
eval just-print

55
samples/Cirru/stdio.cirru Normal file
View File

@@ -0,0 +1,55 @@
set a $ string 1
print a
print (string 1)
print nothing
print
map
a (int 4)
b $ map
a $ int 5
b $ int 6
c $ map
int 7
print
array
int 1
int 2
array
int 3
int 4
print
array
int 1
map
a $ int 2
b $ array
int 3
print
int 1
int 2
print $ code
set a 1
print (get a)
print $ array
int a
array
int a
set container (map)
set container code $ code
set a 1
print (get a)
print $ array
int a
array
int a
print container

View File

@@ -0,0 +1,3 @@
print $ string a
print $ string "a b"

View File

@@ -1,15 +1,19 @@
import 'dart:math' as math;
class Point {
num x, y;
Point(this.x, this.y);
distanceTo(Point other) {
num distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return Math.sqrt(dx * dx + dy * dy);
return math.sqrt(dx * dx + dy * dy);
}
var x, y;
}
main() {
Point p = new Point(2, 3);
Point q = new Point(3, 4);
void main() {
var p = new Point(2, 3);
var q = new Point(3, 4);
print('distance from p to q = ${p.distanceTo(q)}');
}

View File

@@ -1 +0,0 @@
print("hello")

9
samples/Hy/fibonacci.hy Normal file
View File

@@ -0,0 +1,9 @@
;; Fibonacci example in Hy.
(defn fib [n]
(if (<= n 2) n
(+ (fib (- n 1)) (fib (- n 2)))))
(if (= __name__ "__main__")
(for [x [1 2 3 4 5 6 7 8]]
(print (fib x))))

13
samples/Hy/hello-world.hy Normal file
View File

@@ -0,0 +1,13 @@
;; The concurrent.futures example in Hy.
(import [concurrent.futures [ThreadPoolExecutor as-completed]]
[random [randint]]
[sh [sleep]])
(defn task-to-do []
(sleep (randint 1 5)))
(with-as (ThreadPoolExecutor 10) executor
(setv jobs (list-comp (.submit executor task-to-do) (x (range 0 10))))
(for (future (as-completed jobs))
(.result future)))

29
samples/IDL/mg_acosh.pro Normal file
View File

@@ -0,0 +1,29 @@
; docformat = 'rst'
;+
; Inverse hyperbolic cosine. Uses the formula:
;
; $$\text{acosh}(z) = \ln(z + \sqrt{z + 1} \sqrt{z - 1})$$
;
; :Examples:
; The arc hyperbolic sine function looks like::
;
; IDL> x = 2.5 * findgen(1000) / 999. + 1.
; IDL> plot, x, mg_acosh(x), xstyle=1
;
; This should look like:
;
; .. image:: acosh.png
;
; :Returns:
; float, double, complex, or double complex depending on the input
;
; :Params:
; z : in, required, type=numeric
; input
;-
function mg_acosh, z
compile_opt strictarr
return, alog(z + sqrt(z + 1) * sqrt(z - 1))
end

View File

@@ -0,0 +1,9 @@
MODULE mg_analysis
DESCRIPTION Tools for analysis
VERSION 1.0
SOURCE mgalloy
BUILD_DATE January 18, 2011
FUNCTION MG_ARRAY_EQUAL 2 2 KEYWORDS
FUNCTION MG_TOTAL 1 1

35
samples/IDL/mg_gcd.pro Normal file
View File

@@ -0,0 +1,35 @@
; docformat = 'rst'
;+
; Find the greatest common denominator (GCD) for two positive integers.
;
; :Returns:
; integer
;
; :Params:
; a : in, required, type=integer
; first integer
; b : in, required, type=integer
; second integer
;-
function mg_gcd, a, b
compile_opt strictarr
on_error, 2
if (n_params() ne 2) then message, 'incorrect number of arguments'
if (~mg_isinteger(a) || ~mg_isinteger(b)) then begin
message, 'integer arguments required'
endif
_a = abs(a)
_b = abs(b)
minArg = _a < _b
maxArg = _a > _b
if (minArg eq 0) then return, maxArg
remainder = maxArg mod minArg
if (remainder eq 0) then return, minArg
return, mg_gcd(minArg, remainder)
end

42
samples/IDL/mg_trunc.pro Normal file
View File

@@ -0,0 +1,42 @@
; docformat = 'rst'
;+
; Truncate argument towards 0.0, i.e., takes the `FLOOR` of positive values
; and the `CEIL` of negative values.
;
; :Examples:
; Try the main-level program at the end of this file. It does::
;
; IDL> print, mg_trunc([1.2, -1.2, 0.0])
; 1 -1 0
; IDL> print, floor([1.2, -1.2, 0.0])
; 1 -2 0
; IDL> print, ceil([1.2, -1.2, 0.0])
; 2 -1 0
;
; :Returns:
; array of same type as argument
;
; :Params:
; x : in, required, type=float/double
; array containing values to truncate
;-
function mg_trunc, x
compile_opt strictarr
result = ceil(x)
posInd = where(x gt 0, nposInd)
if (nposInd gt 0L) then begin
result[posInd] = floor(x[posInd])
endif
return, result
end
; main-level example program
print, mg_trunc([1.2, -1.2, 0.0])
end

View File

@@ -0,0 +1,29 @@
/*
* The following is a contrived example, but it illustrates most of the features:
*/
{
foo: 'bar',
while: true,
this: 'is a \
multi-line string',
// this is an inline comment
here: 'is another', // inline comment
/* this is a block comment
that continues on another line */
hex: 0xDEADbeef,
half: .5,
delta: +10,
to: Infinity, // and beyond!
finally: 'a trailing comma',
oh: [
"we shouldn't forget",
'arrays can have',
'trailing commas too',
],
}

View File

@@ -0,0 +1,28 @@
// This file is written in JSON5 syntax, naturally, but npm needs a regular
// JSON file, so compile via `npm run build`. Be sure to keep both in sync!
{
name: 'json5',
version: '0.2.0',
description: 'JSON for the ES5 era.',
keywords: ['json', 'es5'],
author: 'Aseem Kishore <aseem.kishore@gmail.com>',
contributors: [
'Max Nanasy <max.nanasy@gmail.com>',
],
main: 'lib/json5.js',
bin: 'lib/cli.js',
dependencies: {},
devDependencies: {
mocha: '~1.0.3',
},
scripts: {
build: './lib/cli.js -c package.json5',
test: 'mocha --ui exports --reporter spec',
},
homepage: 'http://json5.org/',
repository: {
type: 'git',
url: 'https://github.com/aseemk/json5.git',
},
}

View File

@@ -0,0 +1,30 @@
{
"@context": {
"property": "http://example.com/vocab#property"
},
"@id": "../document-relative",
"@type": "#document-relative",
"property": {
"@context": {
"@base": "http://example.org/test/"
},
"@id": "../document-base-overwritten",
"@type": "#document-base-overwritten",
"property": [
{
"@context": null,
"@id": "../document-relative",
"@type": "#document-relative",
"property": "context completely reset, drops property"
},
{
"@context": {
"@base": null
},
"@id": "../document-relative",
"@type": "#document-relative",
"property": "only @base is cleared"
}
]
}
}

61
samples/Mask/view.mask Normal file
View File

@@ -0,0 +1,61 @@
// HTML Elements
header {
img .logo src='/images/~[currentLogo].png' alt=logo;
h4 > 'Bar View'
if (currentUser) {
.account >
a href='/acount' >
'Hello, ~[currentUser.username]'
}
}
.view {
ul {
// Iteration
for ((user, index) of users) {
li.user data-id='~[user.id]' {
// interpolation
.name > '~[ user.username ]'
// expression
.count > '~[: user.level.toFixed(2) ]'
// util
/* Localization sample
* lastActivity: "Am {0:dd. MM} war der letzte Eintrag"
*/
.date > '~[ L: "lastActivity", user.date]'
}
}
}
// Component
:countdownComponent {
input type = text >
:dualbind value='number';
button x-signal='click: countdownStart' > 'Start';
h5 {
'~[bind: number]'
:animation x-slot='countdownStart' {
@model > 'transition | scale(0) > scale(1) | 500ms'
@next > 'background-color | red > blue | 2s linear'
}
}
}
}
footer > :bazCompo {
'Component generated at ~[: $u.format($c.date, "HH-mm") ]'
}

View File

@@ -1,125 +0,0 @@
namespace Loops;
interface
uses System.Linq;
type
ConsoleApp = class
public
class method Main;
method loopsTesting;
method fillData : sequence of Country;
var
Countries : sequence of Country;
end;
type
Country = public class
public
property Name : String;
property Capital : String;
constructor (setName : String; setCapital : String);
end;
implementation
class method ConsoleApp.Main;
begin
Console.WriteLine('Loops example');
Console.WriteLine();
with myConsoleApp := new ConsoleApp() do
myConsoleApp.loopsTesting;
end;
method ConsoleApp.loopsTesting;
begin
{---------------------------------}
{"for" loop, taking every 5th item}
for i : Int32 :=0 to 50 step 5 do
begin
Console.Write(i); Console.Write(' ');
end;
Console.WriteLine(); Console.WriteLine();
{---------------------------------}
{"for" loop, going from high to low value}
for i : Int32 := 10 downto 1 do
begin
Console.Write(i); Console.Write(' ');
end;
Console.WriteLine(); Console.WriteLine();
Countries := fillData;
{---------------------------------}
{loop with defined "index" variable, which will count from 0 through the number of elements looped}
Console.WriteLine('Countries: ');
for each c in Countries index num do
Console.WriteLine(Convert.ToString(num + 1) + ') ' + c.Name);
Console.WriteLine();
Console.WriteLine('Cities: ');
var ind : Integer :=0;
{---------------------------------}
{simple "loop" construct that loops endlessly, until broken out of}
loop
begin
Console.WriteLine(Countries.ElementAt(ind).Capital);
Inc(ind);
if ind = Countries.Count then break;
end;
Console.WriteLine();
{---------------------------------}
{the type of 'c' is inferred automatically}
for each c in Countries do
Console.WriteLine(c.Capital + ' is the capital of ' + c.Name);
Console.WriteLine();
ind := 0;
Console.WriteLine('Cities: ');
{"repeat ... until" loop}
repeat
Console.WriteLine(Countries.ElementAt(ind).Capital);
Inc(ind);
until ind = Countries.Count;
Console.WriteLine();
ind := 0;
Console.WriteLine('Countries: ');
{---------------------------------}
{"while ... do" loop}
while ind < Countries.Count do
begin
Console.WriteLine(Countries.ElementAt(ind).Name);
Inc(ind);
end;
Console.ReadLine();
end;
method ConsoleApp.fillData: sequence of Country;
begin
result := [new Country('UK', 'London'), new Country('USA', 'Washington'), new Country('Germany', 'Berlin'),
new Country('Ukraine', 'Kyiv'), new Country('Russia', 'Moscow'), new Country('France', 'Paris')];
end;
constructor Country (setName :String; setCapital: String);
begin
Name := setName;
Capital := setCapital;
end;
end.

520
samples/PAWN/grandlarc.pwn Normal file
View File

@@ -0,0 +1,520 @@
//----------------------------------------------------------
//
// GRAND LARCENY 1.0
// A freeroam gamemode for SA-MP 0.3
//
//----------------------------------------------------------
#include <a_samp>
#include <core>
#include <float>
#include "../include/gl_common.inc"
#include "../include/gl_spawns.inc"
#pragma tabsize 0
//----------------------------------------------------------
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_NORMAL_PLAYER 0xFFBB7777
#define CITY_LOS_SANTOS 0
#define CITY_SAN_FIERRO 1
#define CITY_LAS_VENTURAS 2
new total_vehicles_from_files=0;
// Class selection globals
new gPlayerCitySelection[MAX_PLAYERS];
new gPlayerHasCitySelected[MAX_PLAYERS];
new gPlayerLastCitySelectionTick[MAX_PLAYERS];
new Text:txtClassSelHelper;
new Text:txtLosSantos;
new Text:txtSanFierro;
new Text:txtLasVenturas;
new thisanimid=0;
new lastanimid=0;
//----------------------------------------------------------
main()
{
print("\n---------------------------------------");
print("Running Grand Larceny - by the SA-MP team\n");
print("---------------------------------------\n");
}
//----------------------------------------------------------
public OnPlayerConnect(playerid)
{
GameTextForPlayer(playerid,"~w~Grand Larceny",3000,4);
SendClientMessage(playerid,COLOR_WHITE,"Welcome to {88AA88}G{FFFFFF}rand {88AA88}L{FFFFFF}arceny");
// class selection init vars
gPlayerCitySelection[playerid] = -1;
gPlayerHasCitySelected[playerid] = 0;
gPlayerLastCitySelectionTick[playerid] = GetTickCount();
//SetPlayerColor(playerid,COLOR_NORMAL_PLAYER);
//Kick(playerid);
/*
Removes vending machines
RemoveBuildingForPlayer(playerid, 1302, 0.0, 0.0, 0.0, 6000.0);
RemoveBuildingForPlayer(playerid, 1209, 0.0, 0.0, 0.0, 6000.0);
RemoveBuildingForPlayer(playerid, 955, 0.0, 0.0, 0.0, 6000.0);
RemoveBuildingForPlayer(playerid, 1775, 0.0, 0.0, 0.0, 6000.0);
RemoveBuildingForPlayer(playerid, 1776, 0.0, 0.0, 0.0, 6000.0);
*/
/*
new ClientVersion[32];
GetPlayerVersion(playerid, ClientVersion, 32);
printf("Player %d reports client version: %s", playerid, ClientVersion);*/
return 1;
}
//----------------------------------------------------------
public OnPlayerSpawn(playerid)
{
if(IsPlayerNPC(playerid)) return 1;
new randSpawn = 0;
SetPlayerInterior(playerid,0);
TogglePlayerClock(playerid,0);
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, 30000);
if(CITY_LOS_SANTOS == gPlayerCitySelection[playerid]) {
randSpawn = random(sizeof(gRandomSpawns_LosSantos));
SetPlayerPos(playerid,
gRandomSpawns_LosSantos[randSpawn][0],
gRandomSpawns_LosSantos[randSpawn][1],
gRandomSpawns_LosSantos[randSpawn][2]);
SetPlayerFacingAngle(playerid,gRandomSpawns_LosSantos[randSpawn][3]);
}
else if(CITY_SAN_FIERRO == gPlayerCitySelection[playerid]) {
randSpawn = random(sizeof(gRandomSpawns_SanFierro));
SetPlayerPos(playerid,
gRandomSpawns_SanFierro[randSpawn][0],
gRandomSpawns_SanFierro[randSpawn][1],
gRandomSpawns_SanFierro[randSpawn][2]);
SetPlayerFacingAngle(playerid,gRandomSpawns_SanFierro[randSpawn][3]);
}
else if(CITY_LAS_VENTURAS == gPlayerCitySelection[playerid]) {
randSpawn = random(sizeof(gRandomSpawns_LasVenturas));
SetPlayerPos(playerid,
gRandomSpawns_LasVenturas[randSpawn][0],
gRandomSpawns_LasVenturas[randSpawn][1],
gRandomSpawns_LasVenturas[randSpawn][2]);
SetPlayerFacingAngle(playerid,gRandomSpawns_LasVenturas[randSpawn][3]);
}
//SetPlayerColor(playerid,COLOR_NORMAL_PLAYER);
SetPlayerSkillLevel(playerid,WEAPONSKILL_PISTOL,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_PISTOL_SILENCED,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_DESERT_EAGLE,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_SHOTGUN,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_SAWNOFF_SHOTGUN,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_SPAS12_SHOTGUN,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_MICRO_UZI,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_MP5,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_AK47,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_M4,200);
SetPlayerSkillLevel(playerid,WEAPONSKILL_SNIPERRIFLE,200);
GivePlayerWeapon(playerid,WEAPON_COLT45,100);
//GivePlayerWeapon(playerid,WEAPON_MP5,100);
TogglePlayerClock(playerid, 0);
return 1;
}
//----------------------------------------------------------
public OnPlayerDeath(playerid, killerid, reason)
{
new playercash;
// if they ever return to class selection make them city
// select again first
gPlayerHasCitySelected[playerid] = 0;
if(killerid == INVALID_PLAYER_ID) {
ResetPlayerMoney(playerid);
} else {
playercash = GetPlayerMoney(playerid);
if(playercash > 0) {
GivePlayerMoney(killerid, playercash);
ResetPlayerMoney(playerid);
}
}
return 1;
}
//----------------------------------------------------------
ClassSel_SetupCharSelection(playerid)
{
if(gPlayerCitySelection[playerid] == CITY_LOS_SANTOS) {
SetPlayerInterior(playerid,11);
SetPlayerPos(playerid,508.7362,-87.4335,998.9609);
SetPlayerFacingAngle(playerid,0.0);
SetPlayerCameraPos(playerid,508.7362,-83.4335,998.9609);
SetPlayerCameraLookAt(playerid,508.7362,-87.4335,998.9609);
}
else if(gPlayerCitySelection[playerid] == CITY_SAN_FIERRO) {
SetPlayerInterior(playerid,3);
SetPlayerPos(playerid,-2673.8381,1399.7424,918.3516);
SetPlayerFacingAngle(playerid,181.0);
SetPlayerCameraPos(playerid,-2673.2776,1394.3859,918.3516);
SetPlayerCameraLookAt(playerid,-2673.8381,1399.7424,918.3516);
}
else if(gPlayerCitySelection[playerid] == CITY_LAS_VENTURAS) {
SetPlayerInterior(playerid,3);
SetPlayerPos(playerid,349.0453,193.2271,1014.1797);
SetPlayerFacingAngle(playerid,286.25);
SetPlayerCameraPos(playerid,352.9164,194.5702,1014.1875);
SetPlayerCameraLookAt(playerid,349.0453,193.2271,1014.1797);
}
}
//----------------------------------------------------------
// Used to init textdraws of city names
ClassSel_InitCityNameText(Text:txtInit)
{
TextDrawUseBox(txtInit, 0);
TextDrawLetterSize(txtInit,1.25,3.0);
TextDrawFont(txtInit, 0);
TextDrawSetShadow(txtInit,0);
TextDrawSetOutline(txtInit,1);
TextDrawColor(txtInit,0xEEEEEEFF);
TextDrawBackgroundColor(txtClassSelHelper,0x000000FF);
}
//----------------------------------------------------------
ClassSel_InitTextDraws()
{
// Init our observer helper text display
txtLosSantos = TextDrawCreate(10.0, 380.0, "Los Santos");
ClassSel_InitCityNameText(txtLosSantos);
txtSanFierro = TextDrawCreate(10.0, 380.0, "San Fierro");
ClassSel_InitCityNameText(txtSanFierro);
txtLasVenturas = TextDrawCreate(10.0, 380.0, "Las Venturas");
ClassSel_InitCityNameText(txtLasVenturas);
// Init our observer helper text display
txtClassSelHelper = TextDrawCreate(10.0, 415.0,
" Press ~b~~k~~GO_LEFT~ ~w~or ~b~~k~~GO_RIGHT~ ~w~to switch cities.~n~ Press ~r~~k~~PED_FIREWEAPON~ ~w~to select.");
TextDrawUseBox(txtClassSelHelper, 1);
TextDrawBoxColor(txtClassSelHelper,0x222222BB);
TextDrawLetterSize(txtClassSelHelper,0.3,1.0);
TextDrawTextSize(txtClassSelHelper,400.0,40.0);
TextDrawFont(txtClassSelHelper, 2);
TextDrawSetShadow(txtClassSelHelper,0);
TextDrawSetOutline(txtClassSelHelper,1);
TextDrawBackgroundColor(txtClassSelHelper,0x000000FF);
TextDrawColor(txtClassSelHelper,0xFFFFFFFF);
}
//----------------------------------------------------------
ClassSel_SetupSelectedCity(playerid)
{
if(gPlayerCitySelection[playerid] == -1) {
gPlayerCitySelection[playerid] = CITY_LOS_SANTOS;
}
if(gPlayerCitySelection[playerid] == CITY_LOS_SANTOS) {
SetPlayerInterior(playerid,0);
SetPlayerCameraPos(playerid,1630.6136,-2286.0298,110.0);
SetPlayerCameraLookAt(playerid,1887.6034,-1682.1442,47.6167);
TextDrawShowForPlayer(playerid,txtLosSantos);
TextDrawHideForPlayer(playerid,txtSanFierro);
TextDrawHideForPlayer(playerid,txtLasVenturas);
}
else if(gPlayerCitySelection[playerid] == CITY_SAN_FIERRO) {
SetPlayerInterior(playerid,0);
SetPlayerCameraPos(playerid,-1300.8754,68.0546,129.4823);
SetPlayerCameraLookAt(playerid,-1817.9412,769.3878,132.6589);
TextDrawHideForPlayer(playerid,txtLosSantos);
TextDrawShowForPlayer(playerid,txtSanFierro);
TextDrawHideForPlayer(playerid,txtLasVenturas);
}
else if(gPlayerCitySelection[playerid] == CITY_LAS_VENTURAS) {
SetPlayerInterior(playerid,0);
SetPlayerCameraPos(playerid,1310.6155,1675.9182,110.7390);
SetPlayerCameraLookAt(playerid,2285.2944,1919.3756,68.2275);
TextDrawHideForPlayer(playerid,txtLosSantos);
TextDrawHideForPlayer(playerid,txtSanFierro);
TextDrawShowForPlayer(playerid,txtLasVenturas);
}
}
//----------------------------------------------------------
ClassSel_SwitchToNextCity(playerid)
{
gPlayerCitySelection[playerid]++;
if(gPlayerCitySelection[playerid] > CITY_LAS_VENTURAS) {
gPlayerCitySelection[playerid] = CITY_LOS_SANTOS;
}
PlayerPlaySound(playerid,1052,0.0,0.0,0.0);
gPlayerLastCitySelectionTick[playerid] = GetTickCount();
ClassSel_SetupSelectedCity(playerid);
}
//----------------------------------------------------------
ClassSel_SwitchToPreviousCity(playerid)
{
gPlayerCitySelection[playerid]--;
if(gPlayerCitySelection[playerid] < CITY_LOS_SANTOS) {
gPlayerCitySelection[playerid] = CITY_LAS_VENTURAS;
}
PlayerPlaySound(playerid,1053,0.0,0.0,0.0);
gPlayerLastCitySelectionTick[playerid] = GetTickCount();
ClassSel_SetupSelectedCity(playerid);
}
//----------------------------------------------------------
ClassSel_HandleCitySelection(playerid)
{
new Keys,ud,lr;
GetPlayerKeys(playerid,Keys,ud,lr);
if(gPlayerCitySelection[playerid] == -1) {
ClassSel_SwitchToNextCity(playerid);
return;
}
// only allow new selection every ~500 ms
if( (GetTickCount() - gPlayerLastCitySelectionTick[playerid]) < 500 ) return;
if(Keys & KEY_FIRE) {
gPlayerHasCitySelected[playerid] = 1;
TextDrawHideForPlayer(playerid,txtClassSelHelper);
TextDrawHideForPlayer(playerid,txtLosSantos);
TextDrawHideForPlayer(playerid,txtSanFierro);
TextDrawHideForPlayer(playerid,txtLasVenturas);
TogglePlayerSpectating(playerid,0);
return;
}
if(lr > 0) {
ClassSel_SwitchToNextCity(playerid);
}
else if(lr < 0) {
ClassSel_SwitchToPreviousCity(playerid);
}
}
//----------------------------------------------------------
public OnPlayerRequestClass(playerid, classid)
{
if(IsPlayerNPC(playerid)) return 1;
if(gPlayerHasCitySelected[playerid]) {
ClassSel_SetupCharSelection(playerid);
return 1;
} else {
if(GetPlayerState(playerid) != PLAYER_STATE_SPECTATING) {
TogglePlayerSpectating(playerid,1);
TextDrawShowForPlayer(playerid, txtClassSelHelper);
gPlayerCitySelection[playerid] = -1;
}
}
return 0;
}
//----------------------------------------------------------
public OnGameModeInit()
{
SetGameModeText("Grand Larceny");
ShowPlayerMarkers(PLAYER_MARKERS_MODE_GLOBAL);
ShowNameTags(1);
SetNameTagDrawDistance(40.0);
EnableStuntBonusForAll(0);
DisableInteriorEnterExits();
SetWeather(2);
SetWorldTime(11);
//UsePlayerPedAnims();
//ManualVehicleEngineAndLights();
//LimitGlobalChatRadius(300.0);
ClassSel_InitTextDraws();
// Player Class
AddPlayerClass(281,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(282,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(283,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(284,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(285,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(286,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(287,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(288,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(289,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(265,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(266,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(267,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(268,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(269,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(270,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(1,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(2,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(3,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(4,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(5,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(6,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(8,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(42,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(65,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
//AddPlayerClass(74,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(86,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(119,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(149,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(208,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(273,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(289,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(47,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(48,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(49,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(50,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(51,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(52,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(53,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(54,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(55,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(56,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(57,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(58,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(68,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(69,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(70,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(71,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(72,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(73,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(75,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(76,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(78,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(79,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(80,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(81,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(82,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(83,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(84,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(85,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(87,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(88,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(89,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(91,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(92,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(93,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(95,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(96,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(97,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(98,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
AddPlayerClass(99,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
// SPECIAL
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/trains.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/pilots.txt");
// LAS VENTURAS
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/lv_law.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/lv_airport.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/lv_gen.txt");
// SAN FIERRO
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/sf_law.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/sf_airport.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/sf_gen.txt");
// LOS SANTOS
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_law.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_airport.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_gen_inner.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_gen_outer.txt");
// OTHER AREAS
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/whetstone.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/bone.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/flint.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/tierra.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/red_county.txt");
printf("Total vehicles from files: %d",total_vehicles_from_files);
return 1;
}
//----------------------------------------------------------
public OnPlayerUpdate(playerid)
{
if(!IsPlayerConnected(playerid)) return 0;
if(IsPlayerNPC(playerid)) return 1;
// changing cities by inputs
if( !gPlayerHasCitySelected[playerid] &&
GetPlayerState(playerid) == PLAYER_STATE_SPECTATING ) {
ClassSel_HandleCitySelection(playerid);
return 1;
}
// No weapons in interiors
if(GetPlayerInterior(playerid) != 0 && GetPlayerWeapon(playerid) != 0) {
SetPlayerArmedWeapon(playerid,0); // fists
return 0; // no syncing until they change their weapon
}
// Don't allow minigun
if(GetPlayerWeapon(playerid) == WEAPON_MINIGUN) {
Kick(playerid);
return 0;
}
/* No jetpacks allowed
if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_USEJETPACK) {
Kick(playerid);
return 0;
}*/
/* For testing animations
new msg[128+1];
new animlib[32+1];
new animname[32+1];
thisanimid = GetPlayerAnimationIndex(playerid);
if(lastanimid != thisanimid)
{
GetAnimationName(thisanimid,animlib,32,animname,32);
format(msg, 128, "anim(%d,%d): %s %s", lastanimid, thisanimid, animlib, animname);
lastanimid = thisanimid;
SendClientMessage(playerid, 0xFFFFFFFF, msg);
}*/
return 1;
}
//----------------------------------------------------------

23
samples/Perl6/RoleQ.pm6 Normal file
View File

@@ -0,0 +1,23 @@
role q {
token stopper { \' }
token escape:sym<\\> { <sym> <item=.backslash> }
token backslash:sym<qq> { <?before 'q'> <quote=.LANG('MAIN','quote')> }
token backslash:sym<\\> { <text=.sym> }
token backslash:sym<stopper> { <text=.stopper> }
token backslash:sym<miscq> { {} . }
method tweak_q($v) { self.panic("Too late for :q") }
method tweak_qq($v) { self.panic("Too late for :qq") }
}
role qq does b1 does c1 does s1 does a1 does h1 does f1 {
token stopper { \" }
token backslash:sym<unrec> { {} (\w) { self.throw_unrecog_backslash_seq: $/[0].Str } }
token backslash:sym<misc> { \W }
method tweak_q($v) { self.panic("Too late for :q") }
method tweak_qq($v) { self.panic("Too late for :qq") }
}

View File

@@ -0,0 +1,22 @@
token pod_formatting_code {
$<code>=<[A..Z]>
'<' { $*POD_IN_FORMATTINGCODE := 1 }
$<content>=[ <!before '>'> <pod_string_character> ]+
'>' { $*POD_IN_FORMATTINGCODE := 0 }
}
token pod_string {
<pod_string_character>+
}
token something:sym«<» {
<!>
}
token name {
<!>
}
token comment:sym<#> {
'#' {} \N*
}

252
samples/Perl6/test.p6 Normal file
View File

@@ -0,0 +1,252 @@
#!/usr/bin/env perl6
use v6;
my $string = 'I look like a # comment!';
if $string eq 'foo' {
say 'hello';
}
regex http-verb {
'GET'
| 'POST'
| 'PUT'
| 'DELETE'
| 'TRACE'
| 'OPTIONS'
| 'HEAD'
}
# a sample comment
say 'Hello from Perl 6!'
#`{
multi-line comment!
}
say 'here';
#`(
multi-line comment!
)
say 'here';
#`{{{
I'm a special comment!
}}}
say 'there';
#`{{
I'm { even } specialer!
}}
say 'there';
#`{{
does {{nesting}} work?
}}
#`«<
trying mixed delimiters
»
my $string = qq<Hooray, arbitrary delimiter!>;
my $string = qq«Hooray, arbitrary delimiter!»;
my $string = q <now with whitespace!>;
my $string = qq<<more strings>>;
my %hash := Hash.new;
=begin pod
Here's some POD! Wooo
=end pod
=for Testing
This is POD (see? role isn't highlighted)
say('this is not!');
=table
Of role things
say('not in your table');
#= A single line declarator "block" (with a keyword like role)
#| Another single line declarator "block" (with a keyword like role)
#={
A declarator block (with a keyword like role)
}
#|{
Another declarator block (with a keyword like role)
}
#= { A single line declarator "block" with a brace (with a keyword like role)
#=«
More declarator blocks! (with a keyword like role)
»
#|«
More declarator blocks! (with a keyword like role)
»
say 'Moar code!';
my $don't = 16;
sub don't($x) {
!$x
}
say don't 'foo';
my %hash = (
:foo(1),
);
say %hash<foo>;
say %hash<<foo>>;
say %hash«foo»;
say %*hash<foo>;
say %*hash<<foo>>;
say %*hash«foo»;
say $<todo>;
say $<todo>;
for (@A Z @B) -> $a, $b {
say $a + $b;
}
Q:PIR {
.loadlib "somelib"
}
my $longstring = q/
lots
of
text
/;
my $heredoc = q:to/END_SQL/;
SELECT * FROM Users
WHERE first_name = 'Rob'
END_SQL
my $hello;
# Fun with regexen
if 'food' ~~ /foo/ {
say 'match!'
}
my $re = /foo/;
my $re2 = m/ foo /;
my $re3 = m:i/ FOO /;
call-a-sub(/ foo /);
call-a-sub(/ foo \/ bar /);
my $re4 = rx/something | something-else/;
my $result = ms/regexy stuff/;
my $sub0 = s/regexy stuff/more stuff/;
my $sub = ss/regexy stuff/more stuff/;
my $trans = tr/regexy stuff/more stuff/;
my @values = <a b c d>;
call-sub(<a b c d>);
call-sub <a b c d>;
my $result = $a < $b;
for <a b c d> -> $letter {
say $letter;
}
sub test-sub {
say @_;
say $!;
say $/;
say $0;
say $1;
say @*ARGS;
say $*ARGFILES;
say &?BLOCK;
say ::?CLASS;
say $?CLASS;
say @=COMMENT;
say %?CONFIG;
say $*CWD;
say $=data;
say %?DEEPMAGIC;
say $?DISTRO;
say $*DISTRO;
say $*EGID;
say %*ENV;
say $*ERR;
say $*EUID;
say $*EXECUTABLE_NAME;
say $?FILE;
say $?GRAMMAR;
say $*GID;
say $*IN;
say @*INC;
say %?LANG;
say $*LANG;
say $?LINE;
say %*META-ARGS;
say $?MODULE;
say %*OPTS;
say %*OPT;
say $?KERNEL;
say $*KERNEL;
say $*OUT;
say $?PACKAGE;
say $?PERL;
say $*PERL;
say $*PID;
say %=pod;
say $*PROGRAM_NAME;
say %*PROTOCOLS;
say ::?ROLE;
say $?ROLE;
say &?ROUTINE;
say $?SCOPE;
say $*TZ;
say $*UID;
say $?USAGE;
say $?VM;
say $?XVM;
}
say <a b c>;
my $perl5_re = m:P5/ fo{2} /;
my $re5 = rx«something | something-else»;
my $M := %*COMPILING<%?OPTIONS><M>;
say $M;
sub regex-name { ... }
my $pair = role-name => 'foo';
$pair = rolesque => 'foo';
my sub something(Str:D $value) { ... }
my $s = q«<
some
string
stuff
»;
my $regex = m«< some chars »;
# after
say $/<foo><bar>;
roleq;

View File

@@ -0,0 +1,41 @@
%!PS-Adobe-3.0
%%Creator: Aaron Puchert
%%Title: The Sierpinski triangle
%%Pages: 1
%%PageOrder: Ascend
%%BeginProlog
% PAGE SETTINGS
/pageset {
28.3464566 28.3464566 scale % set cm = 1
0.5 0.5 translate
0 setlinewidth
} def
% sierpinski(n) draws a sierpinski triangle of order n
/sierpinski {
dup 0 gt {
[0.5 0 0 0.5 0 0] concat dup 1 sub sierpinski
[1 0 0 1 1 0] concat dup 1 sub sierpinski
[1 0 0 1 -1 1] concat dup 1 sub sierpinski
[2 0 0 2 0 -1] concat
} {
newpath
0 0 moveto
1 0 lineto
0 1 lineto
closepath
fill
} ifelse pop} def
%%EndProlog
%%BeginSetup
<< /PageSize [596 843] >> setpagedevice % A4
%%EndSetup
%%Page: Test 1
pageset
[20 0 10 300 sqrt 0 0] concat
9 sierpinski
showpage
%%EOF

View File

@@ -1,68 +0,0 @@
action_module(calculator) .
%[-,-,d1,-] --push(D)--> [-,-,D,-] if mode(init)
push(D) < -
mode(init),
deny([displayed(D1),mode(init)]),
affirm([displayed(D),mode(cont)]).
%[-,-,D1,-] --push(D)--> [-,-,10*D1+D,-] if mode(cont)
push(D) < -
mode(cont),
deny(displayed(D1)),
New = 10*D1 + D,
affirm(displayed(New)).
%[a,op,d,m] --push(clear)--> [0,nop,0,0]
push(clear) < -
deny([accumulator(A),op(O),displayed(D),memory(M),mode(X)]),
affirm([accumulator(0),op(nop),displayed(0),memory(0),mode(init)]).
%[a,op,d,m] --push(mem_rec)--> [a,op,m,m]
push(mem_rec) < -
memory(M),
deny([displayed(D),mode(X)]),
affirm([displayed(M),mode(init)]).
%[a,op,d,m] --push(plus)--> [op(a,d),plus,d,m]
push(plus) < -
displayed(D),
deny([accumulator(A),op(O),mode(X)]),
eval(O,A,D,V), ; use normal arithmetic, i.e., V=O(A,D)
affirm([accumulator(V),op(plus),mode(init)]).
%[a,op,d,m] --push(minus)--> [op(a,d,minus,d,m]
push(minus) lt -
displayed(D),
deny([accumulator(A),op(O),mode(X)]),
eval(O,A,D,V), ; use normal arithmetic, i.e., V=O(A,D)
affirm([accumulator(V),op(minus),mode(init)]).
%[a,op,d,m] --push(times)--> [op(a,d),times,d,m]
push(times) < -
displayed(D),
deny([accumulator(A),op(O),mode(X)]),
eval(O,A,D,V), ; use normal arithmetic, i.e., V=O(A,D)
affirm([accumulator(V),op(times),mode(init)]).
%[a,op,d,m] --push(equal)--> [a,nop,op(a,d),m]
push(equal) < -
accumulator(A),
deny([op(O),displayed(D),mode(X)]),
eval(O,A,D,V),
affirm([op(nop),displayed(V),mode(init)]).
%[a,op,d,m] --push(mem_plus)--> [a,nop,v,plus(m,v)] where v=op(a,d)
push(mem_plus) < -
accumulator(A),
deny([op(O),displayed(D),memory(M),mode(X)]),
eval(O,A,D,V),
eval(plus,M,V,V1),
affirm([op(nop),displayed(V),memory(V1),mode(init)]).
%[a,op,d,m] --push(plus_minus)--> [a,op,-d,m]
push(clear) < -
deny([displayed(D),mode(X)]),
eval(minus,0,D,V),
affirm([displayed(V),mode(init)]).

View File

@@ -1,94 +0,0 @@
%%----- normalize(+Wff,-NormalClauses) ------
normalize(Wff,NormalClauses) :-
conVert(Wff,[],S),
cnF(S,T),
flatten_and(T,U),
make_clauses(U,NormalClauses).
%%----- make a sequence out of a conjunction -----
flatten_and(X /\ Y, F) :-
!,
flatten_and(X,A),
flatten_and(Y, B),
sequence_append(A,B,F).
flatten_and(X,X).
%%----- make a sequence out of a disjunction -----
flatten_or(X \/ Y, F) :-
!,
flatten_or(X,A),
flatten_or(Y,B),
sequence_append(A,B,F).
flatten_or(X,X).
%%----- append two sequences -------------------------------
sequence_append((X,R),S,(X,T)) :- !, sequence_append(R,S,T).
sequence_append((X),S,(X,S)).
%%----- separate into positive and negative literals -----------
separate((A,B),P,N) :-
!,
(A = ~X -> N=[X|N1],
separate(B,P,N1)
;
P=[A|P1],
separate(B,P1,N) ).
separate(A,P,N) :-
(A = ~X -> N=[X],
P = []
;
P=[A],
N = [] ).
%%----- tautology ----------------------------
tautology(P,N) :- some_occurs(N,P).
some_occurs([F|R],B) :-
occurs(F,B) | some_occurs(R,B).
occurs(A,[F|_]) :-
A == F,
!.
occurs(A,[_|R]) :-
occurs(A,R).
make_clauses((A,B),C) :-
!,
flatten_or(A,F),
separate(F,P,N),
(tautology(P,N) ->
make_clauses(B,C)
;
make_clause(P,N,D),
C = [D|R],
make_clauses(B,R) ).
make_clauses(A,C) :-
flatten_or(A,F),
separate(F,P,N),
(tautology(P,N) ->
C = []
;
make_clause(P,N,D),
C = [D] ).
make_clause([],N, false :- B) :-
!,
make_sequence(N,B,',').
make_clause(P,[],H) :-
!,
make_sequence(P,H,'|').
make_clause(P,N, H :- T) :-
make_sequence(P,H,'|'),
make_sequence(N,T,',').
make_sequence([A],A,_) :- !.
make_sequence([F|R],(F|S),'|') :-
make_sequence(R,S,'|').
make_sequence([F|R],(F,S),',') :-
make_sequence(R,S,',').
write_list([F|R]) :-
write(F), write('.'), nl,
write_list(R).
write_list([]).

View File

@@ -0,0 +1,90 @@
:- lib(ic).
/**
* Question 1.11
* vabs(?Val, ?AbsVal)
*/
vabs(Val, AbsVal):-
AbsVal #> 0,
(
Val #= AbsVal
;
Val #= -AbsVal
),
labeling([Val, AbsVal]).
/**
* vabsIC(?Val, ?AbsVal)
*/
vabsIC(Val, AbsVal):-
AbsVal #> 0,
Val #= AbsVal or Val #= -AbsVal,
labeling([Val, AbsVal]).
/**
* Question 1.12
*/
% X #:: -10..10, vabs(X, Y).
% X #:: -10..10, vabsIC(X, Y).
/**
* Question 1.13
* faitListe(?ListVar, ?Taille, +Min, +Max)
*/
faitListe([], 0, _, _):-!.
faitListe([First|Rest], Taille, Min, Max):-
First #:: Min..Max,
Taille1 #= Taille - 1,
faitListe(Rest, Taille1, Min, Max).
/**
* Question 1.14
* suite(?ListVar)
*/
suite([Xi, Xi1, Xi2]):-
checkRelation(Xi, Xi1, Xi2).
suite([Xi, Xi1, Xi2|Rest]):-
checkRelation(Xi, Xi1, Xi2),
suite([Xi1, Xi2|Rest]).
/**
* checkRelation(?Xi, ?Xi1, ?Xi2)
*/
checkRelation(Xi, Xi1, Xi2):-
vabs(Xi1, VabsXi1),
Xi2 #= VabsXi1 - Xi.
/**
* Question 1.15
* checkPeriode(+ListVar).
*/
% TODO Any better solution?
checkPeriode(ListVar):-
length(ListVar, Length),
Length < 10.
checkPeriode([X1, X2, X3, X4, X5, X6, X7, X8, X9, X10|Rest]):-
X1 =:= X10,
checkPeriode([X2, X3, X4, X5, X6, X7, X8, X9, X10|Rest]).
% faitListe(ListVar, 18, -9, 9), suite(ListVar), checkPeriode(ListVar). => 99 solutions
/**
* Tests
*/
/*
vabs(5, 5). => Yes
vabs(5, -5). => No
vabs(-5, 5). => Yes
vabs(X, 5).
vabs(X, AbsX).
vabsIC(5, 5). => Yes
vabsIC(5, -5). => No
vabsIC(-5, 5). => Yes
vabsIC(X, 5).
vabsIC(X, AbsX).
faitListe(ListVar, 5, 1, 3). => 243 solutions
faitListe([_, _, _, _, _], Taille, 1, 3). => Taille = 5 !!!!!!!!!!!!!!!!
faitListe(ListVar, 18, -9, 9), suite(ListVar). => 99 solutions
*/

View File

@@ -1,287 +0,0 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% A* Algorithm
%%%
%%%
%%% Nodes have form S#D#F#A
%%% where S describes the state or configuration
%%% D is the depth of the node
%%% F is the evaluation function value
%%% A is the ancestor list for the node
:- op(400,yfx,'#'). /* Node builder notation */
solve(State,Soln) :- f_function(State,0,F),
search([State#0#F#[]],S), reverse(S,Soln).
f_function(State,D,F) :- h_function(State,H),
F is D + H.
search([State#_#_#Soln|_], Soln) :- goal(State).
search([B|R],S) :- expand(B,Children),
insert_all(Children,R,Open),
search(Open,S).
insert_all([F|R],Open1,Open3) :- insert(F,Open1,Open2),
insert_all(R,Open2,Open3).
insert_all([],Open,Open).
insert(B,Open,Open) :- repeat_node(B,Open), ! .
insert(B,[C|R],[B,C|R]) :- cheaper(B,C), ! .
insert(B,[B1|R],[B1|S]) :- insert(B,R,S), !.
insert(B,[],[B]).
repeat_node(P#_#_#_, [P#_#_#_|_]).
cheaper( _#_#F1#_ , _#_#F2#_ ) :- F1 < F2.
expand(State#D#_#S,All_My_Children) :-
bagof(Child#D1#F#[Move|S],
(D1 is D+1,
move(State,Child,Move),
f_function(Child,D1,F)),
All_My_Children).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% 8-puzzle solver
%%%
%%%
%%% State have form A/B/C/D/E/F/G/H/I
%%% where {A,...,I} = {0,...,8}
%%% 0 represents the empty tile
%%%
goal(1/2/3/8/0/4/7/6/5).
%%% The puzzle moves
left( A/0/C/D/E/F/H/I/J , 0/A/C/D/E/F/H/I/J ).
left( A/B/C/D/0/F/H/I/J , A/B/C/0/D/F/H/I/J ).
left( A/B/C/D/E/F/H/0/J , A/B/C/D/E/F/0/H/J ).
left( A/B/0/D/E/F/H/I/J , A/0/B/D/E/F/H/I/J ).
left( A/B/C/D/E/0/H/I/J , A/B/C/D/0/E/H/I/J ).
left( A/B/C/D/E/F/H/I/0 , A/B/C/D/E/F/H/0/I ).
up( A/B/C/0/E/F/H/I/J , 0/B/C/A/E/F/H/I/J ).
up( A/B/C/D/0/F/H/I/J , A/0/C/D/B/F/H/I/J ).
up( A/B/C/D/E/0/H/I/J , A/B/0/D/E/C/H/I/J ).
up( A/B/C/D/E/F/0/I/J , A/B/C/0/E/F/D/I/J ).
up( A/B/C/D/E/F/H/0/J , A/B/C/D/0/F/H/E/J ).
up( A/B/C/D/E/F/H/I/0 , A/B/C/D/E/0/H/I/F ).
right( A/0/C/D/E/F/H/I/J , A/C/0/D/E/F/H/I/J ).
right( A/B/C/D/0/F/H/I/J , A/B/C/D/F/0/H/I/J ).
right( A/B/C/D/E/F/H/0/J , A/B/C/D/E/F/H/J/0 ).
right( 0/B/C/D/E/F/H/I/J , B/0/C/D/E/F/H/I/J ).
right( A/B/C/0/E/F/H/I/J , A/B/C/E/0/F/H/I/J ).
right( A/B/C/D/E/F/0/I/J , A/B/C/D/E/F/I/0/J ).
down( A/B/C/0/E/F/H/I/J , A/B/C/H/E/F/0/I/J ).
down( A/B/C/D/0/F/H/I/J , A/B/C/D/I/F/H/0/J ).
down( A/B/C/D/E/0/H/I/J , A/B/C/D/E/J/H/I/0 ).
down( 0/B/C/D/E/F/H/I/J , D/B/C/0/E/F/H/I/J ).
down( A/0/C/D/E/F/H/I/J , A/E/C/D/0/F/H/I/J ).
down( A/B/0/D/E/F/H/I/J , A/B/F/D/E/0/H/I/J ).
%%% the heuristic function
h_function(Puzz,H) :- p_fcn(Puzz,P),
s_fcn(Puzz,S),
H is P + 3*S.
%%% the move
move(P,C,left) :- left(P,C).
move(P,C,up) :- up(P,C).
move(P,C,right) :- right(P,C).
move(P,C,down) :- down(P,C).
%%% the Manhattan distance function
p_fcn(A/B/C/D/E/F/G/H/I, P) :-
a(A,Pa), b(B,Pb), c(C,Pc),
d(D,Pd), e(E,Pe), f(F,Pf),
g(G,Pg), h(H,Ph), i(I,Pi),
P is Pa+Pb+Pc+Pd+Pe+Pf+Pg+Ph+Pg+Pi.
a(0,0). a(1,0). a(2,1). a(3,2). a(4,3). a(5,4). a(6,3). a(7,2). a(8,1).
b(0,0). b(1,1). b(2,0). b(3,1). b(4,2). b(5,3). b(6,2). b(7,3). b(8,2).
c(0,0). c(1,2). c(2,1). c(3,0). c(4,1). c(5,2). c(6,3). c(7,4). c(8,3).
d(0,0). d(1,1). d(2,2). d(3,3). d(4,2). d(5,3). d(6,2). d(7,2). d(8,0).
e(0,0). e(1,2). e(2,1). e(3,2). e(4,1). e(5,2). e(6,1). e(7,2). e(8,1).
f(0,0). f(1,3). f(2,2). f(3,1). f(4,0). f(5,1). f(6,2). f(7,3). f(8,2).
g(0,0). g(1,2). g(2,3). g(3,4). g(4,3). g(5,2). g(6,2). g(7,0). g(8,1).
h(0,0). h(1,3). h(2,3). h(3,3). h(4,2). h(5,1). h(6,0). h(7,1). h(8,2).
i(0,0). i(1,4). i(2,3). i(3,2). i(4,1). i(5,0). i(6,1). i(7,2). i(8,3).
%%% the out-of-cycle function
s_fcn(A/B/C/D/E/F/G/H/I, S) :-
s_aux(A,B,S1), s_aux(B,C,S2), s_aux(C,F,S3),
s_aux(F,I,S4), s_aux(I,H,S5), s_aux(H,G,S6),
s_aux(G,D,S7), s_aux(D,A,S8), s_aux(E,S9),
S is S1+S2+S3+S4+S5+S6+S7+S8+S9.
s_aux(0,0) :- !.
s_aux(_,1).
s_aux(X,Y,0) :- Y is X+1, !.
s_aux(8,1,0) :- !.
s_aux(_,_,2).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% 8-puzzle animation -- using VT100 character graphics
%%%
%%%
%%%
puzzle(P) :- solve(P,S),
animate(P,S),
message.
animate(P,S) :- initialize(P),
cursor(1,2), write(S),
cursor(1,22), write('Hit ENTER to step solver.'),
get0(_X),
play_back(S).
:- dynamic location/3.
initialize(A/B/C/D/E/F/H/I/J) :-
cls,
retractall(location(_,_,_)),
assert(location(A,20,5)),
assert(location(B,30,5)),
assert(location(C,40,5)),
assert(location(F,40,10)),
assert(location(J,40,15)),
assert(location(I,30,15)),
assert(location(H,20,15)),
assert(location(D,20,10)),
assert(location(E,30,10)), draw_all.
draw_all :- draw(1), draw(2), draw(3), draw(4),
draw(5), draw(6), draw(7), draw(8).
%%% play_back([left,right,up,...]).
play_back([M|R]) :- call(M), get0(_X), play_back(R).
play_back([]) :- cursor(1,24). %%% Put cursor out of the way
message :- nl,nl,
write(' ********************************************'), nl,
write(' * Enter 8-puzzle goals in the form ... *'), nl,
write(' * ?- puzzle(0/8/1/2/4/3/7/6/5). *'), nl,
write(' * Enter goal ''message'' to reread this. *'), nl,
write(' ********************************************'), nl, nl.
cursor(X,Y) :- put(27), put(91), %%% ESC [
write(Y),
put(59), %%% ;
write(X),
put(72). %%% M
%%% clear the screen, quickly
cls :- put(27), put("["), put("2"), put("J").
%%% video attributes -- bold and blink not working
plain :- put(27), put("["), put("0"), put("m").
reverse_video :- put(27), put("["), put("7"), put("m").
%%% Tile objects, character map(s)
%%% Each tile should be drawn using the character map,
%%% drawn at 'location', which is asserted and retracted
%%% by 'playback'.
character_map(N, [ [' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ', N ,' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' '] ]).
%%% move empty tile (spot) to the left
left :- retract(location(0,X0,Y0)),
Xnew is X0 - 10,
location(Tile,Xnew,Y0),
assert(location(0,Xnew,Y0)),
right(Tile),right(Tile),right(Tile),
right(Tile),right(Tile),
right(Tile),right(Tile),right(Tile),
right(Tile),right(Tile).
up :- retract(location(0,X0,Y0)),
Ynew is Y0 - 5,
location(Tile,X0,Ynew),
assert(location(0,X0,Ynew)),
down(Tile),down(Tile),down(Tile),down(Tile),down(Tile).
right :- retract(location(0,X0,Y0)),
Xnew is X0 + 10,
location(Tile,Xnew,Y0),
assert(location(0,Xnew,Y0)),
left(Tile),left(Tile),left(Tile),left(Tile),left(Tile),
left(Tile),left(Tile),left(Tile),left(Tile),left(Tile).
down :- retract(location(0,X0,Y0)),
Ynew is Y0 + 5,
location(Tile,X0,Ynew),
assert(location(0,X0,Ynew)),
up(Tile),up(Tile),up(Tile),up(Tile),up(Tile).
draw(Obj) :- reverse_video, character_map(Obj,M),
location(Obj,X,Y),
draw(X,Y,M), plain.
%%% hide tile
hide(Obj) :- character_map(Obj,M),
location(Obj,X,Y),
hide(X,Y,M).
hide(_,_,[]).
hide(X,Y,[R|G]) :- hide_row(X,Y,R),
Y1 is Y + 1,
hide(X,Y1,G).
hide_row(_,_,[]).
hide_row(X,Y,[_|R]) :- cursor(X,Y),
write(' '),
X1 is X + 1,
hide_row(X1,Y,R).
%%% draw tile
draw(_,_,[]).
draw(X,Y,[R|G]) :- draw_row(X,Y,R),
Y1 is Y + 1,
draw(X,Y1,G).
draw_row(_,_,[]).
draw_row(X,Y,[P|R]) :- cursor(X,Y),
write(P),
X1 is X + 1,
draw_row(X1,Y,R).
%%% Move an Object up
up(Obj) :- hide(Obj),
retract(location(Obj,X,Y)),
Y1 is Y - 1,
assert(location(Obj,X,Y1)),
draw(Obj).
down(Obj) :- hide(Obj),
retract(location(Obj,X,Y)),
Y1 is Y + 1,
assert(location(Obj,X,Y1)),
draw(Obj).
left(Obj) :- hide(Obj),
retract(location(Obj,X,Y)),
X1 is X - 1,
assert(location(Obj,X1,Y)),
draw(Obj).
right(Obj) :- hide(Obj),
retract(location(Obj,X,Y)),
X1 is X + 1,
assert(location(Obj,X1,Y)),
draw(Obj).
:- message.

View File

@@ -1,13 +0,0 @@
partition([], _, [], []).
partition([X|Xs], Pivot, Smalls, Bigs) :-
( X @< Pivot ->
Smalls = [X|Rest],
partition(Xs, Pivot, Rest, Bigs)
; Bigs = [X|Rest],
partition(Xs, Pivot, Smalls, Rest)
).
quicksort([]) --> [].
quicksort([X|Xs]) -->
{ partition(Xs, X, Smaller, Bigger) },
quicksort(Smaller), [X], quicksort(Bigger).

View File

@@ -1,12 +0,0 @@
/* Prolog test file */
male(john).
male(peter).
female(vick).
female(christie).
parents(john, peter, christie).
parents(vick, peter, christie).
/* X is a brother of Y */
brother(X, Y) :- male(X), parents(X, F, M), parents(Y, F, M).

View File

@@ -0,0 +1,12 @@
-/* Prolog test file */
-male(john).
-male(peter).
-
-female(vick).
-female(christie).
-
-parents(john, peter, christie).
-parents(vick, peter, christie).
-
-/* X is a brother of Y */
-brother(X, Y) :- male(X), parents(X, F, M), parents(Y, F, M).

View File

@@ -1,21 +1,21 @@
turing(Tape0, Tape) :-
perform(q0, [], Ls, Tape0, Rs),
reverse(Ls, Ls1),
append(Ls1, Rs, Tape).
perform(qf, Ls, Ls, Rs, Rs) :- !.
perform(Q0, Ls0, Ls, Rs0, Rs) :-
symbol(Rs0, Sym, RsRest),
once(rule(Q0, Sym, Q1, NewSym, Action)),
action(Action, Ls0, Ls1, [NewSym|RsRest], Rs1),
perform(Q1, Ls1, Ls, Rs1, Rs).
symbol([], b, []).
symbol([Sym|Rs], Sym, Rs).
action(left, Ls0, Ls, Rs0, Rs) :- left(Ls0, Ls, Rs0, Rs).
action(stay, Ls, Ls, Rs, Rs).
action(right, Ls0, [Sym|Ls0], [Sym|Rs], Rs).
left([], [], Rs0, [b|Rs0]).
left([L|Ls], Ls, Rs, [L|Rs]).
-turing(Tape0, Tape) :-
- perform(q0, [], Ls, Tape0, Rs),
- reverse(Ls, Ls1),
- append(Ls1, Rs, Tape).
-
-perform(qf, Ls, Ls, Rs, Rs) :- !.
-perform(Q0, Ls0, Ls, Rs0, Rs) :-
- symbol(Rs0, Sym, RsRest),
- once(rule(Q0, Sym, Q1, NewSym, Action)),
- action(Action, Ls0, Ls1, [NewSym|RsRest], Rs1),
- perform(Q1, Ls1, Ls, Rs1, Rs).
-
-symbol([], b, []).
-symbol([Sym|Rs], Sym, Rs).
-
-action(left, Ls0, Ls, Rs0, Rs) :- left(Ls0, Ls, Rs0, Rs).
-action(stay, Ls, Ls, Rs, Rs).
-action(right, Ls0, [Sym|Ls0], [Sym|Rs], Rs).
-
-left([], [], Rs0, [b|Rs0]).
-left([L|Ls], Ls, Rs, [L|Rs]).

View File

@@ -0,0 +1,5 @@
##polyg=vector
##numpoints=number 10
##output=output vector
##[Example scripts]=group
pts=spsample(polyg,numpoints,type="regular")

View File

@@ -0,0 +1,10 @@
# An example RMarkdown
Some text.
## A graphic in R
```{r}
plot(1:10)
hist(rnorm(10000))
```

7
samples/Scheme/basic.sld Normal file
View File

@@ -0,0 +1,7 @@
(define-library (libs basic)
(export list2 x)
(begin
(define (list2 . objs) objs)
(define x 'libs-basic)
(define not-exported 'should-not-be-exported)
))

321
samples/Shen/graph.shen Normal file
View File

@@ -0,0 +1,321 @@
\* graph.shen --- a library for graph definition and manipulation
Copyright (C) 2011, Eric Schulte
*** License:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*** Commentary:
Graphs are represented as two dictionaries one for vertices and one
for edges. It is important to note that the dictionary implementation
used is able to accept arbitrary data structures as keys. This
structure technically encodes hypergraphs (a generalization of graphs
in which each edge may contain any number of vertices). Examples of a
regular graph G and a hypergraph H with the corresponding data
structure are given below.
--G=<graph Vertices Edges>------------------------------------------------
Vertices Edges
---------- -------
+----Graph G-----+ hash | key -> value hash | key -> value
| | -----+------>-------- -----+-------->---------
| a---b---c g | 1 | a -> [1] 1 | [a b] -> [1 2]
| | | | 2 | b -> [1 2 3] 2 | [b c] -> [2 3]
| d---e---f | 3 | c -> [2 4] 3 | [b d] -> [2 4]
| | 4 | d -> [3 5] 4 | [c e] -> [3 5]
+----------------+ 5 | e -> [4 5 6] 5 | [d e] -> [4 5]
6 | f -> [6] 6 | [e f] -> [5 6]
7 | g -> []
--H=<graph Vertices Edges>------------------------------------------------
Vertices Edges
---------- -------
hash | key -> value hash | key -> value
+-- Hypergraph H----+ -----+------>-------- -----+-------->---------
| | 1 | a -> [1] 1 | [a b [1 2
| +------+ | 2 | b -> [1] | c d -> 3 4
| +------+------+ | 3 | c -> [1] | e f] 5 6]
| |a b c |d e f | | 4 | d -> [1 2] |
| +------+------+ | 5 | e -> [1 2] 2 | [d e [4 5
| |g h i | j | 6 | f -> [1 2] | f g -> 6 7
| +------+ | 7 | g -> [2] | h i] 8 9]
| | 8 | h -> [2]
+-------------------+ 9 | i -> [2]
10 | j -> []
--G=<graph Vertices Edges>-------Graph with associated edge/vertex data---------
Vertices Edges
---------- -------
+----Graph G-----+ hash | key -> value hash | key -> value
| 4 6 7 | -----+------>-------- -----+-------->---------
|0a---b---c g | 1 | a -> (@p 0 [1]) 1 | [a b] -> (@p 4 [1 2])
| 1| 3| | 2 | b -> [1 2 3] 2 | [b c] -> (@p 6 [2 3])
| d---e---f | 3 | c -> [2 4] 3 | [b d] -> (@p 1 [2 4])
| 2 5 | 4 | d -> [3 5] 4 | [c e] -> (@p 3 [3 5])
+----------------+ 5 | e -> [4 5 6] 5 | [d e] -> (@p 2 [4 5])
6 | f -> [6] 6 | [e f] -> (@p 5 [5 6])
7 | g -> (@p 7 [])
V = # of vertices
E = # of edges
M = # of vertex edge associations
size = size of all vertices + all vertices stored in Vertices dict
M * sizeof(int) * 4 + indices into Vertices & Edge dicts
V * sizeof(dict entry) + storage in the Vertex dict
E * sizeof(dict entry) + storage in the Edge dict
2 * sizeof(dict) the Vertices and Edge dicts
*** Code: *\
(require dict)
(require sequence)
(datatype graph
Vertices : dictionary;
Edges : dictoinary;
===================
(vector symbol Vertices Edges);)
(package graph- [graph graph? vertices edges add-vertex
add-edge has-edge? has-vertex? edges-for
neighbors connected-to connected? connected-components
vertex-partition bipartite?
\* included from the sequence library\ *\
take drop take-while drop-while range flatten
filter complement seperate zip indexed reduce
mapcon partition partition-with unique frequencies
shuffle pick remove-first interpose subset?
cartesian-product
\* included from the dict library\ *\
dict? dict dict-> <-dict contents key? keys vals
dictionary make-dict]
(define graph?
X -> (= graph (<-address X 0)))
(define make-graph
\* create a graph with specified sizes for the vertex dict and edge dict *\
{number --> number --> graph}
Vertsize Edgesize ->
(let Graph (absvector 3)
(do (address-> Graph 0 graph)
(address-> Graph 1 (make-dict Vertsize))
(address-> Graph 2 (make-dict Edgesize))
Graph)))
(defmacro graph-macro
\* return a graph taking optional sizes for the vertex and edge dicts *\
[graph] -> [make-graph 1024 1024]
[graph N] -> [make-graph N 1024]
[graph N M] -> [make-graph N M])
(define vert-dict Graph -> (<-address Graph 1))
(define edge-dict Graph -> (<-address Graph 2))
(define vertices
{graph --> (list A)}
Graph -> (keys (vert-dict Graph)))
(define edges
{graph --> (list (list A))}
Graph -> (keys (edge-dict Graph)))
(define get-data
Value V -> (if (tuple? Value)
(fst Value)
(error (make-string "no data for ~S~%" V))))
(define vertex-data
Graph V -> (get-data (<-dict (vert-dict Graph) V) V))
(define edge-data
Graph V -> (get-data (<-dict (edge-dict Graph) V) V))
(define resolve
{(vector (list A)) --> (@p number number) --> A}
Vector (@p Index Place) -> (nth (+ 1 Place) (<-vector Vector Index)))
(define resolve-vert
{graph --> (@p number number) --> A}
Graph Place -> (resolve (<-address (vert-dict Graph) 2) Place))
(define resolve-edge
{graph --> (@p number number) --> A}
Graph Place -> (resolve (<-address (edge-dict Graph) 2) Place))
(define edges-for
{graph --> A --> (list (list A))}
Graph Vert -> (let Val (trap-error (<-dict (vert-dict Graph) Vert) (/. E []))
Edges (if (tuple? Val) (snd Val) Val)
(map (lambda X (fst (resolve-edge Graph X))) Val)))
(define add-vertex-w-data
\* add a vertex to a graph *\
{graph --> A --> B --> A}
G V Data -> (do (dict-> (vert-dict G) V (@p Data (edges-for G V))) V))
(define add-vertex-w/o-data
\* add a vertex to a graph *\
{graph --> A --> B --> A}
G V -> (do (dict-> (vert-dict G) V (edges-for G V)) V))
(defmacro add-vertex-macro
[add-vertex G V] -> [add-vertex-w/o-data G V]
[add-vertex G V D] -> [add-vertex-w-data G V D])
(define update-vert
\* in a dict, add an edge to a vertex's edge list *\
{vector --> (@p number number) --> A --> number}
Vs Edge V -> (let Store (<-address Vs 2)
N (hash V (limit Store))
VertLst (trap-error (<-vector Store N) (/. E []))
Contents (trap-error (<-dict Vs V) (/. E []))
(do (dict-> Vs V (if (tuple? Contents)
(@p (fst Contents)
(adjoin Edge (snd Contents)))
(adjoin Edge Contents)))
(@p N (length VertLst)))))
(define update-edges-vertices
\* add an edge to a graph *\
{graph --> (list A) --> (list A)}
Graph Edge ->
(let Store (<-address (edge-dict Graph) 2)
EdgeID (hash Edge (limit Store))
EdgeLst (trap-error (<-vector Store EdgeID) (/. E []))
(map (update-vert (vert-dict Graph) (@p EdgeID (length EdgeLst))) Edge)))
(define add-edge-w-data
G E D -> (do (dict-> (edge-dict G) E (@p D (update-edges-vertices G E))) E))
(define add-edge-w/o-data
G E -> (do (dict-> (edge-dict G) E (update-edges-vertices G E)) E))
(defmacro add-edge-macro
[add-edge G E] -> [add-edge-w/o-data G E]
[add-edge G E V] -> [add-edge-w-data G E V])
(define has-edge?
{graph --> (list A) --> boolean}
Graph Edge -> (key? (edge-dict Graph) Edge))
(define has-vertex?
{graph --> A --> boolean}
Graph Vertex -> (key? (vert-dict Graph) Vertex))
(define neighbors
\* Return the neighbors of a vertex *\
{graph --> A --> (list A)}
Graph Vert -> (unique (mapcon (remove-first Vert) (edges-for Graph Vert))))
(define connected-to-
{graph --> (list A) --> (list A) --> (list A)}
Graph [] Already -> Already
Graph New Already ->
(let Reachable (unique (mapcon (neighbors Graph) New))
New (difference Reachable Already)
(connected-to- Graph New (append New Already))))
(define connected-to
\* return all vertices connected to the given vertex, including itself *\
{graph --> A --> (list A)}
Graph V -> (connected-to- Graph [V] [V]))
(define connected?
\* return if a graph is fully connected *\
{graph --> boolean}
Graph -> (reduce (/. V Acc
(and Acc
(subset? (vertices Graph) (connected-to Graph V))))
true (vertices Graph)))
(define connected-components-
\* given a graph return a list of connected components *\
{graph --> (list A) --> (list (list A)) --> (list graph)}
Graph [] _ -> []
Graph VS [] -> (map (/. V (let Component (graph 1 0)
(do (add-vertex Component V) Component)))
VS)
Graph [V|VS] ES ->
(let Con-verts (connected-to Graph V)
Con-edges (filter (/. E (subset? E Con-verts)) ES)
Component (graph (length Con-verts) (length Con-edges))
(do (map (add-edge-w/o-data Component) Con-edges)
(cons Component (connected-components- Graph
(difference VS Con-verts)
(difference ES Con-edges))))))
(define connected-components
{graph --> (list graph)}
Graph -> (connected-components- Graph (vertices Graph) (edges Graph)))
(define place-vertex
\* given a graph, vertex and list of partitions, partition the vertex *\
{graph --> A --> (list (list A)) --> (list (list A))}
Graph V [] -> (if (element? V (neighbors Graph V))
(simple-error
(make-string "self-loop ~S, no vertex partition" V))
[[V]])
Graph V [C|CS] -> (let Neighbors (neighbors Graph V)
(if (element? V Neighbors)
(simple-error
(make-string "self-loop ~S, no vertex partition" V))
(if (empty? (intersection C Neighbors))
[[V|C]|CS]
[C|(place-vertex Graph V CS)]))))
(define vertex-partition
\* partition the vertices of a graph *\
{graph --> (list (list A))}
Graph -> (reduce (place-vertex Graph) [] (vertices Graph)))
(define bipartite?
\* check if a graph is bipartite *\
{graph --> boolean}
Graph -> (= 2 (length (vertex-partition Graph))))
)
\* simple tests
(set g (graph))
(add-edge (value g) [chris patton])
(add-edge (value g) [eric chris])
(add-vertex (value g) nobody)
(has-edge? (value g) [patton chris])
(edges-for (value g) chris)
(neighbors (value g) chris)
(neighbors (value g) nobody)
(connected-to (value g) chris)
(connected? (value g))
(connected-components (value g)) <- fail when package wrapper is used
(map (function vertices) (connected-components (value g)))
*\

102
samples/Shen/html.shen Normal file
View File

@@ -0,0 +1,102 @@
\* html.shen --- html generation functions for shen
Copyright (C) 2011, Eric Schulte
*** License:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*** Commentary:
The standard lisp-to-html conversion tool suite. Follows some of
the convertions of Clojure's hiccup.
an example...
(8-) (html [ul#todo1.tasks.stuff [: [title "today"]]
(map (lambda Str [li Str]) ["get milk" "dishes"])])
"<ul class='tasks stuff' id='todo1' title='today'>
<li>get milk</li><li>dishes</li></ul>"
*** Code: *\
(trap-error
(require string)
(/. E (load "../string/string.shen")))
(package string- [html
\* symbols included from string *\
takestr dropstr substr length-str index-str
reverse-str starts-with substr? replace-str
join split trim-left trim-right chomp trim]
(define to-str
\* return argument as a string, if already a string do not change *\
X -> X where (string? X)
X -> (str X))
(define gassoc
X Y -> (hd (tl (assoc X Y))))
(define dassoc
X Y -> (remove (assoc X Y) Y))
(define passoc
[] Y -> Y
[X XV] Y -> (let Orig (gassoc X Y)
New (if (cons? Orig) [XV|Orig] XV)
[[X New]|(dassoc X Y)]))
(define html
X -> X where (string? X)
[Tag [: |Attrs] |Body] ->
(let Tag-comps (css-parse-symbol Tag)
Tag (gassoc tag Tag-comps)
New-attrs (passoc (assoc class Tag-comps)
(passoc (assoc id Tag-comps) Attrs))
(@s (make-string "<~S" Tag) (attributes New-attrs) ">"
(html Body)
(make-string "</~S>" Tag))) where (symbol? Tag)
[Tag|Body] -> (html [Tag [:] Body]) where (symbol? Tag)
[H|HS] -> (@s (html H) (html HS))
[] -> "")
(define css-parse-symbol
{symbol --> [[symbol A]]}
Symbol -> (let String (str Symbol)
Class-split (split (str .) String)
Class (map (function intern) (tl Class-split))
Id-split (split (str #) (hd Class-split))
Tag (hd Id-split)
Id (tl Id-split)
((if (= [] Id) (/. X X) (cons [id (intern (hd Id))]))
((if (= [] Class) (/. X X) (cons [class Class]))
[[tag (intern Tag)]]))))
(define attributes
[] -> ""
[[K V]|AS] -> (@s " " (to-str K) "='"
(if (cons? V) (join " " (map (function str) V)) (to-str V))
"'" (attributes AS)))
)

39
samples/Shen/json.shen Normal file
View File

@@ -0,0 +1,39 @@
(load "grammar.shen")
\*
JSON Lexer
1. Read a stream of characters
2. Whitespace characters not in strings should be discarded.
3. Whitespace characters in strings should be preserved
4. Strings can contain escaped double quotes. e.g. "\""
*\
(define whitespacep
\* e.g. ASCII 32 == #\Space. *\
\* All the others are whitespace characters from an ASCII table. *\
Char -> (member Char ["c#9;" "c#10;" "c#11;" "c#12;" "c#13;" "c#32;"]))
(define replace-whitespace
"" -> ""
(@s Whitespace Suffix) -> (@s "" (replace-whitespace Suffix)) where (whitespacep Whitespace)
(@s Prefix Suffix) -> (@s Prefix (replace-whitespace Suffix)))
(define fetch-until-unescaped-doublequote
[] -> []
["\" "c#34;" | Chars] -> ["\" "c#34;" | (fetch-until-unescaped-doublequote Chars)]
["c#34;" | Chars] -> []
[Char | Chars] -> [Char | (fetch-until-unescaped-doublequote Chars)])
\* (define strip-whitespace-chars *\
\* [] -> [] *\
\* ["c#34;" | Chars] -> ["c#34;" | ( *\
\* [WhitespaceChar | Chars] -> (strip-whitespace-chars Chars) where (whitespace? WhitespaceChar) *\
\* [Char | Chars] -> [Char | (strip-whitespace-chars Chars)]) *\
(define tokenise
JSONString ->
(let CharList (explode JSONString)
CharList))

View File

@@ -0,0 +1,254 @@
(* From Twelf *)
(* Red/Black Trees *)
(* Author: Frank Pfenning *)
functor RedBlackTree
(type key'
val compare : key' * key' -> order)
:> TABLE where type key = key' =
struct
type key = key'
type 'a entry = key * 'a
datatype 'a dict =
Empty (* considered black *)
| Red of 'a entry * 'a dict * 'a dict
| Black of 'a entry * 'a dict * 'a dict
type 'a Table = 'a dict ref
(* Representation Invariants *)
(*
1. The tree is ordered: for every node Red((key1,datum1), left, right) or
Black ((key1,datum1), left, right), every key in left is less than
key1 and every key in right is greater than key1.
2. The children of a red node are black (color invariant).
3. Every path from the root to a leaf has the same number of
black nodes, called the black height of the tree.
*)
local
fun lookup dict key =
let
fun lk (Empty) = NONE
| lk (Red tree) = lk' tree
| lk (Black tree) = lk' tree
and lk' ((key1, datum1), left, right) =
(case compare(key,key1)
of EQUAL => SOME(datum1)
| LESS => lk left
| GREATER => lk right)
in
lk dict
end
(* val restore_right : 'a dict -> 'a dict *)
(*
restore_right (Black(e,l,r)) >=> dict
where (1) Black(e,l,r) is ordered,
(2) Black(e,l,r) has black height n,
(3) color invariant may be violated at the root of r:
one of its children might be red.
and dict is a re-balanced red/black tree (satisfying all invariants)
and same black height n.
*)
fun restore_right (Black(e, Red lt, Red (rt as (_,Red _,_)))) =
Red(e, Black lt, Black rt) (* re-color *)
| restore_right (Black(e, Red lt, Red (rt as (_,_,Red _)))) =
Red(e, Black lt, Black rt) (* re-color *)
| restore_right (Black(e, l, Red(re, Red(rle, rll, rlr), rr))) =
(* l is black, deep rotate *)
Black(rle, Red(e, l, rll), Red(re, rlr, rr))
| restore_right (Black(e, l, Red(re, rl, rr as Red _))) =
(* l is black, shallow rotate *)
Black(re, Red(e, l, rl), rr)
| restore_right dict = dict
(* restore_left is like restore_right, except *)
(* the color invariant may be violated only at the root of left child *)
fun restore_left (Black(e, Red (lt as (_,Red _,_)), Red rt)) =
Red(e, Black lt, Black rt) (* re-color *)
| restore_left (Black(e, Red (lt as (_,_,Red _)), Red rt)) =
Red(e, Black lt, Black rt) (* re-color *)
| restore_left (Black(e, Red(le, ll as Red _, lr), r)) =
(* r is black, shallow rotate *)
Black(le, ll, Red(e, lr, r))
| restore_left (Black(e, Red(le, ll, Red(lre, lrl, lrr)), r)) =
(* r is black, deep rotate *)
Black(lre, Red(le, ll, lrl), Red(e, lrr, r))
| restore_left dict = dict
fun insert (dict, entry as (key,datum)) =
let
(* val ins : 'a dict -> 'a dict inserts entry *)
(* ins (Red _) may violate color invariant at root *)
(* ins (Black _) or ins (Empty) will be red/black tree *)
(* ins preserves black height *)
fun ins (Empty) = Red(entry, Empty, Empty)
| ins (Red(entry1 as (key1, datum1), left, right)) =
(case compare(key,key1)
of EQUAL => Red(entry, left, right)
| LESS => Red(entry1, ins left, right)
| GREATER => Red(entry1, left, ins right))
| ins (Black(entry1 as (key1, datum1), left, right)) =
(case compare(key,key1)
of EQUAL => Black(entry, left, right)
| LESS => restore_left (Black(entry1, ins left, right))
| GREATER => restore_right (Black(entry1, left, ins right)))
in
case ins dict
of Red (t as (_, Red _, _)) => Black t (* re-color *)
| Red (t as (_, _, Red _)) => Black t (* re-color *)
| dict => dict
end
(* function below from .../smlnj-lib/Util/int-redblack-set.sml *)
(* Need to check and improve some time *)
(* Sun Mar 13 08:22:53 2005 -fp *)
(* Remove an item. Returns true if old item found, false otherwise *)
local
exception NotFound
datatype 'a zipper
= TOP
| LEFTB of ('a entry * 'a dict * 'a zipper)
| LEFTR of ('a entry * 'a dict * 'a zipper)
| RIGHTB of ('a dict * 'a entry * 'a zipper)
| RIGHTR of ('a dict * 'a entry * 'a zipper)
in
fun delete t key =
let
fun zip (TOP, t) = t
| zip (LEFTB(x, b, z), a) = zip(z, Black(x, a, b))
| zip (LEFTR(x, b, z), a) = zip(z, Red(x, a, b))
| zip (RIGHTB(a, x, z), b) = zip(z, Black(x, a, b))
| zip (RIGHTR(a, x, z), b) = zip(z, Red(x, a, b))
(* bbZip propagates a black deficit up the tree until either the top
* is reached, or the deficit can be covered. It returns a boolean
* that is true if there is still a deficit and the zipped tree.
*)
fun bbZip (TOP, t) = (true, t)
| bbZip (LEFTB(x, Red(y, c, d), z), a) = (* case 1L *)
bbZip (LEFTR(x, c, LEFTB(y, d, z)), a)
| bbZip (LEFTB(x, Black(w, Red(y, c, d), e), z), a) = (* case 3L *)
bbZip (LEFTB(x, Black(y, c, Red(w, d, e)), z), a)
| bbZip (LEFTR(x, Black(w, Red(y, c, d), e), z), a) = (* case 3L *)
bbZip (LEFTR(x, Black(y, c, Red(w, d, e)), z), a)
| bbZip (LEFTB(x, Black(y, c, Red(w, d, e)), z), a) = (* case 4L *)
(false, zip (z, Black(y, Black(x, a, c), Black(w, d, e))))
| bbZip (LEFTR(x, Black(y, c, Red(w, d, e)), z), a) = (* case 4L *)
(false, zip (z, Red(y, Black(x, a, c), Black(w, d, e))))
| bbZip (LEFTR(x, Black(y, c, d), z), a) = (* case 2L *)
(false, zip (z, Black(x, a, Red(y, c, d))))
| bbZip (LEFTB(x, Black(y, c, d), z), a) = (* case 2L *)
bbZip (z, Black(x, a, Red(y, c, d)))
| bbZip (RIGHTB(Red(y, c, d), x, z), b) = (* case 1R *)
bbZip (RIGHTR(d, x, RIGHTB(c, y, z)), b)
| bbZip (RIGHTR(Red(y, c, d), x, z), b) = (* case 1R *)
bbZip (RIGHTR(d, x, RIGHTB(c, y, z)), b)
| bbZip (RIGHTB(Black(y, Red(w, c, d), e), x, z), b) = (* case 3R *)
bbZip (RIGHTB(Black(w, c, Red(y, d, e)), x, z), b)
| bbZip (RIGHTR(Black(y, Red(w, c, d), e), x, z), b) = (* case 3R *)
bbZip (RIGHTR(Black(w, c, Red(y, d, e)), x, z), b)
| bbZip (RIGHTB(Black(y, c, Red(w, d, e)), x, z), b) = (* case 4R *)
(false, zip (z, Black(y, c, Black(x, Red(w, d, e), b))))
| bbZip (RIGHTR(Black(y, c, Red(w, d, e)), x, z), b) = (* case 4R *)
(false, zip (z, Red(y, c, Black(w, Red(w, d, e), b))))
| bbZip (RIGHTR(Black(y, c, d), x, z), b) = (* case 2R *)
(false, zip (z, Black(x, Red(y, c, d), b)))
| bbZip (RIGHTB(Black(y, c, d), x, z), b) = (* case 2R *)
bbZip (z, Black(x, Red(y, c, d), b))
| bbZip (z, t) = (false, zip(z, t))
fun delMin (Red(y, Empty, b), z) = (y, (false, zip(z, b)))
| delMin (Black(y, Empty, b), z) = (y, bbZip(z, b))
| delMin (Black(y, a, b), z) = delMin(a, LEFTB(y, b, z))
| delMin (Red(y, a, b), z) = delMin(a, LEFTR(y, b, z))
| delMin (Empty, _) = raise Match
fun joinRed (Empty, Empty, z) = zip(z, Empty)
| joinRed (a, b, z) = let
val (x, (needB, b')) = delMin(b, TOP)
in
if needB
then #2(bbZip(z, Red(x, a, b')))
else zip(z, Red(x, a, b'))
end
fun joinBlack (a, Empty, z) = #2(bbZip(z, a))
| joinBlack (Empty, b, z) = #2(bbZip(z, b))
| joinBlack (a, b, z) = let
val (x, (needB, b')) = delMin(b, TOP)
in
if needB
then #2(bbZip(z, Black(x, a, b')))
else zip(z, Black(x, a, b'))
end
fun del (Empty, z) = raise NotFound
| del (Black(entry1 as (key1, datum1), a, b), z) =
(case compare(key,key1)
of EQUAL => joinBlack (a, b, z)
| LESS => del (a, LEFTB(entry1, b, z))
| GREATER => del (b, RIGHTB(a, entry1, z)))
| del (Red(entry1 as (key1, datum1), a, b), z) =
(case compare(key,key1)
of EQUAL => joinRed (a, b, z)
| LESS => del (a, LEFTR(entry1, b, z))
| GREATER => del (b, RIGHTR(a, entry1, z)))
in
(del(t, TOP); true) handle NotFound => false
end
end (* local *)
(* use non-imperative version? *)
fun insertShadow (dict, entry as (key,datum)) =
let val oldEntry = ref NONE (* : 'a entry option ref *)
fun ins (Empty) = Red(entry, Empty, Empty)
| ins (Red(entry1 as (key1, datum1), left, right)) =
(case compare(key,key1)
of EQUAL => (oldEntry := SOME(entry1);
Red(entry, left, right))
| LESS => Red(entry1, ins left, right)
| GREATER => Red(entry1, left, ins right))
| ins (Black(entry1 as (key1, datum1), left, right)) =
(case compare(key,key1)
of EQUAL => (oldEntry := SOME(entry1);
Black(entry, left, right))
| LESS => restore_left (Black(entry1, ins left, right))
| GREATER => restore_right (Black(entry1, left, ins right)))
in
(oldEntry := NONE;
((case ins dict
of Red (t as (_, Red _, _)) => Black t (* re-color *)
| Red (t as (_, _, Red _)) => Black t (* re-color *)
| dict => dict),
!oldEntry))
end
fun app f dict =
let fun ap (Empty) = ()
| ap (Red tree) = ap' tree
| ap (Black tree) = ap' tree
and ap' (entry1, left, right) =
(ap left; f entry1; ap right)
in
ap dict
end
in
fun new (n) = ref (Empty) (* ignore size hint *)
val insert = (fn table => fn entry => (table := insert (!table, entry)))
val insertShadow =
(fn table => fn entry =>
let
val (dict, oldEntry) = insertShadow (!table, entry)
in
(table := dict; oldEntry)
end)
val lookup = (fn table => fn key => lookup (!table) key)
val delete = (fn table => fn key => (delete (!table) key; ()))
val clear = (fn table => (table := Empty))
val app = (fn f => fn table => app f (!table))
end
end; (* functor RedBlackTree *)

1470
samples/Standard ML/main.fun Normal file

File diff suppressed because it is too large Load Diff

380
samples/TeX/problemset.cls Normal file
View File

@@ -0,0 +1,380 @@
% =====================================
% problemset Document Style
% For Problem Sets
%
% Options:
% final hides to-dos
% worksheet hides solutions and places each problem on separate page
% expand places each problem on a separate page
% =====================================
\ProvidesClass{problemset}
\DeclareOption*{\PassOptionsToClass{final}{article}}
\DeclareOption{worksheet}{\providecommand{\@solutionvis}{0}}
\DeclareOption{expand}{\providecommand{\@expand}{1}}
\ProcessOptions\relax
% ================== Packages and Document Options ==================
\LoadClass[10pt,letterpaper]{article}
\RequirePackage[%
top=0.85in,
bottom=1in,
left=1in,
right=1in
]{geometry}
\RequirePackage{pgfkeys} % For mathtable environment.
\RequirePackage{tabularx} % For pset heading
\RequirePackage{float} % Used for floats (tables, figures, etc.)
\RequirePackage{graphicx} % Used for inserting images.
\RequirePackage{enumerate} % Used for the enumerate environment.
\RequirePackage{mathtools} % Required. Loads amsmath.
\RequirePackage{amsthm} % Required. Used for theorem environments.
\RequirePackage{amssymb} % Required.
\RequirePackage{booktabs} % Required. Used for mathtable environment.
\RequirePackage{esdiff} % For derivatives and partial derivatives
\RequirePackage{mathtools} % Optional. Used for \shortintertext.
\RequirePackage{fancyhdr} % Required. For customizing headers/footers.
\RequirePackage{lastpage} % Required. For page count in header/footer.
\RequirePackage{xcolor} % Required. For setting the color of hyperlinks
\RequirePackage[%
obeyFinal, % Disable todos by setting [final] option for class
color=@todoclr,
linecolor=red
]{todonotes} % For keeping track of to-dos.
\RequirePackage[%
colorlinks=true,
linkcolor=navy,
urlcolor=black
]{hyperref} % For following urls and references in a document.
\RequirePackage{url} % Enables urls with the \url tag
\RequirePackage[all]{hypcap}
% hypcap: Links go to object instead of caption. [Keep as last package]
% ================== Appearance Settings ==================
\definecolor{@todoclr}{gray}{0.80} % For To-Dos. 50% brightness
\definecolor{navy}{RGB}{0,0,150} % For coloring hyperlinks
\setlength{\parskip}{1.5ex} % Sets space between paragraphs.
\setlength{\parindent}{0pt} % Indent for first line of new paragraphs.
% Smaller verbatim type size
\let\VERBATIM\verbatim
\def\verbatim{%
\def\verbatim@font{\small\ttfamily}%
\VERBATIM}
% ============= Caption Modifications =============
\usepackage[small]{caption}
\usepackage[footnotesize]{subcaption}
% For no visible number, use: \caption*{Unnumbered figure caption.}
\captionsetup[table]{labelformat=simple, labelsep=period, labelfont=bf}
\captionsetup[figure]{labelformat=simple, labelsep=period, labelfont=bf}
\captionsetup[subtable]{labelformat=parens, labelsep=space, labelfont=bf}
\captionsetup[subfigure]{labelformat=simple, labelsep=period, labelfont=bf}
% ================== Booleans ==================
\def\TRUE{1}
\def\FALSE{0}
\def\SHOW{1}
\def\HIDE{0}
% ============= Gets Document Info, Generates Heading =============
\providecommand{\heading}[5][]{
\thispagestyle{empty}
\listoftodos
\clearpage
\pagenumbering{arabic}
%
\providecommand{\shortname}{#1}
\providecommand{\authorname}{#2}
\providecommand{\coursename}{#3}
\providecommand{\assignment}{#4}
\providecommand{\duedate}{#5}
\begin{minipage}{0.5\textwidth}
\begin{flushleft}
\hypertarget{@assignment}{
\textbf{\assignment}
}\\
\authorname
\end{flushleft}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{flushright}
\coursename\\
\duedate\\
\end{flushright}
\end{minipage}
\thispagestyle{empty}
}
% ============= Headers and Footers =============
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.5pt}
\pagestyle{fancyplain}
\fancyhf{}
\lfoot{%
\fancyplain{}{%
\hyperlink{@assignment}{%
\small{%
\color{black}{%
\assignment
}
}
}
}
}
\cfoot{%
\fancyplain{}{%
\small{%
\coursename
}
}
}
\rfoot{%
\fancyplain{}{%
\small{\shortname~\thepage~of~\pageref{LastPage}}
}
}
% ============= Problem Command =============
% INPUT: Points for question [#1] (Optional)
\newcounter{theproblem} % Problem counter for environment
\providecommand{\problem}[1][]{%
\addtocounter{theproblem}{1}%
\setcounter{table}{0}%
\setcounter{figure}{0}%
\setcounter{equation}{0}%
\noindent%
\textbf{%
Problem~\arabic{theproblem}.}~\textit{\small{#1}}
}
% ============= QED, Page Breaks After QED? =============
\providecommand{\@expand}{\HIDE} % Default is to omit pagebreaks after the solution
\providecommand{\qqed}{\hfill\rule{2mm}{2mm}\ifnum\@expand=\SHOW\\\pagebreak\fi}
% ============= Solution Command =============
\providecommand{\@solutionvis}{1} % Default setting is to show solutions.
\providecommand{\solution}[2][\@solutionvis]{
\vspace{0.5em}\noindent\textbf{Solution.}
\ifnum#1=\SHOW%
#2
\hfill\qqed\vspace{0.1em}
\else%
\pagebreak%
\fi
}
% ============= Chapter, Section, Item Commands =============
\providecommand{\chap}[2][0]{
\ifnum#1=0%
\else%
\setcounter{section}{#1}%
\addtocounter{section}{-1}%
\fi%
\vspace{-1.75em}%
\section{#2}
}
\providecommand{\sect}[2][0]{
\ifnum#1=0%
\else%
\setcounter{subsection}{#1}%
\addtocounter{subsection}{-1}%
\fi%
\vspace{-0.5em}%
\subsection{#2}
}
\providecommand{\subsect}[1]{\noindent\textbf{#1.}}
% ============= Insert Non-Float Image =============
\providecommand{\insertgraphic}[2][0.5\textwidth]{
\vspace{-1em}
\begin{center}
\includegraphics[width=#1]{#2}
\end{center}
\vspace{-1em}
}
% ============= Object Numbering by Problem =============
\renewcommand{\thetable}{\arabic{theproblem}.\arabic{table}}
\renewcommand{\thefigure}{\arabic{theproblem}.\arabic{figure}}
\renewcommand{\theequation}{\arabic{theproblem}.\arabic{equation}}
% ============= Formula Environment =============
\newcounter{formula}
\newenvironment{formula}[1][Formula \arabic{formula}]
{
\addtocounter{formula}{1}
\begin{displaymath}
\tag*{\parbox{5em}{\textbf{\small{#1}}}}
}{
\end{displaymath}\\
}
% ============= Math Table =============
\newif\ifcaption
\pgfkeys
{
/mypkg/title/.store in=\Caption,% Any value assigned to title will be stored in \Caption
/mypkg/title= , % Initialize so \Caption exists
/mypkg/label/.store in=\Label, % Any value assigned to label will be stored in \Label
/mypkg/label= , % Initialize so \Label exists
/mypkg/caption/.is if=caption, % Declare a boolean, defaults to false
}
\newenvironment{mathtable}[2][]{
\pgfkeys{/mypkg/.cd, #1}%
\vspace{-1em}%
\begin{table}[ht!]%
\small \begin{center}%
\begin{displaymath}%
\begin{array}{#2}%
\toprule
}{
\bottomrule
\end{array}%
\end{displaymath}%
\ifcaption%
\vspace{-1em}\caption{\Caption}\label{\Label}%
\fi%
\end{center}%
\end{table}%
\vspace{-1em}%
}
% ============= Double-line Column-Heading for table =============
\providecommand{\double}[2]{%
\multicolumn{1}{c}{%
\genfrac{}{}{0pt}{}{\text{#1}}{\text{#2}}
}
}
% ============= Theorem-Style Environments =============
\theoremstyle{plain} % Bold label, italic letters
\newtheorem{thm}{Theorem}[section] % Numbered by section
\newtheorem{lma}[thm]{Lemma}
\newtheorem{crl}[thm]{Corollary}
\newtheorem{prp}[thm]{Proposition}
\newtheorem{cnj}[thm]{Conjecture}
\newtheorem{alg}[thm]{Algorithm}
% Associated environments (for numbered theorem environments)
\newenvironment{theorem}[2][]{\begin{thm}[#1]\label{#2}}{\end{thm}}
\newenvironment{lemma}[2][]{\begin{lma}[#1]\label{#2}}{\end{lma}}
\newenvironment{corollary}[2][]{\begin{crl}[#1]\label{#2}}{\end{thm}}
\newenvironment{proposition}[2][]{\begin{prp}[#1]\label{#2}}{\end{crl}}
\newenvironment{conjecture}[2][]{\begin{cnj}[#1]\label{#2}}{\end{cnj}}
\newenvironment{algorithm}[2][]{\begin{alg}[#1]\label{#2}}{\end{alg}}
\theoremstyle{remark} % Italic label, roman letters
\newtheorem{rmk}{Remark}[section] % Numbered by section. Remarks are used to expand on and integrate material.
\newtheorem*{note}{Note} % Un-numbered. Notes are used to comment on specific elements of the material.
\newtheorem*{caveat}{Caveat} % Un-numbered. Caveats are used to guide the reader away from a common error.
\newtheorem*{warning}{Warning} % Un-numbered. Warnings are used to guide away from especially egregious errors.
\theoremstyle{definition} % Bold label, roman letters
\newtheorem{dfn}{Definition}[section] % Numbered by section. Definitions of concepts and terms.
\newtheorem{exm}{Example}[section] % Numbered by section. Illustrative examples.
\newtheorem{smm}{Summary}[subsection] % Numbered by subsection. For section summaries.
\newtheorem*{question}{Question} % Un-numbered. For questions to motivate further analysis.
\newtheorem*{speculation}{Speculation} % Un-numbered. For questions that arise but will not be immediately answered.
% Associated environments (for numbered theorem environments)
\newenvironment{remark}[2][]{\begin{rmk}[#1]\label{#2}}{\end{rmk}}
\newenvironment{definition}[2][]{\begin{dfn}[#1]\label{#2}}{\end{dfn}}
\newenvironment{example}[2][]{\begin{exm}[#1]\label{#2}}{\end{exm}}
\newenvironment{summary}[2][]{\begin{smm}[#1]\label{#2}}{\end{smm}}
% ============= Greek Letters =============
\renewcommand{\a}{\ensuremath{\alpha}}
\renewcommand{\b}{\ensuremath{\beta}}
\renewcommand{\c}{\ensuremath{\gamma}}
\newcommand{\ch}{\ensuremath{\chi}}
\renewcommand{\d}{\ensuremath{\delta}}
\newcommand{\ep}{\ensuremath{\epsilon}}
\newcommand{\et}{\ensuremath{\eta}}
\newcommand{\ve}{\ensuremath{\varepsilon}}
\renewcommand{\r}{\ensuremath{\rho}}
\newcommand{\s}{\ensuremath{\sigma}}
\renewcommand{\t}{\ensuremath{\tau}}
\newcommand{\f}{\ensuremath{\psi}}
\newcommand{\w}{\ensuremath{\omega}}
\newcommand{\h}{\ensuremath{\phi}}
\newcommand{\m}{\ensuremath{\mu}}
\renewcommand{\l}{\ensuremath{\lambda}}
\renewcommand{\k}{\ensuremath{\kappa}}
\renewcommand{\v}{\ensuremath{\nu}}
\renewcommand{\i}{\ensuremath{\iota}}
\renewcommand{\o}{\ensuremath{\theta}}
\newcommand{\z}{\ensuremath{\zeta}}
% ============= Mathematical Symbols =============
\providecommand{\NN}{\ensuremath{\mathbb{N}}}
\providecommand{\ZZ}{\ensuremath{\mathbb{Z}}}
\providecommand{\QQ}{\ensuremath{\mathbb{Q}}}
\providecommand{\RR}{\ensuremath{\mathbb{R}}}
\providecommand{\CC}{\ensuremath{\mathbb{C}}}
\providecommand{\pd}{\partial} % 'dee' symbol for partial derivatives
\providecommand{\dd}{\mathrm{d}} % 'dee' symbol for ordinary derivatives
\providecommand{\x}{\times}
\providecommand{\n}{\scalebox{0.6}[1.0]{\ensuremath{-}}}
% ============= Mathematical Macros =============
\providecommand{\Sum}[3][n]{\ensuremath{\sum_{{#1}={#2}}^{#3}}} % Sum from [n]={1}to{2}. \Sum{1}{10}
\providecommand{\infsum}[2][n]{\ensuremath{\sum_{{#1}={#2}}^\infty}} % Infinite sum from [n]={1} \infsum{1}
\providecommand{\Int}[4][x]{\ensuremath{\int_{#3}^{#4}\!{#2}\,\mathrm{d}{#1}}} % Integrate {1} from {2} to {3} with respect to [x]
\providecommand{\Lim}[3][\infty]{\ensuremath{\displaystyle \lim_{{#2}\to{#1}}\!\!{#3}}} % Take the limit from {1} to [infinity] of {3} \Lim{x}{f(x)}
\providecommand{\Frac}[2]{\ensuremath{\,^{#1}\!/\!_{#2}}} % Slanted fraction with proper spacing. Usefule for in-line display of fractions.
\providecommand{\eval}[3]{\ensuremath{\left[ #1 \right \vert_{#2}^{#3}}}
\renewcommand{\L}{\left} % for left-hand right-sizing
\providecommand{\R}{\right} % for right-hand right-sizing
\providecommand{\D}{\diff} % for writing derivatives
\providecommand{\PD}{\diffp} % for writing partial derivatives
\providecommand{\full}{\displaystyle} % Forces display style in math mode
\providecommand{\Deg}{\ensuremath{^\circ}} % for adding a degree symbol, even if not in math mode
\providecommand{\abs}[1]{\left\vert #1 \right\vert} % Absolute Value
\providecommand{\norm}[1]{\left \Vert #1 \right \Vert} % Norm (vector magnitude)
\providecommand{\e}[1]{\ensuremath{\times 10^{#1}}} % Scientific Notation with times symbol
\providecommand{\E}[1]{\ensuremath{10^{#1}}} % Scientific Notation
\renewcommand{\u}[1]{\text{ #1}} % For inserting units in Roman text
\providecommand{\mc}{\text{,}\hspace{1em}} % For inserting comma and space into math mode
\providecommand{\mtxt}[2][]{#1\hspace{0.5em}\text{#2}\hspace{0.5em}} % For insterting text into math mode with space on either side. Option for preceding punctuation.
% ============= Probability and Statistics =============
\providecommand{\prob}[1]{\ensuremath{P\!\left(#1\right)} }
\providecommand{\cndprb}[2]{\ensuremath{P\!\left(#1 \left\vert #2 \right. \right)} }
\providecommand{\cov}[1]{\ensuremath{\text{Cov}\!\left(#1\right)} }
\providecommand{\ex}[1]{\ensuremath{E\!\left[#1\right]} }
% ============= Linear Algebra =============
% Column vectors
\providecommand{\twovector}[3][r]{\left(\begin{array}{#1} #2 \\ #3\end{array}\right)}
\providecommand{\threevector}[4][r]{\left(\begin{array}{#1} #2 \\ #3 \\ #4\end{array}\right)}
\providecommand{\fourvector}[5][r]{\left(\begin{array}{#1} #2 \\ #3 \\ #4 \\ #5 \end{array}\right)}
% ============= Vector Calculus =============
% ------------- Susan Lea's notation ---------------
\providecommand{\vecs}[1]{\ensuremath{\vec{\bm{#1}}} } % bolded symbol, arrow
\providecommand{\vect}[1]{\ensuremath{\vec{\textbf{#1}}} } % bolded text, arrow
\providecommand{\unitvecs}[1]{\bm{\hat{#1}}}
\providecommand{\unitvect}[1]{\hat{\textbf{#1}}}
\providecommand{\Div}[1]{\vecs{\del} \cdot \vect{#1}}
\providecommand{\Curl}[1]{\vecs{\del} \times \vect{#1}}
\providecommand{\Grad}{\vecs{\del}}

View File

@@ -0,0 +1,47 @@
@Code
ViewData("Title") = "Home Page"
End Code
@section featured
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>@ViewData("Title").</h1>
<h2>@ViewData("Message")</h2>
</hgroup>
<p>
To learn more about ASP.NET MVC visit
<a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET MVC.
If you have any questions about ASP.NET MVC visit
<a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET MVC Forum">our forums</a>.
</p>
</div>
</section>
End Section
<h3>We suggest the following:</h3>
<ol class="round">
<li class="one">
<h5>Getting Started</h5>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
enables a clean separation of concerns and that gives you full control over markup
for enjoyable, agile development. ASP.NET MVC includes many features that enable
fast, TDD-friendly development for creating sophisticated applications that use
the latest web standards.
<a href="http://go.microsoft.com/fwlink/?LinkId=245151">Learn more…</a>
</li>
<li class="two">
<h5>Add NuGet packages and jump-start your coding</h5>
NuGet makes it easy to install and update free libraries and tools.
<a href="http://go.microsoft.com/fwlink/?LinkId=245153">Learn more…</a>
</li>
<li class="three">
<h5>Find Web Hosting</h5>
You can easily find a web hosting company that offers the right mix of features
and price for your applications.
<a href="http://go.microsoft.com/fwlink/?LinkId=245157">Learn more…</a>
</li>
</ol>

View File

@@ -0,0 +1,8 @@
Module Module1
Sub Main()
Console.Out.WriteLine("Hello, I am a little sample application to test GitHub's Linguist module.")
Console.Out.WriteLine("I also include a Razor MVC file just to prove it handles cshtml files now.")
End Sub
End Module

47
samples/XML/pt_BR.xml Normal file
View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="pt_BR">
<context>
<name>MainWindow</name>
<message>
<location filename="../forms/mainwindow.ui" line="22"/>
<source>United Kingdom</source>
<translation>Reino Unido</translation>
</message>
<message>
<location filename="../forms/mainwindow.ui" line="38"/>
<source>God save the Queen</source>
<translation>Deus salve a Rainha</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="46"/>
<source>England</source>
<translation>Inglaterra</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="47"/>
<source>Wales</source>
<translation>Gales</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="48"/>
<source>Scotland</source>
<translation>Escócia</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="49"/>
<source>Northern Ireland</source>
<translation>Irlanda Norte</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="51"/>
<source>Portuguese</source>
<translation>Português</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="52"/>
<source>English</source>
<translation>Inglês</translation>
</message>
</context>
</TS>

View File

@@ -0,0 +1,20 @@
---
http_interactions:
- request:
method: get
uri: http://example.com/
body: ''
headers: {}
response:
status:
code: 200
message: OK
headers:
Content-Type:
- text/html;charset=utf-8
Content-Length:
- '26'
body: This is the response body
http_version: '1.1'
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
recorded_with: VCR 2.0.0

View File

@@ -185,6 +185,9 @@ class TestBlob < Test::Unit::TestCase
# PEG.js-generated parsers
assert blob("JavaScript/parser.js").generated?
# Generated PostScript
assert !blob("PostScript/sierpinski.ps").generated?
# These examples are too basic to tell
assert !blob("JavaScript/empty.js").generated?
assert !blob("JavaScript/hello.js").generated?
@@ -208,6 +211,9 @@ class TestBlob < Test::Unit::TestCase
assert !blob("CSS/bootstrap.css").generated?
assert blob("CSS/bootstrap.min.css").generated?
# Generated VCR
assert blob("YAML/vcr_cassette.yml").generated?
assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil)
end
@@ -221,6 +227,11 @@ class TestBlob < Test::Unit::TestCase
# Node dependencies
assert blob("node_modules/coffee-script/lib/coffee-script.js").vendored?
# Bower Components
assert blob("bower_components/custom/custom.js").vendored?
assert blob("app/bower_components/custom/custom.js").vendored?
assert blob("vendor/assets/bower_components/custom/custom.js").vendored?
# Rails vendor/
assert blob("vendor/plugins/will_paginate/lib/will_paginate.rb").vendored?
@@ -270,7 +281,6 @@ class TestBlob < Test::Unit::TestCase
assert blob("ui/minified/jquery.effects.blind.min.js").vendored?
assert blob("ui/minified/jquery.ui.accordion.min.js").vendored?
# MooTools
assert blob("public/javascripts/mootools-core-1.3.2-full-compat.js").vendored?
assert blob("public/javascripts/mootools-core-1.3.2-full-compat-yc.js").vendored?
@@ -292,6 +302,10 @@ class TestBlob < Test::Unit::TestCase
assert blob("public/javascripts/tiny_mce_popup.js").vendored?
assert blob("public/javascripts/tiny_mce_src.js").vendored?
# AngularJS
assert blob("public/javascripts/angular.js").vendored?
assert blob("public/javascripts/angular.min.js").vendored?
# Fabric
assert blob("fabfile.py").vendored?
@@ -323,7 +337,7 @@ class TestBlob < Test::Unit::TestCase
# Test fixtures
assert blob("test/fixtures/random.rkt").vendored?
assert blob("Test/fixtures/random.rkt").vendored?
# Cordova/PhoneGap
assert blob("cordova.js").vendored?
assert blob("cordova.min.js").vendored?
@@ -332,6 +346,14 @@ class TestBlob < Test::Unit::TestCase
# Vagrant
assert blob("Vagrantfile").vendored?
# Gradle
assert blob("gradlew").vendored?
assert blob("gradlew.bat").vendored?
assert blob("gradle/wrapper/gradle-wrapper.properties").vendored?
assert blob("subproject/gradlew").vendored?
assert blob("subproject/gradlew.bat").vendored?
assert blob("subproject/gradle/wrapper/gradle-wrapper.properties").vendored?
end
def test_language

87
test/test_heuristics.rb Normal file
View File

@@ -0,0 +1,87 @@
require 'linguist/heuristics'
require 'linguist/language'
require 'linguist/samples'
require 'test/unit'
class TestHeuristcs < Test::Unit::TestCase
include Linguist
def samples_path
File.expand_path("../../samples", __FILE__)
end
def fixture(name)
File.read(File.join(samples_path, name))
end
def all_fixtures(language_name, file="*")
Dir.glob("#{samples_path}/#{language_name}/#{file}")
end
def test_obj_c_by_heuristics
languages = ["C++", "Objective-C"]
# Only calling out '.h' filenames as these are the ones causing issues
all_fixtures("Objective-C", "*.h").each do |fixture|
results = Heuristics.disambiguate_c(fixture("Objective-C/#{File.basename(fixture)}"), languages)
assert_equal Language["Objective-C"], results.first
end
end
def test_cpp_by_heuristics
languages = ["C++", "Objective-C"]
results = Heuristics.disambiguate_c(fixture("C++/render_adapter.cpp"), languages)
assert_equal Language["C++"], results.first
end
def test_detect_still_works_if_nothing_matches
match = Language.detect("Hello.m", fixture("Objective-C/hello.m"))
assert_equal Language["Objective-C"], match
end
def test_pl_prolog_by_heuristics
languages = ["Perl", "Prolog"]
results = Heuristics.disambiguate_pl(fixture("Prolog/turing.pl"), languages)
assert_equal Language["Prolog"], results.first
end
def test_pl_perl_by_heuristics
languages = ["Perl", "Prolog"]
results = Heuristics.disambiguate_pl(fixture("Perl/perl-test.t"), languages)
assert_equal Language["Perl"], results.first
end
def test_ecl_prolog_by_heuristics
languages = ["ECL", "Prolog"]
results = Heuristics.disambiguate_ecl(fixture("Prolog/or-constraint.ecl"), languages)
assert_equal Language["Prolog"], results.first
end
def test_ecl_ecl_by_heuristics
languages = ["ECL", "Prolog"]
results = Heuristics.disambiguate_ecl(fixture("ECL/sample.ecl"), languages)
assert_equal Language["ECL"], results.first
end
def test_ts_typescript_by_heuristics
languages = ["TypeScript", "XML"]
results = Heuristics.disambiguate_ts(fixture("TypeScript/classes.ts"), languages)
assert_equal Language["TypeScript"], results.first
end
def test_ts_xml_by_heuristics
languages = ["TypeScript", "XML"]
results = Heuristics.disambiguate_ts(fixture("XML/pt_BR.xml"), languages)
assert_equal Language["XML"], results.first
end
def test_cl_by_heuristics
languages = ["Common Lisp", "OpenCL"]
languages.each do |language|
all_fixtures(language).each do |fixture|
results = Heuristics.disambiguate_cl(fixture("#{language}/#{File.basename(fixture)}"), languages)
assert_equal Language[language], results.first
end
end
end
end

View File

@@ -40,6 +40,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Lexer['REBOL'], Language['Rebol'].lexer
assert_equal Lexer['RHTML'], Language['HTML+ERB'].lexer
assert_equal Lexer['RHTML'], Language['RHTML'].lexer
assert_equal Lexer['Ruby'], Language['Crystal'].lexer
assert_equal Lexer['Ruby'], Language['Mirah'].lexer
assert_equal Lexer['Ruby'], Language['Ruby'].lexer
assert_equal Lexer['S'], Language['R'].lexer
@@ -103,6 +104,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Language['Raw token data'], Language.find_by_alias('raw')
assert_equal Language['Ruby'], Language.find_by_alias('rb')
assert_equal Language['Ruby'], Language.find_by_alias('ruby')
assert_equal Language['R'], Language.find_by_alias('r')
assert_equal Language['Scheme'], Language.find_by_alias('scheme')
assert_equal Language['Shell'], Language.find_by_alias('bash')
assert_equal Language['Shell'], Language.find_by_alias('sh')
@@ -191,12 +193,18 @@ class TestLanguage < Test::Unit::TestCase
def test_markup
assert_equal :markup, Language['HTML'].type
assert_equal :markup, Language['SCSS'].type
end
def test_data
assert_equal :data, Language['YAML'].type
end
def test_prose
assert_equal :prose, Language['Markdown'].type
assert_equal :prose, Language['Org'].type
end
def test_other
assert_nil Language['Brainfuck'].type
assert_nil Language['Makefile'].type
@@ -369,7 +377,7 @@ class TestLanguage < Test::Unit::TestCase
end
def test_by_type
assert_equal 9, Language.by_type(:prose).length
assert !Language.by_type(:prose).nil?
end
def test_colorize

View File

@@ -25,6 +25,12 @@ class TestRepository < Test::Unit::TestCase
assert linguist_repo.size > 30_000
end
def test_linguist_breakdown
assert linguist_repo.breakdown_by_file.has_key?("Ruby")
assert linguist_repo.breakdown_by_file["Ruby"].include?("bin/linguist")
assert linguist_repo.breakdown_by_file["Ruby"].include?("lib/linguist/language.rb")
end
def test_binary_override
assert_equal repo(File.expand_path("../../samples/Nimrod", __FILE__)).language, Language["Nimrod"]
end