mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Compare commits
	
		
			94 Commits
		
	
	
		
			test/maste
			...
			v3.1.1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					f811ab1b28 | ||
| 
						 | 
					dd181421a7 | ||
| 
						 | 
					c8754292f4 | ||
| 
						 | 
					61faea0298 | ||
| 
						 | 
					b9ecf61dcb | ||
| 
						 | 
					437f81c4a0 | ||
| 
						 | 
					26dad7dada | ||
| 
						 | 
					b1e5d6f8f8 | ||
| 
						 | 
					8c7b54d6e3 | ||
| 
						 | 
					529d3faaf8 | ||
| 
						 | 
					9f0f4657a2 | ||
| 
						 | 
					90ff1b5896 | ||
| 
						 | 
					feb82e34d6 | ||
| 
						 | 
					4d7a34c177 | ||
| 
						 | 
					5c3385ecd8 | ||
| 
						 | 
					a1af3a509c | ||
| 
						 | 
					2913a87cc4 | ||
| 
						 | 
					69cc86c572 | ||
| 
						 | 
					60144c907e | ||
| 
						 | 
					0d03a94cde | ||
| 
						 | 
					6af5adaac1 | ||
| 
						 | 
					17a28f2e91 | ||
| 
						 | 
					baaa7a5c13 | ||
| 
						 | 
					cfeb2a833c | ||
| 
						 | 
					8b4acf7023 | ||
| 
						 | 
					7393c2ef91 | ||
| 
						 | 
					4948ec2999 | ||
| 
						 | 
					408a325732 | ||
| 
						 | 
					5ca211b9f7 | ||
| 
						 | 
					bc7596a8b5 | ||
| 
						 | 
					6762ca8aa7 | ||
| 
						 | 
					986611ac36 | ||
| 
						 | 
					94b4ad1de6 | ||
| 
						 | 
					3e2f18bf3f | ||
| 
						 | 
					48c06cc299 | ||
| 
						 | 
					f10821ac49 | ||
| 
						 | 
					cd5298dee6 | ||
| 
						 | 
					a8c955609a | ||
| 
						 | 
					aa72012d41 | ||
| 
						 | 
					458831b885 | ||
| 
						 | 
					f5e4789ccb | ||
| 
						 | 
					1b712d2800 | ||
| 
						 | 
					e274196441 | ||
| 
						 | 
					c4c3c27cfe | ||
| 
						 | 
					a2dd9d2c8c | ||
| 
						 | 
					06e095e5fc | ||
| 
						 | 
					b26d5bc1b1 | ||
| 
						 | 
					607792e1b2 | ||
| 
						 | 
					fb38135a61 | ||
| 
						 | 
					a5d5b6e6c7 | ||
| 
						 | 
					2fd2cdf68a | ||
| 
						 | 
					11049ca3ca | ||
| 
						 | 
					c29bea19ef | ||
| 
						 | 
					8c8434ed64 | ||
| 
						 | 
					9281bd043a | ||
| 
						 | 
					6771f7c272 | ||
| 
						 | 
					76b896a66d | ||
| 
						 | 
					a12520763c | ||
| 
						 | 
					819bb7caab | ||
| 
						 | 
					152205a146 | ||
| 
						 | 
					85dbcb5444 | ||
| 
						 | 
					df09a746a0 | ||
| 
						 | 
					5199fcf0a2 | ||
| 
						 | 
					dd557ed00a | ||
| 
						 | 
					addf4e2485 | ||
| 
						 | 
					d9be472ccb | ||
| 
						 | 
					32828a9af5 | ||
| 
						 | 
					d206131df0 | ||
| 
						 | 
					65eaf98d0b | ||
| 
						 | 
					12429b90fe | ||
| 
						 | 
					621042e639 | ||
| 
						 | 
					526244be11 | ||
| 
						 | 
					bc53d0b55e | ||
| 
						 | 
					907d3c5a36 | ||
| 
						 | 
					898f1e215e | ||
| 
						 | 
					324ac83489 | ||
| 
						 | 
					00a873dcc7 | ||
| 
						 | 
					bc34345a56 | ||
| 
						 | 
					659d27cae5 | ||
| 
						 | 
					29072d6eae | ||
| 
						 | 
					1fd59361b5 | ||
| 
						 | 
					5896bb8fa3 | ||
| 
						 | 
					ea1fc90cf5 | ||
| 
						 | 
					463f48f04f | ||
| 
						 | 
					cd58a30c7c | ||
| 
						 | 
					c4260ae681 | ||
| 
						 | 
					b83a364b0e | ||
| 
						 | 
					81fcb4452e | ||
| 
						 | 
					4f1a5cd456 | ||
| 
						 | 
					ae2d3d7e61 | ||
| 
						 | 
					58ae0908e3 | ||
| 
						 | 
					e91caeaade | ||
| 
						 | 
					bd694c60e1 | ||
| 
						 | 
					04f4b05412 | 
@@ -1,4 +1,6 @@
 | 
			
		||||
before_install: 
 | 
			
		||||
  - git fetch origin master:master
 | 
			
		||||
  - git fetch origin v2.0.0:v2.0.0
 | 
			
		||||
  - sudo apt-get install libicu-dev -y
 | 
			
		||||
  - gem update --system 2.1.11
 | 
			
		||||
rvm:
 | 
			
		||||
 
 | 
			
		||||
@@ -152,4 +152,4 @@ If you are the current maintainer of this gem:
 | 
			
		||||
   0. Test behavior locally, branch deploy, whatever needs to happen
 | 
			
		||||
 0. Merge github/linguist PR
 | 
			
		||||
 0. Tag and push: `git tag vx.xx.xx; git push --tags`
 | 
			
		||||
 0. Push to rubygems.org -- `gem push github-linguist-2.10.12.gem`
 | 
			
		||||
 0. Push to rubygems.org -- `gem push github-linguist-3.0.0.gem`
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,9 @@
 | 
			
		||||
#     usage: linguist <path> [<--breakdown>]
 | 
			
		||||
 | 
			
		||||
require 'linguist/file_blob'
 | 
			
		||||
require 'linguist/language'
 | 
			
		||||
require 'linguist/repository'
 | 
			
		||||
require 'rugged'
 | 
			
		||||
 | 
			
		||||
path = ARGV[0] || Dir.pwd
 | 
			
		||||
 | 
			
		||||
@@ -18,7 +20,8 @@ ARGV.shift
 | 
			
		||||
breakdown = true if ARGV[0] == "--breakdown"
 | 
			
		||||
 | 
			
		||||
if File.directory?(path)
 | 
			
		||||
  repo = Linguist::Repository.from_directory(path)
 | 
			
		||||
  rugged = Rugged::Repository.new(path)
 | 
			
		||||
  repo = Linguist::Repository.new(rugged, rugged.head.target_id)
 | 
			
		||||
  repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
 | 
			
		||||
    percentage = ((size / repo.size.to_f) * 100)
 | 
			
		||||
    percentage = sprintf '%.2f' % percentage
 | 
			
		||||
@@ -28,7 +31,7 @@ if File.directory?(path)
 | 
			
		||||
    puts
 | 
			
		||||
    file_breakdown = repo.breakdown_by_file
 | 
			
		||||
    file_breakdown.each do |lang, files|
 | 
			
		||||
      puts "#{lang}:" 
 | 
			
		||||
      puts "#{lang}:"
 | 
			
		||||
      files.each do |file|
 | 
			
		||||
        puts file
 | 
			
		||||
      end
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
 | 
			
		||||
  s.add_dependency 'escape_utils',    '~> 1.0.1'
 | 
			
		||||
  s.add_dependency 'mime-types',      '~> 1.19'
 | 
			
		||||
  s.add_dependency 'pygments.rb',     '~> 0.6.0'
 | 
			
		||||
  s.add_dependency 'rugged',          '~> 0.21.0'
 | 
			
		||||
 | 
			
		||||
  s.add_development_dependency 'json'
 | 
			
		||||
  s.add_development_dependency 'mocha'
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,4 @@
 | 
			
		||||
require 'linguist/generated'
 | 
			
		||||
require 'linguist/language'
 | 
			
		||||
 | 
			
		||||
require 'charlock_holmes'
 | 
			
		||||
require 'escape_utils'
 | 
			
		||||
require 'mime/types'
 | 
			
		||||
@@ -313,15 +311,7 @@ module Linguist
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a Language or nil if none is detected
 | 
			
		||||
    def language
 | 
			
		||||
      return @language if defined? @language
 | 
			
		||||
 | 
			
		||||
      if defined?(@data) && @data.is_a?(String)
 | 
			
		||||
        data = @data
 | 
			
		||||
      else
 | 
			
		||||
        data = lambda { (binary_mime_type? || binary?) ? "" : self.data }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      @language = Language.detect(name.to_s, data, mode)
 | 
			
		||||
      @language ||= Language.detect(self)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Internal: Get the lexer of the blob.
 | 
			
		||||
 
 | 
			
		||||
@@ -52,5 +52,20 @@ module Linguist
 | 
			
		||||
    def size
 | 
			
		||||
      File.size(@path)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Public: Get file extension.
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a String.
 | 
			
		||||
    def extension
 | 
			
		||||
      # File.extname returns nil if the filename is an extension.
 | 
			
		||||
      extension = File.extname(name)
 | 
			
		||||
      basename = File.basename(name)
 | 
			
		||||
      # Checks if the filename is an extension.
 | 
			
		||||
      if extension.empty? && basename[0] == "."
 | 
			
		||||
        basename
 | 
			
		||||
      else
 | 
			
		||||
        extension
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,7 @@ module Linguist
 | 
			
		||||
      name == 'Gemfile.lock' ||
 | 
			
		||||
        minified_files? ||
 | 
			
		||||
        compiled_coffeescript? ||
 | 
			
		||||
        xcode_project_file? ||
 | 
			
		||||
        xcode_file? ||
 | 
			
		||||
        generated_parser? ||
 | 
			
		||||
        generated_net_docfile? ||
 | 
			
		||||
        generated_net_designer_file? ||
 | 
			
		||||
@@ -67,14 +67,14 @@ module Linguist
 | 
			
		||||
        generated_by_zephir?
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Internal: Is the blob an XCode project file?
 | 
			
		||||
    # Internal: Is the blob an Xcode file?
 | 
			
		||||
    #
 | 
			
		||||
    # Generated if the file extension is an XCode project
 | 
			
		||||
    # Generated if the file extension is an Xcode 
 | 
			
		||||
    # file extension.
 | 
			
		||||
    #
 | 
			
		||||
    # Returns true of false.
 | 
			
		||||
    def xcode_project_file?
 | 
			
		||||
      ['.xib', '.nib', '.storyboard', '.pbxproj', '.xcworkspacedata', '.xcuserstate'].include?(extname)
 | 
			
		||||
    def xcode_file?
 | 
			
		||||
      ['.nib', '.xcworkspacedata', '.xcuserstate'].include?(extname)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Internal: Is the blob minified files?
 | 
			
		||||
@@ -256,3 +256,4 @@ module Linguist
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,8 @@ end
 | 
			
		||||
require 'linguist/classifier'
 | 
			
		||||
require 'linguist/heuristics'
 | 
			
		||||
require 'linguist/samples'
 | 
			
		||||
require 'linguist/file_blob'
 | 
			
		||||
require 'linguist/blob_helper'
 | 
			
		||||
 | 
			
		||||
module Linguist
 | 
			
		||||
  # Language names that are recognizable by GitHub. Defined languages
 | 
			
		||||
@@ -92,18 +94,25 @@ module Linguist
 | 
			
		||||
 | 
			
		||||
    # Public: Detects the Language of the blob.
 | 
			
		||||
    #
 | 
			
		||||
    # name - String filename
 | 
			
		||||
    # data - String blob data. A block also maybe passed in for lazy
 | 
			
		||||
    #        loading. This behavior is deprecated and you should always
 | 
			
		||||
    #        pass in a String.
 | 
			
		||||
    # mode - Optional String mode (defaults to nil)
 | 
			
		||||
    # blob - an object that includes the Linguist `BlobHelper` interface;
 | 
			
		||||
    #       see Linguist::LazyBlob and Linguist::FileBlob for examples
 | 
			
		||||
    #
 | 
			
		||||
    # Returns Language or nil.
 | 
			
		||||
    def self.detect(name, data, mode = nil)
 | 
			
		||||
    def self.detect(blob)
 | 
			
		||||
      name = blob.name.to_s
 | 
			
		||||
 | 
			
		||||
      # Check if the blob is possibly binary and bail early; this is a cheap
 | 
			
		||||
      # test that uses the extension name to guess a binary binary mime type.
 | 
			
		||||
      #
 | 
			
		||||
      # We'll perform a more comprehensive test later which actually involves
 | 
			
		||||
      # looking for binary characters in the blob
 | 
			
		||||
      return nil if blob.likely_binary? || blob.binary?
 | 
			
		||||
 | 
			
		||||
      # A bit of an elegant hack. If the file is executable but extensionless,
 | 
			
		||||
      # append a "magic" extension so it can be classified with other
 | 
			
		||||
      # languages that have shebang scripts.
 | 
			
		||||
      if File.extname(name).empty? && mode && (mode.to_i(8) & 05) == 05
 | 
			
		||||
      extension = FileBlob.new(name).extension
 | 
			
		||||
      if extension.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
 | 
			
		||||
        name += ".script!"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
@@ -114,10 +123,10 @@ module Linguist
 | 
			
		||||
      # 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)
 | 
			
		||||
        data = blob.data
 | 
			
		||||
        possible_language_names = possible_languages.map(&:name)
 | 
			
		||||
 | 
			
		||||
        # Don't bother with emptiness
 | 
			
		||||
        # Don't bother with binary contents or an empty file
 | 
			
		||||
        if data.nil? || data == ""
 | 
			
		||||
          nil
 | 
			
		||||
        # Check if there's a shebang line and use that as authoritative
 | 
			
		||||
@@ -183,7 +192,8 @@ module Linguist
 | 
			
		||||
    #
 | 
			
		||||
    # Returns all matching Languages or [] if none were found.
 | 
			
		||||
    def self.find_by_filename(filename)
 | 
			
		||||
      basename, extname = File.basename(filename), File.extname(filename)
 | 
			
		||||
      basename = File.basename(filename)
 | 
			
		||||
      extname = FileBlob.new(filename).extension
 | 
			
		||||
      langs = @filename_index[basename] +
 | 
			
		||||
              @extension_index[extname]
 | 
			
		||||
      langs.compact.uniq
 | 
			
		||||
@@ -395,7 +405,7 @@ module Linguist
 | 
			
		||||
    #
 | 
			
		||||
    # Returns the extensions Array
 | 
			
		||||
    attr_reader :filenames
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    # Public: Return all possible extensions for language
 | 
			
		||||
    def all_extensions
 | 
			
		||||
      (extensions + [primary_extension]).uniq
 | 
			
		||||
 
 | 
			
		||||
@@ -89,7 +89,7 @@ Agda:
 | 
			
		||||
 | 
			
		||||
Alloy:
 | 
			
		||||
  type: programming  # 'modeling' would be more appropiate
 | 
			
		||||
  lexer: Text only
 | 
			
		||||
  lexer: Alloy
 | 
			
		||||
  color: "#cc5c24"
 | 
			
		||||
  extensions:
 | 
			
		||||
  - .als
 | 
			
		||||
@@ -157,7 +157,6 @@ Assembly:
 | 
			
		||||
  - nasm
 | 
			
		||||
  extensions:
 | 
			
		||||
  - .asm
 | 
			
		||||
  - .inc
 | 
			
		||||
 | 
			
		||||
Augeas:
 | 
			
		||||
  type: programming
 | 
			
		||||
@@ -222,6 +221,8 @@ BlitzBasic:
 | 
			
		||||
  - .decls
 | 
			
		||||
 | 
			
		||||
BlitzMax:
 | 
			
		||||
  type: programming
 | 
			
		||||
  color: "#cd6400"
 | 
			
		||||
  extensions:
 | 
			
		||||
  - .bmx
 | 
			
		||||
 | 
			
		||||
@@ -735,12 +736,14 @@ GLSL:
 | 
			
		||||
  - .glsl
 | 
			
		||||
  - .fp
 | 
			
		||||
  - .frag
 | 
			
		||||
  - .frg
 | 
			
		||||
  - .fshader
 | 
			
		||||
  - .geom
 | 
			
		||||
  - .glslv
 | 
			
		||||
  - .gshader
 | 
			
		||||
  - .shader
 | 
			
		||||
  - .vert
 | 
			
		||||
  - .vrx
 | 
			
		||||
  - .vshader
 | 
			
		||||
 | 
			
		||||
Genshi:
 | 
			
		||||
@@ -798,6 +801,12 @@ Gosu:
 | 
			
		||||
  extensions:
 | 
			
		||||
  - .gs
 | 
			
		||||
 | 
			
		||||
Grace:
 | 
			
		||||
  type: programming
 | 
			
		||||
  lexer: Text only
 | 
			
		||||
  extensions:
 | 
			
		||||
  - .grace
 | 
			
		||||
 | 
			
		||||
Grammatical Framework:
 | 
			
		||||
  type: programming
 | 
			
		||||
  lexer: Haskell
 | 
			
		||||
@@ -1336,7 +1345,7 @@ MiniD: # Legacy
 | 
			
		||||
Mirah:
 | 
			
		||||
  type: programming
 | 
			
		||||
  lexer: Ruby
 | 
			
		||||
  search_term: ruby
 | 
			
		||||
  search_term: mirah
 | 
			
		||||
  color: "#c7a938"
 | 
			
		||||
  extensions:
 | 
			
		||||
  - .druby
 | 
			
		||||
@@ -1395,6 +1404,13 @@ Nimrod:
 | 
			
		||||
  - .nim
 | 
			
		||||
  - .nimrod
 | 
			
		||||
 | 
			
		||||
Nit:
 | 
			
		||||
  type: programming
 | 
			
		||||
  lexer: Text only
 | 
			
		||||
  color: "#0d8921"
 | 
			
		||||
  extensions:
 | 
			
		||||
  - .nit
 | 
			
		||||
 | 
			
		||||
Nix:
 | 
			
		||||
  type: programming
 | 
			
		||||
  lexer: Nix
 | 
			
		||||
@@ -1536,6 +1552,8 @@ PHP:
 | 
			
		||||
  - .phpt
 | 
			
		||||
  filenames:
 | 
			
		||||
  - Phakefile
 | 
			
		||||
  interpreters:
 | 
			
		||||
  - php
 | 
			
		||||
 | 
			
		||||
Pan:
 | 
			
		||||
  type: programming
 | 
			
		||||
@@ -1888,6 +1906,7 @@ Ruby:
 | 
			
		||||
  - Jarfile
 | 
			
		||||
  - Mavenfile
 | 
			
		||||
  - Podfile
 | 
			
		||||
  - Puppetfile
 | 
			
		||||
  - Thorfile
 | 
			
		||||
  - Vagrantfile
 | 
			
		||||
  - buildfile
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										37
									
								
								lib/linguist/lazy_blob.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								lib/linguist/lazy_blob.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
require 'linguist/blob_helper'
 | 
			
		||||
require 'rugged'
 | 
			
		||||
 | 
			
		||||
module Linguist
 | 
			
		||||
  class LazyBlob
 | 
			
		||||
    include BlobHelper
 | 
			
		||||
 | 
			
		||||
    MAX_SIZE = 128 * 1024
 | 
			
		||||
 | 
			
		||||
    attr_reader :repository
 | 
			
		||||
    attr_reader :oid
 | 
			
		||||
    attr_reader :name
 | 
			
		||||
    attr_reader :mode
 | 
			
		||||
 | 
			
		||||
    def initialize(repo, oid, name, mode = nil)
 | 
			
		||||
      @repository = repo
 | 
			
		||||
      @oid = oid
 | 
			
		||||
      @name = name
 | 
			
		||||
      @mode = mode
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def data
 | 
			
		||||
      load_blob!
 | 
			
		||||
      @data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def size
 | 
			
		||||
      load_blob!
 | 
			
		||||
      @size
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    protected
 | 
			
		||||
    def load_blob!
 | 
			
		||||
      @data, @size = Rugged::Blob.to_buffer(repository, oid, MAX_SIZE) if @data.nil?
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
require 'linguist/file_blob'
 | 
			
		||||
require 'linguist/lazy_blob'
 | 
			
		||||
require 'rugged'
 | 
			
		||||
 | 
			
		||||
module Linguist
 | 
			
		||||
  # A Repository is an abstraction of a Grit::Repo or a basic file
 | 
			
		||||
