Changeset 38914 in project


Ignore:
Timestamp:
08/29/20 08:56:18 (4 weeks ago)
Author:
Kon Lovett
Message:

add tests, fix logic char-group, remove factorial (!)

Location:
release/5/slib-prec/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/5/slib-prec/trunk/slib-standard-grammar.scm

    r38725 r38914  
    4747(prec:define-grammar (tok:char-group 50 #\/ list2string))
    4848(prec:define-grammar (tok:char-group 51 '(#\+ #\-) list2string))
    49 (prec:define-grammar (tok:char-group 20 '(#\|) list2string))
    50 (prec:define-grammar (tok:char-group 22 #\^ list2string))
    51 (prec:define-grammar (tok:char-group 21 '(#\&) list2string))
    52 (prec:define-grammar (tok:char-group 30 '(#\< #\> #\= #\: #\~) list2string))
    53 (prec:define-grammar (tok:char-group
    54                       40
    55                       (string-append "." tok:decimal-digits)
     49
     50(prec:define-grammar (tok:char-group 30 '(#\< #\> #\= #\: #\~ #\!) list2string))
     51
     52(prec:define-grammar (tok:char-group 39 #\| list2string))
     53(prec:define-grammar (tok:char-group 40 #\& list2string))
     54(prec:define-grammar (tok:char-group 41 #\^ list2string))
     55
     56;numbers, but not 1/4
     57(define tok:number-chars (string-append "." tok:decimal-digits))
     58(prec:define-grammar (tok:char-group 40
     59                      tok:number-chars
    5660                      (lambda (dyn l)
    5761                        (if (equal? '(#\.) l)
    5862                            #\.
    5963                            (string->number (list->string l))))))
    60 (prec:define-grammar (tok:char-group
    61                       41
    62                       (string-append tok:upper-case tok:lower-case "@%?_")
    63                       list2string))
     64
     65(define tok:ident-chars (string-append tok:upper-case tok:lower-case "@%?_"))
     66(prec:define-grammar (tok:char-group 41 tok:ident-chars list2string))
     67
    6468(prec:define-grammar (tok:char-group
    6569                      (lambda (chr) (or (eqv? #\" chr) (eof-object? chr)))
     
    7377;;; Delimiters used to be defined here, but now are defined
    7478;;; dynamically by parse functions.
    75 (prec:define-grammar (prec:delim #\]))
     79(prec:define-grammar (prec:delim #;#\[ #\])) ;4 editor
    7680
    7781;;;prefix operators
     
    8185(prec:define-grammar (prec:prefix '~ 'bitwise-not 120))
    8286
    83 (prec:define-grammar (prec:prefix #\! 'not 70))
     87(prec:define-grammar (prec:prefix '! 'not 70))
    8488
    8589;(prec:define-grammar (prec:prefix ":" 'settemplate! 20))
     
    9195(prec:define-grammar (prec:nary '- '- 100))
    9296
    93 (prec:define-grammar (prec:nary "&&" 'and 60))
     97(prec:define-grammar (prec:nary '&& 'and 60))
    9498(prec:define-grammar (prec:nary "||" 'or 50))
     99;(prec:define-grammar (prec:nary "^^" 'xor 40))
    95100
    96 (prec:define-grammar (prec:nary "&" 'bitwise-and 110))
     101(prec:define-grammar (prec:nary '& 'bitwise-and 110))
    97102(prec:define-grammar (prec:nary "|" 'bitwise-ior 100))
    98 (prec:define-grammar (prec:nary "^" 'bitwise-xor 100))
     103(prec:define-grammar (prec:nary '^ 'bitwise-xor 90))
    99104
    100105;;;infix operators
     
    108113
    109114;(prec:define-grammar (prec:infix '(":=" ":") 'define 180 20))
    110 (prec:define-grammar (prec:infix ":" 'define 180 20))
     115(prec:define-grammar (prec:infix ': 'define 180 20))
    111116
    112117(prec:define-grammar (prec:infix '= '= 80 80))
     118(prec:define-grammar (prec:infix '< '< 80 80))
     119(prec:define-grammar (prec:infix '> '> 80 80))
     120(prec:define-grammar (prec:infix '<= '<= 80 80))
     121(prec:define-grammar (prec:infix '>= '>= 80 80))
     122
    113123;(prec:define-grammar (prec:infix '(~= <>) '<> 80 80))
    114124(prec:define-grammar (prec:infix '<> '<> 80 80))
     125
     126(prec:define-grammar (prec:infix '~= '~= 80 80))
    115127
    116128(prec:define-grammar (prec:infix 'mod 'mod 70 70))
     
    119131
    120132;;;postfix operators
    121 ;(prec:define-grammar (prec:postfix #\! 'factorial 160))
     133;(prec:define-grammar (prec:postfix '! 'factorial 160))
    122134;(prec:define-grammar (prec:postfix #\' 'differential 170))
    123135
  • release/5/slib-prec/trunk/tests/slib-prec-test.scm

    r38725 r38914  
    5656  (test-parse '(+ 1 2 (* abc a)) "1 + 2 + abc * a")
    5757  (test-parse '(* (+ 1 2) (f a b)) "(1 + 2) * f(a, b)")
     58  (test-parse '(expt (+ 1 2) (f a b)) "(1 + 2) ** f(a, b)")
    5859
    5960  (test-parse
     
    6364    '(and (/ (* (+ 1 2) (f a b)) 27.9) PI)
    6465    "(1 + 2) * f(a, b) / 27.9 && PI")
     66
     67  (test-parse
     68    `(or (< a b) (and (f x) (~= i j)))
     69    "a < b || f(x) && i ~= j")
     70
     71  (test-parse
     72    '(or (and BAZ PI) (and FOO BAR))
     73    "BAZ && PI || FOO && BAR")
    6574  (test-parse
    6675    '(or (and BAZ PI) (and (not FOO) BAR))
     
    6877
    6978  (test-parse
    70     '(bitwise-ior (bitwise-xor (bitwise-ior a (bitwise-and b c)) (bitwise-not b)) d)
     79    '(bitwise-ior a (bitwise-and b c) (bitwise-and (bitwise-not b) d))
     80    "a | b & c | ~b & d")
     81  (test-parse
     82    '(bitwise-xor (bitwise-ior a (bitwise-and b c)) (bitwise-ior (bitwise-not b) d))
    7183    "a | b & c ^ ~b | d")
    7284
Note: See TracChangeset for help on using the changeset viewer.