diff --git a/package.json b/package.json index d3b90c6e..41780914 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "http-server": "^0.9.0", "monaco-css": "1.3.2", "monaco-editor-core": "0.9.0", - "monaco-html": "1.3.0", - "monaco-json": "1.3.0", + "monaco-html": "1.3.1", + "monaco-json": "1.3.1", "monaco-languages": "0.8.0", "monaco-typescript": "2.2.0", "rimraf": "^2.5.2", diff --git a/test/playground.generated/creating-the-editor-hard-wrapping.html b/test/playground.generated/creating-the-editor-hard-wrapping.html index 1d971ab0..6fa57522 100644 --- a/test/playground.generated/creating-the-editor-hard-wrapping.html +++ b/test/playground.generated/creating-the-editor-hard-wrapping.html @@ -42,13 +42,11 @@ var editor = monaco.editor.create(document.getElementById("container"), { value: jsCode, language: "javascript", - // If `wrappingColumn` is -1, then no wrapping occurs and - // long lines are rendered on one line. However, this might - // mean that not all code is rendered (... may be used). - // If `wrappingColumn` is 0, then viewport width wrapping is set - // If `wrappingColumn` is > 0, then the lines will wrap at its value - // Defaults to 300 - wrappingColumn: 40, + wordWrap: 'wordWrapColumn', + wordWrapColumn: 40, + + // Set this to false to not auto word wrap minified files + wordWrapMinified: true, // try "same", "indent" or "none" wrappingIndent: "indent" diff --git a/test/playground.generated/customizing-the-appearence-exposed-colors.html b/test/playground.generated/customizing-the-appearence-exposed-colors.html index c01b1190..a79afe51 100644 --- a/test/playground.generated/customizing-the-appearence-exposed-colors.html +++ b/test/playground.generated/customizing-the-appearence-exposed-colors.html @@ -10,38 +10,6 @@ \r\n\r\n\r\n* Bullet lists are easy too\r\n- Another one\r\n+ Another one\r\n\r\nThis is a paragraph, which is text surrounded by\r\nwhitespace. Paragraphs can be on one\r\nline (or many), and can drone on for hours.\r\n\r\nNow some inline markup like _italics_, **bold**,\r\nand `code()`. Note that underscores\r\nin_words_are ignored.\r\n\r\n````application/json\r\n { value: [\"or with a mime type\"] }\r\n````\r\n\r\n> Blockquotes are like quoted text in email replies\r\n>> And, they can be nested\r\n\r\n1. A numbered list\r\n2. Which is numbered\r\n3. With periods and a space\r\n\r\nAnd now some code:\r\n\r\n // Code is just text indented a bit\r\n which(is_easy) to_remember();\r\n\r\nAnd a block\r\n\r\n~~~\r\n// Markdown extra adds un-indented code blocks too\r\n\r\nif (this_is_more_code == true && !indented) {\r\n // tild wrapped code blocks, also not indented\r\n}\r\n~~~\r\n\r\nText with\r\ntwo trailing spaces\r\n(on the right)\r\ncan be used\r\nfor things like poems\r\n\r\n### Horizontal rules\r\n\r\n* * * *\r\n****\r\n--------------------------\r\n\r\n![picture alt](/images/photo.jpeg \"Title is optional\")\r\n\r\n## Markdown plus tables ##\r\n\r\n| Header | Header | Right |\r\n| ------ | ------ | -----: |\r\n| Cell | Cell | $10 |\r\n| Cell | Cell | $20 |\r\n\r\n* Outer pipes on tables are optional\r\n* Colon used for alignment (right versus left)\r\n\r\n## Markdown plus definition lists ##\r\n\r\nBottled water\r\n: $ 1.25\r\n: $ 1.55 (Large)\r\n\r\nMilk\r\nPop\r\n: $ 1.75\r\n\r\n* Multiple definitions and terms are possible\r\n* Definitions can include multiple paragraphs too\r\n\r\n*[ABBR]: Markdown plus abbreviations (produces an tag)" }, + { + "name": "sample.msdax.txt", + "content": " = CALCULATE(SUM(Sales[SalesAmount]), PREVIOUSQUARTER(Calendar[DateKey]))" + }, { "name": "sample.objective-c.txt", "content": "//\r\n// Copyright (c) Microsoft Corporation. All rights reserved.\r\n//\r\n\r\n#import \"UseQuotes.h\"\r\n#import \r\n\r\n/*\r\n\tMulti \r\n\tLine\r\n\tComments \r\n*/\r\n@implementation Test\r\n\r\n- (void) applicationWillFinishLaunching:(NSNotification *)notification\r\n{\r\n}\r\n\r\n- (IBAction)onSelectInput:(id)sender\r\n{\r\n NSString* defaultDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];\r\n \r\n NSOpenPanel* panel = [NSOpenPanel openPanel];\r\n [panel setAllowedFileTypes:[[NSArray alloc] initWithObjects:@\"ipa\", @\"xcarchive\", @\"app\", nil]];\r\n \r\n [panel beginWithCompletionHandler:^(NSInteger result)\r\n {\r\n if (result == NSFileHandlingPanelOKButton)\r\n [self.inputTextField setStringValue:[panel.URL path]];\r\n }];\r\n return YES;\r\n\r\n int hex = 0xFEF1F0F;\r\n\t float ing = 3.14;\r\n\t ing = 3.14e0;\r\n\t ing = 31.4e-2;\r\n}\r\n\r\n-(id) initWithParams:(id) aHandler withDeviceStateManager:(id) deviceStateManager\r\n{\r\n // add a tap gesture recognizer\r\n UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];\r\n NSMutableArray *gestureRecognizers = [NSMutableArray array];\r\n [gestureRecognizers addObject:tapGesture];\r\n [gestureRecognizers addObjectsFromArray:scnView.gestureRecognizers];\r\n scnView.gestureRecognizers = gestureRecognizers;\r\n\r\n\treturn tapGesture;\r\n\treturn nil;\r\n}\r\n\r\n@end\r\n" @@ -136,6 +140,10 @@ define([], function() { return[ "name": "sample.plaintext.txt", "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec cursus aliquet sapien, sed rhoncus leo ullamcorper ornare. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus feugiat eleifend nisl, aliquet rhoncus quam scelerisque vel. Morbi eu pellentesque ex. Nam suscipit maximus leo blandit cursus. Aenean sollicitudin nisi luctus, ornare nibh viverra, laoreet ex. Donec eget nibh sit amet dolor ornare elementum. Morbi sollicitudin enim vitae risus pretium vestibulum. Ut pretium hendrerit libero, non vulputate ante volutpat et. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nullam malesuada turpis vitae est porttitor, id tincidunt neque dignissim. Integer rhoncus vestibulum justo in iaculis. Praesent nec augue ut dui scelerisque gravida vel id velit. Donec vehicula feugiat mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\r\n\r\nPraesent diam lorem, luctus quis ullamcorper non, consequat quis orci. Ut vel massa vel nunc sagittis porttitor a vitae ante. Quisque euismod lobortis imperdiet. Vestibulum tincidunt vehicula posuere. Nulla facilisi. Donec sodales imperdiet risus id ullamcorper. Nulla luctus orci tortor, vitae tincidunt urna aliquet nec. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam consequat dapibus massa. Sed ac pharetra magna, in imperdiet neque. Nullam nunc nisi, consequat vel nunc et, sagittis aliquam arcu. Aliquam non orci magna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed id sem ut sem pulvinar rhoncus. Aenean venenatis nunc eget mi ornare, vitae maximus lacus varius. Quisque quis vestibulum justo.\r\n\r\nDonec euismod luctus volutpat. Donec sed lacinia enim. Vivamus aliquam elit cursus, convallis diam at, volutpat turpis. Sed lacinia nisl in auctor dapibus. Nunc turpis mi, mattis ut rhoncus id, lacinia sed lectus. Donec sodales tellus quis libero gravida pretium et quis magna. Etiam ultricies mollis purus, eget consequat velit. Duis vitae nibh vitae arcu tincidunt congue. Maecenas ut velit in ipsum condimentum dictum quis eget urna. Sed mattis nulla arcu, vitae mattis ligula dictum at.\r\n\r\nPraesent at dignissim dolor. Donec quis placerat sem. Cras vitae placerat sapien, eu sagittis ex. Mauris nec luctus risus. Cras imperdiet semper neque suscipit auctor. Mauris nisl massa, commodo sit amet dignissim id, malesuada sed ante. Praesent varius sapien eget eros vehicula porttitor.\r\n\r\nMauris auctor nunc in quam tempor, eget consectetur nisi rhoncus. Donec et nulla imperdiet, gravida dui at, accumsan velit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin sollicitudin condimentum auctor. Sed lacinia eleifend nisi, id scelerisque leo laoreet sit amet. Morbi congue augue a malesuada pulvinar. Curabitur nec ante finibus, commodo orci vel, aliquam libero. Morbi molestie purus non nunc placerat fermentum. Pellentesque commodo ligula sed pretium aliquam. Praesent ut nibh ex. Vivamus vestibulum velit in leo suscipit, vitae pellentesque urna vulputate. Suspendisse pretium placerat ligula eu ullamcorper. Nam eleifend mi tellus, ut tristique ante ultricies vitae. Quisque venenatis dapibus tellus sit amet mattis. Donec erat arcu, elementum vel nisl at, sagittis vulputate nisi." }, + { + "name": "sample.postiats.txt", + "content": "// http://www.ats-lang.org/\n(* Say Hello! once *)\nval () = print\"Hello!\\n\"\n//\n(* Say Hello! 3 times *)\nval () = 3*delay(print\"Hello!\")\nval () = print_newline((*void*))\n//\n\n//\n(* Build a list of 3 *)\nval xs = $list{int}(0, 1, 2)\n//\nval x0 = xs[0] // legal\nval x1 = xs[1] // legal\nval x2 = xs[2] // legal\nval x3 = xs[3] // illegal\n//\n\n//\nextern\nfun{} f0 (): int\nextern\nfun{} f1 (int): int\nextern\nfun{} repeat_f0f1 (int): int\n//\nimplement\n{}(*tmp*)\nrepeat_f0f1(n) =\n if n = 0\n then f0()\n else f1(repeat_f0f1(n-1))\n // end of [if]\n//\nfun\ntimes (\n m:int, n:int\n) : int = // m*n\n repeat_f0f1 (m) where\n{\n implement f0<> () = 0\n implement f1<> (x) = x + n\n}\n//\nfun\npower (\n m:int, n:int\n) : int = // m^n\n repeat_f0f1 (n) where\n{\n implement f0<> () = 1\n implement f1<> (x) = m * x\n}\n//\nval () =\nprintln! (\"5*5 = \", times(5,5))\nval () =\nprintln! (\"5^2 = \", power(5,2))\nval () =\nprintln! (\"2^10 = \", power(2,10))\nval () =\nprintln! (\"3^10 = \", power(3,10))\n//\n" + }, { "name": "sample.powershell.txt", "content": "$SelectedObjectNames=@();\n$XenCenterNodeSelected = 0;\n#the object info array contains hashmaps, each of which represent a parameter set and describe a target in the XenCenter resource list\nforeach($parameterSet in $ObjInfoArray)\n{\n\tif ($parameterSet[\"class\"] -eq \"blank\")\n\t{\n\t\t#When the XenCenter node is selected a parameter set is created for each of your connected servers with the class and objUuid keys marked as blank\n\t\tif ($XenCenterNodeSelected)\n\t\t{\n\t\t\tcontinue\n\t\t}\n\t\t$XenCenterNodeSelected = 1;\n\t\t$SelectedObjectNames += \"XenCenter\"\n\t}\n\telseif ($parameterSet[\"sessionRef\"] -eq \"null\")\n\t{\n\t\t#When a disconnected server is selected there is no session information, we get null for everything except class\n\t}\n\t\t$SelectedObjectNames += \"a disconnected server\"\n\telse\n\t{\n\t\tConnect-XenServer -url $parameterSet[\"url\"] -opaqueref $parameterSet[\"sessionRef\"]\n\t\t#Use $class to determine which server objects to get\n\t\t#-properties allows us to filter the results to just include the selected object\n\t\t$exp = \"Get-XenServer:{0} -properties @{{uuid='{1}'}}\" -f $parameterSet[\"class\"], $parameterSet[\"objUuid\"]\n\t\t$obj = Invoke-Expression $exp\n\t\t$SelectedObjectNames += $obj.name_label;\n\t} \n}" @@ -164,6 +172,10 @@ define([], function() { return[ "name": "sample.scss.txt", "content": "$baseFontSizeInPixels: 14;\r\n\r\n@function px2em ($font_size, $base_font_size: $baseFontSizeInPixels) { \r\n @return ($font_size / $base_font_size) + em; \r\n}\r\n\r\nh1 {\r\n font-size: px2em(36, $baseFontSizeInPixels);\r\n}\r\nh2 {\r\n font-size: px2em(28, $baseFontSizeInPixels);\r\n}\r\n.class {\r\n font-size: px2em(14, $baseFontSizeInPixels);\r\n}\r\n\r\nnav {\r\n ul {\r\n margin: 0;\r\n padding: 0;\r\n list-style: none;\r\n }\r\n\r\n li { display: inline-block; }\r\n\r\n a {\r\n display: block;\r\n padding: 6px 12px;\r\n text-decoration: none;\r\n }\r\n \r\n @each $animal in puma, sea-slug, egret, salamander {\r\n .#{$animal}-icon {\r\n background-image: url('/images/#{$animal}.png');\r\n }\r\n }\r\n}" }, + { + "name": "sample.sol.txt", + "content": "pragma solidity ^0.4.11;\n\n/// @title Voting with delegation.\ncontract Ballot {\n // This declares a new complex type which will\n // be used for variables later.\n // It will represent a single voter.\n struct Voter {\n uint weight; // weight is accumulated by delegation\n bool voted; // if true, that person already voted\n address delegate; // person delegated to\n uint vote; // index of the voted proposal\n }\n\n // This is a type for a single proposal.\n struct Proposal {\n bytes32 name; // short name (up to 32 bytes)\n uint voteCount; // number of accumulated votes\n }\n\n address public chairperson;\n\n // This declares a state variable that\n // stores a `Voter` struct for each possible address.\n mapping(address => Voter) public voters;\n\n // A dynamically-sized array of `Proposal` structs.\n Proposal[] public proposals;\n\n /// Create a new ballot to choose one of `proposalNames`.\n function Ballot(bytes32[] proposalNames) {\n chairperson = msg.sender;\n voters[chairperson].weight = 1;\n\n // For each of the provided proposal names,\n // create a new proposal object and add it\n // to the end of the array.\n for (uint i = 0; i < proposalNames.length; i++) {\n // `Proposal({...})` creates a temporary\n // Proposal object and `proposals.push(...)`\n // appends it to the end of `proposals`.\n proposals.push(Proposal({\n name: proposalNames[i],\n voteCount: 0\n }));\n }\n }\n\n // Give `voter` the right to vote on this ballot.\n // May only be called by `chairperson`.\n function giveRightToVote(address voter) {\n // If the argument of `require` evaluates to `false`,\n // it terminates and reverts all changes to\n // the state and to Ether balances. It is often\n // a good idea to use this if functions are\n // called incorrectly. But watch out, this\n // will currently also consume all provided gas\n // (this is planned to change in the future).\n require((msg.sender == chairperson) && !voters[voter].voted && (voters[voter].weight == 0));\n voters[voter].weight = 1;\n }\n\n /// Delegate your vote to the voter `to`.\n function delegate(address to) {\n // assigns reference\n Voter sender = voters[msg.sender];\n require(!sender.voted);\n\n // Self-delegation is not allowed.\n require(to != msg.sender);\n\n // Forward the delegation as long as\n // `to` also delegated.\n // In general, such loops are very dangerous,\n // because if they run too long, they might\n // need more gas than is available in a block.\n // In this case, the delegation will not be executed,\n // but in other situations, such loops might\n // cause a contract to get \"stuck\" completely.\n while (voters[to].delegate != address(0)) {\n to = voters[to].delegate;\n\n // We found a loop in the delegation, not allowed.\n require(to != msg.sender);\n }\n\n // Since `sender` is a reference, this\n // modifies `voters[msg.sender].voted`\n sender.voted = true;\n sender.delegate = to;\n Voter delegate = voters[to];\n if (delegate.voted) {\n // If the delegate already voted,\n // directly add to the number of votes\n proposals[delegate.vote].voteCount += sender.weight;\n } else {\n // If the delegate did not vote yet,\n // add to her weight.\n delegate.weight += sender.weight;\n }\n }\n\n /// Give your vote (including votes delegated to you)\n /// to proposal `proposals[proposal].name`.\n function vote(uint proposal) {\n Voter sender = voters[msg.sender];\n require(!sender.voted);\n sender.voted = true;\n sender.vote = proposal;\n\n // If `proposal` is out of the range of the array,\n // this will throw automatically and revert all\n // changes.\n proposals[proposal].voteCount += sender.weight;\n }\n\n /// @dev Computes the winning proposal taking all\n /// previous votes into account.\n function winningProposal() constant\n returns (uint winningProposal)\n {\n uint winningVoteCount = 0;\n for (uint p = 0; p < proposals.length; p++) {\n if (proposals[p].voteCount > winningVoteCount) {\n winningVoteCount = proposals[p].voteCount;\n winningProposal = p;\n }\n }\n }\n\n // Calls winningProposal() function to get the index\n // of the winner contained in the proposals array and then\n // returns the name of the winner\n function winnerName() constant\n returns (bytes32 winnerName)\n {\n winnerName = proposals[winningProposal()].name;\n }\n}" + }, { "name": "sample.sql.txt", "content": "CREATE TABLE dbo.EmployeePhoto\n(\n EmployeeId INT NOT NULL PRIMARY KEY,\n Photo VARBINARY(MAX) FILESTREAM NULL,\n MyRowGuidColumn UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL\n UNIQUE DEFAULT NEWID()\n);\n\nGO\n\n/*\ntext_of_comment\n/* nested comment */\n*/\n\n-- line comment\n\nCREATE NONCLUSTERED INDEX IX_WorkOrder_ProductID\n ON Production.WorkOrder(ProductID)\n WITH (FILLFACTOR = 80,\n PAD_INDEX = ON,\n DROP_EXISTING = ON);\nGO\n\nWHILE (SELECT AVG(ListPrice) FROM Production.Product) < $300\nBEGIN\n UPDATE Production.Product\n SET ListPrice = ListPrice * 2\n SELECT MAX(ListPrice) FROM Production.Product\n IF (SELECT MAX(ListPrice) FROM Production.Product) > $500\n BREAK\n ELSE\n CONTINUE\nEND\nPRINT 'Too much for the market to bear';\n\nMERGE INTO Sales.SalesReason AS [Target]\nUSING (VALUES ('Recommendation','Other'), ('Review', 'Marketing'), ('Internet', 'Promotion'))\n AS [Source] ([NewName], NewReasonType)\nON [Target].[Name] = [Source].[NewName]\nWHEN MATCHED\nTHEN UPDATE SET ReasonType = [Source].NewReasonType\nWHEN NOT MATCHED BY TARGET\nTHEN INSERT ([Name], ReasonType) VALUES ([NewName], NewReasonType)\nOUTPUT $action INTO @SummaryOfChanges;\n\nSELECT ProductID, OrderQty, SUM(LineTotal) AS Total\nFROM Sales.SalesOrderDetail\nWHERE UnitPrice < $5.00\nGROUP BY ProductID, OrderQty\nORDER BY ProductID, OrderQty\nOPTION (HASH GROUP, FAST 10);\n" diff --git a/test/samples/sample.msdax.txt b/test/samples/sample.msdax.txt new file mode 100644 index 00000000..a9f886f0 --- /dev/null +++ b/test/samples/sample.msdax.txt @@ -0,0 +1 @@ + = CALCULATE(SUM(Sales[SalesAmount]), PREVIOUSQUARTER(Calendar[DateKey])) \ No newline at end of file diff --git a/test/samples/sample.postiats.txt b/test/samples/sample.postiats.txt new file mode 100644 index 00000000..63352862 --- /dev/null +++ b/test/samples/sample.postiats.txt @@ -0,0 +1,64 @@ +// http://www.ats-lang.org/ +(* Say Hello! once *) +val () = print"Hello!\n" +// +(* Say Hello! 3 times *) +val () = 3*delay(print"Hello!") +val () = print_newline((*void*)) +// + +// +(* Build a list of 3 *) +val xs = $list{int}(0, 1, 2) +// +val x0 = xs[0] // legal +val x1 = xs[1] // legal +val x2 = xs[2] // legal +val x3 = xs[3] // illegal +// + +// +extern +fun{} f0 (): int +extern +fun{} f1 (int): int +extern +fun{} repeat_f0f1 (int): int +// +implement +{}(*tmp*) +repeat_f0f1(n) = + if n = 0 + then f0() + else f1(repeat_f0f1(n-1)) + // end of [if] +// +fun +times ( + m:int, n:int +) : int = // m*n + repeat_f0f1 (m) where +{ + implement f0<> () = 0 + implement f1<> (x) = x + n +} +// +fun +power ( + m:int, n:int +) : int = // m^n + repeat_f0f1 (n) where +{ + implement f0<> () = 1 + implement f1<> (x) = m * x +} +// +val () = +println! ("5*5 = ", times(5,5)) +val () = +println! ("5^2 = ", power(5,2)) +val () = +println! ("2^10 = ", power(2,10)) +val () = +println! ("3^10 = ", power(3,10)) +// diff --git a/test/samples/sample.sol.txt b/test/samples/sample.sol.txt new file mode 100644 index 00000000..549636f9 --- /dev/null +++ b/test/samples/sample.sol.txt @@ -0,0 +1,139 @@ +pragma solidity ^0.4.11; + +/// @title Voting with delegation. +contract Ballot { + // This declares a new complex type which will + // be used for variables later. + // It will represent a single voter. + struct Voter { + uint weight; // weight is accumulated by delegation + bool voted; // if true, that person already voted + address delegate; // person delegated to + uint vote; // index of the voted proposal + } + + // This is a type for a single proposal. + struct Proposal { + bytes32 name; // short name (up to 32 bytes) + uint voteCount; // number of accumulated votes + } + + address public chairperson; + + // This declares a state variable that + // stores a `Voter` struct for each possible address. + mapping(address => Voter) public voters; + + // A dynamically-sized array of `Proposal` structs. + Proposal[] public proposals; + + /// Create a new ballot to choose one of `proposalNames`. + function Ballot(bytes32[] proposalNames) { + chairperson = msg.sender; + voters[chairperson].weight = 1; + + // For each of the provided proposal names, + // create a new proposal object and add it + // to the end of the array. + for (uint i = 0; i < proposalNames.length; i++) { + // `Proposal({...})` creates a temporary + // Proposal object and `proposals.push(...)` + // appends it to the end of `proposals`. + proposals.push(Proposal({ + name: proposalNames[i], + voteCount: 0 + })); + } + } + + // Give `voter` the right to vote on this ballot. + // May only be called by `chairperson`. + function giveRightToVote(address voter) { + // If the argument of `require` evaluates to `false`, + // it terminates and reverts all changes to + // the state and to Ether balances. It is often + // a good idea to use this if functions are + // called incorrectly. But watch out, this + // will currently also consume all provided gas + // (this is planned to change in the future). + require((msg.sender == chairperson) && !voters[voter].voted && (voters[voter].weight == 0)); + voters[voter].weight = 1; + } + + /// Delegate your vote to the voter `to`. + function delegate(address to) { + // assigns reference + Voter sender = voters[msg.sender]; + require(!sender.voted); + + // Self-delegation is not allowed. + require(to != msg.sender); + + // Forward the delegation as long as + // `to` also delegated. + // In general, such loops are very dangerous, + // because if they run too long, they might + // need more gas than is available in a block. + // In this case, the delegation will not be executed, + // but in other situations, such loops might + // cause a contract to get "stuck" completely. + while (voters[to].delegate != address(0)) { + to = voters[to].delegate; + + // We found a loop in the delegation, not allowed. + require(to != msg.sender); + } + + // Since `sender` is a reference, this + // modifies `voters[msg.sender].voted` + sender.voted = true; + sender.delegate = to; + Voter delegate = voters[to]; + if (delegate.voted) { + // If the delegate already voted, + // directly add to the number of votes + proposals[delegate.vote].voteCount += sender.weight; + } else { + // If the delegate did not vote yet, + // add to her weight. + delegate.weight += sender.weight; + } + } + + /// Give your vote (including votes delegated to you) + /// to proposal `proposals[proposal].name`. + function vote(uint proposal) { + Voter sender = voters[msg.sender]; + require(!sender.voted); + sender.voted = true; + sender.vote = proposal; + + // If `proposal` is out of the range of the array, + // this will throw automatically and revert all + // changes. + proposals[proposal].voteCount += sender.weight; + } + + /// @dev Computes the winning proposal taking all + /// previous votes into account. + function winningProposal() constant + returns (uint winningProposal) + { + uint winningVoteCount = 0; + for (uint p = 0; p < proposals.length; p++) { + if (proposals[p].voteCount > winningVoteCount) { + winningVoteCount = proposals[p].voteCount; + winningProposal = p; + } + } + } + + // Calls winningProposal() function to get the index + // of the winner contained in the proposals array and then + // returns the name of the winner + function winnerName() constant + returns (bytes32 winnerName) + { + winnerName = proposals[winningProposal()].name; + } +} \ No newline at end of file diff --git a/website/index/samples/sample.msdax.txt b/website/index/samples/sample.msdax.txt new file mode 100644 index 00000000..a9f886f0 --- /dev/null +++ b/website/index/samples/sample.msdax.txt @@ -0,0 +1 @@ + = CALCULATE(SUM(Sales[SalesAmount]), PREVIOUSQUARTER(Calendar[DateKey])) \ No newline at end of file diff --git a/website/index/samples/sample.postiats.txt b/website/index/samples/sample.postiats.txt new file mode 100644 index 00000000..63352862 --- /dev/null +++ b/website/index/samples/sample.postiats.txt @@ -0,0 +1,64 @@ +// http://www.ats-lang.org/ +(* Say Hello! once *) +val () = print"Hello!\n" +// +(* Say Hello! 3 times *) +val () = 3*delay(print"Hello!") +val () = print_newline((*void*)) +// + +// +(* Build a list of 3 *) +val xs = $list{int}(0, 1, 2) +// +val x0 = xs[0] // legal +val x1 = xs[1] // legal +val x2 = xs[2] // legal +val x3 = xs[3] // illegal +// + +// +extern +fun{} f0 (): int +extern +fun{} f1 (int): int +extern +fun{} repeat_f0f1 (int): int +// +implement +{}(*tmp*) +repeat_f0f1(n) = + if n = 0 + then f0() + else f1(repeat_f0f1(n-1)) + // end of [if] +// +fun +times ( + m:int, n:int +) : int = // m*n + repeat_f0f1 (m) where +{ + implement f0<> () = 0 + implement f1<> (x) = x + n +} +// +fun +power ( + m:int, n:int +) : int = // m^n + repeat_f0f1 (n) where +{ + implement f0<> () = 1 + implement f1<> (x) = m * x +} +// +val () = +println! ("5*5 = ", times(5,5)) +val () = +println! ("5^2 = ", power(5,2)) +val () = +println! ("2^10 = ", power(2,10)) +val () = +println! ("3^10 = ", power(3,10)) +// diff --git a/website/index/samples/sample.sol.txt b/website/index/samples/sample.sol.txt new file mode 100644 index 00000000..549636f9 --- /dev/null +++ b/website/index/samples/sample.sol.txt @@ -0,0 +1,139 @@ +pragma solidity ^0.4.11; + +/// @title Voting with delegation. +contract Ballot { + // This declares a new complex type which will + // be used for variables later. + // It will represent a single voter. + struct Voter { + uint weight; // weight is accumulated by delegation + bool voted; // if true, that person already voted + address delegate; // person delegated to + uint vote; // index of the voted proposal + } + + // This is a type for a single proposal. + struct Proposal { + bytes32 name; // short name (up to 32 bytes) + uint voteCount; // number of accumulated votes + } + + address public chairperson; + + // This declares a state variable that + // stores a `Voter` struct for each possible address. + mapping(address => Voter) public voters; + + // A dynamically-sized array of `Proposal` structs. + Proposal[] public proposals; + + /// Create a new ballot to choose one of `proposalNames`. + function Ballot(bytes32[] proposalNames) { + chairperson = msg.sender; + voters[chairperson].weight = 1; + + // For each of the provided proposal names, + // create a new proposal object and add it + // to the end of the array. + for (uint i = 0; i < proposalNames.length; i++) { + // `Proposal({...})` creates a temporary + // Proposal object and `proposals.push(...)` + // appends it to the end of `proposals`. + proposals.push(Proposal({ + name: proposalNames[i], + voteCount: 0 + })); + } + } + + // Give `voter` the right to vote on this ballot. + // May only be called by `chairperson`. + function giveRightToVote(address voter) { + // If the argument of `require` evaluates to `false`, + // it terminates and reverts all changes to + // the state and to Ether balances. It is often + // a good idea to use this if functions are + // called incorrectly. But watch out, this + // will currently also consume all provided gas + // (this is planned to change in the future). + require((msg.sender == chairperson) && !voters[voter].voted && (voters[voter].weight == 0)); + voters[voter].weight = 1; + } + + /// Delegate your vote to the voter `to`. + function delegate(address to) { + // assigns reference + Voter sender = voters[msg.sender]; + require(!sender.voted); + + // Self-delegation is not allowed. + require(to != msg.sender); + + // Forward the delegation as long as + // `to` also delegated. + // In general, such loops are very dangerous, + // because if they run too long, they might + // need more gas than is available in a block. + // In this case, the delegation will not be executed, + // but in other situations, such loops might + // cause a contract to get "stuck" completely. + while (voters[to].delegate != address(0)) { + to = voters[to].delegate; + + // We found a loop in the delegation, not allowed. + require(to != msg.sender); + } + + // Since `sender` is a reference, this + // modifies `voters[msg.sender].voted` + sender.voted = true; + sender.delegate = to; + Voter delegate = voters[to]; + if (delegate.voted) { + // If the delegate already voted, + // directly add to the number of votes + proposals[delegate.vote].voteCount += sender.weight; + } else { + // If the delegate did not vote yet, + // add to her weight. + delegate.weight += sender.weight; + } + } + + /// Give your vote (including votes delegated to you) + /// to proposal `proposals[proposal].name`. + function vote(uint proposal) { + Voter sender = voters[msg.sender]; + require(!sender.voted); + sender.voted = true; + sender.vote = proposal; + + // If `proposal` is out of the range of the array, + // this will throw automatically and revert all + // changes. + proposals[proposal].voteCount += sender.weight; + } + + /// @dev Computes the winning proposal taking all + /// previous votes into account. + function winningProposal() constant + returns (uint winningProposal) + { + uint winningVoteCount = 0; + for (uint p = 0; p < proposals.length; p++) { + if (proposals[p].voteCount > winningVoteCount) { + winningVoteCount = proposals[p].voteCount; + winningProposal = p; + } + } + } + + // Calls winningProposal() function to get the index + // of the winner contained in the proposals array and then + // returns the name of the winner + function winnerName() constant + returns (bytes32 winnerName) + { + winnerName = proposals[winningProposal()].name; + } +} \ No newline at end of file