I gave up on the no precedence thing. adding prec to parser

master
Dustin Swan 2 weeks ago
parent 44015e58b1
commit 2570635ba5
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -107,7 +107,6 @@ windowComponent = config \ ui.stateful {
}; };
renderWindows = _ \ renderWindows = _ \
_ = debug "renderWindows, scrollOffset" osState.wm.scrollOffset;
windows = osState.windows; windows = osState.windows;
focused = osState.wm.focusedIndex; focused = osState.wm.focusedIndex;
scrollable { scrollable {
@ -129,10 +128,9 @@ scrollToWindow = index \
windowW = unwrapOr 400 (nth index widths); windowW = unwrapOr 400 (nth index widths);
scrollOffset = osState.wm.scrollOffset; scrollOffset = osState.wm.scrollOffset;
vw = viewport.width; vw = viewport.width;
_ = debug "in scrollToWindow" [windowX, windowW, scrollOffset, vw];
(windowX < scrollOffset (windowX < scrollOffset
| True \ windowX | True \ windowX
| False \ ((windowX + windowW) > (scrollOffset + vw) | False \ (windowX + windowW > scrollOffset + vw
| True \ windowX + windowW - vw | True \ windowX + windowW - vw
| False \ scrollOffset)); | False \ scrollOffset));
@ -156,8 +154,6 @@ os = ui.stateful {
| Key { key = "ArrowRight", meta = True } \ | Key { key = "ArrowRight", meta = True } \
( (
newIndex = min (len osState.windows - 1) (osState.wm.focusedIndex + 1); 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 = [ { state = state, emit = [
osState.wm.focusedIndex := newIndex, osState.wm.focusedIndex := newIndex,
osState.wm.scrollOffset := scrollToWindow 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 { private canStartPrimary(): boolean {
const kind = this.current().kind; const kind = this.current().kind;
return kind === 'ident' || kind === 'type-ident' || return kind === 'ident' || kind === 'type-ident' ||
@ -344,16 +371,17 @@ export class Parser {
return { kind: 'let', name, value, body, ...this.getPos(nameToken) }; return { kind: 'let', name, value, body, ...this.getPos(nameToken) };
} }
private parseInfix(): AST { private parseInfix(minPrec: number = 0): AST {
const token = this.current(); const token = this.current();
let left = this.parseApplication(); let left = this.parseApplication();
while (this.isInfixOp()) { while (this.isInfixOp() && this.precOf(this.current()) >= minPrec) {
const opToken = this.advance(); const opToken = this.advance();
const prec = this.precOf(opToken);
if (opToken.kind === 'tilde') { if (opToken.kind === 'tilde') {
// function application operator // function application operator
const right = this.parseApplication(); const right = this.parseInfix(prec + 1);
left = { left = {
kind: 'apply', kind: 'apply',
@ -364,7 +392,7 @@ export class Parser {
} else { } else {
// operators desugar to function calls // operators desugar to function calls
const opName = this.tokenToOpName(opToken); const opName = this.tokenToOpName(opToken);
const right = this.parseApplication(); const right = this.parseInfix(prec + 1);
left = { left = {
kind: 'apply', kind: 'apply',

Loading…
Cancel
Save