use br-parser-tools

pull/10/head
Matthew Butterick 8 years ago
parent 86df35057c
commit 5723af898e

@ -5,7 +5,7 @@
(for-label racket (for-label racket
brag/support brag/support
brag/examples/nested-word-list brag/examples/nested-word-list
(only-in parser-tools/lex lexer-src-pos) (only-in br-parser-tools/lex lexer-src-pos)
(only-in syntax/parse syntax-parse ~literal))) (only-in syntax/parse syntax-parse ~literal)))
@ -256,11 +256,11 @@ A @emph{token} is the smallest meaningful element of a source program. Tokens ca
If possible, we also want to attach source location information to each token. Why? Because this informatino will be incorporated into the syntax objects produced by @racket[parse]. If possible, we also want to attach source location information to each token. Why? Because this informatino will be incorporated into the syntax objects produced by @racket[parse].
A parser often works in conjunction with a helper function called a @emph{lexer} that converts the raw code of the source program into tokens. The @racketmodname[parser-tools/lex] library can help us write a position-sensitive A parser often works in conjunction with a helper function called a @emph{lexer} that converts the raw code of the source program into tokens. The @racketmodname[br-parser-tools/lex] library can help us write a position-sensitive
tokenizer: tokenizer:
@interaction[#:eval my-eval @interaction[#:eval my-eval
(require parser-tools/lex) (require br-parser-tools/lex)
(define (tokenize ip) (define (tokenize ip)
(port-count-lines! ip) (port-count-lines! ip)
(define my-lexer (define my-lexer
@ -299,7 +299,7 @@ Note also from this lexer example:
@item{@racket[parse] accepts as input either a sequence of tokens, or a @item{@racket[parse] accepts as input either a sequence of tokens, or a
function that produces tokens (which @racket[parse] will call repeatedly to get the next token).} function that produces tokens (which @racket[parse] will call repeatedly to get the next token).}
@item{As an alternative to the basic @racket[token] structure, a token can also be an instance of the @racket[position-token] structure (also found in @racketmodname[parser-tools/lex]). In that case, the token will try to derive its position from that of the position-token.} @item{As an alternative to the basic @racket[token] structure, a token can also be an instance of the @racket[position-token] structure (also found in @racketmodname[br-parser-tools/lex]). In that case, the token will try to derive its position from that of the position-token.}
@item{@racket[parse] will stop if it gets @racket[void] (or @racket['eof]) as a token.} @item{@racket[parse] will stop if it gets @racket[void] (or @racket['eof]) as a token.}
@ -811,8 +811,8 @@ A @deftech{token} in @tt{brag} can be any of the following values:
@item{a string} @item{a string}
@item{a symbol} @item{a symbol}
@item{an instance produced by @racket[token]} @item{an instance produced by @racket[token]}
@item{an instance produced by the token constructors of @racketmodname[parser-tools/lex]} @item{an instance produced by the token constructors of @racketmodname[br-parser-tools/lex]}
@item{an instance of @racketmodname[parser-tools/lex]'s @racket[position-token] whose @item{an instance of @racketmodname[br-parser-tools/lex]'s @racket[position-token] whose
@racket[position-token-token] is a @tech{token}.} @racket[position-token-token] is a @tech{token}.}
] ]
@ -917,7 +917,7 @@ The @racketmodname[brag/support] module provides functions to interact with
@tt{brag} programs. The most useful is the @racket[token] function, which @tt{brag} programs. The most useful is the @racket[token] function, which
produces tokens to be parsed. produces tokens to be parsed.
In addition to the exports shown below, the @racketmodname[brag/support] module also provides everything from @racketmodname[brag/support], and everything from @racketmodname[parser-tools/lex]. In addition to the exports shown below, the @racketmodname[brag/support] module also provides everything from @racketmodname[brag/support], and everything from @racketmodname[br-parser-tools/lex].
@defproc[(token [type (or/c string? symbol?)] @defproc[(token [type (or/c string? symbol?)]

@ -1,5 +1,5 @@
#lang racket/base #lang racket/base
;; This module implements a parser form like the parser-tools's ;; This module implements a parser form like the br-parser-tools's
;; `parser', except that it works on an arbitrary CFG (returning ;; `parser', except that it works on an arbitrary CFG (returning
;; the first sucecssful parse). ;; the first sucecssful parse).
@ -23,7 +23,7 @@
;; different lengths. (Otherwise, in the spirit of finding one ;; different lengths. (Otherwise, in the spirit of finding one
;; successful parse, only the first result is kept.) ;; successful parse, only the first result is kept.)
;; The parser-tools's `parse' is used to transform tokens in the ;; The br-parser-tools's `parse' is used to transform tokens in the
;; grammar to tokens specific to this parser. In other words, this ;; grammar to tokens specific to this parser. In other words, this
;; parser uses `parser' so that it doesn't have to know anything about ;; parser uses `parser' so that it doesn't have to know anything about
;; tokens. ;; tokens.
@ -31,12 +31,12 @@
(require parser-tools/yacc (require br-parser-tools/yacc
parser-tools/lex) br-parser-tools/lex)
(require (for-syntax racket/base (require (for-syntax racket/base
syntax/boundmap syntax/boundmap
parser-tools/private-lex/token-syntax)) br-parser-tools/private-lex/token-syntax))
(provide cfg-parser) (provide cfg-parser)
@ -797,7 +797,7 @@
(module* test racket/base (module* test racket/base
(require (submod "..") (require (submod "..")
parser-tools/lex br-parser-tools/lex
racket/block racket/block
rackunit) rackunit)

@ -19,7 +19,7 @@
;; FIXME: abstract this so we can just call (rules ...) without ;; FIXME: abstract this so we can just call (rules ...) without
;; generating the whole module body. ;; generating the whole module body.
(define (rules-codegen stx (define (rules-codegen stx
#:parser-provider-module [parser-provider-module 'parser-tools/yacc] #:parser-provider-module [parser-provider-module 'br-parser-tools/yacc]
#:parser-provider-form [parser-provider-form 'parser]) #:parser-provider-form [parser-provider-form 'parser])
(syntax-case stx () (syntax-case stx ()
[(_ r ...) [(_ r ...)
@ -36,7 +36,7 @@
(check-all-rules-no-duplicates! rules) (check-all-rules-no-duplicates! rules)
(check-all-rules-satisfiable! rules) (check-all-rules-satisfiable! rules)
;; We flatten the rules so we can use the yacc-style ruleset that parser-tools ;; We flatten the rules so we can use the yacc-style ruleset that br-parser-tools
;; supports. ;; supports.
(define flattened-rules (flatten-rules rules)) (define flattened-rules (flatten-rules rules))
@ -86,7 +86,7 @@
[parser-form parser-provider-form]) [parser-form parser-provider-form])
(quasisyntax/loc stx (quasisyntax/loc stx
(begin (begin
(require parser-tools/lex (require br-parser-tools/lex
parser-module parser-module
brag/codegen/runtime brag/codegen/runtime
brag/support brag/support

@ -3,7 +3,7 @@
(require racket/match (require racket/match
racket/list racket/list
racket/generator racket/generator
(prefix-in lex: parser-tools/lex) (prefix-in lex: br-parser-tools/lex)
brag/support brag/support
brag/private/internal-support) brag/private/internal-support)

@ -5,7 +5,7 @@
;; Danny Yoo (dyoo@hashcollision.org) ;; Danny Yoo (dyoo@hashcollision.org)
;; ;;
;; Intent: make it trivial to generate languages for Racket. At the ;; Intent: make it trivial to generate languages for Racket. At the
;; moment, I find it painful to use parser-tools. This library is ;; moment, I find it painful to use br-parser-tools. This library is
;; meant to make it less agonizing. ;; meant to make it less agonizing.
;; ;;
;; The intended use of this language is as follows: ;; The intended use of this language is as follows:
@ -25,11 +25,11 @@
;; ;;
;; You'll still need to do a little work, by providing a lexer that ;; You'll still need to do a little work, by providing a lexer that
;; defines what the uppercased tokens mean. For example, you can ;; defines what the uppercased tokens mean. For example, you can
;; use the parser-tools/lex lexer tools: ;; use the br-parser-tools/lex lexer tools:
;; ;;
;; (require brag/support ;; (require brag/support
;; parser-tools/lex ;; br-parser-tools/lex
;; parser-tools/lex-sre) ;; br-parser-tools/lex-sre)
;; ;;
;; (define tokenize ;; (define tokenize
;; (lexer-src-pos ;; (lexer-src-pos
@ -91,6 +91,6 @@
#%top-interaction) #%top-interaction)
(define-syntax (rules stx) (define-syntax (rules stx)
(rules-codegen #:parser-provider-module 'brag/cfg-parser/cfg-parser ;; 'parser-tools/yacc (rules-codegen #:parser-provider-module 'brag/cfg-parser/cfg-parser ;; 'br-parser-tools/yacc
#:parser-provider-form 'cfg-parser ;; 'parser #:parser-provider-form 'cfg-parser ;; 'parser
stx)) stx))

@ -4,7 +4,7 @@
;; A simple lexer for simple-line-drawing. ;; A simple lexer for simple-line-drawing.
(require brag/support (require brag/support
parser-tools/lex) br-parser-tools/lex)
(define (tokenize ip) (define (tokenize ip)
(port-count-lines! ip) (port-count-lines! ip)

@ -1,7 +1,7 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base "parser.rkt")) (require (for-syntax racket/base "parser.rkt"))
(require parser-tools/lex (require br-parser-tools/lex
(prefix-in : parser-tools/lex-sre) (prefix-in : br-parser-tools/lex-sre)
"parser.rkt" "parser.rkt"
"rule-structs.rkt" "rule-structs.rkt"
racket/string) racket/string)
@ -115,7 +115,7 @@
;; position->pos: position -> pos ;; position->pos: position -> pos
;; Coerses position structures from parser-tools/lex to our own pos structures. ;; Coerses position structures from br-parser-tools/lex to our own pos structures.
(define (position->pos a-pos) (define (position->pos a-pos)
(pos (position-offset a-pos) (pos (position-offset a-pos)
(position-line a-pos) (position-line a-pos)

@ -1,6 +1,6 @@
#lang racket/base #lang racket/base
(require parser-tools/yacc (require br-parser-tools/yacc
parser-tools/lex br-parser-tools/lex
racket/list racket/list
racket/match racket/match
"rule-structs.rkt") "rule-structs.rkt")
@ -240,7 +240,7 @@
;; position->pos: position -> pos ;; position->pos: position -> pos
;; Coerses position structures from parser-tools/lex to our own pos structures. ;; Coerses position structures from br-parser-tools/lex to our own pos structures.
(define (position->pos a-pos) (define (position->pos a-pos)
(pos (position-offset a-pos) (pos (position-offset a-pos)
(position-line a-pos) (position-line a-pos)

@ -2,7 +2,7 @@
(provide (all-defined-out)) (provide (all-defined-out))
;; We keep our own position structure because parser-tools/lex's position ;; We keep our own position structure because br-parser-tools/lex's position
;; structure is non-transparent, hence highly resistant to unit testing. ;; structure is non-transparent, hence highly resistant to unit testing.
(struct pos (offset line col) (struct pos (offset line col)
#:transparent) #:transparent)

@ -1,5 +1,5 @@
#lang racket/base #lang racket/base
(require parser-tools/lex) (require br-parser-tools/lex)
(provide (all-defined-out)) (provide (all-defined-out))

@ -1,7 +1,7 @@
#lang racket/base #lang racket/base
(require "rule-structs.rkt" (require "rule-structs.rkt"
parser-tools/lex br-parser-tools/lex
racket/match racket/match
syntax/strip-context) syntax/strip-context)

@ -1,11 +1,11 @@
#lang racket/base #lang racket/base
(require parser-tools/lex (require br-parser-tools/lex
racket/string racket/string
racket/struct racket/struct
(prefix-in : parser-tools/lex-sre) (prefix-in : br-parser-tools/lex-sre)
(for-syntax racket/base)) (for-syntax racket/base))
(provide (all-from-out parser-tools/lex) (provide (all-from-out br-parser-tools/lex)
(all-from-out parser-tools/lex-sre) (all-from-out br-parser-tools/lex-sre)
[struct-out token-struct] [struct-out token-struct]
token token
[struct-out exn:fail:parsing]) [struct-out exn:fail:parsing])

@ -1,7 +1,7 @@
#lang racket/base #lang racket/base
(require brag/rules/lexer (require brag/rules/lexer
rackunit rackunit
parser-tools/lex) br-parser-tools/lex)
(define (l s) (define (l s)
(define t (lex/1 (open-input-string s))) (define t (lex/1 (open-input-string s)))

@ -5,8 +5,8 @@
(require brag/examples/simple-line-drawing (require brag/examples/simple-line-drawing
brag/support brag/support
racket/list racket/list
parser-tools/lex br-parser-tools/lex
(prefix-in : parser-tools/lex-sre) (prefix-in : br-parser-tools/lex-sre)
rackunit) rackunit)
(define-tokens tokens (INTEGER STRING |;| EOF)) (define-tokens tokens (INTEGER STRING |;| EOF))
@ -72,5 +72,5 @@ EOF
;; FIXME: add tests to make sure location is as we expect. ;; FIXME: add tests to make sure location is as we expect.
;; ;;
;; FIXME: handle the EOF issue better. Something in cfg-parser ;; FIXME: handle the EOF issue better. Something in cfg-parser
;; appears to deviate from parser-tools/yacc with regards to the stop ;; appears to deviate from br-parser-tools/yacc with regards to the stop
;; token. ;; token.

@ -2,7 +2,7 @@
(require rackunit (require rackunit
parser-tools/lex br-parser-tools/lex
brag/rules/parser brag/rules/parser
brag/rules/lexer brag/rules/lexer
brag/rules/rule-structs) brag/rules/rule-structs)

@ -2,7 +2,7 @@
(require brag/examples/simple-arithmetic-grammar (require brag/examples/simple-arithmetic-grammar
brag/support brag/support
racket/set racket/set
parser-tools/lex br-parser-tools/lex
racket/list racket/list
rackunit) rackunit)

@ -3,8 +3,8 @@
(require brag/examples/simple-line-drawing (require brag/examples/simple-line-drawing
brag/support brag/support
racket/list racket/list
parser-tools/lex br-parser-tools/lex
(prefix-in : parser-tools/lex-sre) (prefix-in : br-parser-tools/lex-sre)
rackunit) rackunit)
(define (make-tokenizer ip) (define (make-tokenizer ip)
@ -68,5 +68,5 @@ EOF
;; FIXME: add tests to make sure location is as we expect. ;; FIXME: add tests to make sure location is as we expect.
;; ;;
;; FIXME: handle the EOF issue better. Something in cfg-parser ;; FIXME: handle the EOF issue better. Something in cfg-parser
;; appears to deviate from parser-tools/yacc with regards to the stop ;; appears to deviate from br-parser-tools/yacc with regards to the stop
;; token. ;; token.

@ -1,7 +1,7 @@
#lang setup/infotab #lang setup/infotab
(define deps '("base" "parser-tools-lib" "rackunit-lib")) (define deps '("base" "br-parser-tools-lib" "rackunit-lib"))
(define build-deps '("at-exp-lib" "parser-tools-doc" "racket-doc" (define build-deps '("at-exp-lib" "br-parser-tools-doc" "racket-doc"
"scribble-lib")) "scribble-lib"))
(define collection 'multi) (define collection 'multi)

Loading…
Cancel
Save