@@ -7,100 +8,146 @@ module Linguist
 | 
			
		||||
  # Its primary purpose is for gathering language statistics across
 | 
			
		||||
  # the entire project.
 | 
			
		||||
  class Repository
 | 
			
		||||
    # Public: Initialize a new Repository from a File directory
 | 
			
		||||
    #
 | 
			
		||||
    # base_path - A path String
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a Repository
 | 
			
		||||
    def self.from_directory(base_path)
 | 
			
		||||
      new Dir["#{base_path}/**/*"].
 | 
			
		||||
        select { |f| File.file?(f) }.
 | 
			
		||||
        map { |path| FileBlob.new(path, base_path) }
 | 
			
		||||
    attr_reader :repository
 | 
			
		||||
 | 
			
		||||
    # Public: Create a new Repository based on the stats of
 | 
			
		||||
    # an existing one
 | 
			
		||||
    def self.incremental(repo, commit_oid, old_commit_oid, old_stats)
 | 
			
		||||
      repo = self.new(repo, commit_oid)
 | 
			
		||||
      repo.load_existing_stats(old_commit_oid, old_stats)
 | 
			
		||||
      repo
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Public: Initialize a new Repository
 | 
			
		||||
    # Public: Initialize a new Repository to be analyzed for language
 | 
			
		||||
    # data
 | 
			
		||||
    #
 | 
			
		||||
    # enum - Enumerator that responds to `each` and
 | 
			
		||||
    #        yields Blob objects
 | 
			
		||||
    # repo - a Rugged::Repository object
 | 
			
		||||
    # commit_oid - the sha1 of the commit that will be analyzed;
 | 
			
		||||
    #              this is usually the master branch
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a Repository
 | 
			
		||||
    def initialize(enum)
 | 
			
		||||
      @enum = enum
 | 
			
		||||
      @computed_stats = false
 | 
			
		||||
      @language = @size = nil
 | 
			
		||||
      @sizes = Hash.new { 0 }
 | 
			
		||||
      @file_breakdown = Hash.new { |h,k| h[k] = Array.new }
 | 
			
		||||
    def initialize(repo, commit_oid)
 | 
			
		||||
      @repository = repo
 | 
			
		||||
      @commit_oid = commit_oid
 | 
			
		||||
 | 
			
		||||
      raise TypeError, 'commit_oid must be a commit SHA1' unless commit_oid.is_a?(String)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Public: Load the results of a previous analysis on this repository
 | 
			
		||||
    # to speed up the new scan.
 | 
			
		||||
    #
 | 
			
		||||
    # The new analysis will be performed incrementally as to only take
 | 
			
		||||
    # into account the file changes since the last time the repository
 | 
			
		||||
    # was scanned
 | 
			
		||||
    #
 | 
			
		||||
    # old_commit_oid - the sha1 of the commit that was previously analyzed
 | 
			
		||||
    # old_stats - the result of the previous analysis, obtained by calling
 | 
			
		||||
    #             Repository#cache on the old repository
 | 
			
		||||
    #
 | 
			
		||||
    # Returns nothing
 | 
			
		||||
    def load_existing_stats(old_commit_oid, old_stats)
 | 
			
		||||
      @old_commit_oid = old_commit_oid
 | 
			
		||||
      @old_stats = old_stats
 | 
			
		||||
      nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Public: Returns a breakdown of language stats.
 | 
			
		||||
    #
 | 
			
		||||
    # Examples
 | 
			
		||||
    #
 | 
			
		||||
    #   # => { Language['Ruby'] => 46319,
 | 
			
		||||
    #          Language['JavaScript'] => 258 }
 | 
			
		||||
    #   # => { 'Ruby' => 46319,
 | 
			
		||||
    #          'JavaScript' => 258 }
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a Hash of Language keys and Integer size values.
 | 
			
		||||
    # Returns a Hash of language names and Integer size values.
 | 
			
		||||
    def languages
 | 
			
		||||
      compute_stats
 | 
			
		||||
      @sizes
 | 
			
		||||
      @sizes ||= begin
 | 
			
		||||
        sizes = Hash.new { 0 }
 | 
			
		||||
        cache.each do |_, (language, size)|
 | 
			
		||||
          sizes[language] += size
 | 
			
		||||
        end
 | 
			
		||||
        sizes
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Public: Get primary Language of repository.
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a Language
 | 
			
		||||
    # Returns a language name
 | 
			
		||||
    def language
 | 
			
		||||
      compute_stats
 | 
			
		||||
      @language
 | 
			
		||||
      @language ||= begin
 | 
			
		||||
        primary = languages.max_by { |(_, size)| size }
 | 
			
		||||
        primary && primary[0]
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Public: Get the total size of the repository.
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a byte size Integer
 | 
			
		||||
    def size
 | 
			
		||||
      compute_stats
 | 
			
		||||
      @size
 | 
			
		||||
      @size ||= languages.inject(0) { |s,(_,v)| s + v }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Public: Return the language breakdown of this repository by file
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a map of language names => [filenames...]
 | 
			
		||||
    def breakdown_by_file
 | 
			
		||||
      compute_stats
 | 
			
		||||
      @file_breakdown
 | 
			
		||||
      @file_breakdown ||= begin
 | 
			
		||||
        breakdown = Hash.new { |h,k| h[k] = Array.new }
 | 
			
		||||
        cache.each do |filename, (language, _)|
 | 
			
		||||
          breakdown[language] << filename
 | 
			
		||||
        end
 | 
			
		||||
        breakdown
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Internal: Compute language breakdown for each blob in the Repository.
 | 
			
		||||
    # Public: Return the cached results of the analysis
 | 
			
		||||
    #
 | 
			
		||||
    # Returns nothing
 | 
			
		||||
    def compute_stats
 | 
			
		||||
      return if @computed_stats
 | 
			
		||||
    # This is a per-file breakdown that can be passed to other instances
 | 
			
		||||
    # of Linguist::Repository to perform incremental scans
 | 
			
		||||
    #
 | 
			
		||||
    # Returns a map of filename => [language, size]
 | 
			
		||||
    def cache
 | 
			
		||||
      @cache ||= begin
 | 
			
		||||
        if @old_commit_oid == @commit_oid
 | 
			
		||||
          @old_stats
 | 
			
		||||
        else
 | 
			
		||||
          compute_stats(@old_commit_oid, @commit_oid, @old_stats)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
      @enum.each do |blob|
 | 
			
		||||
        # Skip files that are likely binary
 | 
			
		||||
        next if blob.likely_binary?
 | 
			
		||||
    protected
 | 
			
		||||
    def compute_stats(old_commit_oid, commit_oid, cache = nil)
 | 
			
		||||
      file_map = cache ? cache.dup : {}
 | 
			
		||||
      old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
 | 
			
		||||
      new_tree = Rugged::Commit.lookup(repository, commit_oid).tree
 | 
			
		||||
 | 
			
		||||
        # Skip vendored or generated blobs
 | 
			
		||||
        next if blob.vendored? || blob.generated? || blob.language.nil?
 | 
			
		||||
      diff = Rugged::Tree.diff(repository, old_tree, new_tree)
 | 
			
		||||
 | 
			
		||||
        # Only include programming languages and acceptable markup languages
 | 
			
		||||
        if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
 | 
			
		||||
      diff.each_delta do |delta|
 | 
			
		||||
        old = delta.old_file[:path]
 | 
			
		||||
        new = delta.new_file[:path]
 | 
			
		||||
 | 
			
		||||
          # Build up the per-file breakdown stats
 | 
			
		||||
          @file_breakdown[blob.language.group.name] << blob.name
 | 
			
		||||
        file_map.delete(old)
 | 
			
		||||
        next if delta.binary
 | 
			
		||||
 | 
			
		||||
          @sizes[blob.language.group] += blob.size
 | 
			
		||||
        if [:added, :modified].include? delta.status
 | 
			
		||||
          # Skip submodules
 | 
			
		||||
          mode = delta.new_file[:mode]
 | 
			
		||||
          next if (mode & 040000) != 0
 | 
			
		||||
 | 
			
		||||
          blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8))
 | 
			
		||||
 | 
			
		||||
          # Skip vendored or generated blobs
 | 
			
		||||
          next if blob.vendored? || blob.generated? || blob.language.nil?
 | 
			
		||||
 | 
			
		||||
          # Only include programming languages and acceptable markup languages
 | 
			
		||||
          if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
 | 
			
		||||
            file_map[new] = [blob.language.group.name, blob.size]
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      # Compute total size
 | 
			
		||||
      @size = @sizes.inject(0) { |s,(_,v)| s + v }
 | 
			
		||||
 | 
			
		||||
      # Get primary language
 | 
			
		||||
      if primary = @sizes.max_by { |(_, size)| size }
 | 
			
		||||
        @language = primary[0]
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      @computed_stats = true
 | 
			
		||||
 | 
			
		||||
      nil
 | 
			
		||||
      file_map
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -40,6 +40,9 @@
 | 
			
		||||
- foundation.min.css
 | 
			
		||||
- foundation.css
 | 
			
		||||
 | 
			
		||||
# Normalize.css
 | 
			
		||||
- normalize.css
 | 
			
		||||
 | 
			
		||||
# Vendored dependencies
 | 
			
		||||
- thirdparty/
 | 
			
		||||
- vendors?/
 | 
			
		||||
@@ -125,6 +128,9 @@
 | 
			
		||||
 | 
			
		||||
## Obj-C ##
 | 
			
		||||
 | 
			
		||||
# Cocoapods
 | 
			
		||||
- ^Pods/
 | 
			
		||||
 | 
			
		||||
# Sparkle
 | 
			
		||||
- (^|/)Sparkle/
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,3 @@
 | 
			
		||||
module Linguist
 | 
			
		||||
  VERSION = "2.12.0"
 | 
			
		||||
  VERSION = "3.1.1"
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,503 +0,0 @@
 | 
			
		||||
 | 
			
		||||
; flat assembler interface for Win32
 | 
			
		||||
; Copyright (c) 1999-2014, Tomasz Grysztar.
 | 
			
		||||
; All rights reserved.
 | 
			
		||||
 | 
			
		||||
CREATE_NEW	       = 1
 | 
			
		||||
CREATE_ALWAYS	       = 2
 | 
			
		||||
OPEN_EXISTING	       = 3
 | 
			
		||||
OPEN_ALWAYS	       = 4
 | 
			
		||||
TRUNCATE_EXISTING      = 5
 | 
			
		||||
 | 
			
		||||
FILE_SHARE_READ        = 1
 | 
			
		||||
FILE_SHARE_WRITE       = 2
 | 
			
		||||
FILE_SHARE_DELETE      = 4
 | 
			
		||||
 | 
			
		||||
GENERIC_READ	       = 80000000h
 | 
			
		||||
GENERIC_WRITE	       = 40000000h
 | 
			
		||||
 | 
			
		||||
STD_INPUT_HANDLE       = 0FFFFFFF6h
 | 
			
		||||
STD_OUTPUT_HANDLE      = 0FFFFFFF5h
 | 
			
		||||
STD_ERROR_HANDLE       = 0FFFFFFF4h
 | 
			
		||||
 | 
			
		||||
MEM_COMMIT	       = 1000h
 | 
			
		||||
MEM_RESERVE	       = 2000h
 | 
			
		||||
MEM_DECOMMIT	       = 4000h
 | 
			
		||||
MEM_RELEASE	       = 8000h
 | 
			
		||||
MEM_FREE	       = 10000h
 | 
			
		||||
MEM_PRIVATE	       = 20000h
 | 
			
		||||
MEM_MAPPED	       = 40000h
 | 
			
		||||
MEM_RESET	       = 80000h
 | 
			
		||||
MEM_TOP_DOWN	       = 100000h
 | 
			
		||||
 | 
			
		||||
PAGE_NOACCESS	       = 1
 | 
			
		||||
PAGE_READONLY	       = 2
 | 
			
		||||
PAGE_READWRITE	       = 4
 | 
			
		||||
PAGE_WRITECOPY	       = 8
 | 
			
		||||
PAGE_EXECUTE	       = 10h
 | 
			
		||||
PAGE_EXECUTE_READ      = 20h
 | 
			
		||||
PAGE_EXECUTE_READWRITE = 40h
 | 
			
		||||
PAGE_EXECUTE_WRITECOPY = 80h
 | 
			
		||||
PAGE_GUARD	       = 100h
 | 
			
		||||
PAGE_NOCACHE	       = 200h
 | 
			
		||||
 | 
			
		||||
init_memory:
 | 
			
		||||
	xor	eax,eax
 | 
			
		||||
	mov	[memory_start],eax
 | 
			
		||||
	mov	eax,esp
 | 
			
		||||
	and	eax,not 0FFFh
 | 
			
		||||
	add	eax,1000h-10000h
 | 
			
		||||
	mov	[stack_limit],eax
 | 
			
		||||
	mov	eax,[memory_setting]
 | 
			
		||||
	shl	eax,10
 | 
			
		||||
	jnz	allocate_memory
 | 
			
		||||
	push	buffer
 | 
			
		||||
	call	[GlobalMemoryStatus]
 | 
			
		||||
	mov	eax,dword [buffer+20]
 | 
			
		||||
	mov	edx,dword [buffer+12]
 | 
			
		||||
	cmp	eax,0
 | 
			
		||||
	jl	large_memory
 | 
			
		||||
	cmp	edx,0
 | 
			
		||||
	jl	large_memory
 | 
			
		||||
	shr	eax,2
 | 
			
		||||
	add	eax,edx
 | 
			
		||||
	jmp	allocate_memory
 | 
			
		||||
    large_memory:
 | 
			
		||||
	mov	eax,80000000h
 | 
			
		||||
    allocate_memory:
 | 
			
		||||
	mov	edx,eax
 | 
			
		||||
	shr	edx,2
 | 
			
		||||
	mov	ecx,eax
 | 
			
		||||
	sub	ecx,edx
 | 
			
		||||
	mov	[memory_end],ecx
 | 
			
		||||
	mov	[additional_memory_end],edx
 | 
			
		||||
	push	PAGE_READWRITE
 | 
			
		||||
	push	MEM_COMMIT
 | 
			
		||||
	push	eax
 | 
			
		||||
	push	0
 | 
			
		||||
	call	[VirtualAlloc]
 | 
			
		||||
	or	eax,eax
 | 
			
		||||
	jz	not_enough_memory
 | 
			
		||||
	mov	[memory_start],eax
 | 
			
		||||
	add	eax,[memory_end]
 | 
			
		||||
	mov	[memory_end],eax
 | 
			
		||||
	mov	[additional_memory],eax
 | 
			
		||||
	add	[additional_memory_end],eax
 | 
			
		||||
	ret
 | 
			
		||||
    not_enough_memory:
 | 
			
		||||
	mov	eax,[additional_memory_end]
 | 
			
		||||
	shl	eax,1
 | 
			
		||||
	cmp	eax,4000h
 | 
			
		||||
	jb	out_of_memory
 | 
			
		||||
	jmp	allocate_memory
 | 
			
		||||
 | 
			
		||||
exit_program:
 | 
			
		||||
	movzx	eax,al
 | 
			
		||||
	push	eax
 | 
			
		||||
	mov	eax,[memory_start]
 | 
			
		||||
	test	eax,eax
 | 
			
		||||
	jz	do_exit
 | 
			
		||||
	push	MEM_RELEASE
 | 
			
		||||
	push	0
 | 
			
		||||
	push	eax
 | 
			
		||||
	call	[VirtualFree]
 | 
			
		||||
    do_exit:
 | 
			
		||||
	call	[ExitProcess]
 | 
			
		||||
 | 
			
		||||
get_environment_variable:
 | 
			
		||||
	mov	ecx,[memory_end]
 | 
			
		||||
	sub	ecx,edi
 | 
			
		||||
	cmp	ecx,4000h
 | 
			
		||||
	jbe	buffer_for_variable_ok
 | 
			
		||||
	mov	ecx,4000h
 | 
			
		||||
    buffer_for_variable_ok:
 | 
			
		||||
	push	ecx
 | 
			
		||||
	push	edi
 | 
			
		||||
	push	esi
 | 
			
		||||
	call	[GetEnvironmentVariable]
 | 
			
		||||
	add	edi,eax
 | 
			
		||||
	cmp	edi,[memory_end]
 | 
			
		||||
	jae	out_of_memory
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
open:
 | 
			
		||||
	push	0
 | 
			
		||||
	push	0
 | 
			
		||||
	push	OPEN_EXISTING
 | 
			
		||||
	push	0
 | 
			
		||||
	push	FILE_SHARE_READ
 | 
			
		||||
	push	GENERIC_READ
 | 
			
		||||
	push	edx
 | 
			
		||||
	call	[CreateFile]
 | 
			
		||||
	cmp	eax,-1
 | 
			
		||||
	je	file_error
 | 
			
		||||
	mov	ebx,eax
 | 
			
		||||
	clc
 | 
			
		||||
	ret
 | 
			
		||||
    file_error:
 | 
			
		||||
	stc
 | 
			
		||||
	ret
 | 
			
		||||
create:
 | 
			
		||||
	push	0
 | 
			
		||||
	push	0
 | 
			
		||||
	push	CREATE_ALWAYS
 | 
			
		||||
	push	0
 | 
			
		||||
	push	FILE_SHARE_READ
 | 
			
		||||
	push	GENERIC_WRITE
 | 
			
		||||
	push	edx
 | 
			
		||||
	call	[CreateFile]
 | 
			
		||||
	cmp	eax,-1
 | 
			
		||||
	je	file_error
 | 
			
		||||
	mov	ebx,eax
 | 
			
		||||
	clc
 | 
			
		||||
	ret
 | 
			
		||||
write:
 | 
			
		||||
	push	0
 | 
			
		||||
	push	bytes_count
 | 
			
		||||
	push	ecx
 | 
			
		||||
	push	edx
 | 
			
		||||
	push	ebx
 | 
			
		||||
	call	[WriteFile]
 | 
			
		||||
	or	eax,eax
 | 
			
		||||
	jz	file_error
 | 
			
		||||
	clc
 | 
			
		||||
	ret
 | 
			
		||||
read:
 | 
			
		||||
	mov	ebp,ecx
 | 
			
		||||
	push	0
 | 
			
		||||
	push	bytes_count
 | 
			
		||||
	push	ecx
 | 
			
		||||
	push	edx
 | 
			
		||||
	push	ebx
 | 
			
		||||
	call	[ReadFile]
 | 
			
		||||
	or	eax,eax
 | 
			
		||||
	jz	file_error
 | 
			
		||||
	cmp	ebp,[bytes_count]
 | 
			
		||||
	jne	file_error
 | 
			
		||||
	clc
 | 
			
		||||
	ret
 | 
			
		||||
close:
 | 
			
		||||
	push	ebx
 | 
			
		||||
	call	[CloseHandle]
 | 
			
		||||
	ret
 | 
			
		||||
lseek:
 | 
			
		||||
	movzx	eax,al
 | 
			
		||||
	push	eax
 | 
			
		||||
	push	0
 | 
			
		||||
	push	edx
 | 
			
		||||
	push	ebx
 | 
			
		||||
	call	[SetFilePointer]
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
display_string:
 | 
			
		||||
	push	[con_handle]
 | 
			
		||||
	call	[GetStdHandle]
 | 
			
		||||
	mov	ebp,eax
 | 
			
		||||
	mov	edi,esi
 | 
			
		||||
	or	ecx,-1
 | 
			
		||||
	xor	al,al
 | 
			
		||||
	repne	scasb
 | 
			
		||||
	neg	ecx
 | 
			
		||||
	sub	ecx,2
 | 
			
		||||
	push	0
 | 
			
		||||
	push	bytes_count
 | 
			
		||||
	push	ecx
 | 
			
		||||
	push	esi
 | 
			
		||||
	push	ebp
 | 
			
		||||
	call	[WriteFile]
 | 
			
		||||
	ret
 | 
			
		||||
display_character:
 | 
			
		||||
	push	ebx
 | 
			
		||||
	mov	[character],dl
 | 
			
		||||
	push	[con_handle]
 | 
			
		||||
	call	[GetStdHandle]
 | 
			
		||||
	mov	ebx,eax
 | 
			
		||||
	push	0
 | 
			
		||||
	push	bytes_count
 | 
			
		||||
	push	1
 | 
			
		||||
	push	character
 | 
			
		||||
	push	ebx
 | 
			
		||||
	call	[WriteFile]
 | 
			
		||||
	pop	ebx
 | 
			
		||||
	ret
 | 
			
		||||
display_number:
 | 
			
		||||
	push	ebx
 | 
			
		||||
	mov	ecx,1000000000
 | 
			
		||||
	xor	edx,edx
 | 
			
		||||
	xor	bl,bl
 | 
			
		||||
      display_loop:
 | 
			
		||||
	div	ecx
 | 
			
		||||
	push	edx
 | 
			
		||||
	cmp	ecx,1
 | 
			
		||||
	je	display_digit
 | 
			
		||||
	or	bl,bl
 | 
			
		||||
	jnz	display_digit
 | 
			
		||||
	or	al,al
 | 
			
		||||
	jz	digit_ok
 | 
			
		||||
	not	bl
 | 
			
		||||
      display_digit:
 | 
			
		||||
	mov	dl,al
 | 
			
		||||
	add	dl,30h
 | 
			
		||||
	push	ecx
 | 
			
		||||
	call	display_character
 | 
			
		||||
	pop	ecx
 | 
			
		||||
      digit_ok:
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	xor	edx,edx
 | 
			
		||||
	mov	ecx,10
 | 
			
		||||
	div	ecx
 | 
			
		||||
	mov	ecx,eax
 | 
			
		||||
	pop	eax
 | 
			
		||||
	or	ecx,ecx
 | 
			
		||||
	jnz	display_loop
 | 
			
		||||
	pop	ebx
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
display_user_messages:
 | 
			
		||||
	mov	[displayed_count],0
 | 
			
		||||
	call	show_display_buffer
 | 
			
		||||
	cmp	[displayed_count],1
 | 
			
		||||
	jb	line_break_ok
 | 
			
		||||
	je	make_line_break
 | 
			
		||||
	mov	ax,word [last_displayed]
 | 
			
		||||
	cmp	ax,0A0Dh
 | 
			
		||||
	je	line_break_ok
 | 
			
		||||
	cmp	ax,0D0Ah
 | 
			
		||||
	je	line_break_ok
 | 
			
		||||
      make_line_break:
 | 
			
		||||
	mov	word [buffer],0A0Dh
 | 
			
		||||
	push	[con_handle]
 | 
			
		||||
	call	[GetStdHandle]
 | 
			
		||||
	push	0
 | 
			
		||||
	push	bytes_count
 | 
			
		||||
	push	2
 | 
			
		||||
	push	buffer
 | 
			
		||||
	push	eax
 | 
			
		||||
	call	[WriteFile]
 | 
			
		||||
      line_break_ok:
 | 
			
		||||
	ret
 | 
			
		||||
display_block:
 | 
			
		||||
	add	[displayed_count],ecx
 | 
			
		||||
	cmp	ecx,1
 | 
			
		||||
	ja	take_last_two_characters
 | 
			
		||||
	jb	block_displayed
 | 
			
		||||
	mov	al,[last_displayed+1]
 | 
			
		||||
	mov	ah,[esi]
 | 
			
		||||
	mov	word [last_displayed],ax
 | 
			
		||||
	jmp	block_ok
 | 
			
		||||
      take_last_two_characters:
 | 
			
		||||
	mov	ax,[esi+ecx-2]
 | 
			
		||||
	mov	word [last_displayed],ax
 | 
			
		||||
      block_ok:
 | 
			
		||||
	push	ecx
 | 
			
		||||
	push	[con_handle]
 | 
			
		||||
	call	[GetStdHandle]
 | 
			
		||||
	pop	ecx
 | 
			
		||||
	push	0
 | 
			
		||||
	push	bytes_count
 | 
			
		||||
	push	ecx
 | 
			
		||||
	push	esi
 | 
			
		||||
	push	eax
 | 
			
		||||
	call	[WriteFile]
 | 
			
		||||
      block_displayed:
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
fatal_error:
 | 
			
		||||
	mov	[con_handle],STD_ERROR_HANDLE
 | 
			
		||||
	mov	esi,error_prefix
 | 
			
		||||
	call	display_string
 | 
			
		||||
	pop	esi
 | 
			
		||||
	call	display_string
 | 
			
		||||
	mov	esi,error_suffix
 | 
			
		||||
	call	display_string
 | 
			
		||||
	mov	al,0FFh
 | 
			
		||||
	jmp	exit_program
 | 
			
		||||
