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 all commits
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
6 changes: 6 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,12 @@ disambiguations:
- language: Markdown
# Markdown syntax for scdoc
pattern: '^#+\s+(NAME|SYNOPSIS|DESCRIPTION)'
- extensions: ['.sim']
rules:
- language: Simula
pattern: '(?i)\bbegin\b.*?\bend\b'
- language: YAML
pattern: '^[\{\[]'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need a test for this heuristic

- extensions: ['.sol']
rules:
- language: Solidity
Expand Down
15 changes: 15 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,7 @@ Dockerfile:
filenames:
- Containerfile
- Dockerfile
- Dockerfile.sim
ace_mode: dockerfile
codemirror_mode: dockerfile
codemirror_mime_type: text/x-dockerfile
Expand Down Expand Up @@ -4204,6 +4205,7 @@ Makefile:
- Makefile.frag
- Makefile.in
- Makefile.inc
- Makefile.sim
- Makefile.wat
- makefile
- makefile.sco
Expand Down Expand Up @@ -6821,6 +6823,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.sim
ace_mode: simula
codemirror_mode: simula
codemirror_mime_type: text/x-simula
language_id: 582204041
Singularity:
type: programming
color: "#64E6AD"
Expand Down Expand Up @@ -8245,6 +8259,7 @@ YAML:
- ".mir"
- ".reek"
- ".rviz"
- ".sim"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a sample for this language if you're going to add this extension here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a sample for this language if you're going to add this extension here.

I'm not 100 % what you meant - was this about the Simula language, or about the YAML fallback?

