More renaming

remotes/jackfirth/master
Jack Firth 3 years ago
parent 386052ac68
commit 6c73ec6f13

@ -48,7 +48,7 @@
[TOKEN (datum->syntax rules-stx 'token)] ; for repl [TOKEN (datum->syntax rules-stx 'token)] ; for repl
[RULE-IDS (map syntax-e rule-ids)] [RULE-IDS (map syntax-e rule-ids)]
[RULES-STX rules-stx]) [RULES-STX rules-stx])
;; this stx object represents the top level of a #lang brag module. ;; this stx object represents the top level of a #lang yaragg module.
;; so any `define`s are automatically available at the repl. ;; so any `define`s are automatically available at the repl.
;; and only identifiers explicitly `provide`d are visible on import. ;; and only identifiers explicitly `provide`d are visible on import.
#'(#%module-begin #'(#%module-begin

@ -1,4 +1,4 @@
#lang brag #lang yaragg
## Equal numbers of 0 and 1s in a string. ## Equal numbers of 0 and 1s in a string.
## ##

@ -1,3 +1,3 @@
#lang brag #lang yaragg
rule: "0"* "1" rule: "0"* "1"

@ -1,3 +1,3 @@
#lang brag #lang yaragg
rule-0n1n: ["0" rule-0n1n "1"] rule-0n1n: ["0" rule-0n1n "1"]

@ -1,4 +1,4 @@
#lang brag #lang yaragg
expr : term (/'+' term)* expr : term (/'+' term)*
@term : factor (/'*' @factor)* @term : factor (/'*' @factor)*

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; Simple baby example of JSON structure ;; Simple baby example of JSON structure
json ::= number | string json ::= number | string

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; Simple baby example of JSON structure ;; Simple baby example of JSON structure
json: number json: number

@ -1,4 +1,4 @@
#lang brag #lang yaragg
#:prefix-out my: #:prefix-out my:
;; Simple baby example of JSON structure ;; Simple baby example of JSON structure

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; Simple baby example of JSON structure ;; Simple baby example of JSON structure
json: number | string json: number | string

@ -1,4 +1,4 @@
#lang brag #lang yaragg
## The following comes from: http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form ## The following comes from: http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form

@ -1,4 +1,4 @@
#lang brag #lang yaragg
start: A c def hello-world start: A c def hello-world
A : "\"\101\\" ; A A : "\"\101\\" ; A
c : '\'\U0063\\' ; c c : '\'\U0063\\' ; c

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; test the curly quantifier ;; test the curly quantifier
start : a-rule | b-rule | c-rule | d-rule | e-rule start : a-rule | b-rule | c-rule | d-rule | e-rule
a-rule : "a"{2} ; exactly 2 a-rule : "a"{2} ; exactly 2

@ -1,4 +1,4 @@
#lang brag #lang yaragg
top : w | x | y | z | a | b | c top : w | x | y | z | a | b | c
w : /"w" ; atom w : /"w" ; atom
x : /("x") ; seq x : /("x") ; seq

@ -1,4 +1,4 @@
#lang brag #lang yaragg
top : expr (/"," expr)* top : expr (/"," expr)*
expr : "x" | list expr : "x" | list
list : "(" expr ("," expr)* ")" list : "(" expr ("," expr)* ")"

@ -1,4 +1,4 @@
#lang brag #lang yaragg
top : xs | ys | zs top : xs | ys | zs
xs : () | "x" xs xs : () | "x" xs

@ -1,4 +1,4 @@
#lang brag #lang yaragg
top : x | y top : x | y
/x : Ø | "x" @x /x : Ø | "x" @x
@y : Ø | "y" y @y : Ø | "y" y

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; Lua parser, adapted from: ;; Lua parser, adapted from:
;; http://www.lua.org/manual/5.1/manual.html#8 ;; http://www.lua.org/manual/5.1/manual.html#8