assembler_error:
 | 
			
		||||
	mov	[con_handle],STD_ERROR_HANDLE
 | 
			
		||||
	call	display_user_messages
 | 
			
		||||
	push	dword 0
 | 
			
		||||
	mov	ebx,[current_line]
 | 
			
		||||
      get_error_lines:
 | 
			
		||||
	mov	eax,[ebx]
 | 
			
		||||
	cmp	byte [eax],0
 | 
			
		||||
	je	get_next_error_line
 | 
			
		||||
	push	ebx
 | 
			
		||||
	test	byte [ebx+7],80h
 | 
			
		||||
	jz	display_error_line
 | 
			
		||||
	mov	edx,ebx
 | 
			
		||||
      find_definition_origin:
 | 
			
		||||
	mov	edx,[edx+12]
 | 
			
		||||
	test	byte [edx+7],80h
 | 
			
		||||
	jnz	find_definition_origin
 | 
			
		||||
	push	edx
 | 
			
		||||
      get_next_error_line:
 | 
			
		||||
	mov	ebx,[ebx+8]
 | 
			
		||||
	jmp	get_error_lines
 | 
			
		||||
      display_error_line:
 | 
			
		||||
	mov	esi,[ebx]
 | 
			
		||||
	call	display_string
 | 
			
		||||
	mov	esi,line_number_start
 | 
			
		||||
	call	display_string
 | 
			
		||||
	mov	eax,[ebx+4]
 | 
			
		||||
	and	eax,7FFFFFFFh
 | 
			
		||||
	call	display_number
 | 
			
		||||
	mov	dl,']'
 | 
			
		||||
	call	display_character
 | 
			
		||||
	pop	esi
 | 
			
		||||
	cmp	ebx,esi
 | 
			
		||||
	je	line_number_ok
 | 
			
		||||
	mov	dl,20h
 | 
			
		||||
	call	display_character
 | 
			
		||||
	push	esi
 | 
			
		||||
	mov	esi,[esi]
 | 
			
		||||
	movzx	ecx,byte [esi]
 | 
			
		||||
	inc	esi
 | 
			
		||||
	call	display_block
 | 
			
		||||
	mov	esi,line_number_start
 | 
			
		||||
	call	display_string
 | 
			
		||||
	pop	esi
 | 
			
		||||
	mov	eax,[esi+4]
 | 
			
		||||
	and	eax,7FFFFFFFh
 | 
			
		||||
	call	display_number
 | 
			
		||||
	mov	dl,']'
 | 
			
		||||
	call	display_character
 | 
			
		||||
      line_number_ok:
 | 
			
		||||
	mov	esi,line_data_start
 | 
			
		||||
	call	display_string
 | 
			
		||||
	mov	esi,ebx
 | 
			
		||||
	mov	edx,[esi]
 | 
			
		||||
	call	open
 | 
			
		||||
	mov	al,2
 | 
			
		||||
	xor	edx,edx
 | 
			
		||||
	call	lseek
 | 
			
		||||
	mov	edx,[esi+8]
 | 
			
		||||
	sub	eax,edx
 | 
			
		||||
	jz	line_data_displayed
 | 
			
		||||
	push	eax
 | 
			
		||||
	xor	al,al
 | 
			
		||||
	call	lseek
 | 
			
		||||
	mov	ecx,[esp]
 | 
			
		||||
	mov	edx,[additional_memory]
 | 
			
		||||
	lea	eax,[edx+ecx]
 | 
			
		||||
	cmp	eax,[additional_memory_end]
 | 
			
		||||
	ja	out_of_memory
 | 
			
		||||
	call	read
 | 
			
		||||
	call	close
 | 
			
		||||
	pop	ecx
 | 
			
		||||
	mov	esi,[additional_memory]
 | 
			
		||||
      get_line_data:
 | 
			
		||||
	mov	al,[esi]
 | 
			
		||||
	cmp	al,0Ah
 | 
			
		||||
	je	display_line_data
 | 
			
		||||
	cmp	al,0Dh
 | 
			
		||||
	je	display_line_data
 | 
			
		||||
	cmp	al,1Ah
 | 
			
		||||
	je	display_line_data
 | 
			
		||||
	or	al,al
 | 
			
		||||
	jz	display_line_data
 | 
			
		||||
	inc	esi
 | 
			
		||||
	loop	get_line_data
 | 
			
		||||
      display_line_data:
 | 
			
		||||
	mov	ecx,esi
 | 
			
		||||
	mov	esi,[additional_memory]
 | 
			
		||||
	sub	ecx,esi
 | 
			
		||||
	call	display_block
 | 
			
		||||
      line_data_displayed:
 | 
			
		||||
	mov	esi,cr_lf
 | 
			
		||||
	call	display_string
 | 
			
		||||
	pop	ebx
 | 
			
		||||
	or	ebx,ebx
 | 
			
		||||
	jnz	display_error_line
 | 
			
		||||
	mov	esi,error_prefix
 | 
			
		||||
	call	display_string
 | 
			
		||||
	pop	esi
 | 
			
		||||
	call	display_string
 | 
			
		||||
	mov	esi,error_suffix
 | 
			
		||||
	call	display_string
 | 
			
		||||
	mov	al,2
 | 
			
		||||
	jmp	exit_program
 | 
			
		||||
 | 
			
		||||
make_timestamp:
 | 
			
		||||
	push	buffer
 | 
			
		||||
	call	[GetSystemTime]
 | 
			
		||||
	movzx	ecx,word [buffer]
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	sub	eax,1970
 | 
			
		||||
	mov	ebx,365
 | 
			
		||||
	mul	ebx
 | 
			
		||||
	mov	ebp,eax
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	sub	eax,1969
 | 
			
		||||
	shr	eax,2
 | 
			
		||||
	add	ebp,eax
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	sub	eax,1901
 | 
			
		||||
	mov	ebx,100
 | 
			
		||||
	div	ebx
 | 
			
		||||
	sub	ebp,eax
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	xor	edx,edx
 | 
			
		||||
	sub	eax,1601
 | 
			
		||||
	mov	ebx,400
 | 
			
		||||
	div	ebx
 | 
			
		||||
	add	ebp,eax
 | 
			
		||||
	movzx	ecx,word [buffer+2]
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	dec	eax
 | 
			
		||||
	mov	ebx,30
 | 
			
		||||
	mul	ebx
 | 
			
		||||
	add	ebp,eax
 | 
			
		||||
	cmp	ecx,8
 | 
			
		||||
	jbe	months_correction
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	sub	eax,7
 | 
			
		||||
	shr	eax,1
 | 
			
		||||
	add	ebp,eax
 | 
			
		||||
	mov	ecx,8
 | 
			
		||||
      months_correction:
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	shr	eax,1
 | 
			
		||||
	add	ebp,eax
 | 
			
		||||
	cmp	ecx,2
 | 
			
		||||
	jbe	day_correction_ok
 | 
			
		||||
	sub	ebp,2
 | 
			
		||||
	movzx	ecx,word [buffer]
 | 
			
		||||
	test	ecx,11b
 | 
			
		||||
	jnz	day_correction_ok
 | 
			
		||||
	xor	edx,edx
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	mov	ebx,100
 | 
			
		||||
	div	ebx
 | 
			
		||||
	or	edx,edx
 | 
			
		||||
	jnz	day_correction
 | 
			
		||||
	mov	eax,ecx
 | 
			
		||||
	mov	ebx,400
 | 
			
		||||
	div	ebx
 | 
			
		||||
	or	edx,edx
 | 
			
		||||
	jnz	day_correction_ok
 | 
			
		||||
      day_correction:
 | 
			
		||||
	inc	ebp
 | 
			
		||||
      day_correction_ok:
 | 
			
		||||
	movzx	eax,word [buffer+6]
 | 
			
		||||
	dec	eax
 | 
			
		||||
	add	eax,ebp
 | 
			
		||||
	mov	ebx,24
 | 
			
		||||
	mul	ebx
 | 
			
		||||
	movzx	ecx,word [buffer+8]
 | 
			
		||||
	add	eax,ecx
 | 
			
		||||
	mov	ebx,60
 | 
			
		||||
	mul	ebx
 | 
			
		||||
	movzx	ecx,word [buffer+10]
 | 
			
		||||
	add	eax,ecx
 | 
			
		||||
	mov	ebx,60
 | 
			
		||||
	mul	ebx
 | 
			
		||||
	movzx	ecx,word [buffer+12]
 | 
			
		||||
	add	eax,ecx
 | 
			
		||||
	adc	edx,0
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
error_prefix db 'error: ',0
 | 
			
		||||
error_suffix db '.'
 | 
			
		||||
cr_lf db 0Dh,0Ah,0
 | 
			
		||||
line_number_start db ' [',0
 | 
			
		||||
line_data_start db ':',0Dh,0Ah,0
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										25
									
								
								samples/BlitzMax/sample.bmx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								samples/BlitzMax/sample.bmx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
SuperStrict
 | 
			
		||||
 | 
			
		||||
Framework Brl.StandardIO
 | 
			
		||||
 | 
			
		||||
Type TMyType
 | 
			
		||||
	Field property:int
 | 
			
		||||
 | 
			
		||||
	Function A:int(param:int)
 | 
			
		||||
		'do nothing
 | 
			
		||||
	End Function
 | 
			
		||||
 | 
			
		||||
	Method B:int(param:int)
 | 
			
		||||
		'do nothing
 | 
			
		||||
	End Method
 | 
			
		||||
End Type
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Global my:TMyType = new TMyType
 | 
			
		||||
?Win32
 | 
			
		||||
	my.A()
 | 
			
		||||
	my.B()
 | 
			
		||||
?Linux
 | 
			
		||||
	my.B()
 | 
			
		||||
	my.A()
 | 
			
		||||
?
 | 
			
		||||
							
								
								
									
										6
									
								
								samples/GLSL/myfragment.frg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								samples/GLSL/myfragment.frg
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
varying vec4 v_color;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_FragColor = v_color;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								samples/GLSL/myvertex.vrx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								samples/GLSL/myvertex.vrx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
uniform mat4 u_MVPMatrix;
 | 
			
		||||
 | 
			
		||||
attribute vec4 a_position;
 | 
			
		||||
attribute vec4 a_color;
 | 
			
		||||
 | 
			
		||||
