Duck util-parser.
This commit is contained in:
parent
b027d19f49
commit
1a2e9ee726
5 changed files with 73 additions and 41 deletions
|
@ -218,3 +218,41 @@ to ```format``` procedure.
|
||||||
(stdout-newline)
|
(stdout-newline)
|
||||||
|
|
||||||
If not quiet, calls ```(newline)```.
|
If not quiet, calls ```(newline)```.
|
||||||
|
|
||||||
|
## util-parser [module]
|
||||||
|
|
||||||
|
(import util-parser)
|
||||||
|
|
||||||
|
This module contains common functions for both configuration and
|
||||||
|
member file parsers. All functions are UTF-8 aware.
|
||||||
|
|
||||||
|
### parser-preprocess-line [procedure]
|
||||||
|
|
||||||
|
(parser-preprocess-line line)
|
||||||
|
|
||||||
|
* ```line``` - a string with contents of one source line
|
||||||
|
|
||||||
|
If the input ```line``` contains the ```#``` character, the rest of
|
||||||
|
the line (including this character) is removed.
|
||||||
|
|
||||||
|
Any leading and trailing space is removed.
|
||||||
|
|
||||||
|
Returns a string representing the preprocessed line.
|
||||||
|
|
||||||
|
### parser-parse-line [procedure]
|
||||||
|
|
||||||
|
(parser-parse-line line)
|
||||||
|
|
||||||
|
* ```line``` - preprocessed line (string)
|
||||||
|
|
||||||
|
If the ```line``` is empty, returns ```#f```.
|
||||||
|
|
||||||
|
If the line contains only one token consisting of non-whitespace
|
||||||
|
characters before the first whitespace character (there is no
|
||||||
|
whitespace), returns a symbol created by interning the whole
|
||||||
|
```line```.
|
||||||
|
|
||||||
|
When the ```line``` contains whitespace character(s), it returns a
|
||||||
|
pair consisting of symbol created by interning the string of
|
||||||
|
non-whitespace characters before the first whitespace character and
|
||||||
|
the string with the rest of the line.
|
||||||
|
|
34
doc/utils.md
34
doc/utils.md
|
@ -177,40 +177,6 @@ sent to the address stored within.
|
||||||
Sends email using mail(1) command. The arguments ```#:to``` and
|
Sends email using mail(1) command. The arguments ```#:to``` and
|
||||||
```#:subject``` are mandatory. Argument ```#:from``` is optional.
|
```#:subject``` are mandatory. Argument ```#:from``` is optional.
|
||||||
|
|
||||||
### Parser
|
|
||||||
|
|
||||||
(import util-parser)
|
|
||||||
|
|
||||||
This module contains common functions for both configuration and
|
|
||||||
member file parsers. All functions are UTF-8 aware.
|
|
||||||
|
|
||||||
(parser-preprocess-line line)
|
|
||||||
|
|
||||||
* ```line``` - a string with contents of one source line
|
|
||||||
|
|
||||||
If the input ```line``` contains the ```#``` character, the rest of
|
|
||||||
the line (including this character) is removed.
|
|
||||||
|
|
||||||
Any leading and trailing space is removed.
|
|
||||||
|
|
||||||
Returns a string representing the preprocessed line.
|
|
||||||
|
|
||||||
(parser-parse-line line)
|
|
||||||
|
|
||||||
* ```line``` - preprocessed line (string)
|
|
||||||
|
|
||||||
If the ```line``` is empty, returns ```#f```.
|
|
||||||
|
|
||||||
If the line contains only one token consisting of non-whitespace
|
|
||||||
characters before the first whitespace character (there is no
|
|
||||||
whitespace), returns a symbol created by interning the whole
|
|
||||||
```line```.
|
|
||||||
|
|
||||||
When the ```line``` contains whitespace character(s), it returns a
|
|
||||||
pair consisting of symbol created by interning the string of
|
|
||||||
non-whitespace characters before the first whitespace character and
|
|
||||||
the string with the rest of the line.
|
|
||||||
|
|
||||||
### Proc
|
### Proc
|
||||||
|
|
||||||
(import util-proc)
|
(import util-proc)
|
||||||
|
|
|
@ -59,11 +59,12 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \
|
||||||
|
|
||||||
GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \
|
GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \
|
||||||
util-time.import.scm util-csv.import.scm util-git.import.scm \
|
util-time.import.scm util-csv.import.scm util-git.import.scm \
|
||||||
util-io.import.scm util-stdout.import.scm
|
util-io.import.scm util-stdout.import.scm \
|
||||||
|
util-parser.import.scm
|
||||||
|
|
||||||
GENDOC-OBJS=gendoc.o duck-extract.o util-time.o util-csv.o util-io.o \
|
GENDOC-OBJS=gendoc.o duck-extract.o util-time.o util-csv.o util-io.o \
|
||||||
progress.o testing.o util-proc.o util-git.o util-io.o \
|
progress.o testing.o util-proc.o util-git.o util-io.o \
|
||||||
util-stdout.o
|
util-stdout.o util-parser.o
|
||||||
|
|
||||||
.PHONY: imports
|
.PHONY: imports
|
||||||
imports: $(HACKERBASE-DEPS)
|
imports: $(HACKERBASE-DEPS)
|
||||||
|
@ -294,7 +295,8 @@ UTIL-IO-SOURCES=util-io.scm
|
||||||
util-io.o: util-io.import.scm
|
util-io.o: util-io.import.scm
|
||||||
util-io.import.scm: $(UTIL-IO-SOURCES)
|
util-io.import.scm: $(UTIL-IO-SOURCES)
|
||||||
|
|
||||||
UTIL-PARSER-SOURCES=util-parser.scm testing.import.scm
|
UTIL-PARSER-SOURCES=util-parser.scm testing.import.scm \
|
||||||
|
duck.import.scm
|
||||||
|
|
||||||
util-parser.o: util-parser.import.scm
|
util-parser.o: util-parser.import.scm
|
||||||
util-parser.import.scm: $(UTIL-PARSER-SOURCES)
|
util-parser.import.scm: $(UTIL-PARSER-SOURCES)
|
||||||
|
|
|
@ -24,4 +24,5 @@
|
||||||
util-csv
|
util-csv
|
||||||
util-git
|
util-git
|
||||||
util-io
|
util-io
|
||||||
util-stdout)
|
util-stdout
|
||||||
|
util-parser)
|
||||||
|
|
|
@ -25,8 +25,12 @@
|
||||||
|
|
||||||
(declare (unit util-parser))
|
(declare (unit util-parser))
|
||||||
|
|
||||||
(module
|
(import duck)
|
||||||
|
|
||||||
|
(module*
|
||||||
util-parser
|
util-parser
|
||||||
|
#:doc ("This module contains common functions for both configuration and
|
||||||
|
member file parsers. All functions are UTF-8 aware.")
|
||||||
(
|
(
|
||||||
parser-preprocess-line
|
parser-preprocess-line
|
||||||
parser-parse-line
|
parser-parse-line
|
||||||
|
@ -39,7 +43,15 @@
|
||||||
|
|
||||||
;; Pass 0: Removes any comments and removes any leading and trailing
|
;; Pass 0: Removes any comments and removes any leading and trailing
|
||||||
;; whitespace.
|
;; whitespace.
|
||||||
(define (parser-preprocess-line line)
|
(define/doc (parser-preprocess-line line)
|
||||||
|
("* ```line``` - a string with contents of one source line
|
||||||
|
|
||||||
|
If the input ```line``` contains the ```#``` character, the rest of
|
||||||
|
the line (including this character) is removed.
|
||||||
|
|
||||||
|
Any leading and trailing space is removed.
|
||||||
|
|
||||||
|
Returns a string representing the preprocessed line.")
|
||||||
(let* ((llen (string-length line))
|
(let* ((llen (string-length line))
|
||||||
(ppos (let ploop ((pidx 0))
|
(ppos (let ploop ((pidx 0))
|
||||||
(if (or (= pidx llen)
|
(if (or (= pidx llen)
|
||||||
|
@ -67,7 +79,20 @@
|
||||||
;; removed, returns either #f if nothing was parsed, symbol if only
|
;; removed, returns either #f if nothing was parsed, symbol if only
|
||||||
;; one token was there and pair of symbol and string if both key and
|
;; one token was there and pair of symbol and string if both key and
|
||||||
;; the value were present.
|
;; the value were present.
|
||||||
(define (parser-parse-line line)
|
(define/doc (parser-parse-line line)
|
||||||
|
("* ```line``` - preprocessed line (string)
|
||||||
|
|
||||||
|
If the ```line``` is empty, returns ```#f```.
|
||||||
|
|
||||||
|
If the line contains only one token consisting of non-whitespace
|
||||||
|
characters before the first whitespace character (there is no
|
||||||
|
whitespace), returns a symbol created by interning the whole
|
||||||
|
```line```.
|
||||||
|
|
||||||
|
When the ```line``` contains whitespace character(s), it returns a
|
||||||
|
pair consisting of symbol created by interning the string of
|
||||||
|
non-whitespace characters before the first whitespace character and
|
||||||
|
the string with the rest of the line.")
|
||||||
(let* ((llen (string-length line))
|
(let* ((llen (string-length line))
|
||||||
(spos (let sloop ((sidx 0))
|
(spos (let sloop ((sidx 0))
|
||||||
(if (or (= sidx llen)
|
(if (or (= sidx llen)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue