Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
(switch dev device)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest Micklei committed Nov 25, 2017
1 parent 2c42554 commit d6789b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type commentInliner interface {

// maybeScanInlineComment tries to scan comment on the current line ; if present then set it for the last element added.
func maybeScanInlineComment(p *Parser, c elementContainer) {
currentLine := p.s.line
currentPos := p.s.pos
// see if there is an inline Comment
line, tok, lit := p.scanIgnoreWhitespace()
esize := len(c.elements())
Expand Down
2 changes: 2 additions & 0 deletions position.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Position struct {
Column int // column number, starting at 1 (byte count)
}

var startPosition = Position{Line: 1, Column: 1}

// IsValid reports whether the position is valid.
func (pos *Position) IsValid() bool { return pos.Line > 0 }

Expand Down
46 changes: 23 additions & 23 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ import (

// scanner represents a lexical scanner.
type scanner struct {
r *bufio.Reader
line int
r *bufio.Reader
pos Position
}

// newScanner returns a new instance of Scanner.
func newScanner(r io.Reader) *scanner {
return &scanner{r: bufio.NewReader(r), line: 1}
return &scanner{r: bufio.NewReader(r), pos: startPosition}
}

// scan returns the next token and literal value.
func (s *scanner) scan() (line int, tok token, lit string) {
func (s *scanner) scan() (pos Position, tok token, lit string) {
// Read the next rune.
ch := s.read()
line = s.line
pos = s.pos
// If we see whitespace then consume all contiguous whitespace.
// If we see a letter then consume as an ident or reserved word.
// If we see a slash then consume all as a comment (can be multiline)
Expand All @@ -65,41 +65,41 @@ func (s *scanner) scan() (line int, tok token, lit string) {
// Otherwise read the individual character.
switch ch {
case eof:
return line, tEOF, ""
return pos, tEOF, ""
case ';':
return line, tSEMICOLON, string(ch)
return pos, tSEMICOLON, string(ch)
case ':':
return line, tCOLON, string(ch)
return pos, tCOLON, string(ch)
case '=':
return line, tEQUALS, string(ch)
return pos, tEQUALS, string(ch)
case '"':
return line, tQUOTE, string(ch)
return pos, tQUOTE, string(ch)
case '\'':
return line, tSINGLEQUOTE, string(ch)
return pos, tSINGLEQUOTE, string(ch)
case '(':
return line, tLEFTPAREN, string(ch)
return pos, tLEFTPAREN, string(ch)
case ')':
return line, tRIGHTPAREN, string(ch)
return pos, tRIGHTPAREN, string(ch)
case '{':
return line, tLEFTCURLY, string(ch)
return pos, tLEFTCURLY, string(ch)
case '}':
return line, tRIGHTCURLY, string(ch)
return pos, tRIGHTCURLY, string(ch)
case '[':
return line, tLEFTSQUARE, string(ch)
return pos, tLEFTSQUARE, string(ch)
case ']':
return line, tRIGHTSQUARE, string(ch)
return pos, tRIGHTSQUARE, string(ch)
case '/':
return line, tCOMMENT, s.scanComment()
return pos, tCOMMENT, s.scanComment()
case '<':
return line, tLESS, string(ch)
return pos, tLESS, string(ch)
case ',':
return line, tCOMMA, string(ch)
return pos, tCOMMA, string(ch)
case '.':
return line, tDOT, string(ch)
return pos, tDOT, string(ch)
case '>':
return line, tGREATER, string(ch)
return pos, tGREATER, string(ch)
}
return line, tILLEGAL, string(ch)
return pos, tILLEGAL, string(ch)
}

// skipWhitespace consumes all whitespace until eof or a non-whitespace rune.
Expand Down

0 comments on commit d6789b6

Please sign in to comment.