I made 2 updates to the pull request:

  1. Pushed 5 more Simula language code samples
  2. Added an example of an existing .sim file on GitHub which would make sense to code-highlight as YAML (it's JSON, but all JSON is valid YAML).

It would be nice if linguist supported a "noop fallback" configuration, where - if we can't positively identify a .sim file as valid Simula code - it would just be treated as unknown text format.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the YAML entry. You added it but didn't add a sample.

I see you've now added samples but you've now also added samples that are too big. Please remove any that are suppressed in the diff and any that aren't real world uses.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I removed the samples!

- ".sublime-syntax"
- ".syntax"
- ".yaml"
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
29 changes: 29 additions & 0 deletions samples/Simula/klant1.sim
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
comment License: program borrowed from S-PORT https://github.com/portablesimula/S-PORT;
begin
! klant 1
beschrijving van een winkel
copyright H.G.Sol;

external class Demos;

Demos begin
Entity class Klant;
begin
Bediendes.Acquire(1);
Hold(5);
Bediendes.Release(1);
Kassieres.Acquire(1);
Hold(2);
Kassieres.Release(1);
end;
ref(Res) Bediendes,Kassieres;
Bediendes:- new Res("bediendes",2);
Kassieres:- new Res("kassieres",1);
Trace;
new Klant("klant").Schedule(1);
new Klant("klant").Schedule(2);
new Klant("klant").Schedule(5);
new Klant("klant").Schedule(6);
Hold(40);
end;
end;
67 changes: 67 additions & 0 deletions samples/Simula/klant4.sim
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
comment License: program borrowed from S-PORT https://github.com/portablesimula/S-PORT;
begin
external class demos;
! klant 4
zelfbediening en artikelvoorraad
copyright H.G.Sol;
Demos begin
Entity class Klant;
begin
Karren.Acquire(1);
Bier.Take(Hoevelheid.Sample);
Hold(Paktijd.Sample);
if Vragen.Sample then
begin
Bediendes.Acquire(1);
Hold(Helptijd.Sample);
Bediendes.Release(1);
end;
Kassieres.Acquire(1);
Hold(Betaaltijd.Sample);
Kassieres.Release(1);
Karren.Release(1);
end;

Entity class Bierleverantie(Frequentie);
real Frequentie;
begin
if Bier.Avail < 100 then
Bier.Give(300);
Hold(1/Frequentie);
Repeat;
end;

Entity class Klantengenerator(Tussentijd);
ref(Rdist)Tussentijd;
begin
new Klant("klant").Schedule(0);
Hold(Tussentijd.Sample);
Repeat;
end;

ref(Res) Karren,Bediendes,Kassieres;
ref(Bin) Bier;
ref(Rdist) Paktijd,Helptijd, Betaaltijd, Tussentijd;
ref(Idist) Hoevelheid;
ref(Bdist) Vragen;

trace;

Karren:- new Res("karren",10);
Bediendes:- new Res("bediendes",2);
Kassieres:- new Res("kassieres",2);
Bier:- new Bin("bier",150);
Tussentijd:- new Negexp("tt",.5);
Paktijd:- new Normal("pt",5,.5);
Helptijd:- new Normal("ht",2,.5);
Betaaltijd:- new Negexp("bt",.5);
Hoevelheid:- new Randint("hv",1,12);
Vragen:- new Draw("vr",.3);

Hold(9*60);
Reset;
new Bierleverantie("bl",1/40).Schedule(30);
new Klantengenerator("kg",Tussentijd).Schedule(0);
Hold(18*60 - 9*60);
end;
end;
91 changes: 91 additions & 0 deletions samples/Simula/powers.sim
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
comment License: program borrowed from S-PORT https://github.com/portablesimula/S-PORT;
begin
comment this program computes the "best" powers of ten re U1100;
integer lower, upper, minlim, ee, pp;

procedure outpower(exp_param,power_param); name exp_param;
integer exp_param,power_param;
begin
integer exp, power;
integer array digits(lower:upper);
integer max,min,digit;

procedure divide(exp); integer exp;
begin integer i, rem;
while exp>0 do begin
exp := exp-1; rem := 0;
i := max+1;
while i>min do begin
i := i-1;
digit := digits(i)//2;
if digits(i)-2*digit>0 then digits(i-1):=digits(i-1)+10;
digits(i):=digit;
end;
if digits(min-1)>0 then begin
min := min-1; digits(min) := 5;
end;
if digits(max)=0 then max:=max-1;
end while;
if max<>0 then begin exp_param:=exp_param+1; goto RETRY end;
end divide;

procedure output;
begin integer i, j, first, last, carry, borrow;
! the number to be output is in digits(min:max);
last := min;
first := max+1;
while first>min do begin
first := first-1;
carry:=borrow:=0;
i := last-1;
while i<first do begin
i := i+1;
digit:=digits(i)*2+carry;
if digit>10 then begin carry:=1; digit:=digit-10 end
else carry:=0;
digit:=digits(i-1)-digit-borrow;
if digit<0 then begin borrow:=1; digit:=digit+10 end
else borrow:=0;
digits(i-1):=digit;
end;
digits(first) := digits(first)-borrow-carry;
if digits(last)<>0 then last:=last-1;
end first;
if digits(0)<4 then begin exp_param:=exp_param-1; goto RETRY end;
if digits(-20)=7
then begin
outint(exp_param,4); outint(power_param,4); outchar(':');
for i:= -20 step -1 until -22 do outchar(char(rank('0')+digits(i)));
outimage;
end
else if digits(-20)=0
then begin
outint(exp_param,4); outint(power_param,4); outchar(':');
for i:= -20 step -1 until -22 do outchar(char(rank('0')+digits(i)));
outimage;
end if;
end output;

RETRY: ! here when the exponent has been corrected;
exp := exp_param; power := power_param;
max:= power+1; !one sign. digit only;
min:= max; !one sign. digit only;
digits(max):=1;
divide(exp);
output;
end outpower;

!outtext("51634306575354226427"); ! outimage;
!outpower(665,200);
!outpower(608,183); ! 75 - denne er best;
!outtext("44446551131230337166"); ! outimage;
!outpower(326,098); ! 74 - denne er best;
!outtext("42154166127714446321"); outimage;
!outpower(167,050); ! 76 - denne er best;

ee := 1026; pp := 308;
while pp>0 do
begin upper := pp; lower := -3.4*upper;
ee := ee-3; pp := pp-1; outpower(ee,pp) end;

end;
Loading