Git Product home page Git Product logo

txexpr's People

Contributors

alexknauth avatar leifandersen avatar mbutterick avatar otherjoel avatar samth avatar zyrolasting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

txexpr's Issues

bad error message in get-* functions

> (get-tag "oi")
; car: contract violation
;   expected: pair?
;   given: "oi"

from my understanding, the define+provide+safe macro should be exporting get-tag with a contract that would raise an error blaming my call to get-tag not the hidden call to car. am I doing something wrong? or is this a bug in the sugar library? if so, the only way I know of fixing this is by using regular constructs like define/contract, hence the absence of an accompanying PR!

switch to MIT license

@AlexKnauth
@zyrolasting
@samth
@LeifAndersen

Consistent with Racket’s overall relicensing from LGPL to Apache+MIT, I’d like to move txexpr from the LGPL to MIT.

Because the MIT license is more permissive, this requires the assent of you, the esteemed contributors.

If you agree, please post a message saying so, e.g. — "I hereby relicense my contributions to txexpr under the MIT license."

On January 1, if you have not agreed to the relicensing, I will remove your code. Thanks.

(Feature request) add a new match pattern to support txexpr

I am a fan of match, but I do agree with your points at https://docs.racket-lang.org/txexpr/index.html#%28part._.Why_not_just_use_match__quasiquote__and_so_on_%29. However, there's a middle ground: add a new match pattern to support txexpr.

#lang racket

(require txexpr)

(define-match-expander txexpr
  (lambda (stx)
    (syntax-case stx ()
      [(_ tag attrs elems)
       #'(? txexpr?
            (app txexpr->list (list tag attrs elems)))])))

(match '(p ([class "foo"]) "hello" "world")
  [(txexpr t a e)
   (println t)
   (println a)
   (println e)])

Would you be interested in adding this to the library?

Support for attributes with boolean values

Currently only strings are valid attribute values for a tagged x-expression. Would it make sense to support non-serialized boolean values in attributes, given that boolean attributes are a thing in XML/HTML5?

I understand how to work around it for now. But serializing #t and #f into strings on my own, and remembering to omit "false" attributes from x-expressions destined for HTML output, feels like I'm doing something that belongs in the library.

add `txexpr*`

Splices rest argument into new txexpr as list of elements.

match pattern for `txexpr*`?

Should there be a match pattern for txexpr*?

If so, should the match-expander look like this, or?

(txexpr* tag)                = (txexpr tag _ '())
(txexpr* tag attrs)          = (txexpr tag attrs '())
(txexpr* tag attrs elem ...) = (txexpr tag attrs (list elem ...))

The weird things are:

  1. How should it deal with "optional pattern" arguments?
  2. How should it deal with "sequence of pattern" arguments?

If an optional-pattern isn't supplied, should it be filled in with _, or the pattern for the default argument? Concretely, if attrs isn't supplied should it be _ or '()? For now I'm leaning towards _, because that's common for match-pattern forms like ?, regexp, and struct*.

If a sequence-pattern is empty (which looks the same as not being supplied), should it be filled in with _, or with the empty sequence? I think it should be the empty sequence, because otherwise it would be hard or unintuitive to express that it must be empty.

However, if someone thinks about optional and sequence arguments as similar, this might seem inconsistent. An unsupplied optional argument looks the same as an empty sequence argument. So, they might think it's weird that if they don't supply any attributes pattern anything goes, but if they don't supply any elements patterns it must be empty.

I'm also unsure with the optional-ness of the attributes pattern because I'm somewhat afraid that someone might try to match with (txexpr* tag elem ...) when they should use (txexpr* tag _ elem ...).

Merge successive strings

Would this function be an appropriate addition to this package?

https://github.com/sanchom/sanchom.github.io/blob/master-source/util.rkt

(define/contract (merge-successive-strings elements)
  (txexpr-elements? . -> . txexpr-elements?)
  (define (conditional-merge element current-list)
    (if (and (not (empty? current-list))
             (string? (first current-list))
             (string? element))
        (cons (string-append (first current-list) element) (drop current-list 1))
        (cons element current-list)))
  (reverse (foldl conditional-merge '() elements)))

(module+ test
  (check-equal? (merge-successive-strings '()) '())
  (check-equal? (merge-successive-strings '("a")) '("a"))
  (check-equal? (merge-successive-strings '(a)) '(a))
  (check-equal? (merge-successive-strings '(a "b")) '(a "b"))
  (check-equal? (merge-successive-strings '("a" "b")) '("ab"))
  (check-equal? (merge-successive-strings '("a" a "b")) '("a" a "b"))
  (check-equal? (merge-successive-strings '("a" "b" " " "c")) '("ab c"))
  (check-equal? (merge-successive-strings '("a" "b" a " " b "c" c d "e" " f" g)) '("ab" a " " b "c" c d "e f" g))
)

xexpr/c-like variants of txexpr-*?

The xml library provides a contract called xexpr/c, which gives a better error message than xexpr? when passed in a non-X-expression:

> (define/contract not-an-xexpr xexpr/c '(b "hello " ("world") 42))
; not-an-xexpr: broke its own contract;
;  Not an Xexpr. Expected a symbol as the element name, given "world"
; Context:
; '(b "hello " ("world") 42)
;   in: xexpr/c
;   contract from: (definition not-an-xexpr)
;   blaming: (definition not-an-xexpr)
;    (assuming the contract is correct)
;   at: readline-input:14:17
; [,bt for context]

I'd like to see such contracts for the txexpr-*? predicates. If making one for all of them is too hard, then I'd be satisfied with just seeing txexpr/c.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.