-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,901 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export type BindingPower = number; | ||
|
||
export type BindingPowerEntry = { left: BindingPower, right: BindingPower }; | ||
export type BindingPowers = { [key: string]: BindingPowerEntry }; | ||
|
||
export const bindingPowers: BindingPowers = { | ||
lowest: { left: 0, right: 1 }, | ||
assignment: { left: 31, right: 30 }, | ||
comparison: { left: 41, right: 40 }, | ||
summative: { left: 50, right: 51 }, | ||
productive: { left: 60, right: 61 }, | ||
prefix: { left: 70, right: 71 }, | ||
call: { left: 80, right: 81 }, | ||
}; | ||
|
||
export const getInfixBindingPower = (infix: string): BindingPowerEntry => { | ||
switch (infix) { | ||
case "=": | ||
return bindingPowers.assignment; | ||
|
||
case "==": | ||
case "!=": | ||
case ">": | ||
case "<": | ||
case ">=": | ||
case "<=": | ||
return bindingPowers.comparison; | ||
|
||
case "+": | ||
case "-": | ||
return bindingPowers.summative; | ||
|
||
case "*": | ||
case "/": | ||
return bindingPowers.productive; | ||
|
||
// for function call, it behaves an infix operator which lies between | ||
// function expression and parameter list, e.g, print("hello") | ||
case "(": | ||
return bindingPowers.call; | ||
|
||
default: | ||
return bindingPowers.lowest; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
import type Position from "../../../util/position"; | ||
|
||
export interface Range { | ||
readonly begin: Position, | ||
readonly end: Position, | ||
}; | ||
|
||
export interface SyntaxNodeBase<T extends string = string, F extends {} = {}> { | ||
type: T, | ||
range: { | ||
begin: Position, | ||
end: Position, | ||
}, | ||
fields: F, | ||
readonly type: T, | ||
readonly range: Range, | ||
readonly fields: F, | ||
}; | ||
|
||
export function createNodeCreator<N extends SyntaxNodeBase>(type: N["type"]) { | ||
function createNode(fields: N["fields"], rangeBegin: Position, rangeEnd: Position) { | ||
const range = { | ||
begin: rangeBegin, | ||
end: rangeEnd, | ||
}; | ||
type Node = { type: N["type"], range: N["range"], fields: N["fields"] }; | ||
|
||
function createNode(fields: N["fields"], range: Range): Node; | ||
function createNode(fields: N["fields"], rangeBegin: Position, rangeEnd: Position): Node; | ||
function createNode(fields: N["fields"], arg1: Range | Position, rangeEnd?: Position): Node { | ||
if (rangeEnd !== undefined) { | ||
const range = { | ||
begin: arg1 as Position, | ||
end: rangeEnd, | ||
}; | ||
|
||
return { type, range, fields }; | ||
} | ||
|
||
return { type, range, fields }; | ||
return { type, range: arg1 as Range, fields }; | ||
}; | ||
|
||
return createNode; | ||
}; | ||
|
||
export type CreateNode<N extends SyntaxNodeBase> = (fields: N["fields"], rangeBegin: Position, rangeEnd: Position) => N; | ||
declare function createNode<N extends SyntaxNodeBase>(fields: N["fields"], range: Range): N; | ||
declare function createNode<N extends SyntaxNodeBase>(fields: N["fields"], rangeBegin: Position, rangeEnd: Position): N; | ||
export type CreateNode<N extends SyntaxNodeBase> = typeof createNode<N>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.