See the screenshot below. :) Something's not right... but it's more functional than I expected. Perhaps there's a JS engine bug I could report to Google...
some javascript, some microsoft oslo, some mgrammar, some Perl 6, some Perl.
syntax Main
= something:any+ => id(something)[or => valuesof(other)];
- added MGraph (projections) recognition (but they're still noops, just like the
variable/symbol assignments/bindings)
- lots of performance/responsiveness improvements, such as canceling the current
parse attempt if another key is pressed in the input or grammar window (kinda
difficult in single-threaded, async-emulated JS), and added lots of "fastfail"
error() combinators in the DynamicParser generator.
- fixed bug with required-interleave accepting only one interleave character
(oops)
- added new shortcut combinators UseFirst & UseSecond
- added smarter error location reporting for the die/error combinators
- added some more parser tests as a result of working on JSMetaSheet (online
spreadsheet workalike, don't try it though, yet. Goals: minimal computation,
maximally responsive UI.) :) The columns resize and cells edit/navigate
generally as expected, but formulas don't evaluate at the moment in most
browsers. :) Yes, as usual I spent way too long on the details of the UI.
Please, no one let me do UI development; I'm sorta (comparatively) slow at it.
- fixed an off-by-one error (wait, TWO off-by-one errors; ha) in the left-
recursion handling (finally discovered after an all-day debugging/diagnosis
session while working on JSMetaSheet. That kinda burned me out for a few
days... As someone commented, "that's part of the price of doing meta-meta-
meta-programming")
//
module JSMeta {
language HelloWorld {
syntax Main = ((Bar('q') | Bar) Bar | Bar Bar Bar)+;
syntax Bar = 'a';
token Bar(param0) = 'b' param0 'z';
interleave Ignored = Language.Base.Whitespace | Language.Grammar.Comment;
}
}
function spawnOf(progenitor) {
// obtain a reference to the function
// that created the object
var Ctor = typeof(progenitor.constructor)!='undefined'
? progenitor.constructor
: getGlobal()[Object.prototype.toString.call(
progenitor).match(/^\[object\s(.*)\]$/)[1]];
// the below shouldn't ever happen
// (except on undefined or null)
if (typeof Ctor != 'function')
throw 'constructor not found';
// save the original prototype of
// the constructor function
var origProto = Ctor.prototype;
// replace the constructor function's
// prototype with the progenitor object
Ctor.prototype = progenitor;
// create a new "child" object, using the same
// constructor function as the progenitor object.
var childObject = new Ctor();
// replace the constructor function's prototype.
Ctor.prototype = origProto;
return childObject;
}
// from http://www.nczonline.net/blog/2008/04/20/get-the-javascript-global/
// by Nicholas C. Zakas
function getGlobal() {
return (function() {
return this;
}).call(null);
}
// for v8(.exe) or jsc(.exe) or whatever
// mozilla's js .exe are named
if (typeof(alert)=='undefined') alert=print;
function Gungan() {
this.toString = function() {
return "_|meesa Gungan|_"
};
if (this.constructor
===Gungan.prototype.constructor) {
// odd quirk here; this is never true in
// v8: (Gungan.prototype instanceof Gungan)
this.parent = Gungan.prototype;
}
}
var jarjar = new Gungan();
jarjar.iq = 100;
var jarjar_kid = spawnOf(jarjar);
alert(jarjar_kid.iq); // alerts "100"
jarjar_kid.iq = 85;
alert(jarjar.iq); // alerts "100"
alert(jarjar_kid.iq); // alerts "85"
alert(jarjar_kid.parent.iq); // alerts "100"
Const HKCU=&H80000001 'HKEY_CURRENT_USER
Const HKLM=&H80000002 'HKEY_LOCAL_MACHINE
Const REG_SZ=1
Const REG_EXPAND_SZ=2
Const REG_BINARY=3
Const REG_DWORD=4
Const REG_MULTI_SZ=7
Const HKCU_IE_PROXY = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set oReg=GetObject("winmgmts:!root/default:StdRegProv")
Main
Sub Main()
' If Proxy is set then turn it off
If GetValue(HKCU,HKCU_IE_PROXY,"ProxyEnable",REG_DWORD) = 1 Then
CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",0,REG_DWORD
wscript.echo "Proxy Disabled"
Else
' If Proxy is not set then turn it on
CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",1,REG_DWORD
wscript.echo "Proxy Enabled" & vbcrlf
End If
End Sub
Function CreateValue(Key,SubKey,ValueName,Value,KeyType)
Select Case KeyType
Case REG_SZ
CreateValue = oReg.SetStringValue(Key,SubKey,ValueName,Value)
Case REG_EXPAND_SZ
CreateValue = oReg.SetExpandedStringValue(Key,SubKey,ValueName,Value)
Case REG_BINARY
CreateValue = oReg.SetBinaryValue(Key,SubKey,ValueName,Value)
Case REG_DWORD
CreateValue = oReg.SetDWORDValue(Key,SubKey,ValueName,Value)
Case REG_MULTI_SZ
CreateValue = oReg.SetMultiStringValue(Key,SubKey,ValueName,Value)
End Select
End Function
Function DeleteValue(Key, SubKey, ValueName)
DeleteValue = oReg.DeleteValue(Key,SubKey,ValueName)
End Function
Function GetValue(Key, SubKey, ValueName, KeyType)
Dim Ret
Select Case KeyType
Case REG_SZ
oReg.GetStringValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_EXPAND_SZ
oReg.GetExpandedStringValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_BINARY
oReg.GetBinaryValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_DWORD
oReg.GetDWORDValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_MULTI_SZ
oReg.GetMultiStringValue Key, SubKey, ValueName, Value
Ret = Value
End Select
GetValue = Ret
End Function
Array.prototype.slice.call(arguments)
function popArgs() {
[].pop.call(arguments);
return arguments;
}
function testArgsPop() {
var oldArgs = arguments;
var newArgs = popArgs.apply(null, arguments);
var oldArgsArray = Array.apply(null, oldArgs);
alert(oldArgsArray.toString());
var newArgsArray = Array.apply(null, newArgs);
alert(newArgsArray.toString());
}
testArgsPop(1,2,3);
// executing this snippet alerts "1,2,3" and then "1,2"
var argsToArray = (function() {
// cache the slice method in a closure
var Array_prototype_slice = Array.prototype.slice;
return function argsToArray() {
return Array_prototype_slice.call(arguments, 0);
};
})();
var arrayCreator = Array;
function argsToArray() {
// don't call argsToArray, just use arrayCreator.apply(null, arguments) directly.
return arrayCreator.apply(null, arguments);
}