@ -1,3 +1,3 @@
#lang brag #lang yaragg
start : ( (X | X Y) A* )* start : ( (X | X Y) A* )*

@ -1,3 +1,3 @@
#lang brag #lang yaragg
nested-word-list: WORD nested-word-list: WORD
| LEFT-PAREN nested-word-list* RIGHT-PAREN | LEFT-PAREN nested-word-list* RIGHT-PAREN

@ -1,2 +1,2 @@
#lang brag #lang yaragg
start: "a" "\"" "'" "\\" 'a' '"' '\'' '\\' start: "a" "\"" "'" "\\" 'a' '"' '\'' '\\'

@ -1,4 +1,4 @@
#lang brag #lang yaragg
expr : term ('+' term)* expr : term ('+' term)*
term : factor ('*' factor)* term : factor ('*' factor)*

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; ;;
;; See: http://stackoverflow.com/questions/12345647/rewrite-this-script-by-designing-an-interpreter-in-racket ;; See: http://stackoverflow.com/questions/12345647/rewrite-this-script-by-designing-an-interpreter-in-racket

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; ;;
;; See: http://stackoverflow.com/questions/12345647/rewrite-this-script-by-designing-an-interpreter-in-racket ;; See: http://stackoverflow.com/questions/12345647/rewrite-this-script-by-designing-an-interpreter-in-racket

@ -1,3 +1,3 @@
#lang brag #lang yaragg
top : ("start" | "atok")+ top : ("start" | "atok")+

@ -1,4 +1,4 @@
#lang brag #lang yaragg
## Statlist grammar ## Statlist grammar

@ -1,4 +1,4 @@
#lang brag #lang yaragg
start: next start: next
next: "0" next: "0"

@ -1,3 +1,3 @@
#lang brag #lang yaragg
/top : sub /top : sub
sub : "x" sub : "x"

@ -1,3 +1,3 @@
#lang brag #lang yaragg
/top : sub /top : sub
/sub : "x" /sub : "x"

@ -1,3 +1,3 @@
#lang brag #lang yaragg
/top : sub /top : sub
@sub : "x" @sub : "x"

@ -1,4 +1,4 @@
#lang brag #lang yaragg
start: (tab | space | newline | letter | return | all)* start: (tab | space | newline | letter | return | all)*
tab: '\t' tab: '\t'
space: " " space: " "

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; A parser for a silly language ;; A parser for a silly language
sentence: verb optional-adjective object sentence: verb optional-adjective object
verb: greeting verb: greeting

