Skip to content

Commit

Permalink
feat!: Add Custom Operators (#62)
Browse files Browse the repository at this point in the history
* feat: Support Custom Operators

* chore: Cleanup Old INFIX Stuff

* chore: Update Tests

* feat: Support Parsing Precedence Level

* feat: Add Support for PostFix

* chore: Refactor Parser Step 1

* fix: Stop TypeCasts And Generics Being Confused For Prefix PostFix Statements

* fix: Make INFIX operators work again

* feat: Support custom assignment operators

* chore: Update Tests

* feat: Support PostFix Statements

* feat: Add More Custom Operators

* feat: Add Operator Tests, Fix Operator Precedence Between INFIX And POSTFIX

* chore: Performance Increase

* feat: Support Operator Imports
  • Loading branch information
spotandjake authored Jan 6, 2023
1 parent b039396 commit dd3e142
Show file tree
Hide file tree
Showing 28 changed files with 12,648 additions and 9,858 deletions.
8 changes: 8 additions & 0 deletions __tests__/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { ILexingResult } from 'chevrotain';
// Read Raw Data
const Parser_Pass = fs.readFileSync('./__tests__/Data/Parser/Parser_Pass.br', 'utf8');
const Literals_pass = fs.readFileSync('./__tests__/Data/Parser/Parser_Pass.br', 'utf8');
const Operator_Precedence_Pass = fs.readFileSync(
'./__tests__/Data/Parser/Operator_Precedence_Pass.br',
'utf8'
);
// Helpers
const serializeInput = (lexStream: ILexingResult): string => {
const tokens = lexStream.tokens.map((token) => {
Expand All @@ -24,3 +28,7 @@ fs.writeFileSync(
'./__tests__/Data/Parser/Literals_Pass.json',
serializeInput(lex(Literals_pass, '', 'file'))
);
fs.writeFileSync(
'./__tests__/Data/Parser/Operator_Precedence_Pass.json',
serializeInput(lex(Operator_Precedence_Pass, '', 'file'))
);
2 changes: 1 addition & 1 deletion __tests__/Data/Parser/Literals_Pass.json

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions __tests__/Data/Parser/Operator_Precedence_Pass.br
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Infix Operators
let aINFIX: i32 = 1n + 1n;
let bINFIX: i32 = 1n - 1n;
let cINFIX: i32 = 1n * 1n;
let dINFIX: i32 = 1n / 1n;
let eINFIX: i32 = 1n % 1n;
let fINFIX: i32 = 1n ^ 1n;
let fINFIX: i32 = 1n == 1n;
// Prefix Operators
let aPREFIX: i32 = +1n;
let bPREFIX: i32 = -1n;
let cPREFIX: i32 = *1n;
let dPREFIX: i32 = /1n;
let ePREFIX: i32 = %1n;
let fPREFIX: i32 = ^1n;
// Postfix Operators
let aPOSTFIX: i32 = 1n+;
let bPOSTFIX: i32 = 1n-;
let cPOSTFIX: i32 = 1n*;
let dPOSTFIX: i32 = 1n/;
let ePOSTFIX: i32 = 1n%;
let fPOSTFIX: i32 = 1n^;

// Precedence
let aPrecedence: i32 = (1n!) + (1n!);
let bPrecedence: i32 = !1n + !1n;
let cPrecedence: i32 = !1n!;
let dPrecedence: i32 = !1n!!;
let ePrecedence: i32 = !!1n!;
let fPrecedence: i32 = +!1n;
let gPrecedence: i32 = 1n!+;
let hPrecedence: i32 = 1n + 1n ** 1n + 1n * 2n / 3n % 4n - 5n ^ 6n == 7n && 8n < 9n > 10n ? 12n;
1 change: 1 addition & 0 deletions __tests__/Data/Parser/Operator_Precedence_Pass.json

Large diffs are not rendered by default.

Loading

0 comments on commit dd3e142

Please sign in to comment.