diff --git a/lexers/embedded/whiley.xml b/lexers/embedded/whiley.xml new file mode 100644 index 000000000..1762c966e --- /dev/null +++ b/lexers/embedded/whiley.xml @@ -0,0 +1,57 @@ + + + Whiley + whiley + *.whiley + text/x-whiley + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lexers/testdata/whiley.actual b/lexers/testdata/whiley.actual new file mode 100644 index 000000000..a889e5b5b --- /dev/null +++ b/lexers/testdata/whiley.actual @@ -0,0 +1,76 @@ + +import uint from std::integer +import uinteger from js::core +import random from js::math +import Document, Window, CanvasRenderingContext2D from w3c::dom +import Element,HTMLCanvasElement, HTMLImageElement, MouseEvent from w3c::dom + +import model +import view + +/** + * Add a given number of bombs to the board. + */ +method add_random_bombs(model::Board board, uint n) -> model::Board: + uinteger remaining = |board.squares| + // Use Knuth's algorithm S + for x in 0..board.width: + for y in 0..board.height: + // Flip a coin (so-to-speak) + if random(remaining) < n: + // create bomb square + model::Square s = model::HiddenSquare(true,false) + // Update board + board = model::set_square(board,(uint) x, (uint) y,s) + // Reduce number of bombs to place + n = n - 1 + // Reduce remaining options + remaining = remaining - 1 + // return updated board + return board + +/** + * Handle a mouse event on the canvas + */ +method onclick_handler(MouseEvent e, &view::State state, Window window): + // Convert from view to world coordinates + uint x = e->offsetX / state->gridsize + uint y = e->offsetY / state->gridsize + // Update board + if e->shiftKey: + state->board = model::flag_square(state->board,x,y) + else: + state->board = model::expose_square(state->board,x,y) + // Render initial board + view::draw_board(*state) + // Finally determine game status + (bool gameOver, bool winner) = model::is_gameover(state->board) + // Check whether game over + if gameOver: + // Yes, but win or lose? + if winner: + window->alert("Well done --- You Found all the Mines!") + else: + window->alert("Game Over --- You Lost!") + // Done + +/** + * Create a new game of Minesweeper + */ +public export method main(uint width, uint height, uint bombs, Window window, HTMLCanvasElement canvas, HTMLImageElement[] images) +// Requires at least 9 images +requires |images| == 13: + Document document = window->document + // NOTE: following should not be required! + Element c = document->getElementById("myCanvas") + // Create a standard sized board + model::Board board = model::Board(width,height) + // Add bombs + board = add_random_bombs(board,bombs) + // Initialise the view state + &view::State state = new view::init(document,canvas,board,images) + // Render initial board + view::draw_board(*state) + // Configure mouse click listener + c->addEventListener("click",&(MouseEvent e -> onclick_handler(e,state,window))) + diff --git a/lexers/testdata/whiley.expected b/lexers/testdata/whiley.expected new file mode 100644 index 000000000..908fd81ce --- /dev/null +++ b/lexers/testdata/whiley.expected @@ -0,0 +1,609 @@ +[ + {"type": "Text","value": "\n"}, + {"type": "KeywordDeclaration","value": "import"}, + {"type": "Text","value": " "}, + {"type": "Name","value": "uint"}, + {"type": "Text","value": " " }, + {"type": "KeywordDeclaration","value": "from" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "std" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "integer" }, + {"type": "Text","value": "\n" }, + {"type": "KeywordDeclaration","value": "import" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "uinteger" }, + {"type": "Text","value": " " }, + {"type": "KeywordDeclaration","value": "from" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "js" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "core" }, + {"type": "Text","value": "\n" }, + {"type": "KeywordDeclaration","value": "import" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "random" }, + {"type": "Text","value": " " }, + {"type": "KeywordDeclaration","value": "from" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "js" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "math" }, + {"type": "Text","value": "\n" }, + {"type": "KeywordDeclaration","value": "import" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Document" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Window" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "CanvasRenderingContext2D" }, + {"type": "Text","value": " " }, + {"type": "KeywordDeclaration","value": "from" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "w3c" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "dom" }, + {"type": "Text","value": "\n" }, + {"type": "KeywordDeclaration","value": "import" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Element" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "HTMLCanvasElement" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "HTMLImageElement" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "MouseEvent" }, + {"type": "Text","value": " " }, + {"type": "KeywordDeclaration","value": "from" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "w3c" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "dom" }, + {"type": "Text","value": "\n\n" }, + {"type": "KeywordDeclaration","value": "import" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Text","value": "\n" }, + {"type": "KeywordDeclaration","value": "import" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "view" }, + {"type": "Text","value": "\n\n" }, + {"type": "CommentMultiline","value": "/**\n * Add a given number of bombs to the board.\n */" }, + {"type": "Text","value": "\n" }, + {"type": "KeywordDeclaration","value": "method" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "add_random_bombs" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "Board" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "uint" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "n" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "->" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "Board" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "Name","value": "uinteger" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "remaining" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "|" }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "." }, + {"type": "Name","value": "squares" }, + {"type": "Operator","value": "|" }, + {"type": "Text","value": " \n " }, + {"type": "CommentSingle","value": "// Use Knuth's algorithm S\n" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "for" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "x" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "in" }, + {"type": "Text","value": " " }, + {"type": "LiteralNumberInteger","value": "0" }, + {"type": "Punctuation","value": ".." }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "." }, + {"type": "Name","value": "width" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "Keyword","value": "for" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "y" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "in" }, + {"type": "Text","value": " " }, + {"type": "LiteralNumberInteger","value": "0" }, + {"type": "Punctuation","value": ".." }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "." }, + {"type": "Name","value": "height" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Flip a coin (so-to-speak)\n" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "if" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "random" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "remaining" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "<" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "n" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// create bomb square\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "Square" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "s" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "HiddenSquare" }, + {"type": "Punctuation","value": "(" }, + {"type": "KeywordConstant","value": "true" }, + {"type": "Punctuation","value": "," }, + {"type": "KeywordConstant","value": "false" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Update board\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "board" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "set_square" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": ",(" }, + {"type": "Name","value": "uint" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "x" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "uint" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "y" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "s" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Reduce number of bombs to place\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "n" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "n" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "-" }, + {"type": "Text","value": " " }, + {"type": "LiteralNumberInteger","value": "1" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Reduce remaining options\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "remaining" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "remaining" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "-" }, + {"type": "Text","value": " " }, + {"type": "LiteralNumberInteger","value": "1" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// return updated board\n" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "return" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "board" }, + {"type": "Text","value": "\n\n" }, + {"type": "CommentMultiline","value": "/**\n * Handle a mouse event on the canvas\n */" }, + {"type": "Text","value": "\n" }, + {"type": "KeywordDeclaration","value": "method" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "onclick_handler" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "MouseEvent" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "e" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "&" }, + {"type": "Name","value": "view" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "State" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "state" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Window" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "window" }, + {"type": "Punctuation","value": ")" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Convert from view to world coordinates\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "uint" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "x" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "e" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "offsetX" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "/" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "state" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "gridsize" }, + {"type": "Text","value": "\n " }, + {"type": "Name","value": "uint" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "y" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "e" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "offsetY" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "/" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "state" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "gridsize" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Update board\n" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "if" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "e" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "shiftKey" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "Name","value": "state" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "board" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "flag_square" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "state" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "x" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "y" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "Keyword","value": "else" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "Name","value": "state" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "board" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "expose_square" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "state" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "x" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "y" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Render initial board\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "view" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "draw_board" }, + {"type": "Punctuation","value": "(" }, + {"type": "Operator","value": "*" }, + {"type": "Name","value": "state" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Finally determine game status\n" }, + {"type": "Text","value": " " }, + {"type": "Punctuation","value": "(" }, + {"type": "KeywordType","value": "bool" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "gameOver" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "KeywordType","value": "bool" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "winner" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "is_gameover" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "state" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Check whether game over\n" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "if" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "gameOver" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Yes, but win or lose?\n" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "if" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "winner" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "Name","value": "window" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "alert" }, + {"type": "Punctuation","value": "(" }, + {"type": "Error","value": "\"" }, + {"type": "Name","value": "Well" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "done" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "---" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "You" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Found" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "all" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "the" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Mines" }, + {"type": "Operator","value": "!" }, + {"type": "Error","value": "\"" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "Keyword","value": "else" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "Name","value": "window" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "alert" }, + {"type": "Punctuation","value": "(" }, + {"type": "Error","value": "\"" }, + {"type": "Name","value": "Game" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Over" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "---" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "You" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Lost" }, + {"type": "Operator","value": "!" }, + {"type": "Error","value": "\"" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Done\n" }, + {"type": "Text","value": "\n" }, + {"type": "CommentMultiline","value": "/**\n * Create a new game of Minesweeper\n */" }, + {"type": "Text","value": "\n" }, + {"type": "Keyword","value": "public" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "export" }, + {"type": "Text","value": " " }, + {"type": "KeywordDeclaration","value": "method" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "main" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "uint" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "width" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "uint" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "height" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "uint" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "bombs" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Window" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "window" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "HTMLCanvasElement" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "canvas" }, + {"type": "Punctuation","value": "," }, + {"type": "Text","value": " " }, + {"type": "Name","value": "HTMLImageElement" }, + {"type": "Punctuation","value": "[]" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "images" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n" }, + {"type": "CommentSingle","value": "// Requires at least 9 images\n" }, + {"type": "Keyword","value": "requires" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "|" }, + {"type": "Name","value": "images" }, + {"type": "Operator","value": "|" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "==" }, + {"type": "Text","value": " " }, + {"type": "LiteralNumberInteger","value": "13" }, + {"type": "Operator","value": ":" }, + {"type": "Text","value": "\n " }, + {"type": "Name","value": "Document" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "document" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "window" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "document" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// NOTE: following should not be required!\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "Element" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "c" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "document" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "getElementById" }, + {"type": "Punctuation","value": "(" }, + {"type": "Error","value": "\"" }, + {"type": "Name","value": "myCanvas" }, + {"type": "Error","value": "\"" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Create a standard sized board\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "Board" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "board" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "model" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "Board" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "width" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "height" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Add bombs\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "board" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "add_random_bombs" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "bombs" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Initialise the view state\n" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "&" }, + {"type": "Name","value": "view" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "State" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "state" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "=" }, + {"type": "Text","value": " " }, + {"type": "Keyword","value": "new" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "view" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "init" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "document" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "canvas" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "board" }, + {"type": "Punctuation","value": "," }, + {"type": "Name","value": "images" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Render initial board\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "view" }, + {"type": "Operator","value": "::" }, + {"type": "Name","value": "draw_board" }, + {"type": "Punctuation","value": "(" }, + {"type": "Operator","value": "*" }, + {"type": "Name","value": "state" }, + {"type": "Punctuation","value": ")" }, + {"type": "Text","value": "\n " }, + {"type": "CommentSingle","value": "// Configure mouse click listener\n" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "c" }, + {"type": "Operator","value": "->" }, + {"type": "Name","value": "addEventListener" }, + {"type": "Punctuation","value": "(" }, + {"type": "Error","value": "\"" }, + {"type": "Name","value": "click" }, + {"type": "Error","value": "\"" }, + {"type": "Punctuation","value": "," }, + {"type": "Operator","value": "&" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "MouseEvent" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "e" }, + {"type": "Text","value": " " }, + {"type": "Operator","value": "->" }, + {"type": "Text","value": " " }, + {"type": "Name","value": "onclick_handler" }, + {"type": "Punctuation","value": "(" }, + {"type": "Name","value": "e"}, + {"type": "Punctuation","value": ","}, + {"type": "Name","value": "state"}, + {"type": "Punctuation","value": ","}, + {"type": "Name","value": "window"}, + {"type": "Punctuation","value": ")))"}, + {"type": "Text","value": "\n \n"} +]