Lines Matching full:self

92 function Parser.new (self, tokens)
93 self.tokens = tokens
94 self.parse_stack = {}
95 self.refs = {}
96 self.current = 0
97 return self
246 Parser.peek = function (self, offset)
248 return self.tokens[offset + self.current]
251 Parser.advance = function (self)
252 self.current = self.current + 1
253 return self.tokens[self.current]
256 Parser.advanceValue = function (self)
257 return self:advance()[2][1]
260 Parser.accept = function (self, type)
261 if self:peekType(type) then
262 return self:advance()
266 Parser.expect = function (self, type, msg)
267 return self:accept(type) or
268 error(msg .. context(self:peek()[1].input))
271 Parser.expectDedent = function (self, msg)
272 return self:accept("dedent") or (self:peek() == nil) or
273 error(msg .. context(self:peek()[2].input))
276 Parser.peekType = function (self, val, offset)
277 return self:peek(offset) and self:peek(offset)[1] == val
280 Parser.ignore = function (self, items)
285 if self:peekType(v) then
286 self:advance()
293 Parser.ignoreSpace = function (self)
294 self:ignore{"space"}
297 Parser.ignoreWhitespace = function (self)
298 self:ignore{"space", "indent", "dedent"}
301 Parser.parse = function (self)
304 if self:peekType("string") and not self:peek().force_text then
305 local char = self:peek()[2][1]:sub(1,1)
307 ref = self:peek()[2][1]:sub(2)
308 self:advanceValue()
309 self:ignoreSpace()
311 ref = self:peek()[2][1]:sub(2)
312 return self.refs[ref]
318 indent = self:accept("indent") and 1 or 0,
319 token = self:peek()
321 push(self.parse_stack, c)
324 result = self:parseDoc()
326 result = self:parseList()
328 result = self:parseInlineHash()
330 result = self:parseInlineList()
332 result = self:parseHash()
334 result = self:parseString("\n")
336 result = self:parseTimestamp()
338 result = tonumber(self:advanceValue())
340 result = self:parsePipe()
342 self:advanceValue();
348 pop(self.parse_stack)
352 self:expectDedent("last ".. term .." is not properly dedented")
356 self.refs[ref] = result
361 Parser.parseDoc = function (self)
362 self:accept("doc")
363 return self:parse()
366 Parser.inline = function (self)
367 local current = self:peek(0)
375 while self:peek(i) and not self:peekType("indent", i) and current.row == self:peek(i).row do
376 inline[self:peek(i)[1]] = true
382 Parser.isInline = function (self)
383 local _, i = self:inline()
387 Parser.parent = function(self, level)
389 return self.parse_stack[#self.parse_stack - level]
392 Parser.parentType = function(self, type, level)
393 return self:parent(level) and self:parent(level).token[1] == type
396 Parser.parseString = function (self)
397 if self:isInline() then
398 local result = self:advanceValue()
405 local types = self:inline()
407 if not self:peekType("indent") or not self:peekType("indent", 2) then
419 if self:peekType("indent") then
420 self:expect("indent", "text block needs to start with indent")
421 local addtl = self:accept("indent")
423 result = result .. "\n" .. self:parseTextBlock("\n")
425 self:expectDedent("text block ending dedent missing")
427 self:expectDedent("text block ending dedent missing")
440 return self:parseTextBlock("\n")
444 Parser.parsePipe = function (self)
445 local pipe = self:expect("pipe")
446 self:expect("indent", "text block needs to start with indent")
447 local result = self:parseTextBlock(pipe.sep)
448 self:expectDedent("text block ending dedent missing")
452 Parser.parseTextBlock = function (self, sep)
453 local token = self:advance()
456 while self:peek() ~= nil and ( indents > 0 or not self:peekType("dedent") ) do
457 local newtoken = self:advance()
473 Parser.parseHash = function (self, hash)
477 if self:isInline() then
478 local id = self:advanceValue()
479 self:expect(":", "expected semi-colon after id")
480 self:ignoreSpace()
481 if self:accept("indent") then
483 hash[id] = self:parse()
485 hash[id] = self:parse()
486 if self:accept("indent") then
490 self:ignoreSpace();
493 while self:peekType("id") do
494 local id = self:advanceValue()
495 self:expect(":","expected semi-colon after id")
496 self:ignoreSpace()
497 hash[id] = self:parse()
498 self:ignoreSpace();
502 self:expectDedent("expected dedent")
509 Parser.parseInlineHash = function (self)
514 self:accept("{")
515 while not self:accept("}") do
516 self:ignoreSpace()
518 self:expect(",","expected comma")
521 self:ignoreWhitespace()
522 if self:peekType("id") then
523 id = self:advanceValue()
525 self:expect(":","expected semi-colon after id")
526 self:ignoreSpace()
527 hash[id] = self:parse()
528 self:ignoreWhitespace()
537 Parser.parseList = function (self)
539 while self:accept("-") do
540 self:ignoreSpace()
541 list[#list + 1] = self:parse()
543 self:ignoreSpace()
548 Parser.parseInlineList = function (self)
551 self:accept("[")
552 while not self:accept("]") do
553 self:ignoreSpace()
555 self:expect(",","expected comma")
558 self:ignoreSpace()
559 list[#list + 1] = self:parse()
560 self:ignoreSpace()
567 Parser.parseTimestamp = function (self)
568 local capture = self:advance()[2]