Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language support for Simula #7025

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,9 @@
[submodule "vendor/grammars/vscode-scala-syntax"]
path = vendor/grammars/vscode-scala-syntax
url = https://github.com/scala/vscode-scala-syntax
[submodule "vendor/grammars/vscode-simula"]
path = vendor/grammars/vscode-simula
url = https://github.com/eirslett/vscode-simula.git
[submodule "vendor/grammars/vscode-singularity"]
path = vendor/grammars/vscode-singularity
url = https://github.com/onnovalkering/vscode-singularity
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,8 @@ vendor/grammars/vscode-ron:
- source.ron
vendor/grammars/vscode-scala-syntax:
- source.scala
vendor/grammars/vscode-simula:
- source.sim
vendor/grammars/vscode-singularity:
- source.singularity
vendor/grammars/vscode-slice:
Expand Down
12 changes: 12 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6821,6 +6821,18 @@ Simple File Verification:
codemirror_mode: properties
codemirror_mime_type: text/x-properties
language_id: 735623761
Simula:
type: programming
color: "#B22F2F"
extensions:
- ".sim"
aliases:
- sim
tm_scope: source.simula
eirslett marked this conversation as resolved.
Show resolved Hide resolved
ace_mode: simula
codemirror_mode: simula
codemirror_mime_type: text/x-simula
language_id: 582204041
Singularity:
type: programming
color: "#64E6AD"
Expand Down
17 changes: 17 additions & 0 deletions samples/Simula/BottlesOfBeer.sim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
! License: MIT;
begin
integer i;
for i := 99 step -1 until 1 do
begin
outint(i, 2);
outtext(" bottles of beer on the wall, ");
outint(i, 2);
outtext(" bottles of beer.");
outimage;
outtext("Take one down and pass it around, ");
outint(i - 1, 2);
outtext(" bottles of beer on the wall.");
outimage;
end;
outtext("No more bottles of beer on the wall, no more bottles of beer.");
end-let's-drink;
108 changes: 108 additions & 0 deletions samples/Simula/TicTacToe.sim
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
! A simple Tic-Tac-Toe game. License: MIT;
begin
ref(TicTacToe) game;
character player;

class TicTacToe;
begin
character array board(1:9);

procedure placeMark(mark, position);
value mark, position;
character mark; integer position;
begin
board(position) := mark;
end-of-place-mark;

boolean procedure checkWinner(player);
value player;
character player;
begin
integer position;
comment
There are 8 possible ways to win: 3 rows, 3 columns, and 2 diagonals.
For reasons of laziness, we just AI-generate them:
;
if board(1) = player and board(2) = player and board(3) = player then
checkWinner := true
else if board(4) = player and board(5) = player and board(6) = player then
checkWinner := true
else if board(7) = player and board(8) = player and board(9) = player then
checkWinner := true
else if board(1) = player and board(4) = player and board(7) = player then
checkWinner := true
else if board(2) = player and board(5) = player and board(8) = player then
checkWinner := true
else if board(3) = player and board(6) = player and board(9) = player then
checkWinner := true
else if board(1) = player and board(5) = player and board(9) = player then
checkWinner := true
else if board(3) = player and board(5) = player and board(7) = player then
checkWinner := true
else
checkWinner := false;
end-of-checkWinner;

character procedure winner;
begin
if checkWinner('X') then winner := 'X'
else if checkWinner('O') then winner := 'O'
else winner := ' ';
end-of-winner;

procedure DrawTopBottom; begin
OutText("+---+---+---+");
OutImage;
end;

procedure draw;
begin
integer row;
OutImage;
DrawTopBottom;
for row := 0 step 1 until 2 do begin
OutText("| " );
OutChar(board(row * 3 + 1));
OutText(" | " );
OutChar(board(row * 3 + 2));
OutText(" | " );
OutChar(board(row * 3 + 3));
OutText(" |");
OutImage;
DrawTopBottom;
end
end-of-draw;

!populate the board with number placeholders;
board(1) := '1';
board(2) := '2';
board(3) := '3';
board(4) := '4';
board(5) := '5';
board(6) := '6';
board(7) := '7';
board(8) := '8';
board(9) := '9';
end-of-TicTacToe;


game :- new TicTacToe;
player := 'X';

while game.winner <> 'X' and game.winner <> 'O' do
begin
game.draw;
OutText("Player ");
OutChar(player);
OutText(" enter position: ");
OutImage;
game.placeMark(player, InInt);
if player = 'X' then player := 'O' else player := 'X';
end;

game.draw;

OutText("The winner is: player ");
OutChar(game.winner);
OutImage;
end-of-program
1 change: 1 addition & 0 deletions vendor/grammars/vscode-simula
Submodule vscode-simula added at 3e5aa7
17 changes: 17 additions & 0 deletions vendor/licenses/git_submodule/vscode-simula.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: vscode-simula
version: 3e5aa76da7f6c4145b665fa7497249b2353ea087
type: git_submodule
homepage: https://github.com/eirslett/vscode-simula.git
license: mit
licenses:
- sources: LICENSE.md
text: |
Copyright 2024 Project contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
notices: []