---input--- # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Alexis Laferrière # # 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Matthieu Lucas # # 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Matthieu Lucas # # 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 #include 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 : // _... 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 # 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(":") # 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}? {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}? {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)}" # 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}." # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Matthieu Lucas # # 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 " 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Matthieu Lucas # # 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 = "

Here you can write HTML stuff.

" 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2012-2013 Alexis Laferrière # # 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 ) # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Alexis Laferrière # # 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}" # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2012-2013 Alexis Laferrière # # 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2004-2008 Jean Privat # # 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 " exit 0 end # Main part if args.length != 1 then usage end print args.first.to_i.fibonacci print "hello world" # 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("theNitProgramming Language") 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("
print 'Hello, World!'
") 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("
$ git clone http://nitlanguage.org/nit.git
") add("p").text("Build the compiler (may be long):") add_html("
$ cd nit\n")
					add_html("$ make
") add("p").text("Compile a program:") add_html("
$ bin/nitc examples/hello_world.nit
") add("p").text("Execute the program:") add_html("
$ ./hello_world
") close("section") close("div") close("article") end end var page = new NitHomepage page.write_to stdout page.write_to_file("nit.html") # 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2014 Alexis Laferrière # # 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2004-2008 Jean Privat # # 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2004-2008 Jean Privat # # 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)) # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Matthieu Lucas # # 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 " 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 # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2013 Matthieu Lucas # # 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 " 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 # 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) # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2014 Lucas Bajolet # # 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 ---tokens--- '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Alexis Laferrière ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text 'import' Keyword ' ' Text 'gtk' Name '\n\n' Text 'class' Keyword ' ' Text 'CalculatorContext' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'result' Name ' ' Text ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'Float' Name.Class ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\n\t' Text 'var' Keyword ' ' Text 'last_op' Name ' ' Text ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'Char' Name.Class ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\n\t' Text 'var' Keyword ' ' Text 'current' Name ' ' Text ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'Float' Name.Class ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t' Text 'var' Keyword ' ' Text 'after_point' Name ' ' Text ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'Int' Name.Class ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\n\t' Text 'fun' Keyword ' ' Text 'push_op' Name '(' Punctuation ' ' Text 'op' Name ' ' Text ':' Punctuation ' ' Text 'Char' Name.Class ' ' Text ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'apply_last_op_if_any' Name '\n\t\t' Text 'if' Keyword ' ' Text 'op' Name ' ' Text '==' Operator ' ' Text "'C'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'self' Name '.' Punctuation 'result' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '.0' Literal.Number.Float '\n\t\t\t' Text 'last_op' Name ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t\t' Text 'else' Keyword '\n\t\t\t' Text 'last_op' Name ' ' Text '=' Operator ' ' Text 'op' Name ' ' Text '# store for next push_op' Comment.Single '\n\t\t' Text 'end' Keyword '\n\n\t\t' Text '# prepare next current' Comment.Single '\n\t\t' Text 'after_point' Name ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t\t' Text 'current' Name ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t' Text 'end' Keyword '\n\n\t' Text 'fun' Keyword ' ' Text 'push_digit' Name '(' Punctuation ' ' Text 'digit' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class ' ' Text ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'current' Name ' ' Text '=' Operator ' ' Text 'current' Name '\n\t\t' Text 'if' Keyword ' ' Text 'current' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'current' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '.0' Literal.Number.Float '\n\n\t\t' Text 'var' Keyword ' ' Text 'after_point' Name ' ' Text '=' Operator ' ' Text 'after_point' Name '\n\t\t' Text 'if' Keyword ' ' Text 'after_point' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword '\n\t\t\t' Text 'current' Name ' ' Text '=' Operator ' ' Text 'current' Name ' ' Text '*' Operator ' 10' Literal.Number.Float '.0' Literal.Number.Float ' ' Text '+' Operator ' ' Text 'digit' Name '.' Punctuation 'to_f' Name '\n\t\t' Text 'else' Keyword '\n\t\t\t' Text 'current' Name ' ' Text '=' Operator ' ' Text 'current' Name ' ' Text '+' Operator ' ' Text 'digit' Name '.' Punctuation 'to_f' Name ' ' Text '*' Operator ' 10' Literal.Number.Float '.0' Literal.Number.Float '.' Punctuation 'pow' Name '(' Punctuation 'after_point' Name '.' Punctuation 'to_f' Name ')' Punctuation '\n\t\t\t' Text 'self' Name '.' Punctuation 'after_point' Name ' ' Text '-' Operator '=' Operator ' 1' Literal.Number.Float '\n\t\t' Text 'end' Keyword '\n\n\t\t' Text 'self' Name '.' Punctuation 'current' Name ' ' Text '=' Operator ' ' Text 'current' Name '\n\t' Text 'end' Keyword '\n\n\t' Text 'fun' Keyword ' ' Text 'switch_to_decimals' Name '\n\t' Text 'do' Keyword '\n\t\t' Text 'if' Keyword ' ' Text 'self' Name '.' Punctuation 'current' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'current' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '.0' Literal.Number.Float '\n\t\t' Text 'if' Keyword ' ' Text 'after_point' Name ' ' Text '!=' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'return' Keyword '\n\n\t\t' Text 'after_point' Name ' ' Text '=' Operator ' ' Text '-1' Literal.Number.Float '\n\t' Text 'end' Keyword '\n\n\t' Text 'fun' Keyword ' ' Text 'apply_last_op_if_any' Name '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'op' Name ' ' Text '=' Operator ' ' Text 'last_op' Name '\n\n\t\t' Text 'var' Keyword ' ' Text 'result' Name ' ' Text '=' Operator ' ' Text 'result' Name '\n\t\t' Text 'if' Keyword ' ' Text 'result' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'result' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '.0' Literal.Number.Float '\n\n\t\t' Text 'var' Keyword ' ' Text 'current' Name ' ' Text '=' Operator ' ' Text 'current' Name '\n\t\t' Text 'if' Keyword ' ' Text 'current' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'current' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '.0' Literal.Number.Float '\n\n\t\t' Text 'if' Keyword ' ' Text 'op' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword '\n\t\t\t' Text 'result' Name ' ' Text '=' Operator ' ' Text 'current' Name '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'op' Name ' ' Text '==' Operator ' ' Text "'+'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'result' Name ' ' Text '=' Operator ' ' Text 'result' Name ' ' Text '+' Operator ' ' Text 'current' Name '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'op' Name ' ' Text '==' Operator ' ' Text "'-'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'result' Name ' ' Text '=' Operator ' ' Text 'result' Name ' ' Text '-' Operator ' ' Text 'current' Name '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'op' Name ' ' Text '==' Operator ' ' Text "'/'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'result' Name ' ' Text '=' Operator ' ' Text 'result' Name ' ' Text '/' Operator ' ' Text 'current' Name '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'op' Name ' ' Text '==' Operator ' ' Text "'*'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'result' Name ' ' Text '=' Operator ' ' Text 'result' Name ' ' Text '*' Operator ' ' Text 'current' Name '\n\t\t' Text 'end' Keyword '\n\t\t' Text 'self' Name '.' Punctuation 'result' Name ' ' Text '=' Operator ' ' Text 'result' Name '\n\t\t' Text 'self' Name '.' Punctuation 'current' Name ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'class' Keyword ' ' Text 'CalculatorGui' Name.Class '\n\t' Text 'super' Keyword ' ' Text 'GtkCallable' Name.Class '\n\n\t' Text 'var' Keyword ' ' Text 'win' Name ' ' Text ':' Punctuation ' ' Text 'GtkWindow' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'container' Name ' ' Text ':' Punctuation ' ' Text 'GtkGrid' Name.Class '\n\n\t' Text 'var' Keyword ' ' Text 'lbl_disp' Name ' ' Text ':' Punctuation ' ' Text 'GtkLabel' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'but_eq' Name ' ' Text ':' Punctuation ' ' Text 'GtkButton' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'but_dot' Name ' ' Text ':' Punctuation ' ' Text 'GtkButton' Name.Class '\n\n\t' Text 'var' Keyword ' ' Text 'context' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CalculatorContext' Name.Class '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'signal' Name '(' Punctuation ' ' Text 'sender' Name ',' Punctuation ' ' Text 'user_data' Name ' ' Text ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'after_point' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'after_point' Name '\n\t\t' Text 'if' Keyword ' ' Text 'after_point' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' \n\t\t ' Text 'after_point' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '\n\t\t' Text 'else' Keyword '\n\t\t ' Text 'after_point' Name ' ' Text '=' Operator ' ' Text '(' Punctuation 'after_point' Name '.' Punctuation 'abs' Name ')' Punctuation '\n\t\t' Text 'end' Keyword '\n\t\t\n\t\t' Text 'if' Keyword ' ' Text 'user_data' Name ' ' Text 'isa' Keyword ' ' Text 'Char' Name.Class ' ' Text 'then' Keyword ' ' Text '# is an operation' Comment.Single '\n\t\t\t' Text 'var' Keyword ' ' Text 'c' Name ' ' Text '=' Operator ' ' Text 'user_data' Name '\n\t\t\t' Text 'if' Keyword ' ' Text 'c' Name ' ' Text '==' Operator ' ' Text "'.'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t\t' Text 'but_dot' Name '.' Punctuation 'sensitive' Name '=' Operator ' ' Text 'false' Keyword '\n\t\t\t\t' Text 'context' Name '.' Punctuation 'switch_to_decimals' Name '\n\t\t\t\t' Text 'lbl_disp' Name '.' Punctuation 'text' Name ' ' Text '=' Operator ' ' Text '"{' Literal.String 'context' Name '.' Punctuation 'current' Name '.' Punctuation 'to_i' Name '}."' Literal.String '\n\t\t\t' Text 'else' Keyword '\n\t\t\t\t' Text 'but_dot' Name '.' Punctuation 'sensitive' Name '=' Operator ' ' Text 'true' Keyword '\n\t\t\t\t' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text 'c' Name ' ' Text ')' Punctuation '\n\t\t\t\t\n\t\t\t\t' Text 'var' Keyword ' ' Text 's' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'result' Name '.' Punctuation 'to_precision_native' Name '(6' Literal.Number.Float ')' Punctuation '\n\t\t\t\t' Text 'var' Keyword ' ' Text 'index' Name ' ' Text ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'Int' Name.Class ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t\t\t\t' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text 's' Name '.' Punctuation 'length' Name '.' Punctuation 'times' Name ' ' Text 'do' Keyword '\n\t\t\t\t ' Text 'var' Keyword ' ' Text 'chiffre' Name ' ' Text '=' Operator ' ' Text 's' Name '.' Punctuation 'chars' Name '[' Punctuation 'i' Name ']' Punctuation '\n\t\t\t\t ' Text 'if' Keyword ' ' Text 'chiffre' Name ' ' Text '==' Operator ' ' Text "'0'" Literal.String.Char ' ' Text 'and' Keyword ' ' Text 'index' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword '\n\t\t\t\t\t' Text 'index' Name ' ' Text '=' Operator ' ' Text 'i' Name '\n\t\t\t\t ' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'chiffre' Name ' ' Text '!=' Operator ' ' Text "'0'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t\t\t' Text 'index' Name ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t\t\t\t ' Text 'end' Keyword '\n\t\t\t\t' Text 'end' Keyword '\n\t\t\t\t' Text 'if' Keyword ' ' Text 'index' Name ' ' Text '!=' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword '\n\t\t\t\t\t' Text 's' Name ' ' Text '=' Operator ' ' Text 's' Name '.' Punctuation 'substring' Name '(0' Literal.Number.Float ',' Punctuation ' ' Text 'index' Name ')' Punctuation '\n\t\t\t\t\t' Text 'if' Keyword ' ' Text 's' Name '.' Punctuation 'chars' Name '[' Punctuation 's' Name '.' Punctuation 'length' Name '-1' Literal.Number.Float ']' Punctuation ' ' Text '==' Operator ' ' Text "','" Literal.String.Char ' ' Text 'then' Keyword ' ' Text 's' Name ' ' Text '=' Operator ' ' Text 's' Name '.' Punctuation 'substring' Name '(0' Literal.Number.Float ',' Punctuation ' ' Text 's' Name '.' Punctuation 'length' Name '-1' Literal.Number.Float ')' Punctuation '\n\t\t\t\t' Text 'end' Keyword '\n\t\t\t\t' Text 'lbl_disp' Name '.' Punctuation 'text' Name ' ' Text '=' Operator ' ' Text 's' Name '\n\t\t\t' Text 'end' Keyword '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'user_data' Name ' ' Text 'isa' Keyword ' ' Text 'Int' Name.Class ' ' Text 'then' Keyword ' ' Text '# is a number' Comment.Single '\n\t\t\t' Text 'var' Keyword ' ' Text 'n' Name ' ' Text '=' Operator ' ' Text 'user_data' Name '\n\t\t\t' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' ' Text 'n' Name ' ' Text ')' Punctuation '\n\t\t\t' Text 'lbl_disp' Name '.' Punctuation 'text' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'current' Name '.' Punctuation 'to_precision_native' Name '(' Punctuation 'after_point' Name ')' Punctuation '\n\t\t' Text 'end' Keyword '\n\t' Text 'end' Keyword '\n\n\t' Text 'init' Keyword '\n\t' Text 'do' Keyword '\n\t\t' Text 'init_gtk' Name '\n\n\t\t' Text 'win' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkWindow' Name.Class '(' Punctuation ' 0' Literal.Number.Float ' ' Text ')' Punctuation '\n\n\t\t' Text 'container' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkGrid' Name.Class '(5' Literal.Number.Float ',5' Literal.Number.Float ',' Punctuation 'true' Name ')' Punctuation '\n\t\t' Text 'win' Name '.' Punctuation 'add' Name '(' Punctuation ' ' Text 'container' Name ' ' Text ')' Punctuation '\n\n\t\t' Text 'lbl_disp' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkLabel' Name.Class '(' Punctuation ' ' Text '"_"' Literal.String ' ' Text ')' Punctuation '\n\t\t' Text 'container' Name '.' Punctuation 'attach' Name '(' Punctuation ' ' Text 'lbl_disp' Name ',' Punctuation ' 0' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float ',' Punctuation ' 5' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n\n\t\t' Text '# digits' Comment.Single '\n\t\t' Text 'for' Keyword ' ' Text 'n' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation '9' Literal.Number.Integer ']' Punctuation ' ' Text 'do' Keyword '\n\t\t\t' Text 'var' Keyword ' ' Text 'but' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkButton' Name.Class '.' Punctuation 'with_label' Name '(' Punctuation ' ' Text 'n' Name '.' Punctuation 'to_s' Name ' ' Text ')' Punctuation '\n\t\t\t' Text 'but' Name '.' Punctuation 'request_size' Name '(' Punctuation ' 64' Literal.Number.Float ',' Punctuation ' 64' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t\t' Text 'but' Name '.' Punctuation 'signal_connect' Name '(' Punctuation ' ' Text '"clicked"' Literal.String ',' Punctuation ' ' Text 'self' Name ',' Punctuation ' ' Text 'n' Name ' ' Text ')' Punctuation '\n\t\t\t' Text 'if' Keyword ' ' Text 'n' Name ' ' Text '==' Operator ' 0' Literal.Number.Float ' ' Text 'then' Keyword '\n\t\t\t\t' Text 'container' Name '.' Punctuation 'attach' Name '(' Punctuation ' ' Text 'but' Name ',' Punctuation ' 0' Literal.Number.Float ',' Punctuation ' 4' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t\t' Text 'else' Keyword ' ' Text 'container' Name '.' Punctuation 'attach' Name '(' Punctuation ' ' Text 'but' Name ',' Punctuation ' ' Text '(' Punctuation 'n' Name '-1' Literal.Number.Float ')' Punctuation '%3' Literal.Number.Float ',' Punctuation ' 3' Literal.Number.Float '-' Operator '(' Punctuation 'n' Name '-1' Literal.Number.Float ')' Punctuation '/3' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t' Text 'end' Keyword '\n\n\t\t' Text '# operators' Comment.Single '\n\t\t' Text 'var' Keyword ' ' Text 'r' Name ' ' Text '=' Operator ' 1' Literal.Number.Float '\n\t\t' Text 'for' Keyword ' ' Text 'op' Name ' ' Text 'in' Keyword ' ' Text '[' Punctuation "'+'" Literal.String.Char ',' Punctuation ' ' Text "'-'" Literal.String.Char ',' Punctuation ' ' Text "'*'" Literal.String.Char ',' Punctuation ' ' Text "'/'" Literal.String.Char ' ' Text ']' Punctuation ' ' Text 'do' Keyword '\n\t\t\t' Text 'var' Keyword ' ' Text 'but' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkButton' Name.Class '.' Punctuation 'with_label' Name '(' Punctuation ' ' Text 'op' Name '.' Punctuation 'to_s' Name ' ' Text ')' Punctuation '\n\t\t\t' Text 'but' Name '.' Punctuation 'request_size' Name '(' Punctuation ' 64' Literal.Number.Float ',' Punctuation ' 64' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t\t' Text 'but' Name '.' Punctuation 'signal_connect' Name '(' Punctuation ' ' Text '"clicked"' Literal.String ',' Punctuation ' ' Text 'self' Name ',' Punctuation ' ' Text 'op' Name ' ' Text ')' Punctuation '\n\t\t\t' Text 'container' Name '.' Punctuation 'attach' Name '(' Punctuation ' ' Text 'but' Name ',' Punctuation ' 3' Literal.Number.Float ',' Punctuation ' ' Text 'r' Name ',' Punctuation ' 1' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t\t' Text 'r' Name '+' Operator '=1' Literal.Number.Float '\n\t\t' Text 'end' Keyword '\n\n\t\t' Text '# =' Comment.Single '\n\t\t' Text 'but_eq' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkButton' Name.Class '.' Punctuation 'with_label' Name '(' Punctuation ' ' Text '"="' Literal.String ' ' Text ')' Punctuation '\n\t\t' Text 'but_eq' Name '.' Punctuation 'request_size' Name '(' Punctuation ' 64' Literal.Number.Float ',' Punctuation ' 64' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t' Text 'but_eq' Name '.' Punctuation 'signal_connect' Name '(' Punctuation ' ' Text '"clicked"' Literal.String ',' Punctuation ' ' Text 'self' Name ',' Punctuation ' ' Text "'='" Literal.String.Char ' ' Text ')' Punctuation '\n\t\t' Text 'container' Name '.' Punctuation 'attach' Name '(' Punctuation ' ' Text 'but_eq' Name ',' Punctuation ' 4' Literal.Number.Float ',' Punctuation ' 3' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ',' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n\n\t\t' Text '# .' Comment.Single '\n\t\t' Text 'but_dot' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkButton' Name.Class '.' Punctuation 'with_label' Name '(' Punctuation ' ' Text '"."' Literal.String ' ' Text ')' Punctuation '\n\t\t' Text 'but_dot' Name '.' Punctuation 'request_size' Name '(' Punctuation ' 64' Literal.Number.Float ',' Punctuation ' 64' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t' Text 'but_dot' Name '.' Punctuation 'signal_connect' Name '(' Punctuation ' ' Text '"clicked"' Literal.String ',' Punctuation ' ' Text 'self' Name ',' Punctuation ' ' Text "'.'" Literal.String.Char ' ' Text ')' Punctuation '\n\t\t' Text 'container' Name '.' Punctuation 'attach' Name '(' Punctuation ' ' Text 'but_dot' Name ',' Punctuation ' 1' Literal.Number.Float ',' Punctuation ' 4' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n\n\t\t' Text '#C' Comment.Single '\n\t\t' Text 'var' Keyword ' ' Text 'but_c' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GtkButton' Name.Class '.' Punctuation 'with_label' Name '(' Punctuation ' ' Text '"C"' Literal.String ' ' Text ')' Punctuation '\n\t\t' Text 'but_c' Name '.' Punctuation 'request_size' Name '(' Punctuation ' 64' Literal.Number.Float ',' Punctuation ' 64' Literal.Number.Float ' ' Text ')' Punctuation '\n\t\t' Text 'but_c' Name '.' Punctuation 'signal_connect' Name '(' Punctuation '"clicked"' Literal.String ',' Punctuation ' ' Text 'self' Name ',' Punctuation ' ' Text "'C'" Literal.String.Char ')' Punctuation '\n\t\t' Text 'container' Name '.' Punctuation 'attach' Name '(' Punctuation ' ' Text 'but_c' Name ',' Punctuation ' 2' Literal.Number.Float ',' Punctuation ' 4' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n\n\t\t' Text 'win' Name '.' Punctuation 'show_all' Name '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text '# context tests' Comment.Single '\n' Text 'var' Keyword ' ' Text 'context' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CalculatorContext' Name.Class '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'+'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 3' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'*'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'='" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'var' Keyword ' ' Text 'r' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'result' Name '.' Punctuation 'to_precision' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'r' Name ' ' Text '==' Operator ' ' Text '"30.00"' Literal.String ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'r' Name '\n\n' Text 'context' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CalculatorContext' Name.Class '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 4' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'switch_to_decimals' Name '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'*'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 3' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'='" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'r' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'result' Name '.' Punctuation 'to_precision' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'r' Name ' ' Text '==' Operator ' ' Text '"42.30"' Literal.String ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'r' Name '\n\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'+'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'='" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'r' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'result' Name '.' Punctuation 'to_precision' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'r' Name ' ' Text '==' Operator ' ' Text '"53.30"' Literal.String ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'r' Name '\n\n' Text 'context' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CalculatorContext' Name.Class '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 4' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'switch_to_decimals' Name '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 3' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'/'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 3' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'='" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'r' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'result' Name '.' Punctuation 'to_precision' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'r' Name ' ' Text '==' Operator ' ' Text '"14.10"' Literal.String ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'r' Name '\n\n' Text '#test multiple decimals' Comment.Single '\n' Text 'context' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CalculatorContext' Name.Class '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 5' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 0' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'switch_to_decimals' Name '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 2' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 3' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'+'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'='" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'r' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'result' Name '.' Punctuation 'to_precision' Name '(' Punctuation ' 3' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'r' Name ' ' Text '==' Operator ' ' Text '"51.123"' Literal.String ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'r' Name '\n\n' Text "#test 'C' button" Comment.Single '\n' Text 'context' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CalculatorContext' Name.Class '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 0' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'+'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_digit' Name '(' Punctuation ' 0' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'='" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'context' Name '.' Punctuation 'push_op' Name '(' Punctuation ' ' Text "'C'" Literal.String.Char ' ' Text ')' Punctuation '\n' Text 'r' Name ' ' Text '=' Operator ' ' Text 'context' Name '.' Punctuation 'result' Name '.' Punctuation 'to_precision' Name '(' Punctuation ' 1' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'r' Name ' ' Text '==' Operator ' ' Text '"0.0"' Literal.String ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'r' Name '\n\n' Text '# graphical application' Comment.Single '\n\n' Text 'if' Keyword ' ' Text '"NIT_TESTING"' Literal.String '.' Punctuation 'environ' Name ' ' Text '!=' Operator ' ' Text '"true"' Literal.String ' ' Text 'then' Keyword '\n\t' Text 'var' Keyword ' ' Text 'app' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CalculatorGui' Name.Class '\n\t' Text 'run_gtk' Name '\n' Text 'end' Keyword '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Matthieu Lucas ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# This sample has been implemented to show you how simple is it to play ' Comment.Single '\n' Text '# with native callbacks (C) through an high level with NIT program.' Comment.Single '\n\n' Text 'module' Keyword ' ' Text 'callback_chimpanze' Name '\n' Text 'import' Keyword ' ' Text 'callback_monkey' Name '\n\n' Text 'class' Keyword ' ' Text 'Chimpanze' Name.Class '\n\t' Text 'super' Keyword ' ' Text 'MonkeyActionCallable' Name.Class '\n\n\t' Text 'fun' Keyword ' ' Text 'create' Name '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'monkey' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Monkey' Name.Class '\n\t\t' Text 'print' Name ' ' Text '"Hum, I\'m sleeping ..."' Literal.String '\n\t\t' Text '# Invoking method which will take some time to compute, and ' Comment.Single '\n\t\t' Text '# will be back in wokeUp method with information.' Comment.Single '\n\t\t' Text '# - Callback method defined in MonkeyActionCallable Interface' Comment.Single '\n\t\t' Text 'monkey' Name '.' Punctuation 'wokeUpAction' Name '(' Punctuation 'self' Name ',' Punctuation ' ' Text '"Hey, I\'m awake."' Literal.String ')' Punctuation '\n\t' Text 'end' Keyword '\n\n\t' Text '# Inherit callback method, defined by MonkeyActionCallable interface' Comment.Single '\n\t' Text '# - Back of wokeUpAction method ' Comment.Single '\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'wokeUp' Name '(' Punctuation ' ' Text 'sender' Name ':' Punctuation 'Monkey' Name.Class ',' Punctuation ' ' Text 'message' Name ':' Punctuation 'Object' Name.Class ' ' Text ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'print' Name ' ' Text 'message' Name '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'm' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Chimpanze' Name.Class '\n' Text 'm' Name '.' Punctuation 'create' Name '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Matthieu Lucas ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# This sample has been implemented to show you how simple is it to play ' Comment.Single '\n' Text '# with native callbacks (C) through an high level with NIT program.' Comment.Single '\n\n' Text 'module' Keyword ' ' Text 'callback_monkey' Name '\n\n' Text 'in' Keyword ' ' Text '"C header"' Literal.String ' ' Text '`{\n\t#include \n\t#include \n\n\ttypedef struct { \n\t\tint id;\n\t\tint age;\n\t} CMonkey;\n\n\ttypedef struct {\n\t\tMonkeyActionCallable toCall;\n\t\tObject message;\n\t} MonkeyAction;\n`}' Text '\n\n' Text 'in' Keyword ' ' Text '"C body"' Literal.String ' ' Text '`{\n\t// Method which reproduce a callback answer\n\t// Please note that a function pointer is only used to reproduce the callback\n\tvoid cbMonkey(CMonkey *mkey, void callbackFunc(CMonkey*, MonkeyAction*), MonkeyAction *data)\n\t{\n\t\tsleep(2);\n\t\tcallbackFunc( mkey, data );\n\t}\n\n\t// Back of background treatment, will be redirected to callback function\n\tvoid nit_monkey_callback_func( CMonkey *mkey, MonkeyAction *data )\n\t{\n\t\t// To call a your method, the signature must be written like this :\n\t\t// _...\n\t\tMonkeyActionCallable_wokeUp( data->toCall, mkey, data->message );\n\t}\n`}' Text '\n\n' Text '# Implementable interface to get callback in defined methods' Comment.Single '\n' Text 'interface' Keyword ' ' Text 'MonkeyActionCallable' Name.Class '\n\t' Text 'fun' Keyword ' ' Text 'wokeUp' Name '(' Punctuation ' ' Text 'sender' Name ':' Punctuation 'Monkey' Name.Class ',' Punctuation ' ' Text 'message' Name ':' Punctuation ' ' Text 'Object' Name.Class ')' Punctuation ' ' Text 'is' Keyword ' ' Text 'abstract' Keyword '\n' Text 'end' Keyword '\n\n' Text '# Defining my object type Monkey, which is, in a low level, a pointer to a C struct (CMonkey)' Comment.Single '\n' Text 'extern' Keyword ' ' Text 'class' Keyword ' ' Text 'Monkey' Name.Class ' ' Text '`{ CMonkey * `}' Text '\n\t\n\t' Text 'new' Keyword ' ' Text '`{\n\t\tCMonkey *monkey = malloc( sizeof(CMonkey) );\n\t\tmonkey->age = 10;\n\t\tmonkey->id = 1;\n\t\treturn monkey;\n\t`}' Text '\n\t\n\t' Text '# Object method which will get a callback in wokeUp method, defined in MonkeyActionCallable interface' Comment.Single '\n\t' Text '# Must be defined as Nit/C method because of C call inside' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'wokeUpAction' Name '(' Punctuation ' ' Text 'toCall' Name ':' Punctuation ' ' Text 'MonkeyActionCallable' Name.Class ',' Punctuation ' ' Text 'message' Name ':' Punctuation ' ' Text 'Object' Name.Class ' ' Text ')' Punctuation ' ' Text 'is' Keyword ' ' Text 'extern' Keyword ' ' Text 'import' Keyword ' ' Text 'MonkeyActionCallable' Name.Class '.' Punctuation 'wokeUp' Name ' ' Text '`{\n\n\t\t// Allocating memory to keep reference of received parameters :\n\t\t// - Object receiver\n\t\t// - Message \n\t\tMonkeyAction *data = malloc( sizeof(MonkeyAction) );\n\n\t\t// Incrementing reference counter to prevent from releasing\n\t\tMonkeyActionCallable_incr_ref( toCall );\n\t\tObject_incr_ref( message );\n\t\t\n\t\tdata->toCall = toCall;\n\t\tdata->message = message;\n\t\t\n\t\t// Calling method which reproduce a callback by passing :\n\t\t// - Receiver\n\t\t// - Function pointer to object return method\n\t\t// - Datas\n\t\tcbMonkey( recv, &nit_monkey_callback_func, data );\n\t`}' Text '\n' Text 'end' Keyword '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Implementation of circular lists' Comment.Single '\n' Text '# This example shows the usage of generics and somewhat a specialisation of collections.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'circular_list' Name '\n\n' Text '# Sequences of elements implemented with a double-linked circular list' Comment.Single '\n' Text 'class' Keyword ' ' Text 'CircularList' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\t' Text '# Like standard Array or LinkedList, CircularList is a Sequence.' Comment.Single '\n\t' Text 'super' Keyword ' ' Text 'Sequence' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\n\t' Text '# The first node of the list if any' Comment.Single '\n\t' Text '# The special case of an empty list is handled by a null node' Comment.Single '\n\t' Text 'private' Keyword ' ' Text 'var' Keyword ' ' Text 'node' Name ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'CLNode' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'iterator' Name ' ' Text 'do' Keyword ' ' Text 'return' Keyword ' ' Text 'new' Keyword ' ' Text 'CircularListIterator' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '(' Punctuation 'self' Name ')' Punctuation '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'first' Name ' ' Text 'do' Keyword ' ' Text 'return' Keyword ' ' Text 'self' Name '.' Punctuation 'node' Name '.' Punctuation 'item' Name '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'push' Name '(' Punctuation 'e' Name ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'new_node' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CLNode' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '(' Punctuation 'e' Name ')' Punctuation '\n\t\t' Text 'var' Keyword ' ' Text 'n' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'node' Name '\n\t\t' Text 'if' Keyword ' ' Text 'n' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword '\n\t\t\t' Text '# the first node' Comment.Single '\n\t\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'new_node' Name '\n\t\t' Text 'else' Keyword '\n\t\t\t' Text '# not the first one, so attach nodes correctly.' Comment.Single '\n\t\t\t' Text 'var' Keyword ' ' Text 'old_last_node' Name ' ' Text '=' Operator ' ' Text 'n' Name '.' Punctuation 'prev' Name '\n\t\t\t' Text 'new_node' Name '.' Punctuation 'next' Name ' ' Text '=' Operator ' ' Text 'n' Name '\n\t\t\t' Text 'new_node' Name '.' Punctuation 'prev' Name ' ' Text '=' Operator ' ' Text 'old_last_node' Name '\n\t\t\t' Text 'old_last_node' Name '.' Punctuation 'next' Name ' ' Text '=' Operator ' ' Text 'new_node' Name '\n\t\t\t' Text 'n' Name '.' Punctuation 'prev' Name ' ' Text '=' Operator ' ' Text 'new_node' Name '\n\t\t' Text 'end' Keyword '\n\t' Text 'end' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'pop' Name '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'n' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'node' Name '\n\t\t' Text 'assert' Keyword ' ' Text 'n' Name ' ' Text '!=' Operator ' ' Text 'null' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'prev' Name ' ' Text '=' Operator ' ' Text 'n' Name '.' Punctuation 'prev' Name '\n\t\t' Text 'if' Keyword ' ' Text 'prev' Name ' ' Text '==' Operator ' ' Text 'n' Name ' ' Text 'then' Keyword '\n\t\t\t' Text '# the only node' Comment.Single '\n\t\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text 'n' Name '.' Punctuation 'item' Name '\n\t\t' Text 'end' Keyword '\n\t\t' Text '# not the only one do detach nodes correctly.' Comment.Single '\n\t\t' Text 'var' Keyword ' ' Text 'prev_prev' Name ' ' Text '=' Operator ' ' Text 'prev' Name '.' Punctuation 'prev' Name '\n\t\t' Text 'n' Name '.' Punctuation 'prev' Name ' ' Text '=' Operator ' ' Text 'prev_prev' Name '\n\t\t' Text 'prev_prev' Name '.' Punctuation 'next' Name ' ' Text '=' Operator ' ' Text 'n' Name '\n\t\t' Text 'return' Keyword ' ' Text 'prev' Name '.' Punctuation 'item' Name '\n\t' Text 'end' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'unshift' Name '(' Punctuation 'e' Name ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text '# Circularity has benefits.' Comment.Single '\n\t\t' Text 'push' Name '(' Punctuation 'e' Name ')' Punctuation '\n\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'node' Name '.' Punctuation 'prev' Name '\n\t' Text 'end' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'shift' Name '\n\t' Text 'do' Keyword '\n\t\t' Text '# Circularity has benefits.' Comment.Single '\n\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'node' Name '.' Punctuation 'next' Name '\n\t\t' Text 'return' Keyword ' ' Text 'self' Name '.' Punctuation 'pop' Name '\n\t' Text 'end' Keyword '\n\n\t' Text '# Move the first at the last position, the second at the first, etc.' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'rotate' Name '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'n' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'node' Name '\n\t\t' Text 'if' Keyword ' ' Text 'n' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'return' Keyword '\n\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'n' Name '.' Punctuation 'next' Name '\n\t' Text 'end' Keyword '\n\n\t' Text '# Sort the list using the Josephus algorithm.' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'josephus' Name '(' Punctuation 'step' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'res' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CircularList' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\t\t' Text 'while' Keyword ' ' Text 'not' Keyword ' ' Text 'self' Name '.' Punctuation 'is_empty' Name ' ' Text 'do' Keyword '\n\t\t\t' Text "# count 'step'" Comment.Single '\n\t\t\t' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text '[1' Literal.Number.Float '..' Punctuation 'step' Name '[' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'rotate' Name '\n\t\t\t' Text '# kill' Comment.Single '\n\t\t\t' Text 'var' Keyword ' ' Text 'x' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'shift' Name '\n\t\t\t' Text 'res' Name '.' Punctuation 'add' Name '(' Punctuation 'x' Name ')' Punctuation '\n\t\t' Text 'end' Keyword '\n\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'res' Name '.' Punctuation 'node' Name '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text '# Nodes of a CircularList' Comment.Single '\n' Text 'private' Keyword ' ' Text 'class' Keyword ' ' Text 'CLNode' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\t' Text '# The current item' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'item' Name ':' Punctuation ' ' Text 'E' Name.Class '\n\n\t' Text '# The next item in the circular list.' Comment.Single '\n\t' Text '# Because of circularity, there is always a next;' Comment.Single '\n\t' Text '# so by default let it be self' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'next' Name ':' Punctuation ' ' Text 'CLNode' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation ' ' Text '=' Operator ' ' Text 'self' Keyword '\n\n\t' Text '# The previous item in the circular list.' Comment.Single '\n\t' Text '# Coherence between next and previous nodes has to be maintained by the' Comment.Single '\n\t' Text '# circular list.' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'prev' Name ':' Punctuation ' ' Text 'CLNode' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation ' ' Text '=' Operator ' ' Text 'self' Keyword '\n' Text 'end' Keyword '\n\n' Text '# An iterator of a CircularList.' Comment.Single '\n' Text 'private' Keyword ' ' Text 'class' Keyword ' ' Text 'CircularListIterator' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\t' Text 'super' Keyword ' ' Text 'IndexedIterator' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\n\t' Text 'redef' Keyword ' ' Text 'var' Keyword ' ' Text 'index' Name ':' Punctuation ' ' Text 'Int' Name.Class '\n\n\t' Text '# The current node pointed.' Comment.Single '\n\t' Text '# Is null if the list is empty.' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'node' Name ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'CLNode' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\n\t' Text '# The list iterated.' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'list' Name ':' Punctuation ' ' Text 'CircularList' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'is_ok' Name '\n\t' Text 'do' Keyword '\n\t\t' Text '# Empty lists are not OK.' Comment.Single '\n\t\t' Text '# Pointing again the first node is not OK.' Comment.Single '\n\t\t' Text 'return' Keyword ' ' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '!=' Operator ' ' Text 'null' Keyword ' ' Text 'and' Keyword ' ' Text '(' Punctuation 'self' Name '.' Punctuation 'index' Name ' ' Text '==' Operator ' 0' Literal.Number.Float ' ' Text 'or' Keyword ' ' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '!=' Operator ' ' Text 'self' Name '.' Punctuation 'list' Name '.' Punctuation 'node' Name ')' Punctuation '\n\t' Text 'end' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'next' Name '\n\t' Text 'do' Keyword '\n\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'node' Name '.' Punctuation 'next' Name '\n\t\t' Text 'self' Name '.' Punctuation 'index' Name ' ' Text '+' Operator '=' Operator ' 1' Literal.Number.Float '\n\t' Text 'end' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'item' Name ' ' Text 'do' Keyword ' ' Text 'return' Keyword ' ' Text 'self' Name '.' Punctuation 'node' Name '.' Punctuation 'item' Name '\n\n\t' Text 'init' Keyword '(' Punctuation 'list' Name ':' Punctuation ' ' Text 'CircularList' Name.Class '[' Punctuation 'E' Name.Class ']' Punctuation ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'self' Name '.' Punctuation 'node' Name ' ' Text '=' Operator ' ' Text 'list' Name '.' Punctuation 'node' Name '\n\t\t' Text 'self' Name '.' Punctuation 'list' Name ' ' Text '=' Operator ' ' Text 'list' Name '\n\t\t' Text 'self' Name '.' Punctuation 'index' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'i' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CircularList' Name.Class '[' Punctuation 'Int' Name.Class ']' Punctuation '\n' Text 'i' Name '.' Punctuation 'add_all' Name '(' Punctuation '[1' Literal.Number.Float ',' Punctuation ' 2' Literal.Number.Float ',' Punctuation ' 3' Literal.Number.Float ',' Punctuation ' 4' Literal.Number.Float ',' Punctuation ' 5' Literal.Number.Float ',' Punctuation ' 6' Literal.Number.Float ',' Punctuation ' 7' Literal.Number.Float ']' Punctuation ')' Punctuation '\n' Text 'print' Name ' ' Text 'i' Name '.' Punctuation 'first' Name '\n' Text 'print' Name ' ' Text 'i' Name '.' Punctuation 'join' Name '(' Punctuation '":"' Literal.String ')' Punctuation '\n\n' Text 'i' Name '.' Punctuation 'push' Name '(8' Literal.Number.Float ')' Punctuation '\n' Text 'print' Name ' ' Text 'i' Name '.' Punctuation 'shift' Name '\n' Text 'print' Name ' ' Text 'i' Name '.' Punctuation 'pop' Name '\n' Text 'i' Name '.' Punctuation 'unshift' Name '(0' Literal.Number.Float ')' Punctuation '\n' Text 'print' Name ' ' Text 'i' Name '.' Punctuation 'join' Name '(' Punctuation '":"' Literal.String ')' Punctuation '\n\n' Text 'i' Name '.' Punctuation 'josephus' Name '(3' Literal.Number.Float ')' Punctuation '\n' Text 'print' Name ' ' Text 'i' Name '.' Punctuation 'join' Name '(' Punctuation '":"' Literal.String ')' Punctuation '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# This module beef up the clock module by allowing a clock to be comparable.' Comment.Single '\n' Text '# It show the usage of class refinement' Comment.Single '\n' Text 'module' Keyword ' ' Text 'clock_more' Name '\n\n' Text 'import' Keyword ' ' Text 'clock' Name '\n\n' Text 'redef' Keyword ' ' Text 'class' Keyword ' ' Text 'Clock' Name.Class '\n\t' Text '# Clock are now comparable' Comment.Single '\n\t' Text 'super' Keyword ' ' Text 'Comparable' Name.Class '\n\n\t' Text '# Comparaison of a clock make only sense with an other clock' Comment.Single '\n\t' Text 'redef' Keyword ' ' Text 'type' Keyword ' ' Text 'OTHER' Name.Class ':' Punctuation ' ' Text 'Clock' Name.Class '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text '<' Operator '(' Punctuation 'o' Name ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text '# Note: < is the only abstract method of Comparable.' Comment.Single '\n\t\t' Text '# All other operators and methods rely on < and ==.' Comment.Single '\n\t\t' Text 'return' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '<' Operator ' ' Text 'o' Name '.' Punctuation 'total_minutes' Name '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'c1' Literal.Number.Float ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Clock' Name.Class '(8' Literal.Number.Float ',' Punctuation ' 12' Literal.Number.Float ')' Punctuation '\n' Text 'var' Keyword ' ' Text 'c2' Literal.Number.Float ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Clock' Name.Class '(8' Literal.Number.Float ',' Punctuation ' 13' Literal.Number.Float ')' Punctuation '\n' Text 'var' Keyword ' ' Text 'c3' Literal.Number.Float ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Clock' Name.Class '(9' Literal.Number.Float ',' Punctuation ' 13' Literal.Number.Float ')' Punctuation '\n\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}<{' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '<' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}<={' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '<=' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}>{' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '>' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}>={' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '>=' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}<=>{' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '<=' Operator '>' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '},{' Literal.String 'c2' Literal.Number.Float '}? max={' Literal.String 'c1' Literal.Number.Float '.' Punctuation 'max' Name '(' Punctuation 'c2' Literal.Number.Float ')' Punctuation '} min={' Literal.String 'c1' Literal.Number.Float '.' Punctuation 'min' Name '(' Punctuation 'c2' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}.is_between({' Literal.String 'c2' Literal.Number.Float '}, {' Literal.String 'c3' Literal.Number.Float '})? {' Literal.String 'c1' Literal.Number.Float '.' Punctuation 'is_between' Name '(' Punctuation 'c2' Literal.Number.Float ',' Punctuation ' ' Text 'c3' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c2' Literal.Number.Float '}.is_between({' Literal.String 'c1' Literal.Number.Float '}, {' Literal.String 'c3' Literal.Number.Float '})? {' Literal.String 'c2' Literal.Number.Float '.' Punctuation 'is_between' Name '(' Punctuation 'c1' Literal.Number.Float ',' Punctuation ' ' Text 'c3' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n\n' Text 'print' Name ' ' Text '"-"' Literal.String '\n\n' Text 'c1' Literal.Number.Float '.' Punctuation 'minutes' Name ' ' Text '+' Operator '=' Operator ' 1' Literal.Number.Float '\n\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}<{' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '<' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}<={' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '<=' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}>{' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '>' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}>={' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '>=' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}<=>{' Literal.String 'c2' Literal.Number.Float '}? {' Literal.String 'c1' Literal.Number.Float '<=' Operator '>' Operator 'c2' Literal.Number.Float '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '},{' Literal.String 'c2' Literal.Number.Float '}? max={' Literal.String 'c1' Literal.Number.Float '.' Punctuation 'max' Name '(' Punctuation 'c2' Literal.Number.Float ')' Punctuation '} min={' Literal.String 'c1' Literal.Number.Float '.' Punctuation 'min' Name '(' Punctuation 'c2' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c1' Literal.Number.Float '}.is_between({' Literal.String 'c2' Literal.Number.Float '}, {' Literal.String 'c3' Literal.Number.Float '})? {' Literal.String 'c1' Literal.Number.Float '.' Punctuation 'is_between' Name '(' Punctuation 'c2' Literal.Number.Float ',' Punctuation ' ' Text 'c3' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n' Text 'print' Name ' ' Text '"{' Literal.String 'c2' Literal.Number.Float '}.is_between({' Literal.String 'c1' Literal.Number.Float '}, {' Literal.String 'c3' Literal.Number.Float '})? {' Literal.String 'c2' Literal.Number.Float '.' Punctuation 'is_between' Name '(' Punctuation 'c1' Literal.Number.Float ',' Punctuation ' ' Text 'c3' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# This module provide a simple wall clock.' Comment.Single '\n' Text '# It is an example of getters and setters.' Comment.Single '\n' Text '# A beefed-up module is available in clock_more' Comment.Single '\n' Text 'module' Keyword ' ' Text 'clock' Name '\n\n' Text '# A simple wall clock with 60 minutes and 12 hours.' Comment.Single '\n' Text 'class' Keyword ' ' Text 'Clock' Name.Class '\n\t' Text '# total number of minutes from 0 to 719' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'total_minutes' Name ':' Punctuation ' ' Text 'Int' Name.Class '\n\t' Text '# Note: only the read acces is public, the write access is private.' Comment.Single '\n\n\t' Text '# number of minutes in the current hour (from 0 to 59)' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'minutes' Name ':' Punctuation ' ' Text 'Int' Name.Class ' ' Text 'do' Keyword ' ' Text 'return' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '%' Operator ' 60' Literal.Number.Float '\n\t\n\t' Text '# set the number of minutes in the current hour.' Comment.Single '\n\t' Text '# if m < 0 or m >= 60, the hour will be changed accordinlgy' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'minutes' Name '=' Operator '(' Punctuation 'm' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'hours' Name ' ' Text '*' Operator ' 60' Literal.Number.Float ' ' Text '+' Operator ' ' Text 'm' Name '\n\n\t' Text '# number of hours (from 0 to 11)' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'hours' Name ':' Punctuation ' ' Text 'Int' Name.Class ' ' Text 'do' Keyword ' ' Text 'return' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '/' Operator ' 60' Literal.Number.Float '\n\n\t' Text '# set the number of hours' Comment.Single '\n\t' Text '# the minutes will not be updated' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'hours' Name '=' Operator '(' Punctuation 'h' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '=' Operator ' ' Text 'h' Name ' ' Text '*' Operator ' 60' Literal.Number.Float ' ' Text '+' Operator ' ' Text 'minutes' Name '\n\n\t' Text '# the position of the hour arrow in the [0..60[ interval' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'hour_pos' Name ':' Punctuation ' ' Text 'Int' Name.Class ' ' Text 'do' Keyword ' ' Text 'return' Keyword ' ' Text 'total_minutes' Name ' ' Text '/' Operator ' 12' Literal.Number.Float '\n\n\t' Text '# replace the arrow of hours (from 0 to 59).' Comment.Single '\n\t' Text '# the hours and the minutes will be updated.' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'hour_pos' Name '=' Operator '(' Punctuation 'h' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '=' Operator ' ' Text 'h' Name ' ' Text '*' Operator ' 12' Literal.Number.Float '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'to_s' Name ' ' Text 'do' Keyword ' ' Text 'return' Keyword ' ' Text '"{' Literal.String 'hours' Name '}:{' Literal.String 'minutes' Name '}"' Literal.String '\n\n\t' Text 'fun' Keyword ' ' Text 'reset' Name '(' Punctuation 'hours' Name ',' Punctuation ' ' Text 'minutes' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '=' Operator ' ' Text 'hours' Name '*60' Literal.Number.Float ' ' Text '+' Operator ' ' Text 'minutes' Name '\n\n\t' Text 'init' Keyword '(' Punctuation 'hours' Name ',' Punctuation ' ' Text 'minutes' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'reset' Name '(' Punctuation 'hours' Name ',' Punctuation ' ' Text 'minutes' Name ')' Punctuation '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text '==' Operator '(' Punctuation 'o' Name ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text '# Note: o is a nullable Object, a type test is required' Comment.Single '\n\t\t' Text '# Thanks to adaptive typing, there is no downcast' Comment.Single '\n\t\t' Text '# i.e. the code is safe!' Comment.Single '\n\t\t' Text 'return' Keyword ' ' Text 'o' Name ' ' Text 'isa' Keyword ' ' Text 'Clock' Name.Class ' ' Text 'and' Keyword ' ' Text 'self' Name '.' Punctuation 'total_minutes' Name ' ' Text '==' Operator ' ' Text 'o' Name '.' Punctuation 'total_minutes' Name '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'c' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Clock' Name.Class '(10' Literal.Number.Float ',50' Literal.Number.Float ')' Punctuation '\n' Text 'print' Name ' ' Text '"It\'s {' Literal.String 'c' Name '} o\'clock."' Literal.String '\n\n' Text 'c' Name '.' Punctuation 'minutes' Name ' ' Text '+' Operator '=' Operator ' 22' Literal.Number.Float '\n' Text 'print' Name ' ' Text '"Now it\'s {' Literal.String 'c' Name '} o\'clock."' Literal.String '\n\n' Text 'print' Name ' ' Text '"The short arrow in on the {' Literal.String 'c' Name '.' Punctuation 'hour_pos' Name '/5' Literal.Number.Float '} and the long arrow in on the {' Literal.String 'c' Name '.' Punctuation 'minutes' Name '/5' Literal.Number.Float '}."' Literal.String '\n\n' Text 'c' Name '.' Punctuation 'hours' Name ' ' Text '-' Operator '=' Operator ' 2' Literal.Number.Float '\n' Text 'print' Name ' ' Text '"Now it\'s {' Literal.String 'c' Name '} o\'clock."' Literal.String '\n\n' Text 'var' Keyword ' ' Text 'c2' Literal.Number.Float ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Clock' Name.Class '(9' Literal.Number.Float ',' Punctuation ' 11' Literal.Number.Float ')' Punctuation '\n' Text 'print' Name ' ' Text '"It\'s {' Literal.String 'c2' Literal.Number.Float '} on the second clock."' Literal.String '\n' Text 'print' Name ' ' Text '"The two clocks are synchronized: {' Literal.String 'c' Name ' ' Text '==' Operator ' ' Text 'c2' Literal.Number.Float '}."' Literal.String '\n' Text 'c2' Literal.Number.Float '.' Punctuation 'minutes' Name ' ' Text '+' Operator '=' Operator ' 1' Literal.Number.Float '\n' Text 'print' Name ' ' Text '"It\'s now {' Literal.String 'c2' Literal.Number.Float '} on the second clock."' Literal.String '\n' Text 'print' Name ' ' Text '"The two clocks are synchronized: {' Literal.String 'c' Name ' ' Text '==' Operator ' ' Text 'c2' Literal.Number.Float '}."' Literal.String '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Matthieu Lucas ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Sample of the Curl module.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'curl_http' Name '\n\n' Text 'import' Keyword ' ' Text 'curl' Name '\n\n' Text '# Small class to represent an Http Fetcher' Comment.Single '\n' Text 'class' Keyword ' ' Text 'MyHttpFetcher' Name.Class '\n\t' Text 'super' Keyword ' ' Text 'CurlCallbacks' Name.Class '\n\n\t' Text 'var' Keyword ' ' Text 'curl' Name ':' Punctuation ' ' Text 'Curl' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'our_body' Name ':' Punctuation ' ' Text 'String' Name.Class ' ' Text '=' Operator ' ' Text '""' Literal.String '\n\n\t' Text 'init' Keyword '(' Punctuation 'curl' Name ':' Punctuation ' ' Text 'Curl' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'curl' Name ' ' Text '=' Operator ' ' Text 'curl' Name '\n\n\t' Text '# Release curl object' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'destroy' Name ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'curl' Name '.' Punctuation 'destroy' Name '\n\n\t' Text '# Header callback' Comment.Single '\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'header_callback' Name '(' Punctuation 'line' Name ':' Punctuation ' ' Text 'String' Name.Class ')' Punctuation ' ' Text 'do' Keyword '\n\t\t' Text '# We keep this callback silent for testing purposes' Comment.Single '\n\t\t' Text '#if not line.has_prefix("Date:") then print "Header_callback : {line}"' Comment.Single '\n\t' Text 'end' Keyword '\n\n\t' Text '# Body callback' Comment.Single '\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'body_callback' Name '(' Punctuation 'line' Name ':' Punctuation ' ' Text 'String' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'self' Name '.' Punctuation 'our_body' Name ' ' Text '=' Operator ' ' Text '"{' Literal.String 'self' Name '.' Punctuation 'our_body' Name '}{' Literal.String 'line' Name '}"' Literal.String '\n\n\t' Text '# Stream callback - Cf : No one is registered' Comment.Single '\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'stream_callback' Name '(' Punctuation 'buffer' Name ':' Punctuation ' ' Text 'String' Name.Class ',' Punctuation ' ' Text 'size' Name ':' Punctuation ' ' Text 'Int' Name.Class ',' Punctuation ' ' Text 'count' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ' ' Text 'do' Keyword ' ' Text 'print' Name ' ' Text '"Stream_callback : {' Literal.String 'buffer' Name '} - {' Literal.String 'size' Name '} - {' Literal.String 'count' Name '}"' Literal.String '\n' Text 'end' Keyword '\n\n\n' Text '# Program' Comment.Single '\n' Text 'if' Keyword ' ' Text 'args' Name '.' Punctuation 'length' Name ' ' Text '<' Operator ' 2' Literal.Number.Float ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Usage: curl_http "' Literal.String '\n' Text 'else' Keyword '\n\t' Text 'var' Keyword ' ' Text 'curl' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Curl' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'url' Name ' ' Text '=' Operator ' ' Text 'args' Name '[1' Literal.Number.Float ']' Punctuation '\n\t' Text 'var' Keyword ' ' Text 'request' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CurlHTTPRequest' Name.Class '(' Punctuation 'url' Name ',' Punctuation ' ' Text 'curl' Name ')' Punctuation '\n\n\t' Text '# HTTP Get Request' Comment.Single '\n\t' Text 'if' Keyword ' ' Text 'args' Name '[0' Literal.Number.Float ']' Punctuation ' ' Text '==' Operator ' ' Text '"GET"' Literal.String ' ' Text 'then' Keyword '\n\t\t' Text 'request' Name '.' Punctuation 'verbose' Name ' ' Text '=' Operator ' ' Text 'false' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'getResponse' Name ' ' Text '=' Operator ' ' Text 'request' Name '.' Punctuation 'execute' Name '\n\n\t\t' Text 'if' Keyword ' ' Text 'getResponse' Name ' ' Text 'isa' Keyword ' ' Text 'CurlResponseSuccess' Name.Class ' ' Text 'then' Keyword '\n\t\t\t' Text 'print' Name ' ' Text '"Status code : {' Literal.String 'getResponse' Name '.' Punctuation 'status_code' Name '}"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Body : {' Literal.String 'getResponse' Name '.' Punctuation 'body_str' Name '}"' Literal.String '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'getResponse' Name ' ' Text 'isa' Keyword ' ' Text 'CurlResponseFailed' Name.Class ' ' Text 'then' Keyword '\n\t\t\t' Text 'print' Name ' ' Text '"Error code : {' Literal.String 'getResponse' Name '.' Punctuation 'error_code' Name '}"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Error msg : {' Literal.String 'getResponse' Name '.' Punctuation 'error_msg' Name '}"' Literal.String '\n\t\t' Text 'end' Keyword '\n\n\t' Text '# HTTP Post Request' Comment.Single '\n\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'args' Name '[0' Literal.Number.Float ']' Punctuation ' ' Text '==' Operator ' ' Text '"POST"' Literal.String ' ' Text 'then' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'myHttpFetcher' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'MyHttpFetcher' Name.Class '(' Punctuation 'curl' Name ')' Punctuation '\n\t\t' Text 'request' Name '.' Punctuation 'delegate' Name ' ' Text '=' Operator ' ' Text 'myHttpFetcher' Name '\n\n\t\t' Text 'var' Keyword ' ' Text 'postDatas' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'HeaderMap' Name.Class '\n\t\t' Text 'postDatas' Name '[' Punctuation '"Bugs Bunny"' Literal.String ']' Punctuation ' ' Text '=' Operator ' ' Text '"Daffy Duck"' Literal.String '\n\t\t' Text 'postDatas' Name '[' Punctuation '"Batman"' Literal.String ']' Punctuation ' ' Text '=' Operator ' ' Text '"Robin likes special characters @#ùà!è§\'(\\"é&://,;<>∞~*"' Literal.String '\n\t\t' Text 'postDatas' Name '[' Punctuation '"Batman"' Literal.String ']' Punctuation ' ' Text '=' Operator ' ' Text '"Yes you can set multiple identical keys, but APACHE will consider only once, the last one"' Literal.String '\n\t\t' Text 'request' Name '.' Punctuation 'datas' Name ' ' Text '=' Operator ' ' Text 'postDatas' Name '\n\t\t' Text 'request' Name '.' Punctuation 'verbose' Name ' ' Text '=' Operator ' ' Text 'false' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'postResponse' Name ' ' Text '=' Operator ' ' Text 'request' Name '.' Punctuation 'execute' Name '\n\n\t\t' Text 'print' Name ' ' Text '"Our body from the callback : {' Literal.String 'myHttpFetcher' Name '.' Punctuation 'our_body' Name '}"' Literal.String '\n\n\t\t' Text 'if' Keyword ' ' Text 'postResponse' Name ' ' Text 'isa' Keyword ' ' Text 'CurlResponseSuccess' Name.Class ' ' Text 'then' Keyword '\n\t\t\t' Text 'print' Name ' ' Text '"*** Answer ***"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Status code : {' Literal.String 'postResponse' Name '.' Punctuation 'status_code' Name '}"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Body should be empty, because we decided to manage callbacks : {' Literal.String 'postResponse' Name '.' Punctuation 'body_str' Name '.' Punctuation 'length' Name '}"' Literal.String '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'postResponse' Name ' ' Text 'isa' Keyword ' ' Text 'CurlResponseFailed' Name.Class ' ' Text 'then' Keyword '\n\t\t\t' Text 'print' Name ' ' Text '"Error code : {' Literal.String 'postResponse' Name '.' Punctuation 'error_code' Name '}"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Error msg : {' Literal.String 'postResponse' Name '.' Punctuation 'error_msg' Name '}"' Literal.String '\n\t\t' Text 'end' Keyword '\n\n\t' Text '# HTTP Get to file Request' Comment.Single '\n\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'args' Name '[0' Literal.Number.Float ']' Punctuation ' ' Text '==' Operator ' ' Text '"GET_FILE"' Literal.String ' ' Text 'then' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'headers' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'HeaderMap' Name.Class '\n\t\t' Text 'headers' Name '[' Punctuation '"Accept"' Literal.String ']' Punctuation ' ' Text '=' Operator ' ' Text '"Moo"' Literal.String '\n\t\t' Text 'request' Name '.' Punctuation 'headers' Name ' ' Text '=' Operator ' ' Text 'headers' Name '\n\t\t' Text 'request' Name '.' Punctuation 'verbose' Name ' ' Text '=' Operator ' ' Text 'false' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'downloadResponse' Name ' ' Text '=' Operator ' ' Text 'request' Name '.' Punctuation 'download_to_file' Name '(' Punctuation 'null' Name ')' Punctuation '\n\n\t\t' Text 'if' Keyword ' ' Text 'downloadResponse' Name ' ' Text 'isa' Keyword ' ' Text 'CurlFileResponseSuccess' Name.Class ' ' Text 'then' Keyword '\n\t\t\t' Text 'print' Name ' ' Text '"*** Answer ***"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Status code : {' Literal.String 'downloadResponse' Name '.' Punctuation 'status_code' Name '}"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Size downloaded : {' Literal.String 'downloadResponse' Name '.' Punctuation 'size_download' Name '}"' Literal.String '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'downloadResponse' Name ' ' Text 'isa' Keyword ' ' Text 'CurlResponseFailed' Name.Class ' ' Text 'then' Keyword '\n\t\t\t' Text 'print' Name ' ' Text '"Error code : {' Literal.String 'downloadResponse' Name '.' Punctuation 'error_code' Name '}"' Literal.String '\n\t\t\t' Text 'print' Name ' ' Text '"Error msg : {' Literal.String 'downloadResponse' Name '.' Punctuation 'error_msg' Name '}"' Literal.String '\n\t\t' Text 'end' Keyword '\n\t' Text '# Program logic' Comment.Single '\n\t' Text 'else' Keyword '\n\t\t' Text 'print' Name ' ' Text '"Usage : Method[POST, GET, GET_FILE]"' Literal.String '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Matthieu Lucas ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Mail sender sample using the Curl module' Comment.Single '\n' Text 'module' Keyword ' ' Text 'curl_mail' Name '\n\n' Text 'import' Keyword ' ' Text 'curl' Name '\n\n' Text 'var' Keyword ' ' Text 'curl' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Curl' Name.Class '\n' Text 'var' Keyword ' ' Text 'mail_request' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'CurlMailRequest' Name.Class '(' Punctuation 'curl' Name ')' Punctuation '\n\n' Text '# Networks' Comment.Single '\n' Text 'var' Keyword ' ' Text 'response' Name ' ' Text '=' Operator ' ' Text 'mail_request' Name '.' Punctuation 'set_outgoing_server' Name '(' Punctuation '"smtps://smtp.example.org:465"' Literal.String ',' Punctuation ' ' Text '"user@example.org"' Literal.String ',' Punctuation ' ' Text '"mypassword"' Literal.String ')' Punctuation '\n' Text 'if' Keyword ' ' Text 'response' Name ' ' Text 'isa' Keyword ' ' Text 'CurlResponseFailed' Name.Class ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Error code : {' Literal.String 'response' Name '.' Punctuation 'error_code' Name '}"' Literal.String '\n\t' Text 'print' Name ' ' Text '"Error msg : {' Literal.String 'response' Name '.' Punctuation 'error_msg' Name '}"' Literal.String '\n' Text 'end' Keyword '\n\n' Text '# Headers' Comment.Single '\n' Text 'mail_request' Name '.' Punctuation 'from' Name ' ' Text '=' Operator ' ' Text '"Billy Bob"' Literal.String '\n' Text 'mail_request' Name '.' Punctuation 'to' Name ' ' Text '=' Operator ' ' Text '[' Punctuation '"user@example.org"' Literal.String ']' Punctuation '\n' Text 'mail_request' Name '.' Punctuation 'cc' Name ' ' Text '=' Operator ' ' Text '[' Punctuation '"bob@example.org"' Literal.String ']' Punctuation '\n' Text 'mail_request' Name '.' Punctuation 'bcc' Name ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\n' Text 'var' Keyword ' ' Text 'headers_body' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'HeaderMap' Name.Class '\n' Text 'headers_body' Name '[' Punctuation '"Content-Type:"' Literal.String ']' Punctuation ' ' Text '=' Operator ' ' Text '"text/html; charset=\\"UTF-8\\""' Literal.String '\n' Text 'headers_body' Name '[' Punctuation '"Content-Transfer-Encoding:"' Literal.String ']' Punctuation ' ' Text '=' Operator ' ' Text '"quoted-printable"' Literal.String '\n' Text 'mail_request' Name '.' Punctuation 'headers_body' Name ' ' Text '=' Operator ' ' Text 'headers_body' Name '\n\n' Text '# Content' Comment.Single '\n' Text 'mail_request' Name '.' Punctuation 'body' Name ' ' Text '=' Operator ' ' Text '"

Here you can write HTML stuff.

"' Literal.String '\n' Text 'mail_request' Name '.' Punctuation 'subject' Name ' ' Text '=' Operator ' ' Text '"Hello From My Nit Program"' Literal.String '\n\n' Text '# Others' Comment.Single '\n' Text 'mail_request' Name '.' Punctuation 'verbose' Name ' ' Text '=' Operator ' ' Text 'false' Keyword '\n\n' Text '# Send mail' Comment.Single '\n' Text 'response' Name ' ' Text '=' Operator ' ' Text 'mail_request' Name '.' Punctuation 'execute' Name '\n' Text 'if' Keyword ' ' Text 'response' Name ' ' Text 'isa' Keyword ' ' Text 'CurlResponseFailed' Name.Class ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Error code : {' Literal.String 'response' Name '.' Punctuation 'error_code' Name '}"' Literal.String '\n\t' Text 'print' Name ' ' Text '"Error msg : {' Literal.String 'response' Name '.' Punctuation 'error_msg' Name '}"' Literal.String '\n' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'response' Name ' ' Text 'isa' Keyword ' ' Text 'CurlMailResponseSuccess' Name.Class ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Mail Sent"' Literal.String '\n' Text 'else' Keyword '\n\t' Text 'print' Name ' ' Text '"Unknown Curl Response type"' Literal.String '\n' Text 'end' Keyword '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2012-2013 Alexis Laferrière ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Draws an arithmetic operation to the terminal' Comment.Single '\n' Text 'module' Keyword ' ' Text 'draw_operation' Name '\n\n' Text 'redef' Keyword ' ' Text 'enum' Keyword ' ' Text 'Int' Name.Class '\n\t' Text 'fun' Keyword ' ' Text 'n_chars' Name ':' Punctuation ' ' Text 'Int' Name.Class ' ' Text '`{\n\t\tint c;\n\t\tif ( abs(recv) >= 10 )\n\t\t\tc = 1+(int)log10f( (float)abs(recv) );\n\t\telse\n\t\t\tc = 1;\n\t\tif ( recv < 0 ) c ++;\n\t\treturn c;\n\t`}' Text '\n' Text 'end' Keyword '\n\n' Text 'redef' Keyword ' ' Text 'enum' Keyword ' ' Text 'Char' Name.Class '\n\t' Text 'fun' Keyword ' ' Text 'as_operator' Name '(' Punctuation 'a' Name ',' Punctuation ' ' Text 'b' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ':' Punctuation ' ' Text 'Int' Name.Class '\n\t' Text 'do' Keyword '\n\t\t' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'+'" Literal.String.Char ' ' Text 'then' Keyword ' ' Text 'return' Keyword ' ' Text 'a' Name ' ' Text '+' Operator ' ' Text 'b' Name '\n\t\t' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'-'" Literal.String.Char ' ' Text 'then' Keyword ' ' Text 'return' Keyword ' ' Text 'a' Name ' ' Text '-' Operator ' ' Text 'b' Name '\n\t\t' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'*'" Literal.String.Char ' ' Text 'then' Keyword ' ' Text 'return' Keyword ' ' Text 'a' Name ' ' Text '*' Operator ' ' Text 'b' Name '\n\t\t' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'/'" Literal.String.Char ' ' Text 'then' Keyword ' ' Text 'return' Keyword ' ' Text 'a' Name ' ' Text '/' Operator ' ' Text 'b' Name '\n\t\t' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'%'" Literal.String.Char ' ' Text 'then' Keyword ' ' Text 'return' Keyword ' ' Text 'a' Name ' ' Text '%' Operator ' ' Text 'b' Name '\n\t\t' Text 'abort' Keyword '\n\t' Text 'end' Keyword '\n\n\t' Text 'fun' Keyword ' ' Text 'override_dispc' Name ':' Punctuation ' ' Text 'Bool' Name.Class '\n\t' Text 'do' Keyword '\n\t\t' Text 'return' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'+'" Literal.String.Char ' ' Text 'or' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'-'" Literal.String.Char ' ' Text 'or' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'*'" Literal.String.Char ' ' Text 'or' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'/'" Literal.String.Char ' ' Text 'or' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'%'" Literal.String.Char '\n\t' Text 'end' Keyword '\n\n\t' Text 'fun' Keyword ' ' Text 'lines' Name '(' Punctuation 's' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation ':' Punctuation ' ' Text 'Array' Name.Class '[' Punctuation 'Line' Name.Class ']' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'+'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '/2' Literal.Number.Float ',1' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '-2' Literal.Number.Float ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'-'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'*'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'var' Keyword ' ' Text 'lines' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Array' Name.Class '[' Punctuation 'Line' Name.Class ']' Punctuation '\n\t\t\t' Text 'for' Keyword ' ' Text 'y' Name ' ' Text 'in' Keyword ' ' Text '[1' Literal.Number.Float '..' Punctuation 's' Name '-1' Literal.Number.Float '[' Punctuation ' ' Text 'do' Keyword '\n\t\t\t\t' Text 'lines' Name '.' Punctuation 'add' Name '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(1' Literal.Number.Float ',' Punctuation 'y' Name ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name '-2' Literal.Number.Float ')' Punctuation ' ' Text ')' Punctuation '\n\t\t\t' Text 'end' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text 'lines' Name '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'/'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' ' Text '-1' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation ' ' Text 's' Name ' ' Text ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'%'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'var' Keyword ' ' Text 'q4' Literal.Number.Float ' ' Text '=' Operator ' ' Text 's' Name '/4' Literal.Number.Float '\n\t\t\t' Text 'var' Keyword ' ' Text 'lines' Name ' ' Text '=' Operator ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation '-1' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t\t' Text 'for' Keyword ' ' Text 'l' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'q4' Literal.Number.Float '[' Punctuation ' ' Text 'do' Keyword '\n\t\t\t\t' Text 'lines' Name '.' Punctuation 'append' Name '(' Punctuation '[' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 'l' Name ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 'q4' Literal.Number.Float ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float '-' Operator 'l' Name ')' Punctuation ',' Punctuation ' ' Text '-1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 'q4' Literal.Number.Float ')' Punctuation ' ' Text ']' Punctuation ')' Punctuation '\n\t\t\t' Text 'end' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text 'lines' Name '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'1'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '/2' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '/2' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation '-1' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'2'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'3'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'4'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'5'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'6'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'7'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'var' Keyword ' ' Text 'tl' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation '\n\t\t\t' Text 'var' Keyword ' ' Text 'tr' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'tl' Name ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'tr' Name ',' Punctuation '-1' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'8'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'9'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '/2' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'else' Keyword ' ' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '==' Operator ' ' Text "'0'" Literal.String.Char ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '[' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation 'new' Keyword ' ' Text 'P' Name.Class '(' Punctuation 's' Name '-1' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation '\n\t\t\t\t' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',' Punctuation 's' Name '-1' Literal.Number.Float ')' Punctuation ',1' Literal.Number.Float ',0' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'Line' Name.Class '(' Punctuation ' ' Text 'new' Keyword ' ' Text 'P' Name.Class '(0' Literal.Number.Float ',0' Literal.Number.Float ')' Punctuation ',' Punctuation ' 0' Literal.Number.Float ',1' Literal.Number.Float ',' Punctuation 's' Name ')' Punctuation ']' Punctuation '\n\t\t' Text 'end' Keyword '\n\t\t' Text 'return' Keyword ' ' Text 'new' Keyword ' ' Text 'Array' Name.Class '[' Punctuation 'Line' Name.Class ']' Punctuation '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'class' Keyword ' ' Text 'P' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'x' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'y' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class '\n' Text 'end' Keyword '\n\n' Text 'redef' Keyword ' ' Text 'class' Keyword ' ' Text 'String' Name.Class '\n\t' Text '# hack is to support a bug in the evaluation software' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'draw' Name '(' Punctuation 'dispc' Name ':' Punctuation ' ' Text 'Char' Name.Class ',' Punctuation ' ' Text 'size' Name ',' Punctuation ' ' Text 'gap' Name ':' Punctuation ' ' Text 'Int' Name.Class ',' Punctuation ' ' Text 'hack' Name ':' Punctuation ' ' Text 'Bool' Name.Class ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'w' Name ' ' Text '=' Operator ' ' Text 'size' Name ' ' Text '*' Operator ' ' Text 'length' Name ' ' Text '+' Operator '(' Punctuation 'length' Name '-1' Literal.Number.Float ')' Punctuation '*' Operator 'gap' Name '\n\t\t' Text 'var' Keyword ' ' Text 'h' Name ' ' Text '=' Operator ' ' Text 'size' Name '\n\t\t' Text 'var' Keyword ' ' Text 'map' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Array' Name.Class '[' Punctuation 'Array' Name.Class '[' Punctuation 'Char' Name.Class ']' Punctuation ']' Punctuation '\n\t\t' Text 'for' Keyword ' ' Text 'x' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'w' Name '[' Punctuation ' ' Text 'do' Keyword '\n\t\t\t' Text 'map' Name '[' Punctuation 'x' Name ']' Punctuation ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Array' Name.Class '[' Punctuation 'Char' Name.Class ']' Punctuation '.' Punctuation 'filled_with' Name '(' Punctuation ' ' Text "' '" Literal.String.Char ',' Punctuation ' ' Text 'h' Name ' ' Text ')' Punctuation '\n\t\t' Text 'end' Keyword '\n\n\t\t' Text 'var' Keyword ' ' Text 'ci' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '\n\t\t' Text 'for' Keyword ' ' Text 'c' Name ' ' Text 'in' Keyword ' ' Text 'self' Name '.' Punctuation 'chars' Name ' ' Text 'do' Keyword '\n\t\t\t' Text 'var' Keyword ' ' Text 'local_dispc' Name '\n\t\t\t' Text 'if' Keyword ' ' Text 'c' Name '.' Punctuation 'override_dispc' Name ' ' Text 'then' Keyword '\n\t\t\t\t' Text 'local_dispc' Name ' ' Text '=' Operator ' ' Text 'c' Name '\n\t\t\t' Text 'else' Keyword '\n\t\t\t\t' Text 'local_dispc' Name ' ' Text '=' Operator ' ' Text 'dispc' Name '\n\t\t\t' Text 'end' Keyword '\n\n\t\t\t' Text 'var' Keyword ' ' Text 'lines' Name ' ' Text '=' Operator ' ' Text 'c' Name '.' Punctuation 'lines' Name '(' Punctuation ' ' Text 'size' Name ' ' Text ')' Punctuation '\n\t\t\t' Text 'for' Keyword ' ' Text 'line' Name ' ' Text 'in' Keyword ' ' Text 'lines' Name ' ' Text 'do' Keyword '\n\t\t\t\t' Text 'var' Keyword ' ' Text 'x' Name ' ' Text '=' Operator ' ' Text 'line' Name '.' Punctuation 'o' Name '.' Punctuation 'x' Name '+' Operator 'ci' Name '*' Operator 'size' Name '\n\t\t\t\t\t' Text 'x' Name ' ' Text '+' Operator '=' Operator ' ' Text 'ci' Name '*' Operator 'gap' Name '\n\t\t\t\t' Text 'var' Keyword ' ' Text 'y' Name ' ' Text '=' Operator ' ' Text 'line' Name '.' Punctuation 'o' Name '.' Punctuation 'y' Name '\n\t\t\t\t' Text 'for' Keyword ' ' Text 's' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'line' Name '.' Punctuation 'len' Name '[' Punctuation ' ' Text 'do' Keyword '\n\t\t\t\t\t' Text 'assert' Keyword ' ' Text 'map' Name '.' Punctuation 'length' Name ' ' Text '>' Operator ' ' Text 'x' Name ' ' Text 'and' Keyword ' ' Text 'map' Name '[' Punctuation 'x' Name ']' Punctuation '.' Punctuation 'length' Name ' ' Text '>' Operator ' ' Text 'y' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"setting {' Literal.String 'x' Name '},{' Literal.String 'y' Name '} as {' Literal.String 'local_dispc' Name '}"' Literal.String '\n\t\t\t\t\t' Text 'map' Name '[' Punctuation 'x' Name ']' Punctuation '[' Punctuation 'y' Name ']' Punctuation ' ' Text '=' Operator ' ' Text 'local_dispc' Name '\n\t\t\t\t\t' Text 'x' Name ' ' Text '+' Operator '=' Operator ' ' Text 'line' Name '.' Punctuation 'step_x' Name '\n\t\t\t\t\t' Text 'y' Name ' ' Text '+' Operator '=' Operator ' ' Text 'line' Name '.' Punctuation 'step_y' Name '\n\t\t\t\t' Text 'end' Keyword '\n\t\t\t' Text 'end' Keyword '\n\n\t\t\t' Text 'ci' Name ' ' Text '+' Operator '=' Operator ' 1' Literal.Number.Float '\n\t\t' Text 'end' Keyword '\n\n\t\t' Text 'if' Keyword ' ' Text 'hack' Name ' ' Text 'then' Keyword '\n\t\t\t' Text 'for' Keyword ' ' Text 'c' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'size' Name '[' Punctuation ' ' Text 'do' Keyword '\n\t\t\t\t' Text 'map' Name '[' Punctuation 'c' Name ']' Punctuation '[0' Literal.Number.Float ']' Punctuation ' ' Text '=' Operator ' ' Text 'map' Name '[' Punctuation 'map' Name '.' Punctuation 'length' Name '-' Operator 'size' Name '+' Operator 'c' Name ']' Punctuation '[0' Literal.Number.Float ']' Punctuation '\n\t\t\t\t' Text 'map' Name '[' Punctuation 'map' Name '.' Punctuation 'length' Name '-' Operator 'size' Name '+' Operator 'c' Name ']' Punctuation '[0' Literal.Number.Float ']' Punctuation ' ' Text '=' Operator ' ' Text "' '" Literal.String.Char '\n\t\t\t' Text 'end' Keyword '\n\t\t' Text 'end' Keyword '\n\n\t\t' Text 'for' Keyword ' ' Text 'y' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'h' Name '[' Punctuation ' ' Text 'do' Keyword '\n\t\t\t' Text 'for' Keyword ' ' Text 'x' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'w' Name '[' Punctuation ' ' Text 'do' Keyword '\n\t\t\t\t' Text 'printn' Name ' ' Text 'map' Name '[' Punctuation 'x' Name ']' Punctuation '[' Punctuation 'y' Name ']' Punctuation '\n\t\t\t' Text 'end' Keyword '\n\t\t\t' Text 'print' Name ' ' Text '""' Literal.String '\n\t\t' Text 'end' Keyword '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'class' Keyword ' ' Text 'Line' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'o' Name ' ' Text ':' Punctuation ' ' Text 'P' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'step_x' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'step_y' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class '\n\t' Text 'var' Keyword ' ' Text 'len' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'a' Name '\n' Text 'var' Keyword ' ' Text 'b' Name '\n' Text 'var' Keyword ' ' Text 'op_char' Name '\n' Text 'var' Keyword ' ' Text 'disp_char' Name '\n' Text 'var' Keyword ' ' Text 'disp_size' Name '\n' Text 'var' Keyword ' ' Text 'disp_gap' Name '\n\n' Text 'if' Keyword ' ' Text '"NIT_TESTING"' Literal.String '.' Punctuation 'environ' Name ' ' Text '==' Operator ' ' Text '"true"' Literal.String ' ' Text 'then' Keyword '\n\t' Text 'a' Name ' ' Text '=' Operator ' 567' Literal.Number.Float '\n\t' Text 'b' Name ' ' Text '=' Operator ' 13' Literal.Number.Float '\n\t' Text 'op_char' Name ' ' Text '=' Operator ' ' Text "'*'" Literal.String.Char '\n\t' Text 'disp_char' Name ' ' Text '=' Operator ' ' Text "'O'" Literal.String.Char '\n\t' Text 'disp_size' Name ' ' Text '=' Operator ' 8' Literal.Number.Float '\n\t' Text 'disp_gap' Name ' ' Text '=' Operator ' 1' Literal.Number.Float '\n' Text 'else' Keyword '\n\t' Text 'printn' Name ' ' Text '"Left operand: "' Literal.String '\n\t' Text 'a' Name ' ' Text '=' Operator ' ' Text 'gets' Name '.' Punctuation 'to_i' Name '\n\n\t' Text 'printn' Name ' ' Text '"Right operand: "' Literal.String '\n\t' Text 'b' Name ' ' Text '=' Operator ' ' Text 'gets' Name '.' Punctuation 'to_i' Name '\n\n\t' Text 'printn' Name ' ' Text '"Operator (+, -, *, /, %): "' Literal.String '\n\t' Text 'op_char' Name ' ' Text '=' Operator ' ' Text 'gets' Name '.' Punctuation 'chars' Name '[0' Literal.Number.Float ']' Punctuation '\n\n\t' Text 'printn' Name ' ' Text '"Char to display: "' Literal.String '\n\t' Text 'disp_char' Name ' ' Text '=' Operator ' ' Text 'gets' Name '.' Punctuation 'chars' Name '[0' Literal.Number.Float ']' Punctuation '\n\n\t' Text 'printn' Name ' ' Text '"Size of text: "' Literal.String '\n\t' Text 'disp_size' Name ' ' Text '=' Operator ' ' Text 'gets' Name '.' Punctuation 'to_i' Name '\n\n\t' Text 'printn' Name ' ' Text '"Space between digits: "' Literal.String '\n\t' Text 'disp_gap' Name ' ' Text '=' Operator ' ' Text 'gets' Name '.' Punctuation 'to_i' Name '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'result' Name ' ' Text '=' Operator ' ' Text 'op_char' Name '.' Punctuation 'as_operator' Name '(' Punctuation ' ' Text 'a' Name ',' Punctuation ' ' Text 'b' Name ' ' Text ')' Punctuation '\n\n' Text 'var' Keyword ' ' Text 'len_a' Name ' ' Text '=' Operator ' ' Text 'a' Name '.' Punctuation 'n_chars' Name '\n' Text 'var' Keyword ' ' Text 'len_b' Name ' ' Text '=' Operator ' ' Text 'b' Name '.' Punctuation 'n_chars' Name '\n' Text 'var' Keyword ' ' Text 'len_res' Name ' ' Text '=' Operator ' ' Text 'result' Name '.' Punctuation 'n_chars' Name '\n' Text 'var' Keyword ' ' Text 'max_len' Name ' ' Text '=' Operator ' ' Text 'len_a' Name '.' Punctuation 'max' Name '(' Punctuation ' ' Text 'len_b' Name '.' Punctuation 'max' Name '(' Punctuation ' ' Text 'len_res' Name ' ' Text ')' Punctuation ' ' Text ')' Punctuation ' ' Text '+' Operator ' 1' Literal.Number.Float '\n\n' Text '# draw first line' Comment.Single '\n' Text 'var' Keyword ' ' Text 'd' Name ' ' Text '=' Operator ' ' Text 'max_len' Name ' ' Text '-' Operator ' ' Text 'len_a' Name '\n' Text 'var' Keyword ' ' Text 'line_a' Name ' ' Text '=' Operator ' ' Text '""' Literal.String '\n' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'd' Name '[' Punctuation ' ' Text 'do' Keyword ' ' Text 'line_a' Name ' ' Text '+' Operator '=' Operator ' ' Text '" "' Literal.String '\n' Text 'line_a' Name ' ' Text '+' Operator '=' Operator ' ' Text 'a' Name '.' Punctuation 'to_s' Name '\n' Text 'line_a' Name '.' Punctuation 'draw' Name '(' Punctuation ' ' Text 'disp_char' Name ',' Punctuation ' ' Text 'disp_size' Name ',' Punctuation ' ' Text 'disp_gap' Name ',' Punctuation ' ' Text 'false' Keyword ' ' Text ')' Punctuation '\n\n' Text 'print' Name ' ' Text '""' Literal.String '\n' Text '# draw second line' Comment.Single '\n' Text 'd' Name ' ' Text '=' Operator ' ' Text 'max_len' Name ' ' Text '-' Operator ' ' Text 'len_b' Name '-1' Literal.Number.Float '\n' Text 'var' Keyword ' ' Text 'line_b' Name ' ' Text '=' Operator ' ' Text 'op_char' Name '.' Punctuation 'to_s' Name '\n' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'd' Name '[' Punctuation ' ' Text 'do' Keyword ' ' Text 'line_b' Name ' ' Text '+' Operator '=' Operator ' ' Text '" "' Literal.String '\n' Text 'line_b' Name ' ' Text '+' Operator '=' Operator ' ' Text 'b' Name '.' Punctuation 'to_s' Name '\n' Text 'line_b' Name '.' Punctuation 'draw' Name '(' Punctuation ' ' Text 'disp_char' Name ',' Punctuation ' ' Text 'disp_size' Name ',' Punctuation ' ' Text 'disp_gap' Name ',' Punctuation ' ' Text 'false' Keyword ' ' Text ')' Punctuation '\n\n' Text '# draw -----' Comment.Single '\n' Text 'print' Name ' ' Text '""' Literal.String '\n' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'disp_size' Name '*' Operator 'max_len' Name '+' Operator '(' Punctuation 'max_len' Name '-1' Literal.Number.Float ')' Punctuation '*' Operator 'disp_gap' Name ']' Punctuation ' ' Text 'do' Keyword '\n\t' Text 'printn' Name ' ' Text '"_"' Literal.String '\n' Text 'end' Keyword '\n' Text 'print' Name ' ' Text '""' Literal.String '\n' Text 'print' Name ' ' Text '""' Literal.String '\n\n' Text '# draw result' Comment.Single '\n' Text 'd' Name ' ' Text '=' Operator ' ' Text 'max_len' Name ' ' Text '-' Operator ' ' Text 'len_res' Name '\n' Text 'var' Keyword ' ' Text 'line_res' Name ' ' Text '=' Operator ' ' Text '""' Literal.String '\n' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation 'd' Name '[' Punctuation ' ' Text 'do' Keyword ' ' Text 'line_res' Name ' ' Text '+' Operator '=' Operator ' ' Text '" "' Literal.String '\n' Text 'line_res' Name ' ' Text '+' Operator '=' Operator ' ' Text 'result' Name '.' Punctuation 'to_s' Name '\n' Text 'line_res' Name '.' Punctuation 'draw' Name '(' Punctuation ' ' Text 'disp_char' Name ',' Punctuation ' ' Text 'disp_size' Name ',' Punctuation ' ' Text 'disp_gap' Name ',' Punctuation ' ' Text 'false' Keyword ' ' Text ')' Punctuation '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Alexis Laferrière ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Example using the privileges module to drop privileges from root' Comment.Single '\n' Text 'module' Keyword ' ' Text 'drop_privileges' Name '\n\n' Text 'import' Keyword ' ' Text 'privileges' Name '\n\n' Text '# basic command line options' Comment.Single '\n' Text 'var' Keyword ' ' Text 'opts' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'OptionContext' Name.Class '\n' Text 'var' Keyword ' ' Text 'opt_ug' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'OptionUserAndGroup' Name.Class '.' Punctuation 'for_dropping_privileges' Name '\n' Text 'opt_ug' Name '.' Punctuation 'mandatory' Name ' ' Text '=' Operator ' ' Text 'true' Keyword '\n' Text 'opts' Name '.' Punctuation 'add_option' Name '(' Punctuation 'opt_ug' Name ')' Punctuation '\n\n' Text '# parse and check command line options' Comment.Single '\n' Text 'opts' Name '.' Punctuation 'parse' Name '(' Punctuation 'args' Name ')' Punctuation '\n' Text 'if' Keyword ' ' Text 'not' Keyword ' ' Text 'opts' Name '.' Punctuation 'errors' Name '.' Punctuation 'is_empty' Name ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text 'opts' Name '.' Punctuation 'errors' Name '\n\t' Text 'print' Name ' ' Text '"Usage: drop_privileges [options]"' Literal.String '\n\t' Text 'opts' Name '.' Punctuation 'usage' Name '\n\t' Text 'exit' Name ' 1' Literal.Number.Float '\n' Text 'end' Keyword '\n\n' Text '# original user' Comment.Single '\n' Text 'print' Name ' ' Text '"before {' Literal.String 'sys' Name '.' Punctuation 'uid' Name '}:{' Literal.String 'sys' Name '.' Punctuation 'gid' Name '}"' Literal.String '\n\n' Text '# make the switch' Comment.Single '\n' Text 'var' Keyword ' ' Text 'user_group' Name ' ' Text '=' Operator ' ' Text 'opt_ug' Name '.' Punctuation 'value' Name '\n' Text 'assert' Keyword ' ' Text 'user_group' Name ' ' Text '!=' Operator ' ' Text 'null' Keyword '\n' Text 'user_group' Name '.' Punctuation 'drop_privileges' Name '\n\n' Text '# final user' Comment.Single '\n' Text 'print' Name ' ' Text '"after {' Literal.String 'sys' Name '.' Punctuation 'uid' Name '}:{' Literal.String 'sys' Name '.' Punctuation 'egid' Name '}"' Literal.String '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2012-2013 Alexis Laferrière ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# This module illustrates some uses of the FFI, specifically' Comment.Single '\n' Text '# how to use extern methods. Which means to implement a Nit method in C.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'extern_methods' Name '\n\n' Text 'redef' Keyword ' ' Text 'enum' Keyword ' ' Text 'Int' Name.Class '\n\t' Text "# Returns self'th fibonnaci number" Comment.Single '\n\t' Text '# implemented here in C for optimization purposes' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'fib' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class ' ' Text 'import' Keyword ' ' Text 'fib' Name ' ' Text '`{\n\t\tif ( recv < 2 )\n\t\t\treturn recv;\n\t\telse\n\t\t\treturn Int_fib( recv-1 ) + Int_fib( recv-2 );\n\t`}' Text '\n\n\t' Text '# System call to sleep for "self" seconds' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'sleep' Name ' ' Text '`{\n\t\tsleep( recv );\n\t`}' Text '\n\n\t' Text '# Return atan2l( self, x ) from libmath' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'atan_with' Name '(' Punctuation ' ' Text 'x' Name ' ' Text ':' Punctuation ' ' Text 'Int' Name.Class ' ' Text ')' Punctuation ' ' Text ':' Punctuation ' ' Text 'Float' Name.Class ' ' Text '`{\n\t\treturn atan2( recv, x );\n\t`}' Text '\n\n\t' Text '# This method callback to Nit methods from C code' Comment.Single '\n\t' Text '# It will use from C code:' Comment.Single '\n\t' Text '# * the local fib method' Comment.Single '\n\t' Text '# * the + operator, a method of Int' Comment.Single '\n\t' Text '# * to_s, a method of all objects' Comment.Single '\n\t' Text '# * String.to_cstring, a method of String to return an equivalent char*' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'foo' Name ' ' Text 'import' Keyword ' ' Text 'fib' Name ',' Punctuation ' ' Text '+' Operator ',' Punctuation ' ' Text 'to_s' Name ',' Punctuation ' ' Text 'String' Name.Class '.' Punctuation 'to_cstring' Name ' ' Text '`{\n\t\tlong recv_fib = Int_fib( recv );\n\t\tlong recv_plus_fib = Int__plus( recv, recv_fib );\n\n\t\tString nit_string = Int_to_s( recv_plus_fib );\n\t\tchar *c_string = String_to_cstring( nit_string );\n\n\t\tprintf( "from C: self + fib(self) = %s\\n", c_string );\n\t`}' Text '\n\n\t' Text '# Equivalent to foo but written in pure Nit' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'bar' Name ' ' Text 'do' Keyword ' ' Text 'print' Name ' ' Text '"from Nit: self + fib(self) = {' Literal.String 'self' Name '+' Operator 'self' Name '.' Punctuation 'fib' Name '}"' Literal.String '\n' Text 'end' Keyword '\n\n' Text 'print' Name ' 12' Literal.Number.Float '.' Punctuation 'fib' Name '\n\n' Text 'print' Name ' ' Text '"sleeping 1 second..."' Literal.String '\n' Text '1' Literal.Number.Integer '.' Punctuation 'sleep' Name '\n\n' Text 'print' Name ' 100' Literal.Number.Float '.' Punctuation 'atan_with' Name '(' Punctuation ' 200' Literal.Number.Float ' ' Text ')' Punctuation '\n' Text '8' Literal.Number.Integer '.' Punctuation 'foo' Name '\n' Text '8' Literal.Number.Integer '.' Punctuation 'bar' Name '\n\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2004-2008 Jean Privat ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# A simple exemple of refinement where a method is added to the integer class.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'fibonacci' Name '\n\n' Text 'redef' Keyword ' ' Text 'class' Keyword ' ' Text 'Int' Name.Class '\n\t' Text '# Calculate the self-th element of the fibonacci sequence.' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'fibonacci' Name ':' Punctuation ' ' Text 'Int' Name.Class '\n\t' Text 'do' Keyword '\n\t\t' Text 'if' Keyword ' ' Text 'self' Keyword ' ' Text '<' Operator ' 2' Literal.Number.Float ' ' Text 'then' Keyword '\n\t\t\t' Text 'return' Keyword ' 1' Literal.Number.Float '\n\t\t' Text 'else' Keyword '\n\t\t\t' Text 'return' Keyword ' ' Text '(' Punctuation 'self' Name '-2' Literal.Number.Float ')' Punctuation '.' Punctuation 'fibonacci' Name ' ' Text '+' Operator ' ' Text '(' Punctuation 'self' Name '-1' Literal.Number.Float ')' Punctuation '.' Punctuation 'fibonacci' Name '\n\t\t' Text 'end' Keyword '\n\t' Text 'end' Keyword ' \n' Text 'end' Keyword '\n\n' Text '# Print usage and exit.' Comment.Single '\n' Text 'fun' Keyword ' ' Text 'usage' Name '\n' Text 'do' Keyword '\n\t' Text 'print' Name ' ' Text '"Usage: fibonnaci "' Literal.String ' \n\t' Text 'exit' Name ' 0' Literal.Number.Float ' \n' Text 'end' Keyword '\n\n' Text '# Main part' Comment.Single '\n' Text 'if' Keyword ' ' Text 'args' Name '.' Punctuation 'length' Name ' ' Text '!=' Operator ' 1' Literal.Number.Float ' ' Text 'then' Keyword '\n\t' Text 'usage' Name '\n' Text 'end' Keyword '\n' Text 'print' Name ' ' Text 'args' Name '.' Punctuation 'first' Name '.' Punctuation 'to_i' Name '.' Punctuation 'fibonacci' Name '\n' Text 'print' Name ' ' Text '"hello world"' Literal.String '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text 'import' Keyword ' ' Text 'html' Name '\n\n' Text 'class' Keyword ' ' Text 'NitHomepage' Name.Class '\n\t' Text 'super' Keyword ' ' Text 'HTMLPage' Name.Class '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'head' Name ' ' Text 'do' Keyword '\n\t\t' Text 'add' Name '(' Punctuation '"meta"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"charset"' Literal.String ',' Punctuation ' ' Text '"utf-8"' Literal.String ')' Punctuation '\n\t\t' Text 'add' Name '(' Punctuation '"title"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Nit"' Literal.String ')' Punctuation '\n\t\t' Text 'add' Name '(' Punctuation '"link"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"rel"' Literal.String ',' Punctuation ' ' Text '"icon"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"http://nitlanguage.org/favicon.ico"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"type"' Literal.String ',' Punctuation ' ' Text '"image/x-icon"' Literal.String ')' Punctuation '\n\t\t' Text 'add' Name '(' Punctuation '"link"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"rel"' Literal.String ',' Punctuation ' ' Text '"stylesheet"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"http://nitlanguage.org/style.css"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"type"' Literal.String ',' Punctuation ' ' Text '"text/css"' Literal.String ')' Punctuation '\n\t\t' Text 'add' Name '(' Punctuation '"link"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"rel"' Literal.String ',' Punctuation ' ' Text '"stylesheet"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"http://nitlanguage.org/local.css"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"type"' Literal.String ',' Punctuation ' ' Text '"text/css"' Literal.String ')' Punctuation '\n\t' Text 'end' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'body' Name ' ' Text 'do' Keyword '\n\t\t' Text 'open' Name '(' Punctuation '"article"' Literal.String ')' Punctuation '.' Punctuation 'add_class' Name '(' Punctuation '"page"' Literal.String ')' Punctuation '\n\t\t\t' Text 'open' Name '(' Punctuation '"section"' Literal.String ')' Punctuation '.' Punctuation 'add_class' Name '(' Punctuation '"pageheader"' Literal.String ')' Punctuation '\n\t\t\t\t' Text 'add_html' Name '(' Punctuation '"theNitProgramming Language"' Literal.String ')' Punctuation '\n\t\t\t\t' Text 'open' Name '(' Punctuation '"header"' Literal.String ')' Punctuation '.' Punctuation 'add_class' Name '(' Punctuation '"header"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'open' Name '(' Punctuation '"div"' Literal.String ')' Punctuation '.' Punctuation 'add_class' Name '(' Punctuation '"topsubtitle"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"A Fun Language for Serious Programming"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'close' Name '(' Punctuation '"div"' Literal.String ')' Punctuation '\n\t\t\t\t' Text 'close' Name '(' Punctuation '"header"' Literal.String ')' Punctuation '\n\t\t\t' Text 'close' Name '(' Punctuation '"section"' Literal.String ')' Punctuation '\n\n\t\t\t' Text 'open' Name '(' Punctuation '"div"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"id"' Literal.String ',' Punctuation ' ' Text '"pagebody"' Literal.String ')' Punctuation '\n\t\t\t\t' Text 'open' Name '(' Punctuation '"section"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"id"' Literal.String ',' Punctuation ' ' Text '"content"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"h1"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"# What is Nit?"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"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."' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"So, what does the famous hello world program look like, in Nit?"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add_html' Name '(' Punctuation '"
print \'Hello, World!\'
"' Literal.String ')' Punctuation '\n\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"h1"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"# Feature Highlights"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"h2"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Usability"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Nit\'s goal is to be usable by real programmers for real projects"' Literal.String ')' Punctuation '\n\n\t\t\t\t\t' Text 'open' Name '(' Punctuation '"ul"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'open' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"a"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"http://en.wikipedia.org/wiki/KISS_principle"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"KISS principle"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'close' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Script-like language without verbosity nor cryptic statements"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Painless static types: static typing should help programmers"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Efficient development, efficient execution, efficient evolution."' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'close' Name '(' Punctuation '"ul"' Literal.String ')' Punctuation '\n\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"h2"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Robustness"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Nit will help you to write bug-free programs"' Literal.String ')' Punctuation '\n\n\t\t\t\t\t' Text 'open' Name '(' Punctuation '"ul"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Strong static typing"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"No more NullPointerException"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'close' Name '(' Punctuation '"ul"' Literal.String ')' Punctuation '\n\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"h2"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Object-Oriented"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Nit\'s guideline is to follow the most powerful OO principles"' Literal.String ')' Punctuation '\n\n\t\t\t\t\t' Text 'open' Name '(' Punctuation '"ul"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'open' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"a"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"./everything_is_an_object/"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Everything is an object"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'close' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'open' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"a"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"./multiple_inheritance/"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Multiple inheritance"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'close' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'open' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"a"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"./refinement/"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Open classes"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'close' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'open' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'add' Name '(' Punctuation '"a"' Literal.String ')' Punctuation '.' Punctuation 'attr' Name '(' Punctuation '"href"' Literal.String ',' Punctuation ' ' Text '"./virtual_types/"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Virtual types"' Literal.String ')' Punctuation '\n\t\t\t\t\t\t' Text 'close' Name '(' Punctuation '"li"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'close' Name '(' Punctuation '"ul"' Literal.String ')' Punctuation '\n\n\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"h1"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"# Getting Started"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Get Nit from its Git repository:"' Literal.String ')' Punctuation '\n\n\t\t\t\t\t' Text 'add_html' Name '(' Punctuation '"
$ git clone http://nitlanguage.org/nit.git
"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Build the compiler (may be long):"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add_html' Name '(' Punctuation '"
$ cd nit\\n"' Literal.String
')'           Punctuation
'\n\t\t\t\t\t' Text
'add_html'    Name
'('           Punctuation
'"$ make
"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Compile a program:"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add_html' Name '(' Punctuation '"
$ bin/nitc examples/hello_world.nit
"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add' Name '(' Punctuation '"p"' Literal.String ')' Punctuation '.' Punctuation 'text' Name '(' Punctuation '"Execute the program:"' Literal.String ')' Punctuation '\n\t\t\t\t\t' Text 'add_html' Name '(' Punctuation '"
$ ./hello_world
"' Literal.String ')' Punctuation '\n\t\t\t\t' Text 'close' Name '(' Punctuation '"section"' Literal.String ')' Punctuation '\n\t\t\t' Text 'close' Name '(' Punctuation '"div"' Literal.String ')' Punctuation '\n\t\t' Text 'close' Name '(' Punctuation '"article"' Literal.String ')' Punctuation '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'page' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'NitHomepage' Name.Class '\n' Text 'page' Name '.' Punctuation 'write_to' Name ' ' Text 'stdout' Name '\n' Text 'page' Name '.' Punctuation 'write_to_file' Name '(' Punctuation '"nit.html"' Literal.String ')' Punctuation '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# An example that defines and uses stacks of integers.' Comment.Single '\n' Text '# The implementation is done with a simple linked list.' Comment.Single '\n' Text '# It features: free constructors, nullable types and some adaptive typing.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'int_stack' Name '\n\n' Text '# A stack of integer implemented by a simple linked list.' Comment.Single '\n' Text '# Note that this is only a toy class since a real linked list will gain to use' Comment.Single '\n' Text '# generics and extends interfaces, like Collection, from the standard library.' Comment.Single '\n' Text 'class' Keyword ' ' Text 'IntStack' Name.Class '\n\t' Text '# The head node of the list.' Comment.Single '\n\t' Text '# Null means that the stack is empty.' Comment.Single '\n\t' Text 'private' Keyword ' ' Text 'var' Keyword ' ' Text 'head' Name ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'ISNode' Name.Class ' ' Text '=' Operator ' ' Text 'null' Keyword '\n\n\t' Text '# Add a new integer in the stack.' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'push' Name '(' Punctuation 'val' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'self' Name '.' Punctuation 'head' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'ISNode' Name.Class '(' Punctuation 'val' Name ',' Punctuation ' ' Text 'self' Name '.' Punctuation 'head' Name ')' Punctuation '\n\t' Text 'end' Keyword '\n\n\t' Text '# Remove and return the last pushed integer.' Comment.Single '\n\t' Text '# Return null if the stack is empty.' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'pop' Name ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'Int' Name.Class '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'head' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'head' Name '\n\t\t' Text 'if' Keyword ' ' Text 'head' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'return' Keyword ' ' Text 'null' Keyword '\n\t\t' Text '# Note: the followings are statically safe because of the' Comment.Single '\n\t\t' Text "# previous 'if'." Comment.Single '\n\t\t' Text 'var' Keyword ' ' Text 'val' Name ' ' Text '=' Operator ' ' Text 'head' Name '.' Punctuation 'val' Name '\n\t\t' Text 'self' Name '.' Punctuation 'head' Name ' ' Text '=' Operator ' ' Text 'head' Name '.' Punctuation 'next' Name '\n\t\t' Text 'return' Keyword ' ' Text 'val' Name '\n\t' Text 'end' Keyword '\n\n\t' Text '# Return the sum of all integers of the stack.' Comment.Single '\n\t' Text '# Return 0 if the stack is empty.' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'sumall' Name ':' Punctuation ' ' Text 'Int' Name.Class '\n\t' Text 'do' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'sum' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '\n\t\t' Text 'var' Keyword ' ' Text 'cur' Name ' ' Text '=' Operator ' ' Text 'self' Name '.' Punctuation 'head' Name '\n\t\t' Text 'while' Keyword ' ' Text 'cur' Name ' ' Text '!=' Operator ' ' Text 'null' Keyword ' ' Text 'do' Keyword '\n\t\t\t' Text '# Note: the followings are statically safe because of' Comment.Single '\n\t\t\t' Text "# the condition of the 'while'." Comment.Single '\n\t\t\t' Text 'sum' Name ' ' Text '+' Operator '=' Operator ' ' Text 'cur' Name '.' Punctuation 'val' Name '\n\t\t\t' Text 'cur' Name ' ' Text '=' Operator ' ' Text 'cur' Name '.' Punctuation 'next' Name '\n\t\t' Text 'end' Keyword '\n\t\t' Text 'return' Keyword ' ' Text 'sum' Name '\n\t' Text 'end' Keyword '\n\n\t' Text '# Note: Because all attributes have a default value, a free constructor' Comment.Single '\n\t' Text '# "init()" is implicitly defined.' Comment.Single '\n' Text 'end' Keyword '\n\n' Text '# A node of a IntStack' Comment.Single '\n' Text 'private' Keyword ' ' Text 'class' Keyword ' ' Text 'ISNode' Name.Class '\n\t' Text '# The integer value stored in the node.' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'val' Name ':' Punctuation ' ' Text 'Int' Name.Class '\n\n\t' Text '# The next node, if any.' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'next' Name ':' Punctuation ' ' Text 'nullable' Keyword ' ' Text 'ISNode' Name.Class '\n\n\t' Text '# Note: A free constructor "init(val: Int, next: nullable ISNode)" is' Comment.Single '\n\t' Text '# implicitly defined.' Comment.Single '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'l' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'IntStack' Name.Class '\n' Text 'l' Name '.' Punctuation 'push' Name '(1' Literal.Number.Float ')' Punctuation '\n' Text 'l' Name '.' Punctuation 'push' Name '(2' Literal.Number.Float ')' Punctuation '\n' Text 'l' Name '.' Punctuation 'push' Name '(3' Literal.Number.Float ')' Punctuation '\n\n' Text 'print' Name ' ' Text 'l' Name '.' Punctuation 'sumall' Name '\n\n' Text "# Note: the 'for' control structure cannot be used on IntStack in its current state." Comment.Single '\n' Text '# It requires a more advanced topic.' Comment.Single '\n' Text "# However, why not using the 'loop' control structure?" Comment.Single '\n' Text 'loop' Keyword '\n\t' Text 'var' Keyword ' ' Text 'i' Name ' ' Text '=' Operator ' ' Text 'l' Name '.' Punctuation 'pop' Name '\n\t' Text 'if' Keyword ' ' Text 'i' Name ' ' Text '==' Operator ' ' Text 'null' Keyword ' ' Text 'then' Keyword ' ' Text 'break' Keyword '\n\t' Text "# The following is statically safe because of the previous 'if'." Comment.Single '\n\t' Text 'print' Name ' ' Text 'i' Name ' ' Text '*' Operator ' 10' Literal.Number.Float '\n' Text 'end' Keyword '\n\n' Text "# Note: 'or else' is used to give an alternative of a null expression." Comment.Single '\n' Text 'l' Name '.' Punctuation 'push' Name '(5' Literal.Number.Float ')' Punctuation '\n' Text 'print' Name ' ' Text 'l' Name '.' Punctuation 'pop' Name ' ' Text 'or' Keyword ' ' Text 'else' Keyword ' 0' Literal.Number.Float ' ' Text '# l.pop gives 5, so print 5' Comment.Single '\n' Text 'print' Name ' ' Text 'l' Name '.' Punctuation 'pop' Name ' ' Text 'or' Keyword ' ' Text 'else' Keyword ' 0' Literal.Number.Float ' ' Text '# l.pop gives null, so print the alternative: 0' Comment.Single '\n\n\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2014 Alexis Laferrière ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Basic example of OpenGL ES 2.0 usage from the book OpenGL ES 2.0 Programming Guide.' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Code reference:' Comment.Single '\n' Text '# https://code.google.com/p/opengles-book-samples/source/browse/trunk/LinuxX11/Chapter_2/Hello_Triangle/Hello_Triangle.c ' Comment.Single '\n' Text 'module' Keyword ' ' Text 'opengles2_hello_triangle' Name '\n\n' Text 'import' Keyword ' ' Text 'glesv2' Name '\n' Text 'import' Keyword ' ' Text 'egl' Name '\n' Text 'import' Keyword ' ' Text 'mnit_linux' Name ' ' Text '# for sdl' Comment.Single '\n' Text 'import' Keyword ' ' Text 'x11' Literal.Number.Float '\n\n' Text 'if' Keyword ' ' Text '"NIT_TESTING"' Literal.String '.' Punctuation 'environ' Name ' ' Text '==' Operator ' ' Text '"true"' Literal.String ' ' Text 'then' Keyword ' ' Text 'exit' Name '(0' Literal.Number.Float ')' Punctuation '\n\n' Text 'var' Keyword ' ' Text 'window_width' Name ' ' Text '=' Operator ' 800' Literal.Number.Float '\n' Text 'var' Keyword ' ' Text 'window_height' Name ' ' Text '=' Operator ' 600' Literal.Number.Float '\n\n' Text '#' Comment.Single '\n' Text '## SDL' Comment.Single '\n' Text '#' Comment.Single '\n' Text 'var' Keyword ' ' Text 'sdl_display' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'SDLDisplay' Name.Class '(' Punctuation 'window_width' Name ',' Punctuation ' ' Text 'window_height' Name ')' Punctuation '\n' Text 'var' Keyword ' ' Text 'sdl_wm_info' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'SDLSystemWindowManagerInfo' Name.Class '\n' Text 'var' Keyword ' ' Text 'x11' Literal.Number.Float '_window_handle' Name.Variable.Instance ' ' Text '=' Operator ' ' Text 'sdl_wm_info' Name '.' Punctuation 'x11' Literal.Number.Float '_window_handle' Name.Variable.Instance '\n\n' Text '#' Comment.Single '\n' Text '## X11' Comment.Single '\n' Text '#' Comment.Single '\n' Text 'var' Keyword ' ' Text 'x_display' Name ' ' Text '=' Operator ' ' Text 'x_open_default_display' Name '\n' Text 'assert' Keyword ' ' Text 'x_display' Name ' ' Text '!=' Operator ' 0' Literal.Number.Float ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"x11 fail"' Literal.String '\n\n' Text '#' Comment.Single '\n' Text '## EGL' Comment.Single '\n' Text '#' Comment.Single '\n' Text 'var' Keyword ' ' Text 'egl_display' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'EGLDisplay' Name.Class '(' Punctuation 'x_display' Name ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'egl_display' Name '.' Punctuation 'is_valid' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"EGL display is not valid"' Literal.String '\n' Text 'egl_display' Name '.' Punctuation 'initialize' Name '\n\n' Text 'print' Name ' ' Text '"EGL version: {' Literal.String 'egl_display' Name '.' Punctuation 'version' Name '}"' Literal.String '\n' Text 'print' Name ' ' Text '"EGL vendor: {' Literal.String 'egl_display' Name '.' Punctuation 'vendor' Name '}"' Literal.String '\n' Text 'print' Name ' ' Text '"EGL extensions: {' Literal.String 'egl_display' Name '.' Punctuation 'extensions' Name '.' Punctuation 'join' Name '(' Punctuation '", "' Literal.String ')' Punctuation '}"' Literal.String '\n' Text 'print' Name ' ' Text '"EGL client APIs: {' Literal.String 'egl_display' Name '.' Punctuation 'client_apis' Name '.' Punctuation 'join' Name '(' Punctuation '", "' Literal.String ')' Punctuation '}"' Literal.String '\n\n' Text 'assert' Keyword ' ' Text 'egl_display' Name '.' Punctuation 'is_valid' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'egl_display' Name '.' Punctuation 'error' Name '\n\n' Text 'var' Keyword ' ' Text 'config_chooser' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'EGLConfigChooser' Name.Class '\n' Text '#config_chooser.surface_type_egl' Comment.Single '\n' Text 'config_chooser' Name '.' Punctuation 'blue_size' Name ' ' Text '=' Operator ' 8' Literal.Number.Float '\n' Text 'config_chooser' Name '.' Punctuation 'green_size' Name ' ' Text '=' Operator ' 8' Literal.Number.Float '\n' Text 'config_chooser' Name '.' Punctuation 'red_size' Name ' ' Text '=' Operator ' 8' Literal.Number.Float '\n' Text '#config_chooser.alpha_size = 8' Comment.Single '\n' Text '#config_chooser.depth_size = 8' Comment.Single '\n' Text '#config_chooser.stencil_size = 8' Comment.Single '\n' Text '#config_chooser.sample_buffers = 1' Comment.Single '\n' Text 'config_chooser' Name '.' Punctuation 'close' Name '\n\n' Text 'var' Keyword ' ' Text 'configs' Name ' ' Text '=' Operator ' ' Text 'config_chooser' Name '.' Punctuation 'choose' Name '(' Punctuation 'egl_display' Name ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'configs' Name ' ' Text '!=' Operator ' ' Text 'null' Keyword ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"choosing config failed: {' Literal.String 'egl_display' Name '.' Punctuation 'error' Name '}"' Literal.String '\n' Text 'assert' Keyword ' ' Text 'not' Keyword ' ' Text 'configs' Name '.' Punctuation 'is_empty' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"no EGL config"' Literal.String '\n\n' Text 'print' Name ' ' Text '"{' Literal.String 'configs' Name '.' Punctuation 'length' Name '} EGL configs available"' Literal.String '\n' Text 'for' Keyword ' ' Text 'config' Name ' ' Text 'in' Keyword ' ' Text 'configs' Name ' ' Text 'do' Keyword '\n\t' Text 'var' Keyword ' ' Text 'attribs' Name ' ' Text '=' Operator ' ' Text 'config' Name '.' Punctuation 'attribs' Name '(' Punctuation 'egl_display' Name ')' Punctuation '\n\t' Text 'print' Name ' ' Text '"* caveats: {' Literal.String 'attribs' Name '.' Punctuation 'caveat' Name '}"' Literal.String '\n\t' Text 'print' Name ' ' Text '" conformant to: {' Literal.String 'attribs' Name '.' Punctuation 'conformant' Name '}"' Literal.String '\n\t' Text 'print' Name ' ' Text '" size of RGBA: {' Literal.String 'attribs' Name '.' Punctuation 'red_size' Name '} {' Literal.String 'attribs' Name '.' Punctuation 'green_size' Name '} {' Literal.String 'attribs' Name '.' Punctuation 'blue_size' Name '} {' Literal.String 'attribs' Name '.' Punctuation 'alpha_size' Name '}"' Literal.String '\n\t' Text 'print' Name ' ' Text '" buffer, depth, stencil: {' Literal.String 'attribs' Name '.' Punctuation 'buffer_size' Name '} {' Literal.String 'attribs' Name '.' Punctuation 'depth_size' Name '} {' Literal.String 'attribs' Name '.' Punctuation 'stencil_size' Name '}"' Literal.String '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'config' Name ' ' Text '=' Operator ' ' Text 'configs' Name '.' Punctuation 'first' Name '\n\n' Text 'var' Keyword ' ' Text 'format' Name ' ' Text '=' Operator ' ' Text 'config' Name '.' Punctuation 'attribs' Name '(' Punctuation 'egl_display' Name ')' Punctuation '.' Punctuation 'native_visual_id' Name '\n\n' Text '# TODO android part' Comment.Single '\n' Text '# Opengles1Display_midway_init(recv, format);' Comment.Single '\n\n' Text 'var' Keyword ' ' Text 'surface' Name ' ' Text '=' Operator ' ' Text 'egl_display' Name '.' Punctuation 'create_window_surface' Name '(' Punctuation 'config' Name ',' Punctuation ' ' Text 'x11' Literal.Number.Float '_window_handle' Name.Variable.Instance ',' Punctuation ' ' Text '[0' Literal.Number.Float ']' Punctuation ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'surface' Name '.' Punctuation 'is_ok' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'egl_display' Name '.' Punctuation 'error' Name '\n\n' Text 'var' Keyword ' ' Text 'context' Name ' ' Text '=' Operator ' ' Text 'egl_display' Name '.' Punctuation 'create_context' Name '(' Punctuation 'config' Name ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'context' Name '.' Punctuation 'is_ok' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text 'egl_display' Name '.' Punctuation 'error' Name '\n\n' Text 'var' Keyword ' ' Text 'make_current_res' Name ' ' Text '=' Operator ' ' Text 'egl_display' Name '.' Punctuation 'make_current' Name '(' Punctuation 'surface' Name ',' Punctuation ' ' Text 'surface' Name ',' Punctuation ' ' Text 'context' Name ')' Punctuation '\n' Text 'assert' Keyword ' ' Text 'make_current_res' Name '\n\n' Text 'var' Keyword ' ' Text 'width' Name ' ' Text '=' Operator ' ' Text 'surface' Name '.' Punctuation 'attribs' Name '(' Punctuation 'egl_display' Name ')' Punctuation '.' Punctuation 'width' Name '\n' Text 'var' Keyword ' ' Text 'height' Name ' ' Text '=' Operator ' ' Text 'surface' Name '.' Punctuation 'attribs' Name '(' Punctuation 'egl_display' Name ')' Punctuation '.' Punctuation 'height' Name '\n' Text 'print' Name ' ' Text '"Width: {' Literal.String 'width' Name '}"' Literal.String '\n' Text 'print' Name ' ' Text '"Height: {' Literal.String 'height' Name '}"' Literal.String '\n\n' Text 'assert' Keyword ' ' Text 'egl_bind_opengl_es_api' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"eglBingAPI failed: {' Literal.String 'egl_display' Name '.' Punctuation 'error' Name '}"' Literal.String '\n\n' Text '#' Comment.Single '\n' Text '## GLESv2' Comment.Single '\n' Text '#' Comment.Single '\n\n' Text 'print' Name ' ' Text '"Can compile shaders? {' Literal.String 'gl_shader_compiler' Name '}"' Literal.String '\n' Text 'assert_no_gl_error' Name '\n\n' Text 'assert' Keyword ' ' Text 'gl_shader_compiler' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"Cannot compile shaders"' Literal.String '\n\n' Text '# gl program' Comment.Single '\n' Text 'print' Name ' ' Text 'gl_error' Name '.' Punctuation 'to_s' Name '\n' Text 'var' Keyword ' ' Text 'program' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GLProgram' Name.Class '\n' Text 'if' Keyword ' ' Text 'not' Keyword ' ' Text 'program' Name '.' Punctuation 'is_ok' Name ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Program is not ok: {' Literal.String 'gl_error' Name '.' Punctuation 'to_s' Name '}\\nLog:"' Literal.String '\n\t' Text 'print' Name ' ' Text 'program' Name '.' Punctuation 'info_log' Name '\n\t' Text 'abort' Keyword '\n' Text 'end' Keyword '\n' Text 'assert_no_gl_error' Name '\n\n' Text '# vertex shader' Comment.Single '\n' Text 'var' Keyword ' ' Text 'vertex_shader' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'GLVertexShader' Name.Class '\n' Text 'assert' Keyword ' ' Text 'vertex_shader' Name '.' Punctuation 'is_ok' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"Vertex shader is not ok: {' Literal.String 'gl_error' Name '}"' Literal.String '\n' Text 'vertex_shader' Name '.' Punctuation 'source' Name ' ' Text '=' Operator ' ' Text '"""\nattribute vec4 vPosition; \nvoid main() \n{ \n gl_Position = vPosition; \n} """\nvertex_shader.compile\nassert vertex_shader.is_compiled else print "Vertex shader compilation failed with: {vertex_shader.info_log} {program.info_log}"\nassert_no_gl_error\n\n# fragment shader\nvar fragment_shader = new GLFragmentShader\nassert fragment_shader.is_ok else print "Fragment shader is not ok: {gl_error}"\nfragment_shader.source = """\nprecision mediump float;\nvoid main()\n{\n\tgl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n}\n"""' Literal.String '\n' Text 'fragment_shader' Name '.' Punctuation 'compile' Name '\n' Text 'assert' Keyword ' ' Text 'fragment_shader' Name '.' Punctuation 'is_compiled' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"Fragment shader compilation failed with: {' Literal.String 'fragment_shader' Name '.' Punctuation 'info_log' Name '}"' Literal.String '\n' Text 'assert_no_gl_error' Name '\n\n' Text 'program' Name '.' Punctuation 'attach_shader' Name ' ' Text 'vertex_shader' Name '\n' Text 'program' Name '.' Punctuation 'attach_shader' Name ' ' Text 'fragment_shader' Name '\n' Text 'program' Name '.' Punctuation 'bind_attrib_location' Name '(0' Literal.Number.Float ',' Punctuation ' ' Text '"vPosition"' Literal.String ')' Punctuation '\n' Text 'program' Name '.' Punctuation 'link' Name '\n' Text 'assert' Keyword ' ' Text 'program' Name '.' Punctuation 'is_linked' Name ' ' Text 'else' Keyword ' ' Text 'print' Name ' ' Text '"Linking failed: {' Literal.String 'program' Name '.' Punctuation 'info_log' Name '}"' Literal.String '\n' Text 'assert_no_gl_error' Name '\n\n' Text '# draw!' Comment.Single '\n' Text 'var' Keyword ' ' Text 'vertices' Name ' ' Text '=' Operator ' ' Text '[0' Literal.Number.Float '.0' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float '.5' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float '.0' Literal.Number.Float ',' Punctuation ' ' Text '-0' Literal.Number.Float '.5' Literal.Number.Float ',' Punctuation ' ' Text '-0' Literal.Number.Float '.5' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float '.0' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float '.5' Literal.Number.Float ',' Punctuation ' ' Text '-0' Literal.Number.Float '.5' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float '.0' Literal.Number.Float ']' Punctuation '\n' Text 'var' Keyword ' ' Text 'vertex_array' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'VertexArray' Name.Class '(0' Literal.Number.Float ',' Punctuation ' 3' Literal.Number.Float ',' Punctuation ' ' Text 'vertices' Name ')' Punctuation '\n' Text 'vertex_array' Name '.' Punctuation 'attrib_pointer' Name '\n' Text 'gl_clear_color' Name '(0' Literal.Number.Float '.5' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float '.0' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float '.5' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float '.0' Literal.Number.Float ')' Punctuation '\n' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text '[0' Literal.Number.Float '..' Punctuation '10000' Literal.Number.Integer '[' Punctuation ' ' Text 'do' Keyword '\n\t' Text 'printn' Name ' ' Text '"."' Literal.String '\n\t' Text 'assert_no_gl_error' Name '\n\t' Text 'gl_viewport' Name '(0' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float ',' Punctuation ' ' Text 'width' Name ',' Punctuation ' ' Text 'height' Name ')' Punctuation '\n\t' Text 'gl_clear_color_buffer' Name '\n\t' Text 'program' Name '.' Punctuation 'use' Name '\n\t' Text 'vertex_array' Name '.' Punctuation 'enable' Name '\n\t' Text 'vertex_array' Name '.' Punctuation 'draw_arrays_triangles' Name '\n\t' Text 'egl_display' Name '.' Punctuation 'swap_buffers' Name '(' Punctuation 'surface' Name ')' Punctuation '\n' Text 'end' Keyword '\n\n' Text '# delete' Comment.Single '\n' Text 'program' Name '.' Punctuation 'delete' Name '\n' Text 'vertex_shader' Name '.' Punctuation 'delete' Name '\n' Text 'fragment_shader' Name '.' Punctuation 'delete' Name '\n\n' Text '#' Comment.Single '\n' Text '## EGL' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# close' Comment.Single '\n' Text 'egl_display' Name '.' Punctuation 'make_current' Name '(' Punctuation 'new' Keyword ' ' Text 'EGLSurface' Name.Class '.' Punctuation 'none' Name ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'EGLSurface' Name.Class '.' Punctuation 'none' Name ',' Punctuation ' ' Text 'new' Keyword ' ' Text 'EGLContext' Name.Class '.' Punctuation 'none' Name ')' Punctuation '\n' Text 'egl_display' Name '.' Punctuation 'destroy_context' Name '(' Punctuation 'context' Name ')' Punctuation '\n' Text 'egl_display' Name '.' Punctuation 'destroy_surface' Name '(' Punctuation 'surface' Name ')' Punctuation '\n\n' Text '#' Comment.Single '\n' Text '## SDL' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# close' Comment.Single '\n' Text 'sdl_display' Name '.' Punctuation 'destroy' Name '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2004-2008 Jean Privat ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# How to print arguments of the command line.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'print_arguments' Name '\n\n' Text 'for' Keyword ' ' Text 'a' Name ' ' Text 'in' Keyword ' ' Text 'args' Name ' ' Text 'do' Keyword '\n\t' Text 'print' Name ' ' Text 'a' Name '\n' Text 'end' Keyword '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2004-2008 Jean Privat ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# A procedural program (without explicit class definition).' Comment.Single '\n' Text '# This program manipulates arrays of integers.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'procedural_array' Name '\n\n' Text "# The sum of the elements of `a'." Comment.Single '\n' Text "# Uses a 'for' control structure." Comment.Single '\n' Text 'fun' Keyword ' ' Text 'array_sum' Name '(' Punctuation 'a' Name ':' Punctuation ' ' Text 'Array' Name.Class '[' Punctuation 'Int' Name.Class ']' Punctuation ')' Punctuation ':' Punctuation ' ' Text 'Int' Name.Class '\n' Text 'do' Keyword '\n\t' Text 'var' Keyword ' ' Text 'sum' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '\n\t' Text 'for' Keyword ' ' Text 'i' Name ' ' Text 'in' Keyword ' ' Text 'a' Name ' ' Text 'do' Keyword '\n\t\t' Text 'sum' Name ' ' Text '=' Operator ' ' Text 'sum' Name ' ' Text '+' Operator ' ' Text 'i' Name '\n\t' Text 'end' Keyword '\n\t' Text 'return' Keyword ' ' Text 'sum' Name '\n' Text 'end' Keyword '\n\n' Text "# The sum of the elements of `a' (alternative version)." Comment.Single '\n' Text "# Uses a 'while' control structure." Comment.Single '\n' Text 'fun' Keyword ' ' Text 'array_sum_alt' Name '(' Punctuation 'a' Name ':' Punctuation ' ' Text 'Array' Name.Class '[' Punctuation 'Int' Name.Class ']' Punctuation ')' Punctuation ':' Punctuation ' ' Text 'Int' Name.Class '\n' Text 'do' Keyword '\n\t' Text 'var' Keyword ' ' Text 'sum' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '\n\t' Text 'var' Keyword ' ' Text 'i' Name ' ' Text '=' Operator ' 0' Literal.Number.Float '\n\t' Text 'while' Keyword ' ' Text 'i' Name ' ' Text '<' Operator ' ' Text 'a' Name '.' Punctuation 'length' Name ' ' Text 'do' Keyword '\n\t\t' Text 'sum' Name ' ' Text '=' Operator ' ' Text 'sum' Name ' ' Text '+' Operator ' ' Text 'a' Name '[' Punctuation 'i' Name ']' Punctuation '\n\t\t' Text 'i' Name ' ' Text '=' Operator ' ' Text 'i' Name ' ' Text '+' Operator ' 1' Literal.Number.Float '\n\t' Text 'end' Keyword '\n\t' Text 'return' Keyword ' ' Text 'sum' Name '\n' Text 'end' Keyword '\n\n' Text '# The main part of the program.' Comment.Single '\n' Text 'var' Keyword ' ' Text 'a' Name ' ' Text '=' Operator ' ' Text '[10' Literal.Number.Float ',' Punctuation ' 5' Literal.Number.Float ',' Punctuation ' 8' Literal.Number.Float ',' Punctuation ' 9' Literal.Number.Float ']' Punctuation '\n' Text 'print' Name '(' Punctuation 'array_sum' Name '(' Punctuation 'a' Name ')' Punctuation ')' Punctuation '\n' Text 'print' Name '(' Punctuation 'array_sum_alt' Name '(' Punctuation 'a' Name ')' Punctuation ')' Punctuation '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Matthieu Lucas ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Client sample using the Socket module which connect to the server sample.' Comment.Single '\n' Text 'module' Keyword ' ' Text 'socket_client' Name '\n\n' Text 'import' Keyword ' ' Text 'socket' Name '\n\n' Text 'if' Keyword ' ' Text 'args' Name '.' Punctuation 'length' Name ' ' Text '<' Operator ' 2' Literal.Number.Float ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Usage : socket_client "' Literal.String '\n\t' Text 'return' Keyword '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 's' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Socket' Name.Class '.' Punctuation 'client' Name '(' Punctuation 'args' Name '[0' Literal.Number.Float ']' Punctuation ',' Punctuation ' ' Text 'args' Name '[1' Literal.Number.Float ']' Punctuation '.' Punctuation 'to_i' Name ')' Punctuation '\n' Text 'print' Name ' ' Text '"[HOST ADDRESS] : {' Literal.String 's' Name '.' Punctuation 'address' Name '}"' Literal.String '\n' Text 'print' Name ' ' Text '"[HOST] : {' Literal.String 's' Name '.' Punctuation 'host' Name '}"' Literal.String '\n' Text 'print' Name ' ' Text '"[PORT] : {' Literal.String 's' Name '.' Punctuation 'port' Name '}"' Literal.String '\n' Text 'print' Name ' ' Text '"Connecting ... {' Literal.String 's' Name '.' Punctuation 'connected' Name '}"' Literal.String '\n' Text 'if' Keyword ' ' Text 's' Name '.' Punctuation 'connected' Name ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Writing ... Hello server !"' Literal.String '\n\t' Text 's' Name '.' Punctuation 'write' Name '(' Punctuation '"Hello server !"' Literal.String ')' Punctuation '\n\t' Text 'print' Name ' ' Text '"[Response from server] : {' Literal.String 's' Name '.' Punctuation 'read' Name '(100' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n\t' Text 'print' Name ' ' Text '"Closing ..."' Literal.String '\n\t' Text 's' Name '.' Punctuation 'close' Name '\n' Text 'end' Keyword '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2013 Matthieu Lucas ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Server sample using the Socket module which allow client to connect' Comment.Single '\n' Text 'module' Keyword ' ' Text 'socket_server' Name '\n\n' Text 'import' Keyword ' ' Text 'socket' Name '\n\n' Text 'if' Keyword ' ' Text 'args' Name '.' Punctuation 'is_empty' Name ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text '"Usage : socket_server "' Literal.String '\n\t' Text 'return' Keyword '\n' Text 'end' Keyword '\n\n' Text 'var' Keyword ' ' Text 'socket' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Socket' Name.Class '.' Punctuation 'server' Name '(' Punctuation 'args' Name '[0' Literal.Number.Float ']' Punctuation '.' Punctuation 'to_i' Name ',' Punctuation ' 1' Literal.Number.Float ')' Punctuation '\n' Text 'print' Name ' ' Text '"[PORT] : {' Literal.String 'socket' Name '.' Punctuation 'port' Name '.' Punctuation 'to_s' Name '}"' Literal.String '\n\n' Text 'var' Keyword ' ' Text 'clients' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Array' Name.Class '[' Punctuation 'Socket' Name.Class ']' Punctuation '\n' Text 'var' Keyword ' ' Text 'max' Name ' ' Text '=' Operator ' ' Text 'socket' Name '\n' Text 'loop' Keyword '\n\t' Text 'var' Keyword ' ' Text 'fs' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'SocketObserver' Name.Class '(' Punctuation 'true' Name ',' Punctuation ' ' Text 'true' Name ',' Punctuation ' ' Text 'true' Name ')' Punctuation '\n\t' Text 'fs' Name '.' Punctuation 'readset' Name '.' Punctuation 'set' Name '(' Punctuation 'socket' Name ')' Punctuation '\n\n\t' Text 'for' Keyword ' ' Text 'c' Name ' ' Text 'in' Keyword ' ' Text 'clients' Name ' ' Text 'do' Keyword ' ' Text 'fs' Name '.' Punctuation 'readset' Name '.' Punctuation 'set' Name '(' Punctuation 'c' Name ')' Punctuation '\n\n\t' Text 'if' Keyword ' ' Text 'fs' Name '.' Punctuation 'select' Name '(' Punctuation 'max' Name ',' Punctuation ' 4' Literal.Number.Float ',' Punctuation ' 0' Literal.Number.Float ')' Punctuation ' ' Text '==' Operator ' 0' Literal.Number.Float ' ' Text 'then' Keyword '\n\t\t' Text 'print' Name ' ' Text '"Error occured in select {' Literal.String 'sys' Name '.' Punctuation 'errno' Name '.' Punctuation 'strerror' Name '}"' Literal.String '\n\t\t' Text 'break' Keyword '\n\t' Text 'end' Keyword '\n\n\t' Text 'if' Keyword ' ' Text 'fs' Name '.' Punctuation 'readset' Name '.' Punctuation 'is_set' Name '(' Punctuation 'socket' Name ')' Punctuation ' ' Text 'then' Keyword '\n\t\t' Text 'var' Keyword ' ' Text 'ns' Name ' ' Text '=' Operator ' ' Text 'socket' Name '.' Punctuation 'accept' Name '\n\t\t' Text 'print' Name ' ' Text '"Accepting {' Literal.String 'ns' Name '.' Punctuation 'address' Name '} ... "' Literal.String '\n\t\t' Text 'print' Name ' ' Text '"[Message from {' Literal.String 'ns' Name '.' Punctuation 'address' Name '}] : {' Literal.String 'ns' Name '.' Punctuation 'read' Name '(100' Literal.Number.Float ')' Punctuation '}"' Literal.String '\n\t\t' Text 'ns' Name '.' Punctuation 'write' Name '(' Punctuation '"Goodbye client."' Literal.String ')' Punctuation '\n\t\t' Text 'print' Name ' ' Text '"Closing {' Literal.String 'ns' Name '.' Punctuation 'address' Name '} ..."' Literal.String '\n\t\t' Text 'ns' Name '.' Punctuation 'close' Name '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text 'import' Keyword ' ' Text 'template' Name '\n\n' Text '### Here, definition of the specific templates' Comment.Single '\n\n' Text '# The root template for composers' Comment.Single '\n' Text 'class' Keyword ' ' Text 'TmplComposers' Name.Class '\n\t' Text 'super' Keyword ' ' Text 'Template' Name.Class '\n\n\t' Text '# Short list of composers' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'composers' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Array' Name.Class '[' Punctuation 'TmplComposer' Name.Class ']' Punctuation '\n\n\t' Text '# Detailled list of composers' Comment.Single '\n\t' Text 'var' Keyword ' ' Text 'composer_details' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'Array' Name.Class '[' Punctuation 'TmplComposerDetail' Name.Class ']' Punctuation '\n\n\t' Text '# Add a composer in both lists' Comment.Single '\n\t' Text 'fun' Keyword ' ' Text 'add_composer' Name '(' Punctuation 'firstname' Name ',' Punctuation ' ' Text 'lastname' Name ':' Punctuation ' ' Text 'String' Name.Class ',' Punctuation ' ' Text 'birth' Name ',' Punctuation ' ' Text 'death' Name ':' Punctuation ' ' Text 'Int' Name.Class ')' Punctuation '\n\t' Text 'do' Keyword '\n\t\t' Text 'composers' Name '.' Punctuation 'add' Name '(' Punctuation 'new' Keyword ' ' Text 'TmplComposer' Name.Class '(' Punctuation 'lastname' Name ')' Punctuation ')' Punctuation '\n\t\t' Text 'composer_details' Name '.' Punctuation 'add' Name '(' Punctuation 'new' Keyword ' ' Text 'TmplComposerDetail' Name.Class '(' Punctuation 'firstname' Name ',' Punctuation ' ' Text 'lastname' Name ',' Punctuation ' ' Text 'birth' Name ',' Punctuation ' ' Text 'death' Name ')' Punctuation ')' Punctuation '\n\t' Text 'end' Keyword '\n\n\t' Text 'redef' Keyword ' ' Text 'fun' Keyword ' ' Text 'rendering' Name ' ' Text 'do' Keyword '\n\t\t' Text 'add' Name ' ' Text '"""\nCOMPOSERS\n=========\n"""\n\t\tadd_all composers\n\t\tadd """\n\nDETAILS\n=======\n"""\n\t\tadd_all composer_details\n\tend\nend\n\n# A composer in the short list of composers\nclass TmplComposer\n\tsuper Template\n\n\t# Short name\n\tvar name: String\n\n\tinit(name: String) do self.name = name\n\n\tredef fun rendering do add "- {name}\\n"\nend\n\n# A composer in the detailled list of composers\nclass TmplComposerDetail\n\tsuper Template\n\n\tvar firstname: String\n\tvar lastname: String\n\tvar birth: Int\n\tvar death: Int\n\n\tinit(firstname, lastname: String, birth, death: Int) do\n\t\tself.firstname = firstname\n\t\tself.lastname = lastname\n\t\tself.birth = birth\n\t\tself.death = death\n\tend\n\n\tredef fun rendering do add """\n\nCOMPOSER: {{{firstname}}} {{{lastname}}}\nBIRTH...: {{{birth}}}\nDEATH...: {{{death}}}\n"""' Literal.String '\n\n' Text 'end' Keyword '\n\n' Text '### Here a simple usage of the templates' Comment.Single '\n\n' Text 'var' Keyword ' ' Text 'f' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'TmplComposers' Name.Class '\n' Text 'f' Name '.' Punctuation 'add_composer' Name '(' Punctuation '"Johann Sebastian"' Literal.String ',' Punctuation ' ' Text '"Bach"' Literal.String ',' Punctuation ' 1685' Literal.Number.Float ',' Punctuation ' 1750' Literal.Number.Float ')' Punctuation '\n' Text 'f' Name '.' Punctuation 'add_composer' Name '(' Punctuation '"George Frideric"' Literal.String ',' Punctuation ' ' Text '"Handel"' Literal.String ',' Punctuation ' 1685' Literal.Number.Float ',' Punctuation ' 1759' Literal.Number.Float ')' Punctuation '\n' Text 'f' Name '.' Punctuation 'add_composer' Name '(' Punctuation '"Wolfgang Amadeus"' Literal.String ',' Punctuation ' ' Text '"Mozart"' Literal.String ',' Punctuation ' 1756' Literal.Number.Float ',' Punctuation ' 1791' Literal.Number.Float ')' Punctuation '\n' Text 'f' Name '.' Punctuation 'write_to' Name '(' Punctuation 'stdout' Name ')' Punctuation '\n' Text '# This file is part of NIT ( http://www.nitlanguage.org ).' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Copyright 2014 Lucas Bajolet ' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Licensed under the Apache License, Version 2.0 (the "License");' Comment.Single '\n' Text '# you may not use this file except in compliance with the License.' Comment.Single '\n' Text '# You may obtain a copy of the License at' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# http://www.apache.org/licenses/LICENSE-2.0' Comment.Single '\n' Text '#' Comment.Single '\n' Text '# Unless required by applicable law or agreed to in writing, software' Comment.Single '\n' Text '# distributed under the License is distributed on an "AS IS" BASIS,' Comment.Single '\n' Text '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' Comment.Single '\n' Text '# See the License for the specific language governing permissions and' Comment.Single '\n' Text '# limitations under the License.' Comment.Single '\n\n' Text '# Sample module for a minimal chat server using Websockets on port 8088' Comment.Single '\n' Text 'module' Keyword ' ' Text 'websocket_server' Name '\n\n' Text 'import' Keyword ' ' Text 'websocket' Name '\n\n' Text 'var' Keyword ' ' Text 'sock' Name ' ' Text '=' Operator ' ' Text 'new' Keyword ' ' Text 'WebSocket' Name.Class '(8088' Literal.Number.Float ',' Punctuation ' 1' Literal.Number.Float ')' Punctuation '\n\n' Text 'var' Keyword ' ' Text 'msg' Name ':' Punctuation ' ' Text 'String' Name.Class '\n\n' Text 'if' Keyword ' ' Text 'sock' Name '.' Punctuation 'listener' Name '.' Punctuation 'eof' Name ' ' Text 'then' Keyword '\n\t' Text 'print' Name ' ' Text 'sys' Name '.' Punctuation 'errno' Name '.' Punctuation 'strerror' Name '\n' Text 'end' Keyword '\n\n' Text 'sock' Name '.' Punctuation 'accept' Name '\n\n' Text 'while' Keyword ' ' Text 'not' Keyword ' ' Text 'sock' Name '.' Punctuation 'listener' Name '.' Punctuation 'eof' Name ' ' Text 'do' Keyword '\n\t' Text 'if' Keyword ' ' Text 'not' Keyword ' ' Text 'sock' Name '.' Punctuation 'connected' Name ' ' Text 'then' Keyword ' ' Text 'sock' Name '.' Punctuation 'accept' Name '\n\t' Text 'if' Keyword ' ' Text 'sys' Name '.' Punctuation 'stdin' Name '.' Punctuation 'poll_in' Name ' ' Text 'then' Keyword '\n\t\t' Text 'msg' Name ' ' Text '=' Operator ' ' Text 'gets' Name '\n\t\t' Text 'printn' Name ' ' Text '"Received message : {' Literal.String 'msg' Name '}"' Literal.String '\n\t\t' Text 'if' Keyword ' ' Text 'msg' Name ' ' Text '==' Operator ' ' Text '"exit"' Literal.String ' ' Text 'then' Keyword ' ' Text 'sock' Name '.' Punctuation 'close' Name '\n\t\t' Text 'if' Keyword ' ' Text 'msg' Name ' ' Text '==' Operator ' ' Text '"disconnect"' Literal.String ' ' Text 'then' Keyword ' ' Text 'sock' Name '.' Punctuation 'disconnect_client' Name '\n\t\t' Text 'sock' Name '.' Punctuation 'write' Name '(' Punctuation 'msg' Name ')' Punctuation '\n\t' Text 'end' Keyword '\n\t' Text 'if' Keyword ' ' Text 'sock' Name '.' Punctuation 'can_read' Name '(10' Literal.Number.Float ')' Punctuation ' ' Text 'then' Keyword '\n\t\t' Text 'msg' Name ' ' Text '=' Operator ' ' Text 'sock' Name '.' Punctuation 'read_line' Name '\n\t\t' Text 'if' Keyword ' ' Text 'msg' Name ' ' Text '!=' Operator ' ' Text '""' Literal.String ' ' Text 'then' Keyword ' ' Text 'print' Name ' ' Text 'msg' Name '\n\t' Text 'end' Keyword '\n' Text 'end' Keyword '\n' Text