I gave up on the no precedence thing. adding prec to parser
This commit is contained in:
parent
44015e58b1
commit
2570635ba5
2 changed files with 33 additions and 9 deletions
|
|
@ -107,7 +107,6 @@ windowComponent = config \ ui.stateful {
|
|||
};
|
||||
|
||||
renderWindows = _ \
|
||||
_ = debug "renderWindows, scrollOffset" osState.wm.scrollOffset;
|
||||
windows = osState.windows;
|
||||
focused = osState.wm.focusedIndex;
|
||||
scrollable {
|
||||
|
|
@ -129,10 +128,9 @@ scrollToWindow = index \
|
|||
windowW = unwrapOr 400 (nth index widths);
|
||||
scrollOffset = osState.wm.scrollOffset;
|
||||
vw = viewport.width;
|
||||
_ = debug "in scrollToWindow" [windowX, windowW, scrollOffset, vw];
|
||||
(windowX < scrollOffset
|
||||
| True \ windowX
|
||||
| False \ ((windowX + windowW) > (scrollOffset + vw)
|
||||
| False \ (windowX + windowW > scrollOffset + vw
|
||||
| True \ windowX + windowW - vw
|
||||
| False \ scrollOffset));
|
||||
|
||||
|
|
@ -156,8 +154,6 @@ os = ui.stateful {
|
|||
| Key { key = "ArrowRight", meta = True } \
|
||||
(
|
||||
newIndex = min (len osState.windows - 1) (osState.wm.focusedIndex + 1);
|
||||
newScrollOffset = scrollToWindow newIndex;
|
||||
_ = debug "new scroll offset in key event handler" newScrollOffset;
|
||||
{ state = state, emit = [
|
||||
osState.wm.focusedIndex := newIndex,
|
||||
osState.wm.scrollOffset := scrollToWindow newIndex
|
||||
|
|
|
|||
|
|
@ -86,6 +86,33 @@ export class Parser {
|
|||
}
|
||||
}
|
||||
|
||||
private precOf(token: Token): number {
|
||||
switch (token.kind) {
|
||||
case 'ampersand':
|
||||
return 1;
|
||||
case 'equals-equals':
|
||||
case 'not-equals':
|
||||
case 'greater-than':
|
||||
case 'greater-equals':
|
||||
case 'less-than':
|
||||
case 'less-equals':
|
||||
return 2;
|
||||
case 'plus':
|
||||
case 'minus':
|
||||
return 3;
|
||||
case 'star':
|
||||
case 'slash':
|
||||
case 'percent':
|
||||
return 4;
|
||||
case 'caret':
|
||||
return 5;
|
||||
case 'tilde':
|
||||
return 6;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private canStartPrimary(): boolean {
|
||||
const kind = this.current().kind;
|
||||
return kind === 'ident' || kind === 'type-ident' ||
|
||||
|
|
@ -344,16 +371,17 @@ export class Parser {
|
|||
return { kind: 'let', name, value, body, ...this.getPos(nameToken) };
|
||||
}
|
||||
|
||||
private parseInfix(): AST {
|
||||
private parseInfix(minPrec: number = 0): AST {
|
||||
const token = this.current();
|
||||
let left = this.parseApplication();
|
||||
|
||||
while (this.isInfixOp()) {
|
||||
while (this.isInfixOp() && this.precOf(this.current()) >= minPrec) {
|
||||
const opToken = this.advance();
|
||||
const prec = this.precOf(opToken);
|
||||
|
||||
if (opToken.kind === 'tilde') {
|
||||
// function application operator
|
||||
const right = this.parseApplication();
|
||||
const right = this.parseInfix(prec + 1);
|
||||
|
||||
left = {
|
||||
kind: 'apply',
|
||||
|
|
@ -364,7 +392,7 @@ export class Parser {
|
|||
} else {
|
||||
// operators desugar to function calls
|
||||
const opName = this.tokenToOpName(opToken);
|
||||
const right = this.parseApplication();
|
||||
const right = this.parseInfix(prec + 1);
|
||||
|
||||
left = {
|
||||
kind: 'apply',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue