permit ::= as rule separator

pull/6/head
Matthew Butterick 7 years ago
parent ef846d113e
commit 30ce210403

@ -30,6 +30,7 @@
) )
(define-lex-abbrev id (:& (complement (:+ digit)) (:+ id-char))) (define-lex-abbrev id (:& (complement (:+ digit)) (:+ id-char)))
(define-lex-abbrev id-separator (:or ":" "::="))
(define lex/1 (define lex/1
(lexer-src-pos (lexer-src-pos
@ -76,11 +77,11 @@
(return-without-pos (lex/1 input-port))] (return-without-pos (lex/1 input-port))]
[(eof) [(eof)
(token-EOF lexeme)] (token-EOF lexeme)]
[(:: id (:* whitespace) ":") [(:: id (:* whitespace) id-separator)
(token-RULE_HEAD lexeme)] (token-RULE_HEAD lexeme)]
[(:: hide-char id (:* whitespace) ":") [(:: hide-char id (:* whitespace) id-separator)
(token-RULE_HEAD_HIDDEN lexeme)] (token-RULE_HEAD_HIDDEN lexeme)]
[(:: splice-char id (:* whitespace) ":") [(:: splice-char id (:* whitespace) id-separator)
(token-RULE_HEAD_SPLICED lexeme)] (token-RULE_HEAD_SPLICED lexeme)]
[id [id
(token-ID lexeme)] (token-ID lexeme)]

@ -59,6 +59,8 @@
(define hide-char #\/) (define hide-char #\/)
(define splice-char #\@) (define splice-char #\@)
(define id-separators-pattern "((:)|(::=))")
;; grammar-parser: (-> token) -> (listof rule) ;; grammar-parser: (-> token) -> (listof rule)
(define grammar-parser (define grammar-parser
(parser (parser
@ -84,7 +86,7 @@
[rule [rule
[(RULE_HEAD pattern) [(RULE_HEAD pattern)
(begin (begin
(define trimmed (regexp-replace #px"\\s*:$" $1 "")) (define trimmed (regexp-replace (pregexp (format "\\s*~a$" id-separators-pattern)) $1 ""))
(rule (position->pos $1-start-pos) (rule (position->pos $1-start-pos)
(position->pos $2-end-pos) (position->pos $2-end-pos)
(lhs-id (position->pos $1-start-pos) (lhs-id (position->pos $1-start-pos)
@ -98,7 +100,7 @@
[(RULE_HEAD_HIDDEN pattern) ; slash indicates hiding [(RULE_HEAD_HIDDEN pattern) ; slash indicates hiding
(begin (begin
(define trimmed (cadr (regexp-match (pregexp (format "~a(\\S+)\\s*:$" hide-char)) $1))) (define trimmed (cadr (regexp-match (pregexp (format "~a(\\S+)\\s*~a$" hide-char id-separators-pattern)) $1)))
(rule (position->pos $1-start-pos) (rule (position->pos $1-start-pos)
(position->pos $2-end-pos) (position->pos $2-end-pos)
(lhs-id (position->pos $1-start-pos) (lhs-id (position->pos $1-start-pos)
@ -113,7 +115,7 @@
[(RULE_HEAD_SPLICED pattern) ; atsign indicates splicing [(RULE_HEAD_SPLICED pattern) ; atsign indicates splicing
(begin (begin
(define trimmed (cadr (regexp-match (pregexp (format "~a(\\S+)\\s*:$" splice-char)) $1))) (define trimmed (cadr (regexp-match (pregexp (format "~a(\\S+)\\s*~a$" splice-char id-separators-pattern)) $1)))
(rule (position->pos $1-start-pos) (rule (position->pos $1-start-pos)
(position->pos $2-end-pos) (position->pos $2-end-pos)
(lhs-id (position->pos $1-start-pos) (lhs-id (position->pos $1-start-pos)

Loading…
Cancel
Save