@ -36,7 +36,7 @@
;; errors with position are sensitive to length of lang line ;; errors with position are sensitive to length of lang line
(define lang-line "#lang brag") (define lang-line "#lang yaragg")
(check-compile-error (format "~a" lang-line) (check-compile-error (format "~a" lang-line)
"The grammar does not appear to have any rules") "The grammar does not appear to have any rules")
@ -52,34 +52,34 @@
(check-compile-error "#lang brag\n x: NUMBER\nx:STRING" (check-compile-error "#lang yaragg\n x: NUMBER\nx:STRING"
"Rule x has a duplicate definition") "Rule x has a duplicate definition")
;; Check to see that missing definitions for rules also raise good syntax ;; Check to see that missing definitions for rules also raise good syntax
;; errors: ;; errors:
(check-compile-error "#lang brag\nx:y" (check-compile-error "#lang yaragg\nx:y"
"Rule y has no definition") "Rule y has no definition")
(check-compile-error "#lang brag\nnumber : 1flarbl" (check-compile-error "#lang yaragg\nnumber : 1flarbl"
"Rule 1flarbl has no definition") "Rule 1flarbl has no definition")
(check-compile-error "#lang brag\nprogram: EOF" (check-compile-error "#lang yaragg\nprogram: EOF"
"Token EOF is reserved and can not be used in a grammar") "Token EOF is reserved and can not be used in a grammar")
;; Nontermination checks: ;; Nontermination checks:
(check-compile-error "#lang brag\nx : x" (check-compile-error "#lang yaragg\nx : x"
"Rule x has no finite derivation") "Rule x has no finite derivation")
(check-compile-error #<<EOF (check-compile-error #<<EOF
#lang brag #lang yaragg
x : x y x : x y
y : "y" y : "y"
EOF EOF
@ -90,7 +90,7 @@ EOF
; This should be illegal too: ; This should be illegal too:
(check-compile-error #<<EOF (check-compile-error #<<EOF
#lang brag #lang yaragg
a : "a" b a : "a" b
b : a | b b : a | b
EOF EOF
@ -100,7 +100,7 @@ EOF
(check-compile-error #<<EOF (check-compile-error #<<EOF
#lang brag #lang yaragg
a : [b] a : [b]
b : [c] b : [c]
c : c c : c
@ -109,7 +109,7 @@ EOF
(check-compile-error #<<EOF (check-compile-error #<<EOF
#lang brag #lang yaragg
a : [b] a : [b]
b : c b : c
c : c c : c
@ -118,7 +118,7 @@ EOF
(check-compile-error #<<EOF (check-compile-error #<<EOF
#lang brag #lang yaragg
a : [a] a : [a]
b : [b] b : [b]
c : c c : c

@ -1,4 +1,4 @@
#lang brag #lang yaragg
;; This used to fail when we had the yacc-based backend, but ;; This used to fail when we had the yacc-based backend, but
;; cfg-parser seems to be ok with it. ;; cfg-parser seems to be ok with it.

@ -3,7 +3,7 @@
racket/date racket/date
file/md5 file/md5
(for-label racket (for-label racket
brag yaragg
yaragg/support yaragg/support
(only-in yaragg-parser-tools/lex lexer-src-pos) (only-in yaragg-parser-tools/lex lexer-src-pos)
(only-in syntax/parse syntax-parse ~literal))) (only-in syntax/parse syntax-parse ~literal)))
@ -26,12 +26,12 @@
@title{brag: a better Racket AST generator} @title{Yaragg: Yet Another Racket AST-Generator Generator}
@author["Danny Yoo (95%)" "Matthew Butterick (5%)"] @author["Danny Yoo (95%)" "Matthew Butterick (5%)"]
@defmodulelang[brag] @defmodulelang[yaragg]
@margin-note{This is a fork of the @link["https://docs.racket-lang.org/ragg"]{@racket[ragg]} package. It has a variety of bugfixes and new features. Some of these features have required new notation that's not necessarily compatible with all existing @racket[ragg] files. @margin-note{This is a fork of the @link["https://docs.racket-lang.org/ragg"]{@racket[ragg]} package. It has a variety of bugfixes and new features. Some of these features have required new notation that's not necessarily compatible with all existing @racket[ragg] files.
@ -77,11 +77,11 @@ This BNF description is also known as a @deftech{grammar}. Just as it does in a
Have we made progress? We have a valid grammar. But we're still missing a @emph{parser}: a function that can use that description to make structures out of a sequence of tokens. Have we made progress? We have a valid grammar. But we're still missing a @emph{parser}: a function that can use that description to make structures out of a sequence of tokens.
Meanwhile, it's clear that we don't yet have a valid program because there's no @litchar{#lang} line. Let's add one: put @litchar{#lang brag} at the top of the grammar, and save it as a file called @filepath{nested-word-list.rkt}. Meanwhile, it's clear that we don't yet have a valid program because there's no @litchar{#lang} line. Let's add one: put @litchar{#lang yaragg} at the top of the grammar, and save it as a file called @filepath{nested-word-list.rkt}.
@filebox["nested-word-list.rkt"]{ @filebox["nested-word-list.rkt"]{
@verbatim{ @verbatim{
#lang brag #lang yaragg
nested-word-list: WORD nested-word-list: WORD
| LEFT-PAREN nested-word-list* RIGHT-PAREN | LEFT-PAREN nested-word-list* RIGHT-PAREN
}} }}
@ -151,7 +151,7 @@ to use:
@itemize[ @itemize[
@item{It provides a @litchar{#lang} for writing BNF grammars. @item{It provides a @litchar{#lang} for writing BNF grammars.
A module written in @litchar{#lang brag} automatically generates a A module written in @litchar{#lang yaragg} automatically generates a
parser. The grammar controls the structure of the syntax objects it generates.} parser. The grammar controls the structure of the syntax objects it generates.}
@item{The language uses a few conventions to simplify the expression of @item{The language uses a few conventions to simplify the expression of
@ -226,7 +226,7 @@ Here's a first pass at expressing the structure of these line-drawing programs.
@filebox["simple-line-drawing.rkt"]{ @filebox["simple-line-drawing.rkt"]{
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
drawing: rows* drawing: rows*
rows: repeat chunk+ ";" rows: repeat chunk+ ";"
repeat: INTEGER repeat: INTEGER
@ -674,7 +674,7 @@ generates.
@subsection[#:tag "brag-syntax"]{Syntax and terminology} @subsection[#:tag "brag-syntax"]{Syntax and terminology}
A program in the @tt{brag} language consists of the language line A program in the @tt{brag} language consists of the language line
@litchar{#lang brag}, followed by a collection of @tech{rule}s and @litchar{#lang yaragg}, followed by a collection of @tech{rule}s and
possibly @tech{line comment}s or @tech{multiline comment}s. possibly @tech{line comment}s or @tech{multiline comment}s.
A @deftech{rule} is a sequence consisting of: a @tech{rule identifier}, a separator (either @litchar{":"} or @litchar{"::="}), and a @tech{pattern}. A @deftech{rule} is a sequence consisting of: a @tech{rule identifier}, a separator (either @litchar{":"} or @litchar{"::="}), and a @tech{pattern}.
@ -726,7 +726,7 @@ A @deftech{pattern} is one of the following:
For example, in the following program: For example, in the following program:
@nested[#:style 'inset @nested[#:style 'inset
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
;; A parser for a silly language ;; A parser for a silly language
sentence: verb optional-adjective object sentence: verb optional-adjective object
verb: greeting verb: greeting
@ -749,7 +749,7 @@ More examples:
BNF for binary BNF for binary
strings that contain an equal number of zeros and ones. strings that contain an equal number of zeros and ones.
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
equal: [zero one | one zero] ;; equal number of "0"s and "1"s. equal: [zero one | one zero] ;; equal number of "0"s and "1"s.
zero: "0" equal | equal "0" ;; has an extra "0" in it. zero: "0" equal | equal "0" ;; has an extra "0" in it.
one: "1" equal | equal "1" ;; has an extra "1" in it. one: "1" equal | equal "1" ;; has an extra "1" in it.
@ -759,7 +759,7 @@ More examples:
@item{A BNF for @item{A BNF for
@link["http://www.json.org/"]{JSON}-like structures. @link["http://www.json.org/"]{JSON}-like structures.
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
json: number | string json: number | string
| array | object | array | object
number: NUMBER number: NUMBER
@ -784,7 +784,7 @@ If the cut is applied to a right-hand pattern element, then that element is omit
For instance, consider this simple grammar for arithmetic expressions: For instance, consider this simple grammar for arithmetic expressions:
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
expr : term ('+' term)* expr : term ('+' term)*
term : factor ('*' factor)* term : factor ('*' factor)*
factor : ("0" | "1" | "2" | "3" factor : ("0" | "1" | "2" | "3"
@ -803,7 +803,7 @@ We get this parse tree:
Suppose we felt the @litchar{+} and @litchar{*} characters were superfluous. We can add cuts to the grammar by prefixing these pattern elements with @litchar{/}: Suppose we felt the @litchar{+} and @litchar{*} characters were superfluous. We can add cuts to the grammar by prefixing these pattern elements with @litchar{/}:
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
expr : term (/'+' term)* expr : term (/'+' term)*
term : factor (/'*' factor)* term : factor (/'*' factor)*
factor : ("0" | "1" | "2" | "3" factor : ("0" | "1" | "2" | "3"
@ -818,7 +818,7 @@ Our parse tree changes accordingly:
Now suppose we apply a cut on the rule name, @racket[factor]: Now suppose we apply a cut on the rule name, @racket[factor]:
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
expr : term (/'+' term)* expr : term (/'+' term)*
term : factor (/'*' factor)* term : factor (/'*' factor)*
/factor : ("0" | "1" | "2" | "3" /factor : ("0" | "1" | "2" | "3"
@ -839,7 +839,7 @@ If the splice is applied to a right-hand pattern element, that element is splice
Suppose we remove the cut from the @racket[factor] rule name and instead splice the second appearance of @racket[factor] in the pattern for the @racket[term] rule: Suppose we remove the cut from the @racket[factor] rule name and instead splice the second appearance of @racket[factor] in the pattern for the @racket[term] rule:
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
expr : term (/'+' term)* expr : term (/'+' term)*
term : factor (/'*' @factor)* term : factor (/'*' @factor)*
factor : ("0" | "1" | "2" | "3" factor : ("0" | "1" | "2" | "3"
@ -854,7 +854,7 @@ The @racket[factor] elements matching the first position of the @racket[term] pa
Finally, suppose we add a splice to the @racket[term] rule name: Finally, suppose we add a splice to the @racket[term] rule name:
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
expr : term (/'+' term)* expr : term (/'+' term)*
@term : factor (/'*' @factor)* @term : factor (/'*' @factor)*
factor : ("0" | "1" | "2" | "3" factor : ("0" | "1" | "2" | "3"
@ -875,7 +875,7 @@ Caveat for the top-level rule: though the rule name can have a cut, it cannot ha
@subsection{Syntax errors} @subsection{Syntax errors}
Besides the basic syntax errors that can occur with a malformed grammar, there Besides the basic syntax errors that can occur with a malformed grammar, there
are a few other classes of situations that @litchar{#lang brag} will consider are a few other classes of situations that @litchar{#lang yaragg} will consider
as syntax errors. as syntax errors.
@tt{brag} will raise a syntax error if the grammar: @tt{brag} will raise a syntax error if the grammar:
@ -888,7 +888,7 @@ as syntax errors.
following program: following program:
@nested[#:style 'code-inset @nested[#:style 'code-inset
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
foo: [bar] foo: [bar]
}| }|
] ]
@ -904,7 +904,7 @@ as syntax errors.
program: program:
@nested[#:style 'code-inset @nested[#:style 'code-inset
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
infinite-a: "a" infinite-a infinite-a: "a" infinite-a
}| }|
] ]
@ -918,7 +918,7 @@ grammars.
@subsection{Semantics} @subsection{Semantics}
A program written in @litchar{#lang brag} produces a module that provides a few A program written in @litchar{#lang yaragg} produces a module that provides a few
bindings. The most important of these is @racket[parse]: bindings. The most important of these is @racket[parse]:
@defproc[(parse [source-path any/c #f] @defproc[(parse [source-path any/c #f]
@ -994,7 +994,7 @@ Thus, it's only the presence of @tech{rule identifier}s in a rule's
@filepath{simple-arithmetic-grammar.rkt}: @filepath{simple-arithmetic-grammar.rkt}:
@filebox["simple-arithmetic-grammar.rkt"]{ @filebox["simple-arithmetic-grammar.rkt"]{
@verbatim|{ @verbatim|{
#lang brag #lang yaragg
expr : term ('+' term)* expr : term ('+' term)*
term : factor ('*' factor)* term : factor ('*' factor)*
factor : INT factor : INT

Loading…
Cancel
Save