Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dobule pipes in language not rendered #73

Closed
leafac opened this issue Jul 19, 2016 · 4 comments
Closed

Dobule pipes in language not rendered #73

leafac opened this issue Jul 19, 2016 · 4 comments

Comments

@leafac
Copy link
Contributor

leafac commented Jul 19, 2016

EDIT: I figured my mistake. See post below.

Minimal working example

#lang racket
(require redex)

(define-language pipe
  [operator ::= \| || \|||])

(module+ test
  (test-equal (redex-match? pipe operator (term \|)) #t)
  (test-equal (redex-match? pipe operator (term ||)) #t)
  (test-equal (redex-match? pipe operator (term \|||)) #t))

(render-language pipe)

Expected behavior

The typeset version of the grammar should include the double pipes in || and |||.

Current behavior

untitled_2_-_drracket

The typeset version of the grammar omits double pipes.

Caveat

Granted, having pipes on the grammar confuses things, since pipes are already used as or in BNF notation. But I'm fine with the font alone distinguishing between BNF operator and language terminal—this lets me stay closer to the language I'm modeling, in which || is an operator.


Can you please confirm that my proposal is indeed expected behavior? If so, can you please help me fix it?

Thanks a lot!

@leafac
Copy link
Contributor Author

leafac commented Jul 19, 2016

Opening this Issue revealed a fundamental misunderstanding of Racket's syntax when it comes to pipes (|). It turns out that my expectations were wrong—Redex's typesetting was right.

See the corrected snippet, with escapes on every | within the identifier:

#lang racket
(require redex)

(define-language pipe
  [operator ::= \| \|\| \|\|\|])

(module+ test
  (test-equal (redex-match? pipe operator (term \|)) #t)
  (test-equal (redex-match? pipe operator (term \|\|)) #t)
  (test-equal (redex-match? pipe operator (term \|\|\|)) #t))

(render-language pipe)

Now the typeset version is what I wanted:

untitled_3_-_drracket

If someone wants to explain what || means and how typesetting worked on my wrong example, I'd be thankful.

@leafac leafac closed this as completed Jul 19, 2016
@rfindler
Copy link
Member

Glad you got this sorted out!

@bennn
Copy link
Contributor

bennn commented Jul 20, 2016

In Racket, || is the empty identifier.

Because identifiers are scoped symbols, and any string can be turned to a symbol -- even "⇒" or "λ" or "hello world" -- and we need something to delimit symbols containing whitespace. The delimiter happens to be |:

> (string->symbol "hello world")
'|hello world|

I guess | is the delimiter because it's close to the other delimiters on many keyboards and looks kind of like braces.

For the official explanation, search for "|" in the docs: link

@leafac
Copy link
Contributor Author

leafac commented Jul 20, 2016

@bennn: Thank you for the explanation. I understand what is going on, now.

I didn't know I could search for punctuation on Racket documentation. In all other search engines that I used, it doesn't work, so I just never thought of trying.

Racket keeps impressing me! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants