Calculator Community => Other Calc-Related Projects and Ideas => Topic started by: Deep Toaster on June 24, 2011, 06:35:20 pm
Title: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on June 24, 2011, 06:35:20 pm
BBify (http://clrhome.org/resources/bbify/)
A little web project I've been working on.
I know it looks horrible, but I'll prettify it up soon. At least it's functional: paste in some Z80 code and click Submit, and it'll wrap stuff in BBCode so you can copy-paste the result straight into a forum. Or HTML, so you can paste it into a webpage, or plain old colored code, so you can paste it into an email!
Right now it can only handle strings, numbers, comments, and directives, but the way I've set it up all I have to do is add a regex array element for any replacements I want to do and it'll put that on the queue.
Better yet, I'm planning to add customized colors. Right now I'm taking colors off the Tango scheme (http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines#Color_Palette), but the way I have it set up I can just add some form elements and you'll be able to change the colors to whatever you want :D
Latest update: http://ourl.ca/9167/289088/
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on June 24, 2011, 06:36:35 pm
This is nice O.O. I wonder if eventually it could be integrated in the forum or something? I think there's a SMF hack ephans/Scout posted that does that with PHP/C++, but someone could modify it to do it with Z80 instead.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on June 24, 2011, 06:37:47 pm
Yeah, I wasn't aware of that one when I started making this :-\
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on June 24, 2011, 06:38:22 pm
Deep Thought, very nice :D I'd like this on the forums like DJ :)
Test:
; Program Name: Memory Checker ; Author: David Gomes ; Version: <<1>>.<1> ; Written for Doors CS <<1>>.<1> and higher .nolist #include "ti83plus.inc" #include "dcs7.inc" .list .org progstart .db $BB,$6D Init: B_CALL (_ClrLCDFull)
set textWrite,(IY + sGrFlags) set fracDrawLFont,(IY + fontFlags)
ld a,1 ld (penCol), a ld (penRow), a ld hl,Title B_CALL (_VPutS)
;The following code was made by Runer112 GetTotalArc: ;——————————————————————————————————————————————; ;—> Returns the total amount of user archive as a <0>-character decimal string ;INPUTS: none ;OUTPUTS: hl=pointer to string (OP3) ;DESTROYS: af bc de ix ;——————————————————————————————————————————————; B_CALL($80BA) add a,a add a,a ld d,0 ld e,a ld hl,GetTotalArc_HWValues add hl,de jr ConvArc GetTotalArc_HWValues: .db (10*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4> .db (94*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4> .db (30*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4> .db (94*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>
GetFreeArc: ;——————————————————————————————————————————————; ;—> Returns the amount of free archive as a <0>-character decimal string ;INPUTS: none ;OUTPUTS: hl=pointer to string (OP3) ;DESTROYS: af bc de ix ;——————————————————————————————————————————————; B_CALL($5014) ;ArcChk ex de,hl inc hl
ConvArc: ;——————————————————————————————————————————————; ;—> Converts a <0>-bit integer into a <1>-character decimal string ;INPUTS: hl=pointer to <0>-bit integer (big-endian) ;OUTPUTS: hl=pointer to string (OP3) ;DESTROYS: af bc de ix ;——————————————————————————————————————————————; rst 20h ld hl,OP3+7 ld de,10 ld (hl),d ld b,7 ConvArc_Loop1: push bc push hl B_CALL($80B1) ;Div32By16 pop hl pop bc ld a,(OP2+3) add a,'0' dec hl ld (hl),a djnz ConvArc_Loop1 ld d,h ld e,l ld bc,6<;<<1>+<2> ConvArc_Loop2: ld a,(de) cp c ret nz ld a,' ' ld (de),a inc de djnz ConvArc_Loop2 ret
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on June 24, 2011, 06:39:22 pm
everything else is great though, maybe add in some highlighting for commands too?
Definitely, and also registers, bcalls, and everything else I highlight in my gedit scheme file.
Maybe add in support for KOS and RogueOS calls too? ( when they are finalized of course )
Sure. No need to give me the actual call lists because it's all just regex -- it highlights the instruction bcall/kcall/rcall one way, then assumes whatever's in the parentheses following or the next word is the routine.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 03, 2011, 08:56:39 pm
Update-bump: instructions, registers, operators, all that fun stuff. I also fixed those annoying bugs.
Spoiler For ephan's code posted earlier:
; Program Name: Memory Checker ; Author: David Gomes ; Version: 1.0 ; Written for Doors CS 7.0 and higher .nolist #include "ti83plus.inc" #include "dcs7.inc" .list .org progstart .db $BB,$6D Init: B_CALL (_ClrLCDFull)
set textWrite,(IY+ sGrFlags) set fracDrawLFont,(IY+ fontFlags)
lda,1 ld (penCol), a ld (penRow), a ldhl,Title B_CALL (_VPutS)
;The following code was made by Runer112 GetTotalArc: ;——————————————————————————————————————————————; ;—> Returns the total amount of user archive as a 7-character decimal string ;INPUTS: none ;OUTPUTS: hl=pointer to string (OP3) ;DESTROYS: af bc de ix ;——————————————————————————————————————————————; B_CALL($80BA) adda,a adda,a ldd,0 lde,a ldhl,GetTotalArc_HWValues addhl,de jr ConvArc GetTotalArc_HWValues: .db (10*$4000)>>24&$FF,(10*$4000)>>16&$FF,(10*$4000)>>8&$FF,(10*$4000)&$FF .db (94*$4000)>>24&$FF,(94*$4000)>>16&$FF,(94*$4000)>>8&$FF,(94*$4000)&$FF .db (30*$4000)>>24&$FF,(30*$4000)>>16&$FF,(30*$4000)>>8&$FF,(30*$4000)&$FF .db (94*$4000)>>24&$FF,(94*$4000)>>16&$FF,(94*$4000)>>8&$FF,(94*$4000)&$FF
GetFreeArc: ;——————————————————————————————————————————————; ;—> Returns the amount of free archive as a 7-character decimal string ;INPUTS: none ;OUTPUTS: hl=pointer to string (OP3) ;DESTROYS: af bc de ix ;——————————————————————————————————————————————; B_CALL($5014) ;ArcChk exde,hl inchl
ConvArc: ;——————————————————————————————————————————————; ;—> Converts a 32-bit integer into a 7-character decimal string ;INPUTS: hl=pointer to 32-bit integer (big-endian) ;OUTPUTS: hl=pointer to string (OP3) ;DESTROYS: af bc de ix ;——————————————————————————————————————————————; rst 20h ldhl,OP3+7 ldde,10 ld (hl),d ldb,7 ConvArc_Loop1: pushbc pushhl B_CALL($80B1) ;Div32By16 pophl popbc lda,(OP2+3) adda,'0' dechl ld (hl),a djnz ConvArc_Loop1 ldd,h lde,l ldbc,6<<8+'0' ConvArc_Loop2: lda,(de) cpc ret nz lda,' ' ld (de),a incde djnz ConvArc_Loop2 ret
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 04, 2011, 01:26:30 pm
Another (huge) update-bump:
Finally, a real UI. It's no longer two text boxes and a ginormous button.
Custom colors! Dynamic preview too for the heck of it.
AJAX updating instead of the form (if you have Javascript enabled), making each submission much, much faster. Still works without JS (for once).
Upload a file! It even echoes anything inside back into the text box so you can keep tweaking it without leaving the page.
EDIT: And now I got banned from my own website x.x
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on July 04, 2011, 06:00:43 pm
O.O
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 04, 2011, 06:01:58 pm
Yep, special feature at http://clrhome.org/resources/bbify/?action=ie <_<
EDIT: Man, your screen is huge!
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: thepenguin77 on July 04, 2011, 09:07:23 pm
Aw it's down. I wonder if Juju could maybe host it? It would probably be more stable.
I'm moving the entire site to his server right now, in fact. You can now access BBify at http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/) (notice I'm taking the opportunity to change my domain name too).
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 03:55:15 pm
WHOO HOO BUMP
Same URL as before: http://clrhome.org/resources/bbify/
New features that don't matter at all:
The BBify'r is now W3C-compliant XHTML.
New features that matter if you use the worst browser in existence:
The BBify'r is now IFE compliant. All the way down to IE7 (can't test below that ATM).
New features that actually do make a difference:
The BBify'r now accepts code from the Pastebin (http://pastebin.com/)! Added a new text box just for that purpose.
EDIT: Another update! Pastes from http://paste.bwns.be/ also work :D
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on August 04, 2011, 04:28:57 pm
Looking awesome Deep Thought, I dislike the W3C Compliant button, it just looks bad :P
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 04:34:42 pm
EDIT: Another update! Pastes from http://paste.bwns.be/ also work :D
w00t, its actually being used \o/
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on August 04, 2011, 04:35:53 pm
Quote
Seriously, though, I have no idea where else to put it. And I want to put it somewhere
My problem is using it, having validated pages is cool, but showing it off is not so cool in my opinion. The only important website using it was python.org, but they removed it recently.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 05:09:28 pm
Seriously, though, I have no idea where else to put it. And I want to put it somewhere
My problem is using it, having validated pages is cool, but showing it off is not so cool in my opinion. The only important website using it was python.org, but they removed it recently.
I was actually planning to have (http://clrhome.org/images/compliant.png) there as well, but yeah, that's a good point.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 06:27:19 pm
Idea: What about one for Axe? I'm starting to work on it (it doesn't work yet).
Can you make it in a way it uses XML files or something like that, so it's easy to make it for all languages?
Guess what? Done!
I don't have time to post the specs right now, but here's the z80.xml (default) set. See if you can understand it, and I'll post more info tomorrow.
Enjoy!
EDIT: Hint: it uses my regex parser that uses <#> for backreferences.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on August 04, 2011, 06:46:40 pm
Nice update Deep Thought :)
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: ben_g on August 04, 2011, 07:29:46 pm
It's a great tool. I already used it a few times when i posted asm source code.
BTW: those terms and conditions, I don't really know how you can agree with them :p And nobody has said anything abouth this. I think nobody here checks them.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 05, 2011, 01:34:57 pm
The XML file should be wrapped in a single <scheme> tag, containing one or more <rule> elements that defines a replacement rule. Each <rule> is parsed one by one, so order is important.
Each <rule> tag has one <f> element and one <r> element, both containing one CDATA section with a preg regex inside. <f> defines the pattern to search for, and should be wrapped in the appropriate delimiters (http://www.php.net/manual/en/regexp.reference.delimiters.php). (Remember that all &, <, and > chars are HTML-escaped.) <r> contains the replacement text, using <#> for backreferences (no escaping since it's in a CDATA).
Actually Nop just uses up a few cycles, so it actually does something, that something is just sitting and waiting though :P
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 10, 2011, 04:12:07 pm
whoo hoo fixed a few bugs with HTML encoding and jim's pastebin and added permalinking (http://clrhome.org/resources/bbify/?t=.nolist%0D%0A%23include++++%22ti83plus.inc%22%0D%0A%23define+++++ProgStart++++%249D95%0D%0A.list%0D%0A.org++++++++ProgStart%2C2%0D%0A.db+++++++++%24BB%2C%246D%0D%0A++++B_CALL++%28_ClrLCDFull%29%0D%0A++++LD++++++HL%2C0%0D%0A++++LD++++++%28PenCol%29%2CHL%0D%0A++++LD++++++HL%2CMessage%0D%0A++++B_CALL++%28_PutS%29+++++%3B+Displays+the+string%0D%0A++++B_CALL++%28_NewLine%29%0D%0A++++RET%0D%0AMessage%3A%0D%0A.db+++++++++%22Hello+world%21%22%2C0%0D%0A.end%0D%0AEND&l=z80#done)EDIT: What the heck. Made it work with any page with a textarea on it!
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 23, 2011, 06:24:56 pm
Update (as always, located at http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/)
URL parameters as input Syntax: http://clrhome.org/resources/bbify/?t=TEXT or http://clrhome.org/resources/bbify/?u=PASTE, where TEXT is raw Z80 text and PASTE is the URL to a pastebin'd code Example: http://clrhome.org/resources/bbify/?u=http://pastebin.com/569yPeu6 (yes, I found a spam post ;D)
Fixed some glitches with < and > in the Z80 ruleset
Fixed a terrible bug that made output non–W3C-compliant
An improved Biebify'r (http://clrhome.org/resources/biebify/) page
EDIT: Whoops, forgot to turn off ?ie in the normal BBify...
Title: Re: BBify your Axe and Z80 code!
Post by: Deep Toaster on August 29, 2011, 01:52:44 pm
Sorry for the triple-post, but the BBify'r now works for Axe! :w00t:
Finished making the rules sheet for Axe syntax. Turns out it's even more complicated than ASM:
For Axe, it does more than just highlight certain strings of text, like with the Z80 rules. It actually recognizes every command you're allowed to use in Axe, so it's a great way to check your syntax. It's lenient on closing parentheses and braces (since Axe Parser does that too).
Axe code should be in TokenIDE format. (I may create a new rule sheet for SourceCoder later on.) The easiest way to grab valid code to put into BBify'r:
Download TokenIDE from http://myserverathome.com/Tokens.zip (http://myserverathome.com/Tokens.zip), extract the zip, and open it
Under the File menu, click Change Token File and choose the AxeTokens.xml packaged with Tokens.zip
Open your Axe source
Copy and paste the code into the BBify'r (http://clrhome.org/resources/bbify/#t), or save as a .txt file and upload
Remember to choose Axe (Tokens) as your engine. And don't worry about those weird ^^r things -- the BBify'r will automagically do replacements for you, such as ^^r to r and -> to →!
Here she is parsing the AXEGOL example program:
Quote from: Axe
.\G\A\M\E\O\F\L\ Full DiagnosticOff ClrDraw For(A,33,62 For(B,17,43 If rand^2 sub(AB End:End:End While getKey!=15:DispGraph For(A,33,62 For(B,17,43 pxl-Test(A-1,B-1)+pxl-Test(A-1,B)+pxl-Test(A-1,B+1)+pxl-Test(A,B-1)+pxl-Test(A,B+1)+pxl-Test(A+1,B-1)+pxl-Test(A+1,B)+pxl-Test(A+1,B+1)→S If S=3oror (S=2 and pxl-Test(A,B Pxl-On(A-32,B Pxl-On(A-32,B End End:End For(A,33,62 For(B,17,43 Pxl-Off(A,B If pxl-Test(A-32,B sub(AB Pxl-Off(A-32,B End End:End End Return
Lbl AB Pxl-On(A,B Return
Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
Thanks! And this is a bit of a late tip, but in case you haven't figured it out yet, put [pre] tags inside the [quote] to make it nice and monospaced. The reason I don't include it automatically is because only SMF supports it.
Title: Re: BBify your Axe and Z80 code!
Post by: Deep Toaster on September 04, 2011, 09:15:23 pm
Big update!
You can now upload .8xp files as Axe source. Valid programs will be automatically detokenized into TokenIDE-style text! That also makes the BBify'r an online detokenizer :D
Title: Re: BBify your Axe and Z80 code!
Post by: DJ Omnimaga on September 04, 2011, 09:58:52 pm
Awesome Deep Thought.
Title: Re: BBify your Axe and Z80 code!
Post by: Deep Toaster on September 24, 2011, 12:17:07 pm
Updates:
It now saves your settings and text after you submit so you can keep tweaking the colors or working on it, in-browser.
Nspire Lua support!
Spoiler For Example:
Quote from: Lua
-- Balance chemical equation -- John Powers 2010-06-03
-- Previous location of mouse pointer self.prev_mousex = 0 self.prev_mousey = 0 end
function View:invalidate() self.window:invalidate() end
function View:add(o) table.insert(self.widgetList, o) if o.acceptsFocus then table.insert(self.focusList, o) end return o end
function View:sendStringToFocus(str) self.focusList[self.currentFocus]:addString(str) self.window:invalidate() end
function View:sendBackspaceToFocus() self.focusList[self.currentFocus]:delChar() self.window:invalidate() end
function View:tabForward() local nextFocus = self.currentFocus + 1 if nextFocus > #self.focusList then nextFocus = 1 end self.currentFocus = nextFocus self.window:invalidate() end
function View:tabBackward() local nextFocus = self.currentFocus - 1 if nextFocus < 1 then nextFocus = #self.focusList end self.currentFocus = nextFocus self.window:invalidate() end
function View:onMouseDown(x, y) -- Find a widget that has a mouse down handler and bounds the click point for _, o in ipairs(self.widgetList) do local md = o.onMouseDown if md and o:contains(x, y) then self.mouseCaptured = o md(o, window, x - o.x, y - o.y) break end end end
function View:onMouseMove(x, y) local prev_mousex = self.prev_mousex local prev_mousey = self.prev_mousey for _, o in ipairs(self.widgetList) do local xyin = o:contains(x, y) local prev_xyin = o:contains(prev_mousex, prev_mousey) if xyin andnot prev_xyin then -- Mouse entered widget o:onMouseEnter(x, y) elseif prev_xyin andnot xyin then -- Mouse left widget o:onMouseLeave(x, y) end end self.prev_mousex = x self.prev_mousey = y end
function View:onMouseUp(x, y) local mc = self.mouseCaptured if mc then self.mouseCaptured = nil if mc:contains(x, y) then mc:onMouseUp(x - mc.x, y - mc.y) else mc:cancelClick() end end end
function View:enterHandler() -- Does the focused widget accept Enter? local o = self.focusList[self.currentFocus] if o.acceptsEnter then o:enterHandler() self.window:invalidate() else-- look for a default Enter handler for _, o in ipairs(self.widgetList) do if o.visible and o.default then o:enterHandler() self.window:invalidate() end end end end
function View:paint(gc) local fo = self.focusList[self.currentFocus] for _, o in ipairs(self.widgetList) do if o.visible then o:paint(gc, fo == o) end end end
function Widget:init(view, x, y, w, h) self.view = view self.x = x self.y = y self.w = w self.h = h self.acceptsFocus = false self.visible = true end
function Widget:contains(x, y) return x >= self.x and x <= self.x + self.w and y >= self.y and y <= self.y + self.h end
function Widget:onMouseEnter(x, y) -- Implemented in subclasses end
function Widget:onMouseLeave(x, y) -- Implemented in subclasses end
--------------------------------------------------------------------- Text
Text = class(Widget)
function Text:init(view, x, y, w, h, text, just, style) if w <= 0 then w = 10 * #text end if h <= 0 then h = 22 end Widget.init(self, view, x, y, w, h) self.text = text or "" if just == "right" then self.just = 2 -- right justified elseif just == "center" then self.just = 1 -- centered else self.just = 0 -- left justified end self.style = style or "r" end
-- Adds a string to the end of the text function Text:addString(str) self.text = self.text .. str self.view:invalidate() end
function Text:stringWidth() local gc = platform.gc() gc:begin() local w = gc:getStringWidth(self.text) gc:finish() return w end
function Text:stringHeight() local gc = platform.gc() gc:begin() local h = gc:getStringHeight(self.text) gc:finish() return h end
function Text:setText(str) self.text = tostring(str) self.view:invalidate() end
-- Deletes character from end of text function Text:delChar() if #self.text > 0 then self.text = self.text:usub(1, -2) self.view:invalidate() end end
-- Returns a formatted version of the text function Text:format() return self.text end
function Text:paint(gc, focused) local text = self:format() gc:setColorRGB(0, 0, 0) if focused then gc:setPen("thin", "dotted") gc:drawRect(self.x, self.y, self.w, self.h) text = text .. "_" end gc:setFont("sansserif", self.style, 11) local x = self.x + 1 if self.just == 1 then-- centered x = self.x + (self.w - gc:getStringWidth(text))/2 elseif self.just == 2 then-- right justified x = self.x + self.w - gc:getStringWidth(text) - 1 end gc:drawString(text, x, self.y + self.h, "bottom") end
function Button:init(view, x, y, w, h, text, default, command) Widget.init(self, view, x, y, w, h)
-- Button configuration self.text = text self.default = default -- is default button when ENTER is pressed self.command = command orfunction() end-- what to do when pressed self.acceptsFocus = true self.acceptsEnter = true
-- Current button state self.clicked = false self.highlighted = false end
-- Act on key press on button function Button:addString(str) if str == " " then self:command() end end
function Button:onMouseDown(x, y) self.clicked = true self.highlighted = true self.view:invalidate() end
function Button:onMouseEnter(x, y) if self.clicked andnot self.highlighted then self.highlighted = true self.view:invalidate() end end
function Button:onMouseLeave(x, y) if self.clicked and self.highlighted then self.highlighted = false self.view:invalidate() end end
function Button:onMouseUp(x, y) if self.clicked then self.highlighted = false self.clicked = false self:command() self.view:invalidate() end end
function Button:cancelClick() self.clicked = false end
function Button:enterHandler() self:command() end
function Button:paint(gc, focused) local x = self.x local y = self.y local w = self.w local h = self.h local radius = 5 local diam = 2*radius
if focused then gc:setPen("thin", "dotted") elseif self.default then gc:setPen("thin", "smooth") else gc:setPen("thin", "smooth") end
local bkgr, bkgg, bkgb = 0xE0, 0xE0, 0xE0 if self.highlighted then bkgr = 0xC0 bkgg = 0xC0 bkgb = 0xC0 end
-- top left corner gc:setColorRGB(bkgr, bkgg, bkgb) gc:fillArc(x, y, diam, diam, 90, 90) gc:setColorRGB(0, 0, 0) gc:drawArc(x, y, diam, diam, 90, 90)
-- bottom left corner gc:setColorRGB(bkgr, bkgg, bkgb) gc:fillArc(x, y + h - diam, diam, diam, 180, 90) gc:setColorRGB(0, 0, 0) gc:drawArc(x, y + h - diam, diam, diam, 180, 90)
-- bottom right corner gc:setColorRGB(bkgr, bkgg, bkgb) gc:fillArc(x + w - diam, y + h - diam, diam, diam, 270, 90) gc:setColorRGB(0, 0, 0) gc:drawArc(x + w - diam, y + h - diam, diam, diam, 270, 90)
-- top right corner gc:setColorRGB(bkgr, bkgg, bkgb) gc:fillArc(x + w - diam, y, diam, diam, 0, 90) gc:setColorRGB(0, 0, 0) gc:drawArc(x + w - diam, y, diam, diam, 0, 90)
-- Draw label gc:setFont("sansserif", "b", 10) gc:drawString(self.text, x + (w - gc:getStringWidth(self.text))/2, y+1, "top") end
function SpinBoxArrow:init(view, x, y, w, h, dir, command) Button.init(self, view, x, y, w, h, nil, false, command) self.dir = dir -- "up" or "down" end
function SpinBoxArrow:onMouseDown(x, y) self:command() end
function SpinBoxArrow:onMouseEnter(x, y) end
function SpinBoxArrow:onMouseLeave(x, y) end
function SpinBoxArrow:onMouseUp(x, y) end
function SpinBoxArrow:paint(gc, focused) local x1 = self.x + self.w/2 local x2 = x1 + 5 local x3 = x2 - 10
local y1, y2, y3
if self.dir == "up" then y1 = self.y y2 = y1 + self.h y3 = y2 else y1 = self.y + self.h y2 = self.y y3 = y2 end
-- Splits up elements in the formula for a molecule. -- Returns a Molecule -- .formula = molecular formula -- .elements = {element = count, ...} function Molecule.splitElements(formula) local m = {} m.formula = formula
local elems = {} for elem, count in formula:gmatch("(%u%l?)(%d*)") do if #count == 0 then count = 1 else count = tonumber(count) end elems[elem] = count end m.elements = elems return m end
-- Splits up molecules in the formula for a reaction. -- Returns a list of Molecules function Molecule.splitMolecules(formula) local molecules = {} for mol in formula:gmatch("[^%s+]+") do molecules[#molecules + 1] = Molecule.splitElements(mol) end return molecules end
--------------------------------------------------------------------- Element Text
ElementText = class(Text)
function ElementText:init(view, x, y, w, h, name, molecules) Text.init(self, view, x, y, w, h) self.name = name self.molecules = molecules end
-- Count total atoms in molecules function ElementText:total() local total = 0 for _, m in ipairs(self.molecules) do local count = m.elements[self.name] if count then total = total + m.controller:value() * count end end return total end
function ElementText:format() return self:total() .. " " .. self.name end
--------------------------------------------------------------------- Beam balance -- -- This is a visual widget that looks like a balance. It leans in the direction -- of the heavier side or is level when the same number of elements on each side.
Balance = class(Widget)
-- The balance needs references to the elements on left and right sides. These -- must be ElementText objects. function Balance:init(view, x, y, leftElement, rightElement) Widget.init(self, view, x, y, self.width, self.height)
self.left = leftElement self.right = rightElement end
function Balance:paint(gc) local left = self.left:total() local right = self.right:total() local x = self.x local y = self.y
local color = {0, 0, 255} -- blue local leftBeamEndpoint = {0, self.midy} local rightBeamEndpoint = {self.width, self.midy} local leftRadius = self.smallRadius local rightRadius = self.smallRadius
if left > right then -- Left side is heavier color = {255, 0, 0} -- red leftBeamEndpoint = {self.leftx, self.bottomy} rightBeamEndpoint = {self.rightx, 0} leftRadius = self.largeRadius rightRadius = self.smallRadius
elseif left < right then -- Right side is heavier color = {255, 0, 0} leftBeamEndpoint = {self.leftx, 0} rightBeamEndpoint = {self.rightx, self.bottomy} leftRadius = self.smallRadius rightRadius = self.largeRadius
end
gc:setPen("thin", "smooth")
gc:setColorRGB(unpack(color))
-- Draw pedestal local x1 = self.width/2 - 3 local y1 = self.height local x2 = self.width/2 local y2 = self.height/2 local x3 = self.width/2 + 3 local y3 = self.height gc:drawPolyLine({x1+x, y1+y, x2+x, y2+y, x3+x, y3+y, x1+x, y1+y})
function createBalanceScreen(window, input_formula, output_formula)
theView = View(window)
-- Title theView:add(Text(theView, 10, 2, 300, 22, "Balance Chemical Formula", "center", "b"))
local input_molecules = Molecule.splitMolecules(input_formula) local output_molecules = Molecule.splitMolecules(output_formula)
-- Survey the elements local elements = {} for _, m in ipairs(input_molecules) do for elem, count in pairs(m.elements) do elements[elem] = true end end
local x = 10 local y = 33 local sb_width = 15
-- Display reactants for i, m in ipairs(input_molecules) do local sb = SpinBox(theView, x, y, 15, 22) theView:add(sb) x = x + sb_width local molecule = MoleculeText(theView, x, y, 0, 0, sb, m) theView:add(molecule) m.controller = molecule
x = x + molecule:stringWidth()
if i < #input_molecules then local plus = Text(theView, x, y, 0, 0, "+") theView:add(plus) x = x + plus:stringWidth() end end
-- Arrow theView:add(Text(theView, x+3, y, 14, 22, string.uchar(0x2192), "center")) x = x + 17
-- Display resultants for i, m in ipairs(output_molecules) do local sb = SpinBox(theView, x, y, 15, 22) theView:add(sb) x = x + sb_width local molecule = MoleculeText(theView, x, y, 0, 0, sb, m) theView:add(molecule) m.controller = molecule
x = x + molecule:stringWidth()
if i < #output_molecules then local plus = Text(theView, x, y, 0, 0, "+") theView:add(plus) x = x + plus:stringWidth() end end
-- Display elements
local col1x = 30 local col3x = 210 y = 75 for elename, _ in pairs(elements) do -- Reactants local left = ElementText(theView, col1x, y, 70, 22, elename, input_molecules) theView:add(left)
-- Resultants local right = ElementText(theView, col3x, y, 70, 22, elename, output_molecules) theView:add(right)
-- Balance theView:add(Balance(theView, 110, y, left, right))
y = y + 34 end
-- Edit button theView:add(Button(theView, 110, y, 100, 22, "Edit", true, function() createEditScreen(window, input_formula, output_formula) end ))
function on.charIn(ch) theView:sendStringToFocus(ch) end
function on.backspaceKey(ch) theView:sendBackspaceToFocus() end
function on.tabKey() theView:tabForward() end
function on.backtabKey() theView:tabBackward() end
function on.paint(gc) theView:paint(gc) end
function on.enterKey(gc) theView:enterHandler() end
function on.mouseDown(x, y) theView:onMouseDown(x, y) end
function on.mouseMove(x, y) theView:onMouseMove(x, y) end
function on.mouseUp(x, y) theView:onMouseUp(x, y) end
function on.save() return {input = input.text, output = output.text} end
function on.restore(state) createEditScreen(platform.window, state.input, state.output) end
Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
Title: Re: BBify your Z80, Axe, and Lua
Post by: mrmprog on September 24, 2011, 02:15:29 pm
Nice! Now axe code won't be such a pain. I like how it saves the stuff so you can keep working, and the colors.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 01, 2011, 10:25:53 pm
As Darl181 suggested, I've fixed the bug where Axe comments have a backslash before every token when uploading an Axe source.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Darl181 on October 01, 2011, 10:53:50 pm
Hm, it seems it's replacing [Sto►] arrows with "?"
EDIT: wait a sec, for the copy/paste in the piratepad which text editor did you use?
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 01, 2011, 11:00:34 pm
Notepad++, which is probably why. The editor's UI only supports ASCII. BBify handles it perfectly:
Quote from: Axe
→
Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 18, 2011, 11:48:26 pm
UPDATE: TIOS v3.0.2 and Luna make this update seem a bit late in coming, but whatever. Just like with Axe source programs, you can now upload your Lua source in TI Document format, as long as it's unencrypted (for Lua on OS 3.0.1 and before)! It'll read the Lua code from your TNS documents.
Title: Re: BBify your Z80, Axe, and Lua
Post by: DJ Omnimaga on October 18, 2011, 11:59:35 pm
Nice to hear it supports Nspire too. I was sure it was only for z80 stuff. Good job so far. :)
Does it support TI-BASIC, Casio BASIC, C and BBC Basic, btw? (The first two might be a bit obsolete though due to SourceCoder)
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 19, 2011, 12:14:18 am
I wasn't planning on BASIC support since SourceCoder does that very well, but C and other languages might be possible.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Jim Bauwens on October 19, 2011, 03:32:44 am
I somehow must have skipped all of this D: Lua support \o/ /me hugs Deep Thought
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 19, 2011, 10:38:29 am
Yep :) I don't think I've posted this yet, so here's more information about the Lua syntax it supports. Standard Lua control structures, operators, and keywords are supported, but not individual libraries like table, math, and debug. Instead, it recognizes and highlights functions and libraries specific to Nspire Lua like timer, gc, and D2Editor.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Chockosta on October 19, 2011, 02:16:37 pm
Just amazing ! I love Lua support ! /me gives respect to DT
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 07, 2011, 07:51:49 pm
Update: 83P-series TI-BASIC detokenizing and syntax highlighting has been added, and lots of bugs with Axe syntax have been fixed! It now automatically checks if a program you upload is an Axe source or TI-BASIC program.
Quote from: TI-BASIC
"THE GAME→Str0 0 For(I,1,8 30Ans+inData("ABCDEFGHIJKLMNOPQRSTUVWXYZtheta :?",sub(Str0,I,1 End Ans→J " →Str0 J For(I,1,8 Ans/30→J sub("ABCDEFGHIJKLMNOPQRSTUVWXYZtheta :?",round(3�float{Ans),�),1)+Str0→Str0 nib{J End Str0
Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 08, 2011, 02:49:49 pm
Might it be possible to disable the coloring? It gets pretty hard if you want to modify your code later when every token has its own color tag x.x
Also, for some reason some chars (esp. zeroes) don't display/get parsed properly or something, firefox shows a diamond with a ?
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 08, 2011, 03:48:07 pm
Quote from: Darl181
Might it be possible to disable the coloring? It gets pretty hard if you want to modify your code later when every token has its own color tag
Yeah, I added a "Plain text" option for highlighting, but remember you can always copy-paste your code back into BBify (not the BBCode, but what shows up on the forum).
Quote from: Darl181
Also, for some reason some chars (esp. zeroes) don't display/get parsed properly or something, firefox shows a diamond with a ?
I thought I'd fixed that. Do you have the code you used?
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 09, 2011, 11:18:23 am
The code attached in this (http://ourl.ca/9165/259893) post. It seemed to center on the sprite declarations in particular, if that helps.
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 09, 2011, 06:35:01 pm
Fixed. All zeros were being parsed as null bytes :P
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 12, 2011, 11:14:15 am
...and now it's putting slashes between every token again x.x
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 12, 2011, 11:48:14 am
It doesn't for me ??? Only in the input box after detokenizing, and that's to prevent it from reading a minus sign followed by a greater-than sign as → and so on. \ separates ambiguous characters in TokenIDE.
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 12, 2011, 05:37:35 pm
Nvm, it was set as "Plain Text" :P
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 12, 2011, 07:26:45 pm
Should I remove the slashes even for plain text?
Title: BBify: detokenize and highlight your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on January 01, 2012, 03:00:47 pm
UPDATE: I had this idea months ago, but I finally sat down and made it today. The BBify'r now has a "BBify Builder" function, where you type some stuff and watch it generate a language rules sheet for you. So you can now use it to highlight the syntax of any language without needing to know regular expressions. Just type what it asks you to type and it builds everything for you.
When you're done, you can choose to download the XML file (and upload it as a custom rules sheet to use) or save it online—it'll be there as an option the next time you need it!
(http://img.removedfromgame.com/imgs/bbify.png)
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on January 01, 2012, 03:12:18 pm
I'm not sure, but maybe make the options more prominent? Maybe not fill one in by default or something, and require that one is checked.
I actually got rid of the Plain Text option :/ If you need your code without highlighting, just post it in a forum (you can use Preview) and copy-paste the result.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on March 30, 2013, 06:07:03 pm
Major necro-update
The BBify'r now generates code coloring in HTML as well as BBCode!
That means two things:
Instant previews of what your colored code will look like. You can even copy-paste the text directly from the preview into, say, an email or HTML editor.
HTML code for your syntax-colored code. Use this box if you need to paste it directly into a webpage.
As always: http://clrhome.org/bbify/
I might change the URL and the name of the project someday, since it's not just for BBCode conversion anymore.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Jonius7 on July 11, 2013, 06:57:39 am
I was reminded of this topic by this topic: http://ourl.ca/119725 And bbify literally went offline 5 minutes after I started using it. And now it's back online. EDIT: It didn't seem to work for uploading code files, it would submit/reload the page but do nothing else.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Sorunome on July 11, 2013, 11:12:26 am
Ui, nice, this is useful! We should have a modified [code] tag though to also highlight for like basic or axe :P
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on July 11, 2013, 01:32:35 pm
I was reminded of this topic by this topic: http://ourl.ca/119725 And bbify literally went offline 5 minutes after I started using it. And now it's back online.
I'm on a free server that seems to have gotten worse over time. Looking for a new host soon.
EDIT: It didn't seem to work for uploading code files, it would submit/reload the page but do nothing else.
Works for me.
There are two file upload buttons, one for the (optional) stylesheet and one for the actual code. Are you sure you uploaded it in the right place?
I think I'll reverse the order of steps on the page. Seems to make more sense to put code in first, and then customize colors and stuff.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Jonius7 on July 12, 2013, 03:29:56 am
Yeah step 3, under give me your code, with the code box on the left and the upload file/url link on the right. The code box works, the file upload doesn't.
EDIT: oh wait a minute it wasn't working before, now it's uploading... but it didn't seem to work. What kind of TI-nspire/Lua files can it accept?
EDIT: it works for Axe 8xp :)
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on July 12, 2013, 01:00:13 pm
You're right—seems file uploads worked with 8XP and unencrypted (OS 3.0.1) TNS files, which get detokenized and parsed, but not plain-text source code :P Fixed.
Thanks for the bug report!
Supported filetypes are 8XP (protected or unprotected), TNS (unencrypted only), and plain-text.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: DJ Omnimaga on July 26, 2013, 01:18:29 am
I was reminded of this topic by this topic: http://ourl.ca/119725 And bbify literally went offline 5 minutes after I started using it. And now it's back online.
I'm on a free server that seems to have gotten worse over time. Looking for a new host soon.
I assume that Omnimaga hosting (like ASM Unsquisher) isn't an option?
(Also you might want to backup your site and tools more often since your hosting is getting worse and worse. No one knows if it won't shut down tomorrow or at any other moment without warning)
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on July 26, 2013, 01:04:05 pm
I was reminded of this topic by this topic: http://ourl.ca/119725 And bbify literally went offline 5 minutes after I started using it. And now it's back online.
I'm on a free server that seems to have gotten worse over time. Looking for a new host soon.
I assume that Omnimaga hosting (like ASM Unsquisher) isn't an option?
(Also you might want to backup your site and tools more often since your hosting is getting worse and worse. No one knows if it won't shut down tomorrow or at any other moment without warning)
I'm looking into getting a paid host of my own, preferably a VPS.
You're completely right that the uptime's getting worse. 000webhost "guarantees" 99% uptime, and their official "independent" uptime tracker at http://www.serviceuptime.com/users/monitoring.php?S=6c8ef11fcca35bab3d971cdce3d7179b shows well above 99%. But notice how they stopped keeping track of uptime last year (specifically doomsday). Meanwhile, Pingdom tells me my uptime's been dropping steadily, and now it's around 75% >:(
On the other hand, I'm taking backups every night straight into my Google Drive, and one of my flash drives is a mirror of the complete site, so data loss isn't a problem.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: DJ Omnimaga on July 29, 2013, 09:31:56 pm
Yeah, hosting providers try to lure new customers by offering really good uptime and sometimes speed, then once the customers have settled in for a while, they slowly degrade the performances then eventually offer more expensive plans to those who are no longer satantified by the performances. Then they just shut down their free hosting entirely.
The other scenario is when they offer a pool of resources just for free hosting, but that are split between customers. If the company doesn't upgrade, it really gets slow when there are 1000 customers.