Swift-Barcelona is a subset of Swift 5. This repository is the Source-academy compatible implementation of Swift-Barcelona, conforming to the <language>-slang
API.
To write Swift-Barcelona codes on Source Academy on your local machine,
- Clone the repository cs4215-project-2022-barcelona to your machine.
This repository contains the implementation of Swift-Barcelona.
- Clone the repository cs4215-project-2022-frontend-barcelona to the same folder on your machine.
This repository contains the Source Academy.
-
Go to the repository folder
cs4215-project-2022-barcelona
in the terminal. -
Run the following command to install required dependencies:
$ yarn install
- Replace the file
node_modules/@types/estree/index.d.ts
with this file.
The reason for this step is that installing the dependencies in the previous step would overwrite the modified ESTree file, and the modified ESTree file is necessary for Swift-Barcelona.
- Generate the antlr4ts lexer and parser with the following command:
$ yarn run antlr4ts
- Delete line 9-11 of the file
src/lang/CalcLexer.ts
.
import { LexerATNSimulator } from "antlr4ts/atn/LexerATNSimulator";
import { NotNull } from "antlr4ts/Decorators"; // REMOVE
import { Override } from "antlr4ts/Decorators"; // REMOVE
import { RuleContext } from "antlr4ts/RuleContext"; // REMOVE
import { Vocabulary } from "antlr4ts/Vocabulary";
The reason for this step is that although NotNull
, Override
, RuleContext
are auto-generated, they are never used in this file which will stop users from building the project.
- Delete line 7, 9, 13-14 of the file
src/lang/CalcParser.ts
.
import { FailedPredicateException } from "antlr4ts/FailedPredicateException";
import { NotNull } from "antlr4ts/Decorators"; // REMOVE
import { NoViableAltException } from "antlr4ts/NoViableAltException";
import { Override } from "antlr4ts/Decorators"; // REMOVE
import { Parser } from "antlr4ts/Parser";
import { ParserRuleContext } from "antlr4ts/ParserRuleContext";
import { ParserATNSimulator } from "antlr4ts/atn/ParserATNSimulator";
import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; // REMOVE
import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor"; // REMOVE
import { RecognitionException } from "antlr4ts/RecognitionException";
The reason for this step is that although NotNull
, Override
,
ParserTreeListener
, ParserTreeVisitor
are auto-generated, they are
never used in this file which will stop users from building the project.
- Build the project with the following command:
$ yarn build
- Link the project:
$ yarn link
-
Go to the folder
cs4215-project-2022-frontend-barcelona
in the terminal. -
Link the frontend to the built implementation of Swift-Barcelona:
$ yarn link x-slang
- Delete line 49 of the file
package.json
"flexboxgrid-helpers": "^1.1.3",
"x-slang": "^0.4.70", // REMOVE
"lodash": "^4.17.20",
The reason for this step is that we are using the x-slang of our own. Delete this line so that it will not try to find x-slang online when installing the dependencies in the next step. We will need to add it back after installing the dependencies.
- Install required dependencies:
$ yarn install
- Add
"x-slang":"^0.4.70",
back to the filepackage.json
.
"flexboxgrid-helpers": "^1.1.3",
"x-slang": "^0.4.70", // ADD
"lodash": "^4.17.20",
- Start the Source Academy:
$ yarn run start
- When you see
Compiled successfully!
in the terminal, access Source Academy in your browser at localhost:8000.
The sample test code can be found in testcase.