-
Notifications
You must be signed in to change notification settings - Fork 79
Add AST.Placeable #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,26 @@ | |
|
||
import { ParserStream } from './stream'; | ||
import { ParseError } from './errors'; | ||
import { includes } from './util'; | ||
|
||
const INLINE_WS = [' ', '\t']; | ||
|
||
export class FTLParserStream extends ParserStream { | ||
peekLineWS() { | ||
peekInlineWS() { | ||
let ch = this.currentPeek(); | ||
while (ch) { | ||
if (ch !== ' ' && ch !== '\t') { | ||
if (!includes(INLINE_WS, ch)) { | ||
break; | ||
} | ||
ch = this.peek(); | ||
} | ||
} | ||
|
||
skipWSLines() { | ||
skipBlankLines() { | ||
while (true) { | ||
this.peekLineWS(); | ||
this.peekInlineWS(); | ||
|
||
if (this.currentPeek() === '\n') { | ||
if (this.currentPeekIs('\n')) { | ||
this.skipToPeek(); | ||
this.next(); | ||
} else { | ||
|
@@ -28,9 +31,9 @@ export class FTLParserStream extends ParserStream { | |
} | ||
} | ||
|
||
skipLineWS() { | ||
skipInlineWS() { | ||
while (this.ch) { | ||
if (this.ch !== ' ' && this.ch !== '\t') { | ||
if (!includes(INLINE_WS, this.ch)) { | ||
break; | ||
} | ||
this.next(); | ||
|
@@ -84,22 +87,6 @@ export class FTLParserStream extends ParserStream { | |
return ((cc >= 48 && cc <= 57) || cc === 45); // 0-9 | ||
} | ||
|
||
isPeekNextLineIndented() { | ||
if (!this.currentPeekIs('\n')) { | ||
return false; | ||
} | ||
|
||
this.peek(); | ||
|
||
if (this.currentPeekIs(' ')) { | ||
this.resetPeek(); | ||
return true; | ||
} | ||
|
||
this.resetPeek(); | ||
return false; | ||
} | ||
|
||
isPeekNextLineVariantStart() { | ||
if (!this.currentPeekIs('\n')) { | ||
return false; | ||
|
@@ -109,7 +96,7 @@ export class FTLParserStream extends ParserStream { | |
|
||
const ptr = this.getPeekIndex(); | ||
|
||
this.peekLineWS(); | ||
this.peekInlineWS(); | ||
|
||
if (this.getPeekIndex() - ptr === 0) { | ||
this.resetPeek(); | ||
|
@@ -137,7 +124,7 @@ export class FTLParserStream extends ParserStream { | |
|
||
const ptr = this.getPeekIndex(); | ||
|
||
this.peekLineWS(); | ||
this.peekInlineWS(); | ||
|
||
if (this.getPeekIndex() - ptr === 0) { | ||
this.resetPeek(); | ||
|
@@ -162,7 +149,7 @@ export class FTLParserStream extends ParserStream { | |
|
||
const ptr = this.getPeekIndex(); | ||
|
||
this.peekLineWS(); | ||
this.peekInlineWS(); | ||
|
||
if (this.getPeekIndex() - ptr === 0) { | ||
this.resetPeek(); | ||
|
@@ -191,7 +178,7 @@ export class FTLParserStream extends ParserStream { | |
|
||
const ptr = this.getPeekIndex(); | ||
|
||
this.peekLineWS(); | ||
this.peekInlineWS(); | ||
|
||
if (this.getPeekIndex() - ptr === 0) { | ||
this.resetPeek(); | ||
|
@@ -208,7 +195,7 @@ export class FTLParserStream extends ParserStream { | |
} | ||
|
||
skipToNextEntryStart() { | ||
while (this.next()) { | ||
while (this.ch) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the syntax error happens exactly on the newline character, |
||
if (this.currentIs('\n') && !this.peekCharIs('\n')) { | ||
this.next(); | ||
if (this.ch === undefined || this.isIDStart() || | ||
|
@@ -217,6 +204,7 @@ export class FTLParserStream extends ParserStream { | |
break; | ||
} | ||
} | ||
this.next(); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,22 @@ export function serialize(resource, opts) { | |
} | ||
|
||
export function lineOffset(source, pos) { | ||
// Substract 1 to get the offset. | ||
// Subtract 1 to get the offset. | ||
return source.substring(0, pos).split('\n').length - 1; | ||
} | ||
|
||
export function columnOffset(source, pos) { | ||
const lastLineBreak = source.lastIndexOf('\n', pos); | ||
return lastLineBreak === -1 | ||
? pos | ||
// Substracting two offsets gives length; substract 1 to get the offset. | ||
: pos - lastLineBreak - 1; | ||
// Find the last line break starting backwards from the index just before | ||
// pos. This allows us to correctly handle ths case where the character at | ||
// pos is a line break as well. | ||
const fromIndex = pos - 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this, |
||
const prevLineBreak = source.lastIndexOf('\n', fromIndex); | ||
|
||
// pos is a position in the first line of source. | ||
if (prevLineBreak === -1) { | ||
return pos; | ||
} | ||
|
||
// Subtracting two offsets gives length; subtract 1 to get the offset. | ||
return pos - prevLineBreak - 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't used anywhere.