use br-parser-tools

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

@ -5,7 +5,7 @@
(for-label racket
brag/support
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)))
@ -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].
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:
@interaction[#:eval my-eval
(require parser-tools/lex)
(require br-parser-tools/lex)
(define (tokenize ip)
(port-count-lines! ip)
(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
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.}
@ -811,8 +811,8 @@ A @deftech{token} in @tt{brag} can be any of the following values:
@item{a string}
@item{a symbol}
@item{an instance produced by @racket[token]}
@item{an instance produced by the token constructors of @racketmodname[parser-tools/lex]}
@item{an instance of @racketmodname[parser-tools/lex]'s @racket[position-token] whose
@item{an instance produced by the token constructors of @racketmodname[br-parser-tools/lex]}
@item{an instance of @racketmodname[br-parser-tools/lex]'s @racket[position-token] whose
@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
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?)]

@ -1,5 +1,5 @@
#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
;; the first sucecssful parse).
@ -23,7 +23,7 @@
;; different lengths. (Otherwise, in the spirit of finding one
;; 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
;; parser uses `parser' so that it doesn't have to know anything about
;; tokens.
@ -31,12 +31,12 @@
(require parser-tools/yacc
parser-tools/lex)
(require br-parser-tools/yacc
br-parser-tools/lex)
(require (for-syntax racket/base
syntax/boundmap
parser-tools/private-lex/token-syntax))
br-parser-tools/private-lex/token-syntax))
(provide cfg-parser)
@ -797,7 +797,7 @@
(module* test racket/base
(require (submod "..")
parser-tools/lex
br-parser-tools/lex
racket/block
rackunit)

@ -19,7 +19,7 @@
;; FIXME: abstract this so we can just call (rules ...) without
;; generating the whole module body.
(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])
(syntax-case stx ()
[(_ r ...)
@ -36,7 +36,7 @@
(check-all-rules-no-duplicates! 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.
(define flattened-rules (flatten-rules rules))
@ -86,7 +86,7 @@
[parser-form parser-provider-form])
(quasisyntax/loc stx
(begin
(require parser-tools/lex
(require br-parser-tools/lex
parser-module
brag/codegen/runtime
brag/support

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

@ -5,7 +5,7 @@
;; Danny Yoo (dyoo@hashcollision.org)
;;
;; 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.
;;
;; 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
;; 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
;; parser-tools/lex
;; parser-tools/lex-sre)
;; br-parser-tools/lex
;; br-parser-tools/lex-sre)
;;
;; (define tokenize
;; (lexer-src-pos
@ -91,6 +91,6 @@
#%top-interaction)
(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
stx))

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

@ -1,7 +1,7 @@
#lang racket/base
(require (for-syntax racket/base "parser.rkt"))
(require parser-tools/lex
(prefix-in : parser-tools/lex-sre)
(require br-parser-tools/lex
(prefix-in : br-parser-tools/lex-sre)
"parser.rkt"
"rule-structs.rkt"
racket/string)
@ -115,7 +115,7 @@
;; 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)
(pos (position-offset a-pos)
(position-line a-pos)

@ -1,6 +1,6 @@
#lang racket/base
(require parser-tools/yacc
parser-tools/lex
(require br-parser-tools/yacc
br-parser-tools/lex
racket/list
racket/match
"rule-structs.rkt")
@ -240,7 +240,7 @@
;; 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)
(pos (position-offset a-pos)
(position-line a-pos)

@ -2,7 +2,7 @@
(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.
(struct pos (offset line col)
#:transparent)

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

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

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

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

@ -5,8 +5,8 @@
(require brag/examples/simple-line-drawing
brag/support
racket/list
parser-tools/lex
(prefix-in : parser-tools/lex-sre)
br-parser-tools/lex
(prefix-in : br-parser-tools/lex-sre)
rackunit)
(define-tokens tokens (INTEGER STRING |;| EOF))
@ -72,5 +72,5 @@ EOF
;; FIXME: add tests to make sure location is as we expect.
;;
;; 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.

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

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

@ -3,8 +3,8 @@
(require brag/examples/simple-line-drawing
brag/support
racket/list
parser-tools/lex
(prefix-in : parser-tools/lex-sre)
br-parser-tools/lex
(prefix-in : br-parser-tools/lex-sre)
rackunit)
(define (make-tokenizer ip)
@ -68,5 +68,5 @@ EOF
;; FIXME: add tests to make sure location is as we expect.
;;
;; 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.

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

Loading…
Cancel
Save