varying vec4 v_color;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	v_color = a_color;
 | 
			
		||||
	gl_Position =  u_MVPMatrix * pos;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								samples/Grace/ackerman_function.grace
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								samples/Grace/ackerman_function.grace
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
method ack (m : Number, n : Number) -> Number {
 | 
			
		||||
  print "ack {m} {n}"
 | 
			
		||||
  if (m < = 0) then {n + 1}
 | 
			
		||||
   elseif {n <= 0} then {ack((m -1), 1)}
 | 
			
		||||
   else {ack(m -1, ack(m, n-1))}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										554
									
								
								samples/Grace/grace_IDE.grace
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										554
									
								
								samples/Grace/grace_IDE.grace
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,554 @@
 | 
			
		||||
import "gtk" as gtk
 | 
			
		||||
import "io" as io
 | 
			
		||||
import "mgcollections" as collections
 | 
			
		||||
import "button_factory" as button_factory
 | 
			
		||||
import "dialog_factory" as dialog_factory
 | 
			
		||||
import "syntax_highlighter" as highlighter
 | 
			
		||||
import "auto_completer" as aComp
 | 
			
		||||
 | 
			
		||||
//TODO
 | 
			
		||||
 | 
			
		||||
// Autocomplete typing
 | 
			
		||||
 | 
			
		||||
// FileChooser
 | 
			
		||||
// Themes
 | 
			
		||||
 | 
			
		||||
// Details for the Top Level Window
 | 
			
		||||
def window = gtk.window(gtk.GTK_WINDOW_TOPLEVEL)
 | 
			
		||||
window.title := "Grace"
 | 
			
		||||
window.set_default_size(700, 700)
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
// Placeholder for the console window that can be popped out
 | 
			
		||||
// of the main window
 | 
			
		||||
var popped := gtk.window(gtk.GTK_WINDOW_TOPLEVEL)
 | 
			
		||||
 | 
			
		||||
// Initialise the Boxes
 | 
			
		||||
def mBox = gtk.box(gtk.GTK_ORIENTATION_VERTICAL, 2)
 | 
			
		||||
def buttonBox = gtk.box(gtk.GTK_ORIENTATION_HORIZONTAL, 2)
 | 
			
		||||
var consoleButtons := gtk.box(gtk.GTK_ORIENTATION_HORIZONTAL, 3)
 | 
			
		||||
var consoleBox := gtk.box(gtk.GTK_ORIENTATION_VERTICAL, 2)
 | 
			
		||||
var editorBox := gtk.box(gtk.GTK_ORIENTATION_VERTICAL, 2)
 | 
			
		||||
var splitPane := gtk.paned(gtk.GTK_ORIENTATION_VERTICAL, 2)
 | 
			
		||||
def menuBox = gtk.box(gtk.GTK_ORIENTATION_HORIZONTAL, 4)
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
// Initialise the buttons
 | 
			
		||||
def runButton = button_factory.make("run")
 | 
			
		||||
var clearButton := button_factory.make("clear")
 | 
			
		||||
var outButton := button_factory.make("out")
 | 
			
		||||
var errorButton := button_factory.make("error")
 | 
			
		||||
var popButton := button_factory.make("pop")
 | 
			
		||||
def newButton = button_factory.make("new")
 | 
			
		||||
def openButton = button_factory.make("open")
 | 
			
		||||
def saveButton = button_factory.make("save")
 | 
			
		||||
def saveAsButton = button_factory.make("saveAs")
 | 
			
		||||
def closeButton = button_factory.make("close")
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
// Details for the default text editor and scrolled window
 | 
			
		||||
var tEdit := gtk.text_view
 | 
			
		||||
tEdit.set_size_request(700, 400)
 | 
			
		||||
 | 
			
		||||
var scrolled_main := gtk.scrolled_window
 | 
			
		||||
scrolled_main.set_size_request(700, 400)
 | 
			
		||||
scrolled_main.add(tEdit)
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
// Widget that allows multiple files to be edited (tabs)
 | 
			
		||||
var notebook := gtk.notebook
 | 
			
		||||
notebook.scrollable := true
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
// Maps for holding the text_views and scrolled_windows
 | 
			
		||||
var editor_map := collections.map.new
 | 
			
		||||
editor_map.put(0, tEdit)
 | 
			
		||||
var scrolled_map := collections.map.new
 | 
			
		||||
scrolled_map.put(0, scrolled_main)
 | 
			
		||||
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
// Class that manages the syntax highlighting (This needs to be passed around otherwise
 | 
			
		||||
// the text_tag table gets confused, ie there can only be one)
 | 
			
		||||
def lighter = highlighter.Syntax_Highlighter.new(notebook, editor_map)
 | 
			
		||||
tEdit.buffer.on "changed" do {
 | 
			
		||||
    lighter.highlightLine
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Class that manages any auto completion that is required
 | 
			
		||||
def completer =  aComp.Auto_Completer.new(window, notebook, editor_map)
 | 
			
		||||
 | 
			
		||||
// Utility methods
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
method deleteCompileFiles(page_num : Number) {
 | 
			
		||||
    def cur_scrolled = scrolled_map.get(page_num)
 | 
			
		||||
    var filename := notebook.get_tab_label_text(cur_scrolled)
 | 
			
		||||
    filename := filename.substringFrom(0)to(filename.size - 7) //Removes .grace extension
 | 
			
		||||
 | 
			
		||||
    io.system("rm -f files/" ++ filename)
 | 
			
		||||
    io.system("rm -f files/" ++ filename ++ ".c")
 | 
			
		||||
    io.system("rm -f files/" ++ filename ++ ".gcn")
 | 
			
		||||
    io.system("rm -f files/" ++ filename ++ ".gct")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var currentConsole := "output"      // Which console is being shown
 | 
			
		||||
var out := false
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var outText := ""
 | 
			
		||||
var errorText := ""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Give actions to the buttons
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
runButton.on "clicked" do {
 | 
			
		||||
    clearConsoles()
 | 
			
		||||
 | 
			
		||||
    // Get the details for the current page selected
 | 
			
		||||
    def cur_page_num = notebook.current_page
 | 
			
		||||
    def cur_page = editor_map.get(cur_page_num)
 | 
			
		||||
    def cur_scrolled = scrolled_map.get(cur_page_num)
 | 
			
		||||
    def cur_page_label = notebook.get_tab_label_text(cur_scrolled)
 | 
			
		||||
 | 
			
		||||
    // Initialise text iterators
 | 
			
		||||
    def sIter = gtk.text_iter
 | 
			
		||||
    def eIter = gtk.text_iter
 | 
			
		||||
 | 
			
		||||
    // Set one at the beggining and one at the end of the text
 | 
			
		||||
    cur_page.buffer.get_iter_at_offset(sIter, 0)
 | 
			
		||||
    cur_page.buffer.get_iter_at_offset(eIter, -1)
 | 
			
		||||
 | 
			
		||||
    // Get the text between the text iterators
 | 
			
		||||
    def text = cur_page.buffer.get_text(sIter, eIter, true)
 | 
			
		||||
 | 
			
		||||
    // Save the text to the file (in case the user hasn't already saved it)
 | 
			
		||||
    def file = io.open("files/" ++ cur_page_label, "w")
 | 
			
		||||
    file.write(text)
 | 
			
		||||
    file.close
 | 
			
		||||
 | 
			
		||||
    // Run the program and pipe the output and errors into files to be read
 | 
			
		||||
    io.system("../minigrace/minigrace " ++ "files/" ++ cur_page_label ++ " > output.txt 2> error.txt")
 | 
			
		||||
    def outputFile = io.open("output.txt", "r")
 | 
			
		||||
    def errorFile = io.open("error.txt", "r")
 | 
			
		||||
    outText := outputFile.read
 | 
			
		||||
    errorText := errorFile.read
 | 
			
		||||
 | 
			
		||||
    io.system("rm -f output.txt error.txt")
 | 
			
		||||
 | 
			
		||||
    var switched := false
 | 
			
		||||
 | 
			
		||||
    // Change the console to output if there is output text
 | 
			
		||||
    if((outText.size > 0) && (currentConsole != "output")) then {
 | 
			
		||||
        switch_to_output()
 | 
			
		||||
        switched := true
 | 
			
		||||
    }
 | 
			
		||||
    // Change the console to errors if there were errors
 | 
			
		||||
    if((errorText.size > 0) && (currentConsole != "errors")) then {
 | 
			
		||||
        switch_to_errors()
 | 
			
		||||
        switched := true
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Remember to populate the console if it wasn't switched
 | 
			
		||||
    if(!switched) then {
 | 
			
		||||
        populateConsoles
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
clearButton.on "clicked" do {
 | 
			
		||||
    clearConsoles()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
outButton.on "clicked" do {
 | 
			
		||||
    switch_to_output()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
errorButton.on "clicked" do {
 | 
			
		||||
    switch_to_errors()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
popButton.on "clicked" do {
 | 
			
		||||
    if(out) then {
 | 
			
		||||
        popIn()
 | 
			
		||||
    } else {
 | 
			
		||||
        popOut()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Gives a dialog to let the user create a new file to edit
 | 
			
		||||
newButton.on "clicked" do {
 | 
			
		||||
    def new_window_class = dialog_factory.new.new(notebook, editor_map, scrolled_map, lighter)
 | 
			
		||||
 | 
			
		||||
    def new_window = new_window_class.window()
 | 
			
		||||
    new_window.show_all
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Gives a dialog that lets the user open a file to edit
 | 
			
		||||
openButton.on "clicked" do {
 | 
			
		||||
    def open_window_class = dialog_factory.open.new(notebook, editor_map, scrolled_map, lighter)
 | 
			
		||||
 | 
			
		||||
    def open_window = open_window_class.window()
 | 
			
		||||
    open_window.show_all
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Saves the current file (if the name is Untitled.grace it will ask for a new name)
 | 
			
		||||
saveButton.on "clicked" do {
 | 
			
		||||
    def cur_page_num = notebook.current_page
 | 
			
		||||
    def cur_page = editor_map.get(cur_page_num)
 | 
			
		||||
    def cur_scrolled = scrolled_map.get(cur_page_num)
 | 
			
		||||
    def cur_page_label = notebook.get_tab_label_text(cur_scrolled)
 | 
			
		||||
 | 
			
		||||
    if(cur_page_label == "Untitled.grace") then {
 | 
			
		||||
        def saveAs_window_class = dialog_factory.save.new(notebook, editor_map, scrolled_map, true)
 | 
			
		||||
 | 
			
		||||
        def saveAs_window = saveAs_window_class.window()
 | 
			
		||||
        saveAs_window.show_all
 | 
			
		||||
    } else {
 | 
			
		||||
        // Initialise text iterators
 | 
			
		||||
        def sIter = gtk.text_iter
 | 
			
		||||
        def eIter = gtk.text_iter
 | 
			
		||||
 | 
			
		||||
        // Set one at the beggining and one at the end of the text
 | 
			
		||||
        cur_page.buffer.get_iter_at_offset(sIter, 0)
 | 
			
		||||
        cur_page.buffer.get_iter_at_offset(eIter, -1)
 | 
			
		||||
 | 
			
		||||
        // Get the text between the text iterators
 | 
			
		||||
        def text = cur_page.buffer.get_text(sIter, eIter, true)
 | 
			
		||||
 | 
			
		||||
        // Save the file
 | 
			
		||||
        def file = io.open("files/" ++ cur_page_label, "w")
 | 
			
		||||
        file.write(text)
 | 
			
		||||
        file.close
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Gives a dialog that lets the user save the file with a new name
 | 
			
		||||
saveAsButton.on "clicked" do {
 | 
			
		||||
    def saveAs_window_class = dialog_factory.save.new(notebook, editor_map, scrolled_map, false)
 | 
			
		||||
 | 
			
		||||
    def saveAs_window = saveAs_window_class.window()
 | 
			
		||||
    saveAs_window.show_all
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This will close a tab on the notebook
 | 
			
		||||
// It also "removes" the page from the map,
 | 
			
		||||
// by creating a new temporary map and putting all but
 | 
			
		||||
// the removed page in.
 | 
			
		||||
closeButton.on "clicked" do {
 | 
			
		||||
    def page_num = notebook.current_page
 | 
			
		||||
    def num_pages = notebook.n_pages
 | 
			
		||||
 | 
			
		||||
    if(num_pages > 1) then {
 | 
			
		||||
        deleteCompileFiles(page_num)
 | 
			
		||||
 | 
			
		||||
        def e_map = collections.map.new
 | 
			
		||||
        def s_map = collections.map.new
 | 
			
		||||
 | 
			
		||||
        // Copy every page up to the current page into the new maps
 | 
			
		||||
        var x := 0
 | 
			
		||||
        while {x < page_num} do {
 | 
			
		||||
            var eValue := editor_map.get(x)
 | 
			
		||||
            var sValue := scrolled_map.get(x)
 | 
			
		||||
            e_map.put(x, eValue)
 | 
			
		||||
            s_map.put(x, sValue)
 | 
			
		||||
 | 
			
		||||
            x := x + 1
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Copy every page after the current page into the new map (shifted one down)
 | 
			
		||||
        x := page_num + 1
 | 
			
		||||
        while {x < num_pages} do {
 | 
			
		||||
            var eValue := editor_map.get(x)
 | 
			
		||||
            var sValue := scrolled_map.get(x)
 | 
			
		||||
            e_map.put((x - 1), eValue)
 | 
			
		||||
            s_map.put((x - 1), sValue)
 | 
			
		||||
 | 
			
		||||
            x := x + 1
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        editor_map := e_map
 | 
			
		||||
        scrolled_map := s_map
 | 
			
		||||
        notebook.remove_page(page_num)
 | 
			
		||||
 | 
			
		||||
        notebook.show_all
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Consoles:
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
var outConsole := gtk.text_view
 | 
			
		||||
var outScroll := gtk.scrolled_window
 | 
			
		||||
var errorConsole := gtk.text_view
 | 
			
		||||
var errorScroll := gtk.scrolled_window
 | 
			
		||||
var errorTag := errorConsole.buffer.create_tag("fixed", "foreground", "red")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Creates a new output console
 | 
			
		||||
method createOut {
 | 
			
		||||
    outConsole := gtk.text_view
 | 
			
		||||
    outScroll := gtk.scrolled_window
 | 
			
		||||
    outScroll.add(outConsole)
 | 
			
		||||
    if(out) then {
 | 
			
		||||
        outConsole.set_size_request(400, 400)
 | 
			
		||||
        outScroll.set_size_request(400, 400)
 | 
			
		||||
    } else {
 | 
			
		||||
        outConsole.set_size_request(700, 200)
 | 
			
		||||
        outScroll.set_size_request(700, 200)
 | 
			
		||||
    }
 | 
			
		||||
    outConsole.editable := false
 | 
			
		||||
    outConsole.buffer.set_text("[Output]:", -1)
 | 
			
		||||
}
 | 
			
		||||
createOut()
 | 
			
		||||
 | 
			
		||||
// Creates a new error console
 | 
			
		||||
method createError {
 | 
			
		||||
    errorConsole := gtk.text_view
 | 
			
		||||
    errorScroll := gtk.scrolled_window
 | 
			
		||||
    errorScroll.add(errorConsole)
 | 
			
		||||
    if(out) then {
 | 
			
		||||
        errorConsole.set_size_request(400, 400)
 | 
			
		||||
        errorScroll.set_size_request(400, 400)
 | 
			
		||||
    } else {
 | 
			
		||||
        errorConsole.set_size_request(700, 200)
 | 
			
		||||
        errorScroll.set_size_request(700, 200)
 | 
			
		||||
    }
 | 
			
		||||
    errorConsole.editable := false
 | 
			
		||||
    errorConsole.buffer.set_text("[Errors]:", -1)
 | 
			
		||||
    errorTag := errorConsole.buffer.create_tag("fixed", "foreground", "red")
 | 
			
		||||
}
 | 
			
		||||
createError()
 | 
			
		||||
 | 
			
		||||
// Switches the console being shown to be output. This requires
 | 
			
		||||
// the output console to be remade as it would have been destroyed when
 | 
			
		||||
// it was switched previously
 | 
			
		||||
method switch_to_output {
 | 
			
		||||
    if(currentConsole != "output") then {
 | 
			
		||||
        currentConsole := "output"
 | 
			
		||||
        consoleBox.remove(errorScroll)     // This destroys the errorConsole
 | 
			
		||||
 | 
			
		||||
        createOut()
 | 
			
		||||
 | 
			
		||||
        consoleBox.add(outScroll)
 | 
			
		||||
 | 
			
		||||
        populateConsoles()
 | 
			
		||||
        if(out) then {
 | 
			
		||||
            popped.show_all
 | 
			
		||||
        } else {
 | 
			
		||||
            window.show_all
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Switches the console being shown to be errors. This requires
 | 
			
		||||
// the error console to be remade as it would have been destroyed when
 | 
			
		||||
// it was switched previously
 | 
			
		||||
method switch_to_errors {
 | 
			
		||||
    if(currentConsole != "errors") then {
 | 
			
		||||
        currentConsole := "errors"
 | 
			
		||||
        consoleBox.remove(outScroll)       // This destroys the outConsole
 | 
			
		||||
 | 
			
		||||
        createError()
 | 
			
		||||
 | 
			
		||||
        consoleBox.add(errorScroll)
 | 
			
		||||
 | 
			
		||||
        populateConsoles()
 | 
			
		||||
        if(out) then {
 | 
			
		||||
            popped.show_all
 | 
			
		||||
        } else {
 | 
			
		||||
            window.show_all
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// If there is text to be put into the consoles this will add it
 | 
			
		||||
method populateConsoles {
 | 
			
		||||
    if((outText.size > 0) && (currentConsole == "output")) then {
 | 
			
		||||
        outConsole.buffer.set_text(outText, -1)
 | 
			
		||||
    }
 | 
			
		||||
    if((errorText.size > 0) && (currentConsole == "errors")) then {
 | 
			
		||||
        def sIter = gtk.text_iter
 | 
			
		||||
        def eIter = gtk.text_iter
 | 
			
		||||
 | 
			
		||||
        errorConsole.buffer.set_text(errorText, -1)
 | 
			
		||||
        errorConsole.buffer.get_iter_at_offset(sIter, 0)
 | 
			
		||||
        errorConsole.buffer.get_iter_at_offset(eIter, -1)
 | 
			
		||||
        errorConsole.buffer.apply_tag(errorTag, sIter, eIter)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
method clearConsoles {
 | 
			
		||||
    if(currentConsole == "output") then {
 | 
			
		||||
        outConsole.buffer.set_text("[Output]:", -1)
 | 
			
		||||
        outText := ""
 | 
			
		||||
    }
 | 
			
		||||
    if(currentConsole == "errors") then {
 | 
			
		||||
        errorConsole.buffer.set_text("[Errors]:", -1)
 | 
			
		||||
        errorText := ""
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Identical as the popIn method, but can be connected to the window's destroy button
 | 
			
		||||
def popInBlock = {
 | 
			
		||||
    consoleBox.reparent(splitPane)
 | 
			
		||||
    popButton.label := "Pop Out"
 | 
			
		||||
 | 
			
		||||
    if(currentConsole == "output") then {
 | 
			
		||||
        outConsole.set_size_request(700, 200)
 | 
			
		||||
        outScroll.set_size_request(700, 200)
 | 
			
		||||
    }
 | 
			
		||||
    if(currentConsole == "errors") then {
 | 
			
		||||
     errorConsole.set_size_request(700, 200)
 | 
			
		||||
     errorScroll.set_size_request(700, 200)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def cur_page_num = notebook.current_page
 | 
			
		||||
    def cur_scrolled = scrolled_map.get(cur_page_num)
 | 
			
		||||
    def cur_page = editor_map.get(cur_page_num)
 | 
			
		||||
 | 
			
		||||
    cur_page.set_size_request(700, 400)
 | 
			
		||||
    cur_scrolled.set_size_request(700, 400)
 | 
			
		||||
 | 
			
		||||
    out := false
 | 
			
		||||
    popped.visible := false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// This pops the console out into a separate window
 | 
			
		||||
method popOut {
 | 
			
		||||
    popped := gtk.window(gtk.GTK_WINDOW_TOPLEVEL)
 | 
			
		||||
 | 
			
		||||
    consoleBox.reparent(popped)
 | 
			
		||||
    popButton.label := "Pop In"
 | 
			
		||||
 | 
			
		||||
    if(currentConsole == "output") then {
 | 
			
		||||
        outConsole.set_size_request(400, 400)
 | 
			
		||||
        outScroll.set_size_request(400, 400)
 | 
			
		||||
    }
 | 
			
		||||
    if(currentConsole == "errors") then {
 | 
			
		||||
        errorConsole.set_size_request(400, 400)
 | 
			
		||||
        errorScroll.set_size_request(400, 400)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def cur_page_num = notebook.current_page
 | 
			
		||||
    def cur_scrolled = scrolled_map.get(cur_page_num)
 | 
			
		||||
    def cur_page = editor_map.get(cur_page_num)
 | 
			
		||||
 | 
			
		||||
    cur_page.set_size_request(700, 580)
 | 
			
		||||
    cur_scrolled.set_size_request(700, 580)
 | 
			
		||||
 | 
			
		||||
    out := true
 | 
			
		||||
    popped.visible := true
 | 
			
		||||
    popped.connect("destroy", popInBlock)
 | 
			
		||||
    popped.show_all
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Puts the console back into the main window
 | 
			
		||||
method popIn {
 | 
			
		||||
    consoleBox.reparent(splitPane)
 | 
			
		||||
    popButton.label := "Pop Out"
 | 
			
		||||
 | 
			
		||||
    if(currentConsole == "output") then {
 | 
			
		||||
        outConsole.set_size_request(700, 200)
 | 
			
		||||
        outScroll.set_size_request(700, 200)
 | 
			
		||||
    }
 | 
			
		||||
    if(currentConsole == "errors") then {
 | 
			
		||||
        errorConsole.set_size_request(700, 200)
 | 
			
		||||
        errorScroll.set_size_request(700, 200)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def cur_page_num = notebook.current_page
 | 
			
		||||
    def cur_scrolled = scrolled_map.get(cur_page_num)
 | 
			
		||||
    def cur_page = editor_map.get(cur_page_num)
 | 
			
		||||
 | 
			
		||||
    cur_page.set_size_request(700, 400)
 | 
			
		||||
    cur_scrolled.set_size_request(700, 400)
 | 
			
		||||
 | 
			
		||||
    out := false
 | 
			
		||||
    popped.visible := false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
clearConsoles()
 | 
			
		||||
// -------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Patch everything together
 | 
			
		||||
 | 
			
		||||
var hSeparator1 := gtk.separator(gtk.GTK_ORIENTATION_HORIZONTAL)
 | 
			
		||||
var hSeparator2 := gtk.separator(gtk.GTK_ORIENTATION_HORIZONTAL)
 | 
			
		||||
 | 
			
		||||
menuBox.add(newButton)
 | 
			
		||||
menuBox.add(openButton)
 | 
			
		||||
menuBox.add(saveButton)
 | 
			
		||||
menuBox.add(saveAsButton)
 | 
			
		||||
buttonBox.add(runButton)
 | 
			
		||||
buttonBox.add(closeButton)
 | 
			
		||||
 | 
			
		||||
consoleButtons.add(outButton)
 | 
			
		||||
consoleButtons.add(errorButton)
 | 
			
		||||
consoleButtons.add(clearButton)
 | 
			
		||||
consoleButtons.add(popButton)
 | 
			
		||||
 | 
			
		||||
consoleBox.add(hSeparator1)
 | 
			
		||||
consoleBox.add(consoleButtons)
 | 
			
		||||
consoleBox.add(outScroll)
 | 
			
		||||
 | 
			
		||||
editorBox.add(hSeparator2)
 | 
			
		||||
notebook.add(scrolled_main)
 | 
			
		||||
notebook.set_tab_label_text(scrolled_main, "Untitled.grace")
 | 
			
		||||
editorBox.add(notebook)
 | 
			
		||||
 | 
			
		||||
splitPane.add1(editorBox)
 | 
			
		||||
splitPane.add2(consoleBox)
 | 
			
		||||
 | 
			
		||||
mBox.add(menuBox)
 | 
			
		||||
mBox.add(buttonBox)
 | 
			
		||||
mBox.add(splitPane)
 | 
			
		||||
 | 
			
		||||
window.add(mBox)
 | 
			
		||||
 | 
			
		||||
def exit = {
 | 
			
		||||
    var x := 0
 | 
			
		||||
    while {x < notebook.n_pages} do {
 | 
			
		||||
        deleteCompileFiles(x)
 | 
			
		||||
 | 
			
		||||
        x := x + 1
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Delete the compile files of the IDE
 | 
			
		||||
    io.system("rm -f Grace_IDE.gct Grace_IDE.c Grace_IDE.gcn")
 | 
			
		||||
    io.system("rm -f scanner.gct scanner.c scanner.gcn")
 | 
			
		||||
    io.system("rm -f syntax_highlighter.gct syntax_highlighter.c syntax_highlighter.gcn")
 | 
			
		||||
    io.system("rm -f syntax_colors.gct syntax_colors.c syntax_colors.gcn")
 | 
			
		||||
    io.system("rm -f button_factory.gct button_factory.c button_factory.gcn")
 | 
			
		||||
    io.system("rm -f dialog_factory.gct dialog_factory.c dialog_factory.gcn")
 | 
			
		||||
    io.system("rm -f auto_completer.gct auto_completer.c auto_completer.gcn")
 | 
			
		||||
 | 
			
		||||
    print "Grace IDE Closed Successfully"
 | 
			
		||||
    gtk.main_quit
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
window.connect("destroy", exit)
 | 
			
		||||
window.show_all
 | 
			
		||||
 | 
			
		||||
gtk.main
 | 
			
		||||
							
								
								
									
										272
									
								
								samples/Nit/calculator.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										272
									
								
								samples/Nit/calculator.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,272 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
import gtk
 | 
			
		||||
 | 
			
		||||
class CalculatorContext
 | 
			
		||||
	var result : nullable Float = null
 | 
			
		||||
 | 
			
		||||
	var last_op : nullable Char = null
 | 
			
		||||
 | 
			
		||||
	var current : nullable Float = null
 | 
			
		||||
	var after_point : nullable Int = null
 | 
			
		||||
 | 
			
		||||
	fun push_op( op : Char )
 | 
			
		||||
	do
 | 
			
		||||
		apply_last_op_if_any
 | 
			
		||||
		if op == 'C' then
 | 
			
		||||
			self.result = 0.0
 | 
			
		||||
			last_op = null
 | 
			
		||||
		else
 | 
			
		||||
			last_op = op # store for next push_op
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		# prepare next current
 | 
			
		||||
		after_point = null
 | 
			
		||||
		current = null
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	fun push_digit( digit : Int )
 | 
			
		||||
	do
 | 
			
		||||
		var current = current
 | 
			
		||||
		if current == null then current = 0.0
 | 
			
		||||
 | 
			
		||||
		var after_point = after_point
 | 
			
		||||
		if after_point == null then
 | 
			
		||||
			current = current * 10.0 + digit.to_f
 | 
			
		||||
		else
 | 
			
		||||
			current = current + digit.to_f * 10.0.pow(after_point.to_f)
 | 
			
		||||
			self.after_point -= 1
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		self.current = current
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	fun switch_to_decimals
 | 
			
		||||
	do
 | 
			
		||||
		if self.current == null then current = 0.0
 | 
			
		||||
		if after_point != null then return
 | 
			
		||||
 | 
			
		||||
		after_point = -1
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	fun apply_last_op_if_any
 | 
			
		||||
	do
 | 
			
		||||
		var op = last_op
 | 
			
		||||
 | 
			
		||||
		var result = result
 | 
			
		||||
		if result == null then result = 0.0
 | 
			
		||||
 | 
			
		||||
		var current = current
 | 
			
		||||
		if current == null then current = 0.0
 | 
			
		||||
 | 
			
		||||
		if op == null then
 | 
			
		||||
			result = current
 | 
			
		||||
		else if op == '+' then
 | 
			
		||||
			result = result + current
 | 
			
		||||
		else if op == '-' then
 | 
			
		||||
			result = result - current
 | 
			
		||||
		else if op == '/' then
 | 
			
		||||
			result = result / current
 | 
			
		||||
		else if op == '*' then
 | 
			
		||||
			result = result * current
 | 
			
		||||
		end
 | 
			
		||||
		self.result = result
 | 
			
		||||
		self.current = null
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class CalculatorGui
 | 
			
		||||
	super GtkCallable
 | 
			
		||||
 | 
			
		||||
	var win : GtkWindow
 | 
			
		||||
	var container : GtkGrid
 | 
			
		||||
 | 
			
		||||
	var lbl_disp : GtkLabel
 | 
			
		||||
	var but_eq : GtkButton
 | 
			
		||||
	var but_dot : GtkButton
 | 
			
		||||
 | 
			
		||||
	var context = new CalculatorContext
 | 
			
		||||
 | 
			
		||||
	redef fun signal( sender, user_data )
 | 
			
		||||
	do
 | 
			
		||||
		var after_point = context.after_point
 | 
			
		||||
		if after_point == null then 
 | 
			
		||||
		    after_point = 0
 | 
			
		||||
		else
 | 
			
		||||
		    after_point = (after_point.abs)
 | 
			
		||||
		end
 | 
			
		||||
		
 | 
			
		||||
		if user_data isa Char then # is an operation
 | 
			
		||||
			var c = user_data
 | 
			
		||||
			if c == '.' then
 | 
			
		||||
				but_dot.sensitive= false
 | 
			
		||||
				context.switch_to_decimals
 | 
			
		||||
				lbl_disp.text = "{context.current.to_i}."
 | 
			
		||||
			else
 | 
			
		||||
				but_dot.sensitive= true
 | 
			
		||||
				context.push_op( c )
 | 
			
		||||
				
 | 
			
		||||
				var s = context.result.to_precision_native(6)
 | 
			
		||||
				var index : nullable Int = null
 | 
			
		||||
				for i in s.length.times do
 | 
			
		||||
				    var chiffre = s.chars[i]
 | 
			
		||||
				    if chiffre == '0' and index == null then
 | 
			
		||||
					index = i
 | 
			
		||||
				    else if chiffre != '0' then
 | 
			
		||||
					index = null
 | 
			
		||||
				    end
 | 
			
		||||
				end
 | 
			
		||||
				if index != null then
 | 
			
		||||
					s = s.substring(0, index)
 | 
			
		||||
					if s.chars[s.length-1] == ',' then s = s.substring(0, s.length-1)
 | 
			
		||||
				end
 | 
			
		||||
				lbl_disp.text = s
 | 
			
		||||
			end
 | 
			
		||||
		else if user_data isa Int then # is a number
 | 
			
		||||
			var n = user_data
 | 
			
		||||
			context.push_digit( n )
 | 
			
		||||
			lbl_disp.text = context.current.to_precision_native(after_point)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	init
 | 
			
		||||
	do
 | 
			
		||||
		init_gtk
 | 
			
		||||
 | 
			
		||||
		win = new GtkWindow( 0 )
 | 
			
		||||
 | 
			
		||||
		container = new GtkGrid(5,5,true)
 | 
			
		||||
		win.add( container )
 | 
			
		||||
 | 
			
		||||
		lbl_disp = new GtkLabel( "_" )
 | 
			
		||||
		container.attach( lbl_disp, 0, 0, 5, 1 )
 | 
			
		||||
 | 
			
		||||
		# digits
 | 
			
		||||
		for n in [0..9] do
 | 
			
		||||
			var but = new GtkButton.with_label( n.to_s )
 | 
			
		||||
			but.request_size( 64, 64 )
 | 
			
		||||
			but.signal_connect( "clicked", self, n )
 | 
			
		||||
			if n == 0 then
 | 
			
		||||
				container.attach( but, 0, 4, 1, 1 )
 | 
			
		||||
			else container.attach( but, (n-1)%3, 3-(n-1)/3, 1, 1 )
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		# operators
 | 
			
		||||
		var r = 1
 | 
			
		||||
		for op in ['+', '-', '*', '/' ] do
 | 
			
		||||
			var but = new GtkButton.with_label( op.to_s )
 | 
			
		||||
			but.request_size( 64, 64 )
 | 
			
		||||
			but.signal_connect( "clicked", self, op )
 | 
			
		||||
			container.attach( but, 3, r, 1, 1 )
 | 
			
		||||
			r+=1
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		# =
 | 
			
		||||
		but_eq = new GtkButton.with_label( "=" )
 | 
			
		||||
		but_eq.request_size( 64, 64 )
 | 
			
		||||
		but_eq.signal_connect( "clicked", self, '=' )
 | 
			
		||||
		container.attach( but_eq, 4, 3, 1, 2 )
 | 
			
		||||
 | 
			
		||||
		# .
 | 
			
		||||
		but_dot = new GtkButton.with_label( "." )
 | 
			
		||||
		but_dot.request_size( 64, 64 )
 | 
			
		||||
		but_dot.signal_connect( "clicked", self, '.' )
 | 
			
		||||
		container.attach( but_dot, 1, 4, 1, 1 )
 | 
			
		||||
 | 
			
		||||
		#C
 | 
			
		||||
		var but_c =  new GtkButton.with_label( "C" )
 | 
			
		||||
		but_c.request_size( 64, 64 )
 | 
			
		||||
		but_c.signal_connect("clicked", self, 'C')
 | 
			
		||||
		container.attach( but_c, 2, 4, 1, 1 )
 | 
			
		||||
 | 
			
		||||
		win.show_all
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# context tests
 | 
			
		||||
var context = new CalculatorContext
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_digit( 2 )
 | 
			
		||||
context.push_op( '+' )
 | 
			
		||||
context.push_digit( 3 )
 | 
			
		||||
context.push_op( '*' )
 | 
			
		||||
context.push_digit( 2 )
 | 
			
		||||
context.push_op( '=' )
 | 
			
		||||
var r = context.result.to_precision( 2 )
 | 
			
		||||
assert r == "30.00" else print r
 | 
			
		||||
 | 
			
		||||
context = new CalculatorContext
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_digit( 4 )
 | 
			
		||||
context.switch_to_decimals
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_op( '*' )
 | 
			
		||||
context.push_digit( 3 )
 | 
			
		||||
context.push_op( '=' )
 | 
			
		||||
r = context.result.to_precision( 2 )
 | 
			
		||||
assert r == "42.30" else print r
 | 
			
		||||
 | 
			
		||||
context.push_op( '+' )
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_op( '=' )
 | 
			
		||||
r = context.result.to_precision( 2 )
 | 
			
		||||
assert r == "53.30" else print r
 | 
			
		||||
 | 
			
		||||
context = new CalculatorContext
 | 
			
		||||
context.push_digit( 4 )
 | 
			
		||||
context.push_digit( 2 )
 | 
			
		||||
context.switch_to_decimals
 | 
			
		||||
context.push_digit( 3 )
 | 
			
		||||
context.push_op( '/' )
 | 
			
		||||
context.push_digit( 3 )
 | 
			
		||||
context.push_op( '=' )
 | 
			
		||||
r = context.result.to_precision( 2 )
 | 
			
		||||
assert r == "14.10" else print r
 | 
			
		||||
 | 
			
		||||
#test multiple decimals
 | 
			
		||||
context = new CalculatorContext
 | 
			
		||||
context.push_digit( 5 )
 | 
			
		||||
context.push_digit( 0 )
 | 
			
		||||
context.switch_to_decimals
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_digit( 2 )
 | 
			
		||||
context.push_digit( 3 )
 | 
			
		||||
context.push_op( '+' )
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_op( '=' )
 | 
			
		||||
r = context.result.to_precision( 3 )
 | 
			
		||||
assert r == "51.123" else print r
 | 
			
		||||
 | 
			
		||||
#test 'C' button
 | 
			
		||||
context = new CalculatorContext
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_digit( 0 )
 | 
			
		||||
context.push_op( '+' )
 | 
			
		||||
context.push_digit( 1 )
 | 
			
		||||
context.push_digit( 0 )
 | 
			
		||||
context.push_op( '=' )
 | 
			
		||||
context.push_op( 'C' )
 | 
			
		||||
r = context.result.to_precision( 1 )
 | 
			
		||||
assert r == "0.0" else print r
 | 
			
		||||
 | 
			
		||||
# graphical application
 | 
			
		||||
 | 
			
		||||
if "NIT_TESTING".environ != "true" then
 | 
			
		||||
	var app = new CalculatorGui
 | 
			
		||||
	run_gtk
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										45
									
								
								samples/Nit/callback_chimpanze.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								samples/Nit/callback_chimpanze.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# This sample has been implemented to show you how simple is it to play 
 | 
			
		||||
# with native callbacks (C) through an high level with NIT program.
 | 
			
		||||
 | 
			
		||||
module callback_chimpanze
 | 
			
		||||
import callback_monkey
 | 
			
		||||
 | 
			
		||||
class Chimpanze
 | 
			
		||||
	super MonkeyActionCallable
 | 
			
		||||
 | 
			
		||||
	fun create
 | 
			
		||||
	do
 | 
			
		||||
		var monkey = new Monkey
 | 
			
		||||
		print "Hum, I'm sleeping ..."
 | 
			
		||||
		# Invoking method which will take some time to compute, and 
 | 
			
		||||
		# will be back in wokeUp method with information.
 | 
			
		||||
		# - Callback method defined in MonkeyActionCallable Interface
 | 
			
		||||
		monkey.wokeUpAction(self, "Hey, I'm awake.")
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Inherit callback method, defined by MonkeyActionCallable interface
 | 
			
		||||
	# - Back of wokeUpAction method 
 | 
			
		||||
	redef fun wokeUp( sender:Monkey, message:Object )
 | 
			
		||||
	do
 | 
			
		||||
		print message
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var m = new Chimpanze
 | 
			
		||||
m.create
 | 
			
		||||
							
								
								
									
										92
									
								
								samples/Nit/callback_monkey.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								samples/Nit/callback_monkey.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# This sample has been implemented to show you how simple is it to play 
 | 
			
		||||
# with native callbacks (C) through an high level with NIT program.
 | 
			
		||||
 | 
			
		||||
module callback_monkey
 | 
			
		||||
 | 
			
		||||
in "C header" `{
 | 
			
		||||
	#include <stdio.h>
 | 
			
		||||
	#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
	typedef struct { 
 | 
			
		||||
		int id;
 | 
			
		||||
		int age;
 | 
			
		||||
	} CMonkey;
 | 
			
		||||
 | 
			
		||||
	typedef struct {
 | 
			
		||||
		MonkeyActionCallable toCall;
 | 
			
		||||
		Object message;
 | 
			
		||||
	} MonkeyAction;
 | 
			
		||||
`}
 | 
			
		||||
 | 
			
		||||
in "C body" `{
 | 
			
		||||
	// Method which reproduce a callback answer
 | 
			
		||||
	// Please note that a function pointer is only used to reproduce the callback
 | 
			
		||||
	void cbMonkey(CMonkey *mkey, void callbackFunc(CMonkey*, MonkeyAction*), MonkeyAction *data)
 | 
			
		||||
	{
 | 
			
		||||
		sleep(2);
 | 
			
		||||
		callbackFunc( mkey, data );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Back of background treatment, will be redirected to callback function
 | 
			
		||||
	void nit_monkey_callback_func( CMonkey *mkey, MonkeyAction *data )
 | 
			
		||||
	{
 | 
			
		||||
		// To call a your method, the signature must be written like this :
 | 
			
		||||
		// <Interface Name>_<Method>...
 | 
			
		||||
		MonkeyActionCallable_wokeUp( data->toCall, mkey, data->message );
 | 
			
		||||
	}
 | 
			
		||||
`}
 | 
			
		||||
 | 
			
		||||
# Implementable interface to get callback in defined methods
 | 
			
		||||
interface MonkeyActionCallable
 | 
			
		||||
	fun wokeUp( sender:Monkey, message: Object) is abstract
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Defining my object type Monkey, which is, in a low level, a pointer to a C struct (CMonkey)
 | 
			
		||||
extern class Monkey `{ CMonkey * `}
 | 
			
		||||
	
 | 
			
		||||
	new `{
 | 
			
		||||
		CMonkey *monkey = malloc( sizeof(CMonkey) );
 | 
			
		||||
		monkey->age = 10;
 | 
			
		||||
		monkey->id = 1;
 | 
			
		||||
		return monkey;
 | 
			
		||||
	`}
 | 
			
		||||
	
 | 
			
		||||
	# Object method which will get a callback in wokeUp method, defined in MonkeyActionCallable interface
 | 
			
		||||
	# Must be defined as Nit/C method because of C call inside
 | 
			
		||||
	fun wokeUpAction( toCall: MonkeyActionCallable, message: Object ) is extern import MonkeyActionCallable.wokeUp `{
 | 
			
		||||
 | 
			
		||||
		// Allocating memory to keep reference of received parameters :
 | 
			
		||||
		// - Object receiver
 | 
			
		||||
		// - Message 
 | 
			
		||||
		MonkeyAction *data = malloc( sizeof(MonkeyAction) );
 | 
			
		||||
 | 
			
		||||
		// Incrementing reference counter to prevent from releasing
 | 
			
		||||
		MonkeyActionCallable_incr_ref( toCall );
 | 
			
		||||
		Object_incr_ref( message );
 | 
			
		||||
		
 | 
			
		||||
		data->toCall = toCall;
 | 
			
		||||
		data->message = message;
 | 
			
		||||
		
 | 
			
		||||
		// Calling method which reproduce a callback by passing :
 | 
			
		||||
		// - Receiver
 | 
			
		||||
		// - Function pointer to object return method
 | 
			
		||||
		// - Datas
 | 
			
		||||
		cbMonkey( recv, &nit_monkey_callback_func, data );
 | 
			
		||||
	`}
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										167
									
								
								samples/Nit/circular_list.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								samples/Nit/circular_list.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,167 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Implementation of circular lists
 | 
			
		||||
# This example shows the usage of generics and somewhat a specialisation of collections.
 | 
			
		||||
module circular_list
 | 
			
		||||
 | 
			
		||||
# Sequences of elements implemented with a double-linked circular list
 | 
			
		||||
class CircularList[E]
 | 
			
		||||
	# Like standard Array or LinkedList, CircularList is a Sequence.
 | 
			
		||||
	super Sequence[E]
 | 
			
		||||
 | 
			
		||||
	# The first node of the list if any
 | 
			
		||||
	# The special case of an empty list is handled by a null node
 | 
			
		||||
	private var node: nullable CLNode[E] = null
 | 
			
		||||
 | 
			
		||||
	redef fun iterator do return new CircularListIterator[E](self)
 | 
			
		||||
 | 
			
		||||
	redef fun first do return self.node.item
 | 
			
		||||
 | 
			
		||||
	redef fun push(e)
 | 
			
		||||
	do
 | 
			
		||||
		var new_node = new CLNode[E](e)
 | 
			
		||||
		var n = self.node
 | 
			
		||||
		if n == null then
 | 
			
		||||
			# the first node
 | 
			
		||||
			self.node = new_node
 | 
			
		||||
		else
 | 
			
		||||
			# not the first one, so attach nodes correctly.
 | 
			
		||||
			var old_last_node = n.prev
 | 
			
		||||
			new_node.next = n
 | 
			
		||||
			new_node.prev = old_last_node
 | 
			
		||||
			old_last_node.next = new_node
 | 
			
		||||
			n.prev = new_node
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun pop
 | 
			
		||||
	do
 | 
			
		||||
		var n = self.node
 | 
			
		||||
		assert n != null
 | 
			
		||||
		var prev = n.prev
 | 
			
		||||
		if prev == n then
 | 
			
		||||
			# the only node
 | 
			
		||||
			self.node = null
 | 
			
		||||
			return n.item
 | 
			
		||||
		end
 | 
			
		||||
		# not the only one do detach nodes correctly.
 | 
			
		||||
		var prev_prev = prev.prev
 | 
			
		||||
		n.prev = prev_prev
 | 
			
		||||
		prev_prev.next = n
 | 
			
		||||
		return prev.item
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun unshift(e)
 | 
			
		||||
	do
 | 
			
		||||
		# Circularity has benefits.
 | 
			
		||||
		push(e)
 | 
			
		||||
		self.node = self.node.prev
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun shift
 | 
			
		||||
	do
 | 
			
		||||
		# Circularity has benefits.
 | 
			
		||||
		self.node = self.node.next
 | 
			
		||||
		return self.pop
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Move the first at the last position, the second at the first, etc.
 | 
			
		||||
	fun rotate
 | 
			
		||||
	do
 | 
			
		||||
		var n = self.node
 | 
			
		||||
		if n == null then return
 | 
			
		||||
		self.node = n.next
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Sort the list using the Josephus algorithm.
 | 
			
		||||
	fun josephus(step: Int)
 | 
			
		||||
	do
 | 
			
		||||
		var res = new CircularList[E]
 | 
			
		||||
		while not self.is_empty do
 | 
			
		||||
			# count 'step'
 | 
			
		||||
			for i in [1..step[ do self.rotate
 | 
			
		||||
			# kill
 | 
			
		||||
			var x = self.shift
 | 
			
		||||
			res.add(x)
 | 
			
		||||
		end
 | 
			
		||||
		self.node = res.node
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Nodes of a CircularList
 | 
			
		||||
private class CLNode[E]
 | 
			
		||||
	# The current item
 | 
			
		||||
	var item: E
 | 
			
		||||
 | 
			
		||||
	# The next item in the circular list.
 | 
			
		||||
	# Because of circularity, there is always a next;
 | 
			
		||||
	# so by default let it be self
 | 
			
		||||
	var next: CLNode[E] = self
 | 
			
		||||
 | 
			
		||||
	# The previous item in the circular list.
 | 
			
		||||
	# Coherence between next and previous nodes has to be maintained by the
 | 
			
		||||
	# circular list.
 | 
			
		||||
	var prev: CLNode[E] = self
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# An iterator of a CircularList.
 | 
			
		||||
private class CircularListIterator[E]
 | 
			
		||||
	super IndexedIterator[E]
 | 
			
		||||
 | 
			
		||||
	redef var index: Int
 | 
			
		||||
 | 
			
		||||
	# The current node pointed.
 | 
			
		||||
	# Is null if the list is empty.
 | 
			
		||||
	var node: nullable CLNode[E]
 | 
			
		||||
 | 
			
		||||
	# The list iterated.
 | 
			
		||||
	var list: CircularList[E]
 | 
			
		||||
 | 
			
		||||
	redef fun is_ok
 | 
			
		||||
	do
 | 
			
		||||
		# Empty lists are not OK.
 | 
			
		||||
		# Pointing again the first node is not OK.
 | 
			
		||||
		return self.node != null and (self.index == 0 or self.node != self.list.node)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun next
 | 
			
		||||
	do
 | 
			
		||||
		self.node = self.node.next
 | 
			
		||||
		self.index += 1
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun item do return self.node.item
 | 
			
		||||
 | 
			
		||||
	init(list: CircularList[E])
 | 
			
		||||
	do
 | 
			
		||||
		self.node = list.node
 | 
			
		||||
		self.list = list
 | 
			
		||||
		self.index = 0
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var i = new CircularList[Int]
 | 
			
		||||
i.add_all([1, 2, 3, 4, 5, 6, 7])
 | 
			
		||||
print i.first
 | 
			
		||||
print i.join(":")
 | 
			
		||||
 | 
			
		||||
i.push(8)
 | 
			
		||||
print i.shift
 | 
			
		||||
print i.pop
 | 
			
		||||
i.unshift(0)
 | 
			
		||||
print i.join(":")
 | 
			
		||||
 | 
			
		||||
i.josephus(3)
 | 
			
		||||
print i.join(":")
 | 
			
		||||
							
								
								
									
										78
									
								
								samples/Nit/clock.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								samples/Nit/clock.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,78 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# This module provide a simple wall clock.
 | 
			
		||||
# It is an example of getters and setters.
 | 
			
		||||
# A beefed-up module is available in clock_more
 | 
			
		||||
module clock
 | 
			
		||||
 | 
			
		||||
# A simple wall clock with 60 minutes and 12 hours.
 | 
			
		||||
class Clock
 | 
			
		||||
	# total number of minutes from 0 to 719
 | 
			
		||||
	var total_minutes: Int
 | 
			
		||||
	# Note: only the read acces is public, the write access is private.
 | 
			
		||||
 | 
			
		||||
	# number of minutes in the current hour (from 0 to 59)
 | 
			
		||||
	fun minutes: Int do return self.total_minutes % 60
 | 
			
		||||
	
 | 
			
		||||
	# set the number of minutes in the current hour.
 | 
			
		||||
	# if m < 0 or m >= 60, the hour will be changed accordinlgy
 | 
			
		||||
	fun minutes=(m: Int) do self.total_minutes = self.hours * 60 + m
 | 
			
		||||
 | 
			
		||||
	# number of hours (from 0 to 11)
 | 
			
		||||
	fun hours: Int do return self.total_minutes / 60
 | 
			
		||||
 | 
			
		||||
	# set the number of hours
 | 
			
		||||
	# the minutes will not be updated
 | 
			
		||||
	fun hours=(h: Int) do self.total_minutes = h * 60 + minutes
 | 
			
		||||
 | 
			
		||||
	# the position of the hour arrow in the [0..60[ interval
 | 
			
		||||
	fun hour_pos: Int do return total_minutes / 12
 | 
			
		||||
 | 
			
		||||
	# replace the arrow of hours (from 0 to 59).
 | 
			
		||||
	# the hours and the minutes will be updated.
 | 
			
		||||
	fun hour_pos=(h: Int) do self.total_minutes = h * 12
 | 
			
		||||
 | 
			
		||||
	redef fun to_s do return "{hours}:{minutes}"
 | 
			
		||||
 | 
			
		||||
	fun reset(hours, minutes: Int) do self.total_minutes = hours*60 + minutes
 | 
			
		||||
 | 
			
		||||
	init(hours, minutes: Int) do self.reset(hours, minutes)
 | 
			
		||||
 | 
			
		||||
	redef fun ==(o)
 | 
			
		||||
	do
 | 
			
		||||
		# Note: o is a nullable Object, a type test is required
 | 
			
		||||
		# Thanks to adaptive typing, there is no downcast
 | 
			
		||||
		# i.e. the code is safe!
 | 
			
		||||
		return o isa Clock and self.total_minutes == o.total_minutes
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var c = new Clock(10,50)
 | 
			
		||||
print "It's {c} o'clock."
 | 
			
		||||
 | 
			
		||||
c.minutes += 22
 | 
			
		||||
print "Now it's {c} o'clock."
 | 
			
		||||
 | 
			
		||||
print "The short arrow in on the {c.hour_pos/5} and the long arrow in on the {c.minutes/5}."
 | 
			
		||||
 | 
			
		||||
c.hours -= 2
 | 
			
		||||
print "Now it's {c} o'clock."
 | 
			
		||||
 | 
			
		||||
var c2 = new Clock(9, 11)
 | 
			
		||||
print "It's {c2} on the second clock."
 | 
			
		||||
print "The two clocks are synchronized: {c == c2}."
 | 
			
		||||
c2.minutes += 1
 | 
			
		||||
print "It's now {c2} on the second clock."
 | 
			
		||||
print "The two clocks are synchronized: {c == c2}."
 | 
			
		||||
							
								
								
									
										60
									
								
								samples/Nit/clock_more.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								samples/Nit/clock_more.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# This module beef up the clock module by allowing a clock to be comparable.
 | 
			
		||||
# It show the usage of class refinement
 | 
			
		||||
module clock_more
 | 
			
		||||
 | 
			
		||||
import clock
 | 
			
		||||
 | 
			
		||||
redef class Clock
 | 
			
		||||
	# Clock are now comparable
 | 
			
		||||
	super Comparable
 | 
			
		||||
 | 
			
		||||
	# Comparaison of a clock make only sense with an other clock
 | 
			
		||||
	redef type OTHER: Clock
 | 
			
		||||
 | 
			
		||||
	redef fun <(o)
 | 
			
		||||
	do
 | 
			
		||||
		# Note: < is the only abstract method of Comparable.
 | 
			
		||||
		#       All other operators and methods rely on < and ==.
 | 
			
		||||
		return self.total_minutes < o.total_minutes
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var c1 = new Clock(8, 12)
 | 
			
		||||
var c2 = new Clock(8, 13)
 | 
			
		||||
var c3 = new Clock(9, 13)
 | 
			
		||||
 | 
			
		||||
print "{c1}<{c2}? {c1<c2}"
 | 
			
		||||
print "{c1}<={c2}? {c1<=c2}"
 | 
			
		||||
print "{c1}>{c2}? {c1>c2}"
 | 
			
		||||
print "{c1}>={c2}? {c1>=c2}"
 | 
			
		||||
print "{c1}<=>{c2}? {c1<=>c2}"
 | 
			
		||||
print "{c1},{c2}? max={c1.max(c2)} min={c1.min(c2)}"
 | 
			
		||||
print "{c1}.is_between({c2}, {c3})? {c1.is_between(c2, c3)}"
 | 
			
		||||
print "{c2}.is_between({c1}, {c3})? {c2.is_between(c1, c3)}"
 | 
			
		||||
 | 
			
		||||
print "-"
 | 
			
		||||
 | 
			
		||||
c1.minutes += 1
 | 
			
		||||
 | 
			
		||||
print "{c1}<{c2}? {c1<c2}"
 | 
			
		||||
print "{c1}<={c2}? {c1<=c2}"
 | 
			
		||||
print "{c1}>{c2}? {c1>c2}"
 | 
			
		||||
print "{c1}>={c2}? {c1>=c2}"
 | 
			
		||||
print "{c1}<=>{c2}? {c1<=>c2}"
 | 
			
		||||
print "{c1},{c2}? max={c1.max(c2)} min={c1.min(c2)}"
 | 
			
		||||
print "{c1}.is_between({c2}, {c3})? {c1.is_between(c2, c3)}"
 | 
			
		||||
print "{c2}.is_between({c1}, {c3})? {c2.is_between(c1, c3)}"
 | 
			
		||||
							
								
								
									
										113
									
								
								samples/Nit/curl_http.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								samples/Nit/curl_http.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,113 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Sample of the Curl module.
 | 
			
		||||
module curl_http
 | 
			
		||||
 | 
			
		||||
import curl
 | 
			
		||||
 | 
			
		||||
# Small class to represent an Http Fetcher
 | 
			
		||||
class MyHttpFetcher
 | 
			
		||||
	super CurlCallbacks
 | 
			
		||||
 | 
			
		||||
	var curl: Curl
 | 
			
		||||
	var our_body: String = ""
 | 
			
		||||
 | 
			
		||||
	init(curl: Curl) do self.curl = curl
 | 
			
		||||
 | 
			
		||||
	# Release curl object
 | 
			
		||||
	fun destroy do self.curl.destroy
 | 
			
		||||
 | 
			
		||||
	# Header callback
 | 
			
		||||
	redef fun header_callback(line: String) do
 | 
			
		||||
		# We keep this callback silent for testing purposes
 | 
			
		||||
		#if not line.has_prefix("Date:") then print "Header_callback : {line}"
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Body callback
 | 
			
		||||
	redef fun body_callback(line: String) do self.our_body = "{self.our_body}{line}"
 | 
			
		||||
 | 
			
		||||
	# Stream callback - Cf : No one is registered
 | 
			
		||||
	redef fun stream_callback(buffer: String, size: Int, count: Int) do print "Stream_callback : {buffer} - {size} - {count}"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Program
 | 
			
		||||
if args.length < 2 then
 | 
			
		||||
	print "Usage: curl_http <method wished [POST, GET, GET_FILE]> <target url>"
 | 
			
		||||
else
 | 
			
		||||
	var curl = new Curl
 | 
			
		||||
	var url = args[1]
 | 
			
		||||
	var request = new CurlHTTPRequest(url, curl)
 | 
			
		||||
 | 
			
		||||
	# HTTP Get Request
 | 
			
		||||
	if args[0] == "GET" then
 | 
			
		||||
		request.verbose = false
 | 
			
		||||
		var getResponse = request.execute
 | 
			
		||||
 | 
			
		||||
		if getResponse isa CurlResponseSuccess then
 | 
			
		||||
			print "Status code : {getResponse.status_code}"
 | 
			
		||||
			print "Body : {getResponse.body_str}"
 | 
			
		||||
		else if getResponse isa CurlResponseFailed then
 | 
			
		||||
			print "Error code : {getResponse.error_code}"
 | 
			
		||||
			print "Error msg : {getResponse.error_msg}"
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	# HTTP Post Request
 | 
			
		||||
	else if args[0] == "POST" then
 | 
			
		||||
		var myHttpFetcher = new MyHttpFetcher(curl)
 | 
			
		||||
		request.delegate = myHttpFetcher
 | 
			
		||||
 | 
			
		||||
		var postDatas = new HeaderMap
 | 
			
		||||
		postDatas["Bugs Bunny"] = "Daffy Duck"
 | 
			
		||||
		postDatas["Batman"] = "Robin likes special characters @#ùà!è§'(\"é&://,;<>∞~*"
 | 
			
		||||
		postDatas["Batman"] = "Yes you can set multiple identical keys, but APACHE will consider only once, the last one"
 | 
			
		||||
		request.datas = postDatas
 | 
			
		||||
		request.verbose = false
 | 
			
		||||
		var postResponse = request.execute
 | 
			
		||||
 | 
			
		||||
		print "Our body from the callback : {myHttpFetcher.our_body}"
 | 
			
		||||
 | 
			
		||||
		if postResponse isa CurlResponseSuccess then
 | 
			
		||||
			print "*** Answer ***"
 | 
			
		||||
			print "Status code : {postResponse.status_code}"
 | 
			
		||||
			print "Body should be empty, because we decided to manage callbacks : {postResponse.body_str.length}"
 | 
			
		||||
		else if postResponse isa CurlResponseFailed then
 | 
			
		||||
			print "Error code : {postResponse.error_code}"
 | 
			
		||||
			print "Error msg : {postResponse.error_msg}"
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	# HTTP Get to file Request
 | 
			
		||||
	else if args[0] == "GET_FILE" then
 | 
			
		||||
		var headers = new HeaderMap
 | 
			
		||||
		headers["Accept"] = "Moo"
 | 
			
		||||
		request.headers = headers
 | 
			
		||||
		request.verbose = false
 | 
			
		||||
		var downloadResponse = request.download_to_file(null)
 | 
			
		||||
 | 
			
		||||
		if downloadResponse isa CurlFileResponseSuccess then
 | 
			
		||||
			print "*** Answer ***"
 | 
			
		||||
			print "Status code : {downloadResponse.status_code}"
 | 
			
		||||
			print "Size downloaded : {downloadResponse.size_download}"
 | 
			
		||||
		else if downloadResponse isa CurlResponseFailed then
 | 
			
		||||
			print "Error code : {downloadResponse.error_code}"
 | 
			
		||||
			print "Error msg : {downloadResponse.error_msg}"
 | 
			
		||||
		end
 | 
			
		||||
	# Program logic
 | 
			
		||||
	else
 | 
			
		||||
		print "Usage : Method[POST, GET, GET_FILE]"
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										59
									
								
								samples/Nit/curl_mail.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								samples/Nit/curl_mail.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Mail sender sample using the Curl module
 | 
			
		||||
module curl_mail
 | 
			
		||||
 | 
			
		||||
import curl
 | 
			
		||||
 | 
			
		||||
var curl = new Curl
 | 
			
		||||
var mail_request = new CurlMailRequest(curl)
 | 
			
		||||
 | 
			
		||||
# Networks
 | 
			
		||||
var response = mail_request.set_outgoing_server("smtps://smtp.example.org:465", "user@example.org", "mypassword")
 | 
			
		||||
if response isa CurlResponseFailed then
 | 
			
		||||
	print "Error code : {response.error_code}"
 | 
			
		||||
	print "Error msg : {response.error_msg}"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Headers
 | 
			
		||||
mail_request.from = "Billy Bob"
 | 
			
		||||
mail_request.to = ["user@example.org"]
 | 
			
		||||
mail_request.cc = ["bob@example.org"]
 | 
			
		||||
mail_request.bcc = null
 | 
			
		||||
 | 
			
		||||
var headers_body = new HeaderMap
 | 
			
		||||
headers_body["Content-Type:"] = "text/html; charset=\"UTF-8\""
 | 
			
		||||
headers_body["Content-Transfer-Encoding:"] = "quoted-printable"
 | 
			
		||||
mail_request.headers_body = headers_body
 | 
			
		||||
 | 
			
		||||
# Content
 | 
			
		||||
mail_request.body = "<h1>Here you can write HTML stuff.</h1>"
 | 
			
		||||
mail_request.subject = "Hello From My Nit Program"
 | 
			
		||||
 | 
			
		||||
# Others
 | 
			
		||||
mail_request.verbose = false
 | 
			
		||||
 | 
			
		||||
# Send mail
 | 
			
		||||
response = mail_request.execute
 | 
			
		||||
if response isa CurlResponseFailed then
 | 
			
		||||
	print "Error code : {response.error_code}"
 | 
			
		||||
	print "Error msg : {response.error_msg}"
 | 
			
		||||
else if response isa CurlMailResponseSuccess then
 | 
			
		||||
	print "Mail Sent"
 | 
			
		||||
else
 | 
			
		||||
	print "Unknown Curl Response type"
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										243
									
								
								samples/Nit/draw_operation.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										243
									
								
								samples/Nit/draw_operation.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,243 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2012-2013 Alexis Laferrière <alexis.laf@xymus.net>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Draws an arithmetic operation to the terminal
 | 
			
		||||
module draw_operation
 | 
			
		||||
 | 
			
		||||
redef enum Int
 | 
			
		||||
	fun n_chars: Int `{
 | 
			
		||||
		int c;
 | 
			
		||||
		if ( abs(recv) >= 10 )
 | 
			
		||||
			c = 1+(int)log10f( (float)abs(recv) );
 | 
			
		||||
		else
 | 
			
		||||
			c = 1;
 | 
			
		||||
		if ( recv < 0 ) c ++;
 | 
			
		||||
		return c;
 | 
			
		||||
	`}
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
redef enum Char
 | 
			
		||||
	fun as_operator(a, b: Int): Int
 | 
			
		||||
	do
 | 
			
		||||
		if self == '+' then return a + b
 | 
			
		||||
		if self == '-' then return a - b
 | 
			
		||||
		if self == '*' then return a * b
 | 
			
		||||
		if self == '/' then return a / b
 | 
			
		||||
		if self == '%' then return a % b
 | 
			
		||||
		abort
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	fun override_dispc: Bool
 | 
			
		||||
	do
 | 
			
		||||
		return self == '+' or self == '-' or self == '*' or self == '/' or self == '%'
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	fun lines(s: Int): Array[Line]
 | 
			
		||||
	do
 | 
			
		||||
		if self == '+' then
 | 
			
		||||
			return [new Line(new P(0,s/2),1,0,s), new Line(new P(s/2,1),0,1,s-2)]
 | 
			
		||||
		else if self == '-' then
 | 
			
		||||
			return [new Line(new P(0,s/2),1,0,s)]
 | 
			
		||||
		else if self == '*' then
 | 
			
		||||
			var lines = new Array[Line]
 | 
			
		||||
			for y in [1..s-1[ do
 | 
			
		||||
				lines.add( new Line(new P(1,y), 1,0,s-2) )
 | 
			
		||||
			end
 | 
			
		||||
			return lines
 | 
			
		||||
		else if self == '/' then
 | 
			
		||||
			return [new Line(new P(s-1,0), -1,1, s )]
 | 
			
		||||
		else if self == '%' then
 | 
			
		||||
			var q4 = s/4
 | 
			
		||||
			var lines = [new Line(new P(s-1,0),-1,1,s)]
 | 
			
		||||
			for l in [0..q4[ do
 | 
			
		||||
				lines.append([ new Line( new P(0,l), 1,0,q4), new Line( new P(s-1,s-1-l), -1,0,q4) ])
 | 
			
		||||
			end
 | 
			
		||||
			return lines
 | 
			
		||||
		else if self == '1' then
 | 
			
		||||
			return [new Line(new P(s/2,0), 0,1,s),new Line(new P(0,s-1),1,0,s),
 | 
			
		||||
				new Line( new P(s/2,0),-1,1,s/2)]
 | 
			
		||||
		else if self == '2' then
 | 
			
		||||
			return [new Line(new P(0,0), 1,0,s),new Line(new P(s-1,0),0,1,s/2),
 | 
			
		||||
				new Line( new P(0,s-1),1,0,s), new Line( new P(0,s/2), 0,1,s/2),
 | 
			
		||||
				new Line( new P(0,s/2), 1,0,s)]
 | 
			
		||||
		else if self == '3' then
 | 
			
		||||
			return [new Line(new P(0,0), 1,0,s),new Line(new P(s-1,0),0,1,s),
 | 
			
		||||
				new Line( new P(0,s-1),1,0,s), new Line( new P(0,s/2), 1,0,s)]
 | 
			
		||||
		else if self == '4' then
 | 
			
		||||
			return [new Line(new P(s-1,0),0,1,s), new Line( new P(0,0), 0,1,s/2),
 | 
			
		||||
				new Line( new P(0,s/2), 1,0,s)]
 | 
			
		||||
		else if self == '5' then
 | 
			
		||||
			return [new Line(new P(0,0), 1,0,s),new Line(new P(s-1,s/2),0,1,s/2),
 | 
			
		||||
				new Line( new P(0,s-1),1,0,s), new Line( new P(0,0), 0,1,s/2),
 | 
			
		||||
				new Line( new P(0,s/2), 1,0,s)]
 | 
			
		||||
		else if self == '6' then
 | 
			
		||||
			return [new Line(new P(0,0), 1,0,s),new Line(new P(s-1,s/2),0,1,s/2),
 | 
			
		||||
				new Line( new P(0,s-1),1,0,s), new Line( new P(0,0), 0,1,s),
 | 
			
		||||
				new Line( new P(0,s/2), 1,0,s)]
 | 
			
		||||
		else if self == '7' then
 | 
			
		||||
			var tl = new P(0,0)
 | 
			
		||||
			var tr = new P(s-1,0)
 | 
			
		||||
			return [new Line(tl, 1,0,s), new Line(tr,-1,1,s)]
 | 
			
		||||
		else if self == '8' then
 | 
			
		||||
			return [new Line(new P(0,0), 1,0,s),new Line(new P(s-1,0),0,1,s),
 | 
			
		||||
				new Line( new P(0,s-1),1,0,s), new Line( new P(0,0), 0,1,s),
 | 
			
		||||
				new Line( new P(0,s/2), 1,0,s)]
 | 
			
		||||
		else if self == '9' then
 | 
			
		||||
			return [new Line(new P(0,0), 1,0,s),new Line(new P(s-1,0),0,1,s),
 | 
			
		||||
				new Line( new P(0,s-1),1,0,s), new Line( new P(0,0), 0,1,s/2),
 | 
			
		||||
				new Line( new P(0,s/2), 1,0,s)]
 | 
			
		||||
		else if self == '0' then
 | 
			
		||||
			return [new Line(new P(0,0), 1,0,s),new Line(new P(s-1,0),0,1,s),
 | 
			
		||||
				new Line( new P(0,s-1),1,0,s), new Line( new P(0,0), 0,1,s)]
 | 
			
		||||
		end
 | 
			
		||||
		return new Array[Line]
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class P
 | 
			
		||||
	var x : Int
 | 
			
		||||
	var y : Int
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
redef class String
 | 
			
		||||
	# hack is to support a bug in the evaluation software
 | 
			
		||||
	fun draw(dispc: Char, size, gap: Int, hack: Bool)
 | 
			
		||||
	do
 | 
			
		||||
		var w = size * length +(length-1)*gap
 | 
			
		||||
		var h = size
 | 
			
		||||
		var map = new Array[Array[Char]]
 | 
			
		||||
		for x in [0..w[ do
 | 
			
		||||
			map[x] = new Array[Char].filled_with( ' ',  h )
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		var ci = 0
 | 
			
		||||
		for c in self.chars do
 | 
			
		||||
			var local_dispc
 | 
			
		||||
			if c.override_dispc then
 | 
			
		||||
				local_dispc = c
 | 
			
		||||
			else
 | 
			
		||||
				local_dispc = dispc
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			var lines = c.lines( size )
 | 
			
		||||
			for line in lines do
 | 
			
		||||
				var x = line.o.x+ci*size
 | 
			
		||||
					x += ci*gap
 | 
			
		||||
				var y = line.o.y
 | 
			
		||||
				for s in [0..line.len[ do
 | 
			
		||||
					assert map.length > x and map[x].length > y else print "setting {x},{y} as {local_dispc}"
 | 
			
		||||
					map[x][y] = local_dispc
 | 
			
		||||
					x += line.step_x
 | 
			
		||||
					y += line.step_y
 | 
			
		||||
				end
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			ci += 1
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		if hack then
 | 
			
		||||
			for c in [0..size[ do
 | 
			
		||||
				map[c][0] = map[map.length-size+c][0]
 | 
			
		||||
				map[map.length-size+c][0] = ' '
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		for y in [0..h[ do
 | 
			
		||||
			for x in [0..w[ do
 | 
			
		||||
				printn map[x][y]
 | 
			
		||||
			end
 | 
			
		||||
			print ""
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Line
 | 
			
		||||
	var o : P
 | 
			
		||||
	var step_x : Int
 | 
			
		||||
	var step_y : Int
 | 
			
		||||
	var len : Int
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var a
 | 
			
		||||
var b
 | 
			
		||||
var op_char
 | 
			
		||||
var disp_char
 | 
			
		||||
var disp_size
 | 
			
		||||
var disp_gap
 | 
			
		||||
 | 
			
		||||
if "NIT_TESTING".environ == "true" then
 | 
			
		||||
	a = 567
 | 
			
		||||
	b = 13
 | 
			
		||||
	op_char = '*'
 | 
			
		||||
	disp_char = 'O'
 | 
			
		||||
	disp_size = 8
 | 
			
		||||
	disp_gap = 1
 | 
			
		||||
else
 | 
			
		||||
	printn "Left operand: "
 | 
			
		||||
	a = gets.to_i
 | 
			
		||||
 | 
			
		||||
	printn "Right operand: "
 | 
			
		||||
	b = gets.to_i
 | 
			
		||||
 | 
			
		||||
	printn "Operator (+, -, *, /, %): "
 | 
			
		||||
	op_char = gets.chars[0]
 | 
			
		||||
 | 
			
		||||
	printn "Char to display: "
 | 
			
		||||
	disp_char = gets.chars[0]
 | 
			
		||||
 | 
			
		||||
	printn "Size of text: "
 | 
			
		||||
	disp_size = gets.to_i
 | 
			
		||||
 | 
			
		||||
	printn "Space between digits: "
 | 
			
		||||
	disp_gap = gets.to_i
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var result = op_char.as_operator( a, b )
 | 
			
		||||
 | 
			
		||||
var len_a = a.n_chars
 | 
			
		||||
var len_b = b.n_chars
 | 
			
		||||
var len_res = result.n_chars
 | 
			
		||||
var max_len = len_a.max( len_b.max( len_res ) ) + 1
 | 
			
		||||
 | 
			
		||||
# draw first line
 | 
			
		||||
var d = max_len - len_a
 | 
			
		||||
var line_a = ""
 | 
			
		||||
for i in [0..d[ do line_a += " "
 | 
			
		||||
line_a += a.to_s
 | 
			
		||||
line_a.draw( disp_char, disp_size, disp_gap, false )
 | 
			
		||||
 | 
			
		||||
print ""
 | 
			
		||||
# draw second line
 | 
			
		||||
d = max_len - len_b-1
 | 
			
		||||
var line_b = op_char.to_s
 | 
			
		||||
for i in [0..d[ do line_b += " "
 | 
			
		||||
line_b += b.to_s
 | 
			
		||||
line_b.draw( disp_char, disp_size, disp_gap, false )
 | 
			
		||||
 | 
			
		||||
# draw -----
 | 
			
		||||
print ""
 | 
			
		||||
for i in [0..disp_size*max_len+(max_len-1)*disp_gap] do
 | 
			
		||||
	printn "_"
 | 
			
		||||
end
 | 
			
		||||
print ""
 | 
			
		||||
print ""
 | 
			
		||||
 | 
			
		||||
# draw result
 | 
			
		||||
d = max_len - len_res
 | 
			
		||||
var line_res = ""
 | 
			
		||||
for i in [0..d[ do line_res += " "
 | 
			
		||||
line_res += result.to_s
 | 
			
		||||
line_res.draw( disp_char, disp_size, disp_gap, false )
 | 
			
		||||
							
								
								
									
										46
									
								
								samples/Nit/drop_privileges.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								samples/Nit/drop_privileges.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Example using the privileges module to drop privileges from root
 | 
			
		||||
module drop_privileges
 | 
			
		||||
 | 
			
		||||
import privileges
 | 
			
		||||
 | 
			
		||||
# basic command line options
 | 
			
		||||
var opts = new OptionContext
 | 
			
		||||
var opt_ug = new OptionUserAndGroup.for_dropping_privileges
 | 
			
		||||
opt_ug.mandatory = true
 | 
			
		||||
opts.add_option(opt_ug)
 | 
			
		||||
 | 
			
		||||
# parse and check command line options
 | 
			
		||||
opts.parse(args)
 | 
			
		||||
if not opts.errors.is_empty then
 | 
			
		||||
	print opts.errors
 | 
			
		||||
	print "Usage: drop_privileges [options]"
 | 
			
		||||
	opts.usage
 | 
			
		||||
	exit 1
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# original user
 | 
			
		||||
print "before {sys.uid}:{sys.gid}"
 | 
			
		||||
 | 
			
		||||
# make the switch
 | 
			
		||||
var user_group = opt_ug.value
 | 
			
		||||
assert user_group != null
 | 
			
		||||
user_group.drop_privileges
 | 
			
		||||
 | 
			
		||||
# final user
 | 
			
		||||
print "after {sys.uid}:{sys.egid}"
 | 
			
		||||
							
								
								
									
										69
									
								
								samples/Nit/extern_methods.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								samples/Nit/extern_methods.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2012-2013 Alexis Laferrière <alexis.laf@xymus.net>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# This module illustrates some uses of the FFI, specifically
 | 
			
		||||
# how to use extern methods. Which means to implement a Nit method in C.
 | 
			
		||||
module extern_methods
 | 
			
		||||
 | 
			
		||||
redef enum Int
 | 
			
		||||
	# Returns self'th fibonnaci number
 | 
			
		||||
	# implemented here in C for optimization purposes
 | 
			
		||||
	fun fib : Int import fib `{
 | 
			
		||||
		if ( recv < 2 )
 | 
			
		||||
			return recv;
 | 
			
		||||
		else
 | 
			
		||||
			return Int_fib( recv-1 ) + Int_fib( recv-2 );
 | 
			
		||||
	`}
 | 
			
		||||
 | 
			
		||||
	# System call to sleep for "self" seconds
 | 
			
		||||
	fun sleep `{
 | 
			
		||||
		sleep( recv );
 | 
			
		||||
	`}
 | 
			
		||||
 | 
			
		||||
	# Return atan2l( self, x ) from libmath
 | 
			
		||||
	fun atan_with( x : Int ) : Float `{
 | 
			
		||||
		return atan2( recv, x );
 | 
			
		||||
	`}
 | 
			
		||||
 | 
			
		||||
	# This method callback to Nit methods from C code
 | 
			
		||||
	# It will use from C code:
 | 
			
		||||
	# * the local fib method
 | 
			
		||||
	# * the + operator, a method of Int
 | 
			
		||||
	# * to_s, a method of all objects
 | 
			
		||||
	# * String.to_cstring, a method of String to return an equivalent char*
 | 
			
		||||
	fun foo import fib, +, to_s, String.to_cstring `{
 | 
			
		||||
		long recv_fib = Int_fib( recv );
 | 
			
		||||
		long recv_plus_fib = Int__plus( recv, recv_fib );
 | 
			
		||||
 | 
			
		||||
		String nit_string = Int_to_s( recv_plus_fib );
 | 
			
		||||
		char *c_string = String_to_cstring( nit_string );
 | 
			
		||||
 | 
			
		||||
		printf( "from C: self + fib(self) = %s\n", c_string );
 | 
			
		||||
	`}
 | 
			
		||||
 | 
			
		||||
	# Equivalent to foo but written in pure Nit
 | 
			
		||||
	fun bar do print "from Nit: self + fib(self) = {self+self.fib}"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
print 12.fib
 | 
			
		||||
 | 
			
		||||
print "sleeping 1 second..."
 | 
			
		||||
1.sleep
 | 
			
		||||
 | 
			
		||||
print 100.atan_with( 200 )
 | 
			
		||||
8.foo
 | 
			
		||||
8.bar
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										43
									
								
								samples/Nit/fibonacci.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								samples/Nit/fibonacci.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2004-2008 Jean Privat <jean@pryen.org>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# A simple exemple of refinement where a method is added to the integer class.
 | 
			
		||||
module fibonacci
 | 
			
		||||
 | 
			
		||||
redef class Int
 | 
			
		||||
	# Calculate the self-th element of the fibonacci sequence.
 | 
			
		||||
	fun fibonacci: Int
 | 
			
		||||
	do
 | 
			
		||||
		if self < 2 then
 | 
			
		||||
			return 1
 | 
			
		||||
		else
 | 
			
		||||
			return (self-2).fibonacci + (self-1).fibonacci
 | 
			
		||||
		end
 | 
			
		||||
	end 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Print usage and exit.
 | 
			
		||||
fun usage
 | 
			
		||||
do
 | 
			
		||||
	print "Usage: fibonnaci <integer>" 
 | 
			
		||||
	exit 0 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Main part
 | 
			
		||||
if args.length != 1 then
 | 
			
		||||
	usage
 | 
			
		||||
end
 | 
			
		||||
print args.first.to_i.fibonacci
 | 
			
		||||
							
								
								
									
										1
									
								
								samples/Nit/hello_world.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								samples/Nit/hello_world.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
print "hello world"
 | 
			
		||||
							
								
								
									
										105
									
								
								samples/Nit/html_page.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								samples/Nit/html_page.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,105 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
import html
 | 
			
		||||
 | 
			
		||||
class NitHomepage
 | 
			
		||||
	super HTMLPage
 | 
			
		||||
 | 
			
		||||
	redef fun head do
 | 
			
		||||
		add("meta").attr("charset", "utf-8")
 | 
			
		||||
		add("title").text("Nit")
 | 
			
		||||
		add("link").attr("rel", "icon").attr("href", "http://nitlanguage.org/favicon.ico").attr("type", "image/x-icon")
 | 
			
		||||
		add("link").attr("rel", "stylesheet").attr("href", "http://nitlanguage.org/style.css").attr("type", "text/css")
 | 
			
		||||
		add("link").attr("rel", "stylesheet").attr("href", "http://nitlanguage.org/local.css").attr("type", "text/css")
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun body do
 | 
			
		||||
		open("article").add_class("page")
 | 
			
		||||
			open("section").add_class("pageheader")
 | 
			
		||||
				add_html("<a id='toptitle_first' class='toptitle'>the</a><a id='toptitle_second' class='toptitle' href=''>Nit</a><a id='toptitle_third' class='toptitle' href=''>Programming Language</a>")
 | 
			
		||||
				open("header").add_class("header")
 | 
			
		||||
					open("div").add_class("topsubtitle")
 | 
			
		||||
						add("p").text("A Fun Language for Serious Programming")
 | 
			
		||||
					close("div")
 | 
			
		||||
				close("header")
 | 
			
		||||
			close("section")
 | 
			
		||||
 | 
			
		||||
			open("div").attr("id", "pagebody")
 | 
			
		||||
				open("section").attr("id", "content")
 | 
			
		||||
					add("h1").text("# What is Nit?")
 | 
			
		||||
					add("p").text("Nit is an object-oriented programming language. The goal of Nit is to propose a robust statically typed programming language where structure is not a pain.")
 | 
			
		||||
					add("p").text("So, what does the famous hello world program look like, in Nit?")
 | 
			
		||||
					add_html("<pre><tt><span class='normal'>print </span><span class='string'>'Hello, World!'</span></tt></pre>")
 | 
			
		||||
 | 
			
		||||
					add("h1").text("# Feature Highlights")
 | 
			
		||||
					add("h2").text("Usability")
 | 
			
		||||
					add("p").text("Nit's goal is to be usable by real programmers for real projects")
 | 
			
		||||
 | 
			
		||||
					open("ul")
 | 
			
		||||
						open("li")
 | 
			
		||||
						add("a").attr("href", "http://en.wikipedia.org/wiki/KISS_principle").text("KISS principle")
 | 
			
		||||
						close("li")
 | 
			
		||||
						add("li").text("Script-like language without verbosity nor cryptic statements")
 | 
			
		||||
						add("li").text("Painless static types: static typing should help programmers")
 | 
			
		||||
						add("li").text("Efficient development, efficient execution, efficient evolution.")
 | 
			
		||||
					close("ul")
 | 
			
		||||
 | 
			
		||||
					add("h2").text("Robustness")
 | 
			
		||||
					add("p").text("Nit will help you to write bug-free programs")
 | 
			
		||||
 | 
			
		||||
					open("ul")
 | 
			
		||||
						add("li").text("Strong static typing")
 | 
			
		||||
						add("li").text("No more NullPointerException")
 | 
			
		||||
					close("ul")
 | 
			
		||||
 | 
			
		||||
					add("h2").text("Object-Oriented")
 | 
			
		||||
					add("p").text("Nit's guideline is to follow the most powerful OO principles")
 | 
			
		||||
 | 
			
		||||
					open("ul")
 | 
			
		||||
						open("li")
 | 
			
		||||
						add("a").attr("href", "./everything_is_an_object/").text("Everything is an object")
 | 
			
		||||
						close("li")
 | 
			
		||||
						open("li")
 | 
			
		||||
						add("a").attr("href", "./multiple_inheritance/").text("Multiple inheritance")
 | 
			
		||||
						close("li")
 | 
			
		||||
						open("li")
 | 
			
		||||
						add("a").attr("href", "./refinement/").text("Open classes")
 | 
			
		||||
						close("li")
 | 
			
		||||
						open("li")
 | 
			
		||||
						add("a").attr("href", "./virtual_types/").text("Virtual types")
 | 
			
		||||
						close("li")
 | 
			
		||||
					close("ul")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
					add("h1").text("# Getting Started")
 | 
			
		||||
					add("p").text("Get Nit from its Git repository:")
 | 
			
		||||
 | 
			
		||||
					add_html("<pre><code>$ git clone http://nitlanguage.org/nit.git</code></pre>")
 | 
			
		||||
					add("p").text("Build the compiler (may be long):")
 | 
			
		||||
					add_html("<pre><code>$ cd nit\n")
 | 
			
		||||
					add_html("$ make</code></pre>")
 | 
			
		||||
					add("p").text("Compile a program:")
 | 
			
		||||
					add_html("<pre><code>$ bin/nitc examples/hello_world.nit</code></pre>")
 | 
			
		||||
					add("p").text("Execute the program:")
 | 
			
		||||
					add_html("<pre><code>$ ./hello_world</code></pre>")
 | 
			
		||||
				close("section")
 | 
			
		||||
			close("div")
 | 
			
		||||
		close("article")
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var page = new NitHomepage
 | 
			
		||||
page.write_to stdout
 | 
			
		||||
page.write_to_file("nit.html")
 | 
			
		||||
							
								
								
									
										100
									
								
								samples/Nit/int_stack.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								samples/Nit/int_stack.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,100 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# An example that defines and uses stacks of integers.
 | 
			
		||||
# The implementation is done with a simple linked list.
 | 
			
		||||
# It features: free constructors, nullable types and some adaptive typing.
 | 
			
		||||
module int_stack
 | 
			
		||||
 | 
			
		||||
# A stack of integer implemented by a simple linked list.
 | 
			
		||||
# Note that this is only a toy class since a real linked list will gain to use
 | 
			
		||||
# generics and extends interfaces, like Collection, from the standard library.
 | 
			
		||||
class IntStack
 | 
			
		||||
	# The head node of the list.
 | 
			
		||||
	# Null means that the stack is empty.
 | 
			
		||||
	private var head: nullable ISNode = null
 | 
			
		||||
 | 
			
		||||
	# Add a new integer in the stack.
 | 
			
		||||
	fun push(val: Int)
 | 
			
		||||
	do
 | 
			
		||||
		self.head = new ISNode(val, self.head)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Remove and return the last pushed integer.
 | 
			
		||||
	# Return null if the stack is empty.
 | 
			
		||||
	fun pop: nullable Int
 | 
			
		||||
	do
 | 
			
		||||
		var head = self.head
 | 
			
		||||
		if head == null then return null
 | 
			
		||||
		# Note: the followings are statically safe because of the
 | 
			
		||||
		# previous 'if'.
 | 
			
		||||
		var val = head.val
 | 
			
		||||
		self.head = head.next
 | 
			
		||||
		return val
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Return the sum of all integers of the stack.
 | 
			
		||||
	# Return 0 if the stack is empty.
 | 
			
		||||
	fun sumall: Int
 | 
			
		||||
	do
 | 
			
		||||
		var sum = 0
 | 
			
		||||
		var cur = self.head
 | 
			
		||||
		while cur != null do
 | 
			
		||||
			# Note: the followings are statically safe because of
 | 
			
		||||
			# the condition of the 'while'.
 | 
			
		||||
			sum += cur.val
 | 
			
		||||
			cur = cur.next
 | 
			
		||||
		end
 | 
			
		||||
		return sum
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Note: Because all attributes have a default value, a free constructor
 | 
			
		||||
	# "init()" is implicitly defined.
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# A node of a IntStack
 | 
			
		||||
private class ISNode
 | 
			
		||||
	# The integer value stored in the node.
 | 
			
		||||
	var val: Int
 | 
			
		||||
 | 
			
		||||
	# The next node, if any.
 | 
			
		||||
	var next: nullable ISNode
 | 
			
		||||
 | 
			
		||||
	# Note: A free constructor "init(val: Int, next: nullable ISNode)" is
 | 
			
		||||
	# implicitly defined.
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var l = new IntStack
 | 
			
		||||
l.push(1)
 | 
			
		||||
l.push(2)
 | 
			
		||||
l.push(3)
 | 
			
		||||
 | 
			
		||||
print l.sumall
 | 
			
		||||
 | 
			
		||||
# Note: the 'for' control structure cannot be used on IntStack in its current state.
 | 
			
		||||
# It requires a more advanced topic.
 | 
			
		||||
# However, why not using the 'loop' control structure?
 | 
			
		||||
loop
 | 
			
		||||
	var i = l.pop
 | 
			
		||||
	if i == null then break
 | 
			
		||||
	# The following is statically safe because of the previous 'if'.
 | 
			
		||||
	print i * 10
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Note: 'or else' is used to give an alternative of a null expression.
 | 
			
		||||
l.push(5)
 | 
			
		||||
print l.pop or else 0 # l.pop gives 5, so print 5
 | 
			
		||||
print l.pop or else 0 # l.pop gives null, so print the alternative: 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										193
									
								
								samples/Nit/opengles2_hello_triangle.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										193
									
								
								samples/Nit/opengles2_hello_triangle.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,193 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Basic example of OpenGL ES 2.0 usage from the book OpenGL ES 2.0 Programming Guide.
 | 
			
		||||
#
 | 
			
		||||
# Code reference:
 | 
			
		||||
# https://code.google.com/p/opengles-book-samples/source/browse/trunk/LinuxX11/Chapter_2/Hello_Triangle/Hello_Triangle.c 
 | 
			
		||||
module opengles2_hello_triangle
 | 
			
		||||
 | 
			
		||||
import glesv2
 | 
			
		||||
import egl
 | 
			
		||||
import mnit_linux # for sdl
 | 
			
		||||
import x11
 | 
			
		||||
 | 
			
		||||
if "NIT_TESTING".environ == "true" then exit(0)
 | 
			
		||||
 | 
			
		||||
var window_width = 800
 | 
			
		||||
var window_height = 600
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
## SDL
 | 
			
		||||
#
 | 
			
		||||
var sdl_display = new SDLDisplay(window_width, window_height)
 | 
			
		||||
var sdl_wm_info = new SDLSystemWindowManagerInfo
 | 
			
		||||
var x11_window_handle = sdl_wm_info.x11_window_handle
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
## X11
 | 
			
		||||
#
 | 
			
		||||
var x_display = x_open_default_display
 | 
			
		||||
assert x_display != 0 else print "x11 fail"
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
## EGL
 | 
			
		||||
#
 | 
			
		||||
var egl_display = new EGLDisplay(x_display)
 | 
			
		||||
assert egl_display.is_valid else print "EGL display is not valid"
 | 
			
		||||
egl_display.initialize
 | 
			
		||||
 | 
			
		||||
print "EGL version: {egl_display.version}"
 | 
			
		||||
print "EGL vendor: {egl_display.vendor}"
 | 
			
		||||
print "EGL extensions: {egl_display.extensions.join(", ")}"
 | 
			
		||||
print "EGL client APIs: {egl_display.client_apis.join(", ")}"
 | 
			
		||||
 | 
			
		||||
assert egl_display.is_valid else print egl_display.error
 | 
			
		||||
 | 
			
		||||
var config_chooser = new EGLConfigChooser
 | 
			
		||||
#config_chooser.surface_type_egl
 | 
			
		||||
config_chooser.blue_size = 8
 | 
			
		||||
config_chooser.green_size = 8
 | 
			
		||||
config_chooser.red_size = 8
 | 
			
		||||
#config_chooser.alpha_size = 8
 | 
			
		||||
#config_chooser.depth_size = 8
 | 
			
		||||
#config_chooser.stencil_size = 8
 | 
			
		||||
#config_chooser.sample_buffers = 1
 | 
			
		||||
config_chooser.close
 | 
			
		||||
 | 
			
		||||
var configs = config_chooser.choose(egl_display)
 | 
			
		||||
assert configs != null else print "choosing config failed: {egl_display.error}"
 | 
			
		||||
assert not configs.is_empty else print "no EGL config"
 | 
			
		||||
 | 
			
		||||
print "{configs.length} EGL configs available"
 | 
			
		||||
for config in configs do
 | 
			
		||||
	var attribs = config.attribs(egl_display)
 | 
			
		||||
	print "* caveats: {attribs.caveat}"
 | 
			
		||||
	print "  conformant to: {attribs.conformant}"
 | 
			
		||||
	print "  size of RGBA: {attribs.red_size} {attribs.green_size} {attribs.blue_size} {attribs.alpha_size}"
 | 
			
		||||
	print "  buffer, depth, stencil: {attribs.buffer_size} {attribs.depth_size} {attribs.stencil_size}"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var config = configs.first
 | 
			
		||||
 | 
			
		||||
var format = config.attribs(egl_display).native_visual_id
 | 
			
		||||
 | 
			
		||||
# TODO android part
 | 
			
		||||
# Opengles1Display_midway_init(recv, format);
 | 
			
		||||
 | 
			
		||||
var surface = egl_display.create_window_surface(config, x11_window_handle, [0])
 | 
			
		||||
assert surface.is_ok else print egl_display.error
 | 
			
		||||
 | 
			
		||||
var context = egl_display.create_context(config)
 | 
			
		||||
assert context.is_ok else print egl_display.error
 | 
			
		||||
 | 
			
		||||
var make_current_res = egl_display.make_current(surface, surface, context)
 | 
			
		||||
assert make_current_res
 | 
			
		||||
 | 
			
		||||
var width = surface.attribs(egl_display).width
 | 
			
		||||
var height = surface.attribs(egl_display).height
 | 
			
		||||
print "Width: {width}"
 | 
			
		||||
print "Height: {height}"
 | 
			
		||||
 | 
			
		||||
assert egl_bind_opengl_es_api else print "eglBingAPI failed: {egl_display.error}"
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
## GLESv2
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
print "Can compile shaders? {gl_shader_compiler}"
 | 
			
		||||
assert_no_gl_error
 | 
			
		||||
 | 
			
		||||
assert gl_shader_compiler else print "Cannot compile shaders"
 | 
			
		||||
 | 
			
		||||
# gl program
 | 
			
		||||
print gl_error.to_s
 | 
			
		||||
var program = new GLProgram
 | 
			
		||||
if not program.is_ok then
 | 
			
		||||
	print "Program is not ok: {gl_error.to_s}\nLog:"
 | 
			
		||||
	print program.info_log
 | 
			
		||||
	abort
 | 
			
		||||
end
 | 
			
		||||
assert_no_gl_error
 | 
			
		||||
 | 
			
		||||
# vertex shader
 | 
			
		||||
var vertex_shader = new GLVertexShader
 | 
			
		||||
assert vertex_shader.is_ok else print "Vertex shader is not ok: {gl_error}"
 | 
			
		||||
vertex_shader.source = """
 | 
			
		||||
attribute vec4 vPosition;   
 | 
			
		||||
void main()                 
 | 
			
		||||
{                           
 | 
			
		||||
  gl_Position = vPosition;  
 | 
			
		||||
}                           """
 | 
			
		||||
vertex_shader.compile
 | 
			
		||||
assert vertex_shader.is_compiled else print "Vertex shader compilation failed with: {vertex_shader.info_log} {program.info_log}"
 | 
			
		||||
assert_no_gl_error
 | 
			
		||||
 | 
			
		||||
# fragment shader
 | 
			
		||||
var fragment_shader = new GLFragmentShader
 | 
			
		||||
assert fragment_shader.is_ok else print "Fragment shader is not ok: {gl_error}"
 | 
			
		||||
fragment_shader.source = """
 | 
			
		||||
precision mediump float;
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
 | 
			
		||||
}
 | 
			
		||||
"""
 | 
			
		||||
fragment_shader.compile
 | 
			
		||||
assert fragment_shader.is_compiled else print "Fragment shader compilation failed with: {fragment_shader.info_log}"
 | 
			
		||||
assert_no_gl_error
 | 
			
		||||
 | 
			
		||||
program.attach_shader vertex_shader
 | 
			
		||||
program.attach_shader fragment_shader
 | 
			
		||||
program.bind_attrib_location(0, "vPosition")
 | 
			
		||||
program.link
 | 
			
		||||
assert program.is_linked else print "Linking failed: {program.info_log}"
 | 
			
		||||
assert_no_gl_error
 | 
			
		||||
 | 
			
		||||
# draw!
 | 
			
		||||
var vertices = [0.0, 0.5, 0.0, -0.5, -0.5, 0.0, 0.5, -0.5, 0.0]
 | 
			
		||||
var vertex_array = new VertexArray(0, 3, vertices)
 | 
			
		||||
vertex_array.attrib_pointer
 | 
			
		||||
gl_clear_color(0.5, 0.0, 0.5, 1.0)
 | 
			
		||||
for i in [0..10000[ do
 | 
			
		||||
	printn "."
 | 
			
		||||
	assert_no_gl_error
 | 
			
		||||
	gl_viewport(0, 0, width, height)
 | 
			
		||||
	gl_clear_color_buffer
 | 
			
		||||
	program.use
 | 
			
		||||
	vertex_array.enable
 | 
			
		||||
	vertex_array.draw_arrays_triangles
 | 
			
		||||
	egl_display.swap_buffers(surface)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# delete
 | 
			
		||||
program.delete
 | 
			
		||||
vertex_shader.delete
 | 
			
		||||
fragment_shader.delete
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
## EGL
 | 
			
		||||
#
 | 
			
		||||
# close
 | 
			
		||||
egl_display.make_current(new EGLSurface.none, new EGLSurface.none, new EGLContext.none)
 | 
			
		||||
egl_display.destroy_context(context)
 | 
			
		||||
egl_display.destroy_surface(surface)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
## SDL
 | 
			
		||||
#
 | 
			
		||||
# close
 | 
			
		||||
sdl_display.destroy
 | 
			
		||||
							
								
								
									
										22
									
								
								samples/Nit/print_arguments.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								samples/Nit/print_arguments.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2004-2008 Jean Privat <jean@pryen.org>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# How to print arguments of the command line.
 | 
			
		||||
module print_arguments
 | 
			
		||||
 | 
			
		||||
for a in args do
 | 
			
		||||
	print a
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										48
									
								
								samples/Nit/procedural_array.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								samples/Nit/procedural_array.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2004-2008 Jean Privat <jean@pryen.org>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# A procedural program (without explicit class definition).
 | 
			
		||||
# This program manipulates arrays of integers.
 | 
			
		||||
module procedural_array
 | 
			
		||||
 | 
			
		||||
# The sum of the elements of `a'.
 | 
			
		||||
# Uses a 'for' control structure.
 | 
			
		||||
fun array_sum(a: Array[Int]): Int
 | 
			
		||||
do
 | 
			
		||||
	var sum = 0
 | 
			
		||||
	for i in a do
 | 
			
		||||
		sum = sum + i
 | 
			
		||||
	end
 | 
			
		||||
	return sum
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# The sum of the elements of `a' (alternative version).
 | 
			
		||||
# Uses a 'while' control structure.
 | 
			
		||||
fun array_sum_alt(a: Array[Int]): Int
 | 
			
		||||
do
 | 
			
		||||
	var sum = 0
 | 
			
		||||
	var i = 0
 | 
			
		||||
	while i < a.length do
 | 
			
		||||
		sum = sum + a[i]
 | 
			
		||||
		i = i + 1
 | 
			
		||||
	end
 | 
			
		||||
	return sum
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# The main part of the program.
 | 
			
		||||
var a = [10, 5, 8, 9]
 | 
			
		||||
print(array_sum(a))
 | 
			
		||||
print(array_sum_alt(a))
 | 
			
		||||
							
								
								
									
										38
									
								
								samples/Nit/socket_client.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								samples/Nit/socket_client.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Client sample using the Socket module which connect to the server sample.
 | 
			
		||||
module socket_client
 | 
			
		||||
 | 
			
		||||
import socket
 | 
			
		||||
 | 
			
		||||
if args.length < 2 then
 | 
			
		||||
	print "Usage : socket_client <host> <port>"
 | 
			
		||||
	return
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var s = new Socket.client(args[0], args[1].to_i)
 | 
			
		||||
print "[HOST ADDRESS] : {s.address}"
 | 
			
		||||
print "[HOST] : {s.host}"
 | 
			
		||||
print "[PORT] : {s.port}"
 | 
			
		||||
print "Connecting ... {s.connected}"
 | 
			
		||||
if s.connected then
 | 
			
		||||
	print "Writing ... Hello server !"
 | 
			
		||||
	s.write("Hello server !")
 | 
			
		||||
	print "[Response from server] : {s.read(100)}"
 | 
			
		||||
	print "Closing ..."
 | 
			
		||||
	s.close
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										52
									
								
								samples/Nit/socket_server.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								samples/Nit/socket_server.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Server sample using the Socket module which allow client to connect
 | 
			
		||||
module socket_server
 | 
			
		||||
 | 
			
		||||
import socket
 | 
			
		||||
 | 
			
		||||
if args.is_empty then
 | 
			
		||||
	print "Usage : socket_server <port>"
 | 
			
		||||
	return
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
var socket = new Socket.server(args[0].to_i, 1)
 | 
			
		||||
print "[PORT] : {socket.port.to_s}"
 | 
			
		||||
 | 
			
		||||
var clients = new Array[Socket]
 | 
			
		||||
var max = socket
 | 
			
		||||
loop
 | 
			
		||||
	var fs = new SocketObserver(true, true, true)
 | 
			
		||||
	fs.readset.set(socket)
 | 
			
		||||
 | 
			
		||||
	for c in clients do fs.readset.set(c)
 | 
			
		||||
 | 
			
		||||
	if fs.select(max, 4, 0) == 0 then
 | 
			
		||||
		print "Error occured in select {sys.errno.strerror}"
 | 
			
		||||
		break
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if fs.readset.is_set(socket) then
 | 
			
		||||
		var ns = socket.accept
 | 
			
		||||
		print "Accepting {ns.address} ... "
 | 
			
		||||
		print "[Message from {ns.address}] : {ns.read(100)}"
 | 
			
		||||
		ns.write("Goodbye client.")
 | 
			
		||||
		print "Closing {ns.address} ..."
 | 
			
		||||
		ns.close
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										94
									
								
								samples/Nit/tmpl_composer.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								samples/Nit/tmpl_composer.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,94 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
import template
 | 
			
		||||
 | 
			
		||||
### Here, definition of the specific templates
 | 
			
		||||
 | 
			
		||||
# The root template for composers
 | 
			
		||||
class TmplComposers
 | 
			
		||||
	super Template
 | 
			
		||||
 | 
			
		||||
	# Short list of composers
 | 
			
		||||
	var composers = new Array[TmplComposer]
 | 
			
		||||
 | 
			
		||||
	# Detailled list of composers
 | 
			
		||||
	var composer_details = new Array[TmplComposerDetail]
 | 
			
		||||
 | 
			
		||||
	# Add a composer in both lists
 | 
			
		||||
	fun add_composer(firstname, lastname: String, birth, death: Int)
 | 
			
		||||
	do
 | 
			
		||||
		composers.add(new TmplComposer(lastname))
 | 
			
		||||
		composer_details.add(new TmplComposerDetail(firstname, lastname, birth, death))
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun rendering do
 | 
			
		||||
		add """
 | 
			
		||||
COMPOSERS
 | 
			
		||||
=========
 | 
			
		||||
"""
 | 
			
		||||
		add_all composers
 | 
			
		||||
		add """
 | 
			
		||||
 | 
			
		||||
DETAILS
 | 
			
		||||
=======
 | 
			
		||||
"""
 | 
			
		||||
		add_all composer_details
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# A composer in the short list of composers
 | 
			
		||||
class TmplComposer
 | 
			
		||||
	super Template
 | 
			
		||||
 | 
			
		||||
	# Short name
 | 
			
		||||
	var name: String
 | 
			
		||||
 | 
			
		||||
	init(name: String) do self.name = name
 | 
			
		||||
 | 
			
		||||
	redef fun rendering do add "- {name}\n"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# A composer in the detailled list of composers
 | 
			
		||||
class TmplComposerDetail
 | 
			
		||||
	super Template
 | 
			
		||||
 | 
			
		||||
	var firstname: String
 | 
			
		||||
	var lastname: String
 | 
			
		||||
	var birth: Int
 | 
			
		||||
	var death: Int
 | 
			
		||||
 | 
			
		||||
	init(firstname, lastname: String, birth, death: Int) do
 | 
			
		||||
		self.firstname = firstname
 | 
			
		||||
		self.lastname = lastname
 | 
			
		||||
		self.birth = birth
 | 
			
		||||
		self.death = death
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	redef fun rendering do add """
 | 
			
		||||
 | 
			
		||||
COMPOSER: {{{firstname}}} {{{lastname}}}
 | 
			
		||||
BIRTH...: {{{birth}}}
 | 
			
		||||
DEATH...: {{{death}}}
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
### Here a simple usage of the templates
 | 
			
		||||
 | 
			
		||||
var f = new TmplComposers
 | 
			
		||||
f.add_composer("Johann Sebastian", "Bach", 1685, 1750)
 | 
			
		||||
f.add_composer("George Frideric", "Handel", 1685, 1759)
 | 
			
		||||
f.add_composer("Wolfgang Amadeus", "Mozart", 1756, 1791)
 | 
			
		||||
f.write_to(stdout)
 | 
			
		||||
							
								
								
									
										46
									
								
								samples/Nit/websocket_server.nit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								samples/Nit/websocket_server.nit
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
# This file is part of NIT ( http://www.nitlanguage.org ).
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2014 Lucas Bajolet <r4pass@hotmail.com>
 | 
			
		||||
#
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
# Sample module for a minimal chat server using Websockets on port 8088
 | 
			
		||||
module websocket_server
 | 
			
		||||
 | 
			
		||||
import websocket
 | 
			
		||||
 | 
			
		||||
var sock = new WebSocket(8088, 1)
 | 
			
		||||
 | 
			
		||||
var msg: String
 | 
			
		||||
 | 
			
		||||
if sock.listener.eof then
 | 
			
		||||
	print sys.errno.strerror
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
sock.accept
 | 
			
		||||
 | 
			
		||||
while not sock.listener.eof do
 | 
			
		||||
	if not sock.connected then sock.accept
 | 
			
		||||
	if sys.stdin.poll_in then
 | 
			
		||||
		msg = gets
 | 
			
		||||
		printn "Received message : {msg}"
 | 
			
		||||
		if msg == "exit" then sock.close
 | 
			
		||||
		if msg == "disconnect" then sock.disconnect_client
 | 
			
		||||
		sock.write(msg)
 | 
			
		||||
	end
 | 
			
		||||
	if sock.can_read(10) then
 | 
			
		||||
		msg = sock.read_line
 | 
			
		||||
		if msg != "" then print msg
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										34
									
								
								samples/PHP/filenames/.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										34
									
								
								samples/PHP/filenames/.php
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
#!/usr/bin/env php
 | 
			
		||||
<?
 | 
			
		||||
$aMenuLinks = Array(
 | 
			
		||||
	Array(
 | 
			
		||||
		"Blog", 
 | 
			
		||||
		SITE_DIR, 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		"" 
 | 
			
		||||
	),
 | 
			
		||||
	Array(
 | 
			
		||||
		"Photos", 
 | 
			
		||||
		SITE_DIR."photo/", 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		"" 
 | 
			
		||||
	),
 | 
			
		||||
	Array(
 | 
			
		||||
		"About me", 
 | 
			
		||||
		SITE_DIR."about.php", 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		"" 
 | 
			
		||||
	),
 | 
			
		||||
	Array(
 | 
			
		||||
		"Contact", 
 | 
			
		||||
		SITE_DIR."contacts.php", 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		Array(), 
 | 
			
		||||
		"" 
 | 
			
		||||
	),
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										542
									
								
								samples/XML/filenames/.cproject
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										542
									
								
								samples/XML/filenames/.cproject
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,542 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
			
		||||
<?fileVersion 4.0.0?>
 | 
			
		||||
 | 
			
		||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
 | 
			
		||||
	<storageModule moduleId="org.eclipse.cdt.core.settings">
 | 
			
		||||
		<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.1803931088">
 | 
			
		||||
			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1803931088" moduleId="org.eclipse.cdt.core.settings" name="Debug">
 | 
			
		||||
				<externalSettings/>
 | 
			
		||||
				<extensions>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
				</extensions>
 | 
			
		||||
			</storageModule>
 | 
			
		||||
			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
 | 
			
		||||
				<configuration artifactName="Graph抽象資料結構" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1803931088" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
 | 
			
		||||
					<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1803931088." name="/" resourcePath="">
 | 
			
		||||
						<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1808064337" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
 | 
			
		||||
							<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.475427293" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
 | 
			
		||||
							<builder buildPath="${workspace_loc:/Graph抽象資料結構/Debug}" id="cdt.managedbuild.target.gnu.builder.exe.debug.939020465" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.archiver.base.1433738663" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1829995894" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
 | 
			
		||||
								<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.442000851" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.cpp.compiler.exe.debug.option.debugging.level.508927038" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.cpp.compiler.option.include.paths.343012625" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths"/>
 | 
			
		||||
								<option id="gnu.cpp.compiler.option.preprocessor.def.432825827" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
 | 
			
		||||
									<listOptionValue builtIn="false" value="DEBUG"/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1791758539" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1529597285" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
 | 
			
		||||
								<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.1364110929" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.c.compiler.exe.debug.option.debugging.level.1080217050" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.c.compiler.option.include.paths.1256182591" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths"/>
 | 
			
		||||
								<option id="gnu.c.compiler.option.preprocessor.def.symbols.1858410383" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
 | 
			
		||||
									<listOptionValue builtIn="false" value="DEBUG"/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.24351646" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1253142147" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.2139040707" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1870115166" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
 | 
			
		||||
									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
 | 
			
		||||
									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
 | 
			
		||||
								</inputType>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.2025871733" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1643445921" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
						</toolChain>
 | 
			
		||||
					</folderInfo>
 | 
			
		||||
					<sourceEntries>
 | 
			
		||||
						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
 | 
			
		||||
					</sourceEntries>
 | 
			
		||||
				</configuration>
 | 
			
		||||
			</storageModule>
 | 
			
		||||
			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
 | 
			
		||||
			<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
 | 
			
		||||
			<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
 | 
			
		||||
		</cconfiguration>
 | 
			
		||||
		<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.32754498">
 | 
			
		||||
			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.32754498" moduleId="org.eclipse.cdt.core.settings" name="Release">
 | 
			
		||||
				<externalSettings/>
 | 
			
		||||
				<extensions>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
				</extensions>
 | 
			
		||||
			</storageModule>
 | 
			
		||||
			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
 | 
			
		||||
				<configuration artifactName="Graph抽象資料結構" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.32754498" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
 | 
			
		||||
					<folderInfo id="cdt.managedbuild.config.gnu.exe.release.32754498." name="/" resourcePath="">
 | 
			
		||||
						<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.1285242355" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
 | 
			
		||||
							<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.1495976902" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
 | 
			
		||||
							<builder buildPath="${workspace_loc:/Graph抽象資料結構/Release}" id="cdt.managedbuild.target.gnu.builder.exe.release.1973733698" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.archiver.base.1600860298" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1473926095" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
 | 
			
		||||
								<option id="gnu.cpp.compiler.exe.release.option.optimization.level.1632726668" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.cpp.compiler.exe.release.option.debugging.level.2009085397" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.cpp.compiler.option.include.paths.1869632172" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths"/>
 | 
			
		||||
								<option id="gnu.cpp.compiler.option.preprocessor.def.1246679568" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
 | 
			
		||||
									<listOptionValue builtIn="false" value="NDEBUG"/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1744095710" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.478520411" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
 | 
			
		||||
								<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.1683736183" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.c.compiler.exe.release.option.debugging.level.171063916" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
 | 
			
		||||
								<option id="gnu.c.compiler.option.include.paths.1466846915" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths"/>
 | 
			
		||||
								<option id="gnu.c.compiler.option.preprocessor.def.symbols.659261280" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
 | 
			
		||||
									<listOptionValue builtIn="false" value="NDEBUG"/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.892999416" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.977357087" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.1587341853" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1655647987" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
 | 
			
		||||
									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
 | 
			
		||||
									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
 | 
			
		||||
								</inputType>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.721843795" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
 | 
			
		||||
								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.827453761" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
						</toolChain>
 | 
			
		||||
					</folderInfo>
 | 
			
		||||
					<sourceEntries>
 | 
			
		||||
						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
 | 
			
		||||
					</sourceEntries>
 | 
			
		||||
				</configuration>
 | 
			
		||||
			</storageModule>
 | 
			
		||||
			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
 | 
			
		||||
			<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
 | 
			
		||||
			<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
 | 
			
		||||
		</cconfiguration>
 | 
			
		||||
	</storageModule>
 | 
			
		||||
	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
 | 
			
		||||
		<project id="Graph抽象資料結構.cdt.managedbuild.target.gnu.exe.1361850129" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/>
 | 
			
		||||
	</storageModule>
 | 
			
		||||
	<storageModule moduleId="scannerConfiguration">
 | 
			
		||||
		<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
 | 
			
		||||
		<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="specsFile">
 | 
			
		||||
				<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="makefileGenerator">
 | 
			
		||||
				<runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="specsFile">
 | 
			
		||||
				<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="specsFile">
 | 
			
		||||
				<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="specsFile">
 | 
			
		||||
				<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="specsFile">
 | 
			
		||||
				<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/${specs_file}"'" command="sh" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="specsFile">
 | 
			
		||||
				<runAction arguments="-c 'g++ -E -P -v -dD "${plugin_state_location}/specs.cpp"'" command="sh" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
 | 
			
		||||
			<buildOutputProvider>
 | 
			
		||||
				<openAction enabled="true" filePath=""/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</buildOutputProvider>
 | 
			
		||||
			<scannerInfoProvider id="specsFile">
 | 
			
		||||
				<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/specs.c"'" command="sh" useDefault="true"/>
 | 
			
		||||
				<parser enabled="true"/>
 | 
			
		||||
			</scannerInfoProvider>
 | 
			
		||||
		</profile>
 | 
			
		||||
		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1803931088;cdt.managedbuild.config.gnu.exe.debug.1803931088.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1529597285;cdt.managedbuild.tool.gnu.c.compiler.input.24351646">
 | 
			
		||||
			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="makefileGenerator">
 | 
			
		||||
					<runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/${specs_file}"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'g++ -E -P -v -dD "${plugin_state_location}/specs.cpp"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/specs.c"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
		</scannerConfigBuildInfo>
 | 
			
		||||
		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.32754498;cdt.managedbuild.config.gnu.exe.release.32754498.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1473926095;cdt.managedbuild.tool.gnu.cpp.compiler.input.1744095710">
 | 
			
		||||
			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="makefileGenerator">
 | 
			
		||||
					<runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/${specs_file}"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'g++ -E -P -v -dD "${plugin_state_location}/specs.cpp"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/specs.c"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
		</scannerConfigBuildInfo>
 | 
			
		||||
		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1803931088;cdt.managedbuild.config.gnu.exe.debug.1803931088.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1829995894;cdt.managedbuild.tool.gnu.cpp.compiler.input.1791758539">
 | 
			
		||||
			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="makefileGenerator">
 | 
			
		||||
					<runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/${specs_file}"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'g++ -E -P -v -dD "${plugin_state_location}/specs.cpp"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/specs.c"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
		</scannerConfigBuildInfo>
 | 
			
		||||
		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.32754498;cdt.managedbuild.config.gnu.exe.release.32754498.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.478520411;cdt.managedbuild.tool.gnu.c.compiler.input.892999416">
 | 
			
		||||
			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="makefileGenerator">
 | 
			
		||||
					<runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/${specs_file}"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'g++ -E -P -v -dD "${plugin_state_location}/specs.cpp"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
			<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
 | 
			
		||||
				<buildOutputProvider>
 | 
			
		||||
					<openAction enabled="true" filePath=""/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</buildOutputProvider>
 | 
			
		||||
				<scannerInfoProvider id="specsFile">
 | 
			
		||||
					<runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/specs.c"'" command="sh" useDefault="true"/>
 | 
			
		||||
					<parser enabled="true"/>
 | 
			
		||||
				</scannerInfoProvider>
 | 
			
		||||
			</profile>
 | 
			
		||||
		</scannerConfigBuildInfo>
 | 
			
		||||
	</storageModule>
 | 
			
		||||
	<storageModule moduleId="refreshScope"/>
 | 
			
		||||
</cproject>
 | 
			
		||||
@@ -140,6 +140,13 @@ class TestBlob < Test::Unit::TestCase
 | 
			
		||||
    assert !blob("Perl/script.pl").binary?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_all_binary
 | 
			
		||||
    Samples.each do |sample|
 | 
			
		||||
      blob = blob(sample[:path])
 | 
			
		||||
      assert ! (blob.likely_binary? || blob.binary?), "#{sample[:path]} is a binary file"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_text
 | 
			
		||||
    assert blob("Text/README").text?
 | 
			
		||||
    assert blob("Text/dump.sql").text?
 | 
			
		||||
@@ -185,9 +192,9 @@ class TestBlob < Test::Unit::TestCase
 | 
			
		||||
    assert !blob("Text/README").generated?
 | 
			
		||||
 | 
			
		||||
    # Xcode project files
 | 
			
		||||
    assert blob("XML/MainMenu.xib").generated?
 | 
			
		||||
    assert !blob("XML/MainMenu.xib").generated?
 | 
			
		||||
    assert blob("Binary/MainMenu.nib").generated?
 | 
			
		||||
    assert blob("XML/project.pbxproj").generated?
 | 
			
		||||
    assert !blob("XML/project.pbxproj").generated?
 | 
			
		||||
 | 
			
		||||
    # Gemfile.locks
 | 
			
		||||
    assert blob("Gemfile.lock").generated?
 | 
			
		||||
@@ -277,7 +284,7 @@ class TestBlob < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
    # 'thirdparty' directory
 | 
			
		||||
    assert blob("thirdparty/lib/main.c").vendored?
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    # 'extern(al)' directory
 | 
			
		||||
    assert blob("extern/util/__init__.py").vendored?
 | 
			
		||||
    assert blob("external/jquery.min.js").vendored?
 | 
			
		||||
@@ -386,6 +393,12 @@ class TestBlob < Test::Unit::TestCase
 | 
			
		||||
    # NuGet Packages
 | 
			
		||||
    assert blob("packages/Modernizr.2.0.6/Content/Scripts/modernizr-2.0.6-development-only.js").vendored?
 | 
			
		||||
 | 
			
		||||
    # Normalize
 | 
			
		||||
    assert blob("some/asset/path/normalize.css").vendored?
 | 
			
		||||
 | 
			
		||||
    # Cocoapods
 | 
			
		||||
    assert blob('Pods/blah').vendored?
 | 
			
		||||
 | 
			
		||||
    # Html5shiv
 | 
			
		||||
    assert blob("Scripts/html5shiv.js").vendored?
 | 
			
		||||
    assert blob("Scripts/html5shiv.min.js").vendored?
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
require 'linguist/heuristics'
 | 
			
		||||
require 'linguist/language'
 | 
			
		||||
require 'linguist/samples'
 | 
			
		||||
require 'linguist/file_blob'
 | 
			
		||||
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
 | 
			
		||||
@@ -35,7 +36,8 @@ class TestHeuristcs < Test::Unit::TestCase
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_detect_still_works_if_nothing_matches
 | 
			
		||||
    match = Language.detect("Hello.m", fixture("Objective-C/hello.m"))
 | 
			
		||||
    blob = Linguist::FileBlob.new(File.join(samples_path, "Objective-C/hello.m"))
 | 
			
		||||
    match = Language.detect(blob)
 | 
			
		||||
    assert_equal Language["Objective-C"], match
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
 
 | 
			
		||||
@@ -167,7 +167,7 @@ class TestLanguage < Test::Unit::TestCase
 | 
			
		||||
    assert_equal 'pot',           Language['Gettext Catalog'].search_term
 | 
			
		||||
    assert_equal 'irc',           Language['IRC log'].search_term
 | 
			
		||||
    assert_equal 'lhs',           Language['Literate Haskell'].search_term
 | 
			
		||||
    assert_equal 'ruby',          Language['Mirah'].search_term
 | 
			
		||||
    assert_equal 'mirah',         Language['Mirah'].search_term
 | 
			
		||||
    assert_equal 'raw',           Language['Raw token data'].search_term
 | 
			
		||||
    assert_equal 'bash',          Language['Shell'].search_term
 | 
			
		||||
    assert_equal 'vim',           Language['VimL'].search_term
 | 
			
		||||
@@ -249,8 +249,7 @@ class TestLanguage < Test::Unit::TestCase
 | 
			
		||||
    assert_equal Language['Nginx'], Language.find_by_filename('nginx.conf').first
 | 
			
		||||
    assert_equal ['C', 'C++', 'Objective-C'], Language.find_by_filename('foo.h').map(&:name).sort
 | 
			
		||||
    assert_equal [], Language.find_by_filename('rb')
 | 
			
		||||
    assert_equal [], Language.find_by_filename('.rb')
 | 
			
		||||
    assert_equal [], Language.find_by_filename('.nkt')
 | 
			
		||||
    assert_equal [], Language.find_by_filename('.null')
 | 
			
		||||
    assert_equal [Language['Shell']], Language.find_by_filename('.bashrc')
 | 
			
		||||
    assert_equal [Language['Shell']], Language.find_by_filename('bash_profile')
 | 
			
		||||
    assert_equal [Language['Shell']], Language.find_by_filename('.zshrc')
 | 
			
		||||
 
 | 
			
		||||
@@ -3,22 +3,24 @@ require 'linguist/repository'
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
 | 
			
		||||
class TestRepository < Test::Unit::TestCase
 | 
			
		||||
  include Linguist
 | 
			
		||||
 | 
			
		||||
  def repo(base_path)
 | 
			
		||||
    Repository.from_directory(base_path)
 | 
			
		||||
  def rugged_repository
 | 
			
		||||
    @rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def linguist_repo
 | 
			
		||||
    repo(File.expand_path("../..", __FILE__))
 | 
			
		||||
  def master_oid
 | 
			
		||||
    'd40b4a33deba710e2f494db357c654fbe5d4b419'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def linguist_repo(oid = master_oid)
 | 
			
		||||
    Linguist::Repository.new(rugged_repository, oid)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_linguist_language
 | 
			
		||||
    # assert_equal Language['Ruby'], linguist_repo.language
 | 
			
		||||
    assert_equal 'Ruby', linguist_repo.language
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_linguist_languages
 | 
			
		||||
    # assert linguist_repo.languages[Language['Ruby']] > 10_000
 | 
			
		||||
    assert linguist_repo.languages['Ruby'] > 10_000
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_linguist_size
 | 
			
		||||
@@ -31,7 +33,18 @@ class TestRepository < Test::Unit::TestCase
 | 
			
		||||
    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"]
 | 
			
		||||
  def test_incremental_stats
 | 
			
		||||
    old_commit = '3d7364877d6794f6cc2a86b493e893968a597332'
 | 
			
		||||
    old_repo = linguist_repo(old_commit)
 | 
			
		||||
 | 
			
		||||
    assert old_repo.languages['Ruby'] > 10_000
 | 
			
		||||
    assert old_repo.size > 30_000
 | 
			
		||||
 | 
			
		||||
    new_repo = Linguist::Repository.incremental(rugged_repository, master_oid, old_commit, old_repo.cache)
 | 
			
		||||
 | 
			
		||||
    assert new_repo.languages['Ruby'] > old_repo.languages['Ruby']
 | 
			
		||||
    assert new_repo.size > old_repo.size
 | 
			
		||||
 | 
			
		||||
    assert_equal linguist_repo.cache, new_repo.cache
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user