Esempio n. 1
0
func (c *Context) scanNextToken() (int, string) {
	token := int(c.scanner.Scan())
	s := c.scanner.TokenText()

	for s == "!" || s == "#" {
		c.skipComments()

		token = int(c.scanner.Scan())
		s = c.scanner.TokenText()
	}

	log.Debugf("token text: %s\n", s)

	return token, s
}
Esempio n. 2
0
func (l *Lexer) scanInclude(rawfilename string) error {
	curDir, err := filepath.Abs(".")
	if err != nil {
		return err
	}

	baseDir := filepath.Dir(l.ctx.filename)
	os.Chdir(baseDir)
	defer os.Chdir(curDir)

	rawpaths, err := filepath.Glob(rawfilename)
	if err != nil {
		return err
	}

	if len(rawpaths) < 1 {
		log.Infof("warning: %s: No such file or directory", rawfilename)
	}

	prevctx := l.ctx
	defer func() { l.ctx = prevctx }()

	for _, rawpath := range rawpaths {
		relpath := filepath.Join(baseDir, rawpath)
		log.Debugf("--> Parsing ... %s\n", relpath)

		f, err := os.Open(rawpath)
		if err != nil {
			return err
		}

		l.ctx = NewContext(f, relpath)
		l.run()

		f.Close()
	}

	return nil
}