Merge branch 'master' of git://factorcode.org/git/factor
commit
708051b89d
|
@ -0,0 +1,12 @@
|
|||
IN: compiler.tests
|
||||
USING: io.streams.string kernel tools.test eval ;
|
||||
|
||||
: declaration-test-1 ( -- a ) 3 ; flushable
|
||||
|
||||
: declaration-test ( -- ) declaration-test-1 drop ;
|
||||
|
||||
[ "" ] [ [ declaration-test ] with-string-writer ] unit-test
|
||||
|
||||
[ ] [ "IN: compiler.tests USE: io : declaration-test-1 ( -- a ) \"X\" print f ;" eval ] unit-test
|
||||
|
||||
[ "X" ] [ [ declaration-test ] with-string-writer ] unit-test
|
|
@ -565,6 +565,12 @@ M: integer infinite-loop infinite-loop ;
|
|||
|
||||
[ ] [ [ too-deep ] final-info drop ] unit-test
|
||||
|
||||
[ ] [ [ reversed boa slice boa nth-unsafe * ] final-info drop ] unit-test
|
||||
|
||||
MIXIN: empty-mixin
|
||||
|
||||
[ ] [ [ { empty-mixin } declare empty-mixin? ] final-info drop ] unit-test
|
||||
|
||||
! [ V{ string } ] [
|
||||
! [ dup string? t xor [ "A" throw ] [ ] if ] final-classes
|
||||
! ] unit-test
|
||||
|
|
|
@ -68,9 +68,10 @@ M: float-array >pprint-sequence ;
|
|||
USING: hints math.vectors arrays ;
|
||||
|
||||
HINTS: vneg { float-array } { array } ;
|
||||
HINTS: v*n { float-array object } { array object } ;
|
||||
HINTS: v/n { float-array object } { array object } ;
|
||||
HINTS: n/v { object float-array } { object array } ;
|
||||
HINTS: v*n { float-array float } { array object } ;
|
||||
HINTS: n*v { float float-array } { array object } ;
|
||||
HINTS: v/n { float-array float } { array object } ;
|
||||
HINTS: n/v { float float-array } { object array } ;
|
||||
HINTS: v+ { float-array float-array } { array array } ;
|
||||
HINTS: v- { float-array float-array } { array array } ;
|
||||
HINTS: v* { float-array float-array } { array array } ;
|
||||
|
|
|
@ -123,7 +123,7 @@ SYMBOLS: +read-only+ +hidden+ +system+
|
|||
+not-content-indexed+ +encrypted+ ;
|
||||
|
||||
: win32-file-attribute ( n attr symbol -- n )
|
||||
>r dupd mask? [ r> , ] [ r> drop ] if ;
|
||||
>r dupd mask? r> swap [ , ] [ drop ] if ;
|
||||
|
||||
: win32-file-attributes ( n -- seq )
|
||||
[
|
||||
|
|
|
@ -33,11 +33,9 @@ TUPLE: CreateProcess-args
|
|||
CreateProcess-args >tuple< CreateProcess win32-error=0/f ;
|
||||
|
||||
: count-trailing-backslashes ( str n -- str n )
|
||||
>r "\\" ?tail [
|
||||
r> 1+ count-trailing-backslashes
|
||||
] [
|
||||
r>
|
||||
] if ;
|
||||
>r "\\" ?tail r> swap [
|
||||
1+ count-trailing-backslashes
|
||||
] when ;
|
||||
|
||||
: fix-trailing-backslashes ( str -- str' )
|
||||
0 count-trailing-backslashes
|
||||
|
|
|
@ -7,9 +7,8 @@ IN: ui.gadgets.canvas
|
|||
|
||||
TUPLE: canvas < gadget dlist ;
|
||||
|
||||
: <canvas> ( -- canvas )
|
||||
canvas new-gadget
|
||||
black solid-interior ;
|
||||
: new-canvas ( class -- canvas )
|
||||
new-gadget black solid-interior ; inline
|
||||
|
||||
: delete-canvas-dlist ( canvas -- )
|
||||
dup find-gl-context
|
||||
|
|
|
@ -7,5 +7,5 @@ TUPLE: handler < wrapper table ;
|
|||
|
||||
: <handler> ( child -- handler ) handler new-wrapper ;
|
||||
|
||||
M: handler handle-gesture* ( gadget gesture delegate -- ? )
|
||||
table>> at dup [ call f ] [ 2drop t ] if ;
|
||||
M: handler handle-gesture ( gesture gadget -- ? )
|
||||
over table>> at dup [ call f ] [ 2drop t ] if ;
|
|
@ -33,7 +33,7 @@ M: dimensions-not-equal summary drop "Dimensions do not match" ;
|
|||
\ <dimensioned> [ >dimensioned< ] define-inverse
|
||||
|
||||
: dimensions ( dimensioned -- top bot )
|
||||
{ dimensioned-top dimensioned-bot } get-slots ;
|
||||
[ top>> ] [ bot>> ] bi ;
|
||||
|
||||
: check-dimensions ( d d -- )
|
||||
[ dimensions 2array ] bi@ =
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
! Factor port of the raytracer benchmark from
|
||||
! http://www.ffconsultancy.com/free/ray_tracer/languages.html
|
||||
|
||||
USING: float-arrays compiler generic io io.files kernel math
|
||||
math.functions math.vectors math.parser namespaces sequences
|
||||
sequences.private words io.encodings.binary ;
|
||||
USING: arrays accessors float-arrays io io.files
|
||||
io.encodings.binary kernel math math.functions math.vectors
|
||||
math.parser namespaces sequences sequences.private words ;
|
||||
IN: benchmark.raytracer
|
||||
|
||||
! parameters
|
||||
|
@ -23,32 +23,33 @@ IN: benchmark.raytracer
|
|||
|
||||
: delta 1.4901161193847656E-8 ; inline
|
||||
|
||||
TUPLE: ray orig dir ;
|
||||
TUPLE: ray { orig float-array read-only } { dir float-array read-only } ;
|
||||
|
||||
C: <ray> ray
|
||||
|
||||
TUPLE: hit normal lambda ;
|
||||
TUPLE: hit { normal float-array read-only } { lambda float read-only } ;
|
||||
|
||||
C: <hit> hit
|
||||
|
||||
GENERIC: intersect-scene ( hit ray scene -- hit )
|
||||
|
||||
TUPLE: sphere center radius ;
|
||||
TUPLE: sphere { center float-array read-only } { radius float read-only } ;
|
||||
|
||||
C: <sphere> sphere
|
||||
|
||||
: sphere-v ( sphere ray -- v )
|
||||
swap sphere-center swap ray-orig v- ; inline
|
||||
swap center>> swap orig>> v- ; inline
|
||||
|
||||
: sphere-b ( ray v -- b ) swap ray-dir v. ; inline
|
||||
: sphere-b ( ray v -- b ) swap dir>> v. ; inline
|
||||
|
||||
: sphere-disc ( sphere v b -- d )
|
||||
sq swap norm-sq - swap sphere-radius sq + ; inline
|
||||
sq swap norm-sq - swap radius>> sq + ; inline
|
||||
|
||||
: -+ ( x y -- x-y x+y ) [ - ] 2keep + ; inline
|
||||
|
||||
: sphere-b/d ( b d -- t )
|
||||
-+ dup 0.0 < [ 2drop 1.0/0.0 ] [ >r [ 0.0 > ] keep r> ? ] if ; inline
|
||||
-+ dup 0.0 <
|
||||
[ 2drop 1.0/0.0 ] [ [ [ 0.0 > ] keep ] dip ? ] if ; inline
|
||||
|
||||
: ray-sphere ( sphere ray -- t )
|
||||
2dup sphere-v tuck sphere-b [ sphere-disc ] keep
|
||||
|
@ -56,29 +57,31 @@ C: <sphere> sphere
|
|||
inline
|
||||
|
||||
: sphere-n ( ray sphere l -- n )
|
||||
pick ray-dir n*v swap sphere-center v- swap ray-orig v+ ;
|
||||
pick dir>> n*v swap center>> v- swap orig>> v+ ;
|
||||
inline
|
||||
|
||||
: if-ray-sphere ( hit ray sphere quot -- hit )
|
||||
#! quot: hit ray sphere l -- hit
|
||||
>r pick hit-lambda >r 2dup swap ray-sphere dup r> >=
|
||||
[ 3drop ] r> if ; inline
|
||||
[
|
||||
pick lambda>> [ 2dup swap ray-sphere dup ] dip >=
|
||||
[ 3drop ]
|
||||
] dip if ; inline
|
||||
|
||||
M: sphere intersect-scene ( hit ray sphere -- hit )
|
||||
[ [ sphere-n normalize ] keep <hit> nip ] if-ray-sphere ;
|
||||
|
||||
TUPLE: group objs ;
|
||||
TUPLE: group < sphere { objs array read-only } ;
|
||||
|
||||
: <group> ( objs bound -- group )
|
||||
{ set-group-objs set-delegate } group construct ;
|
||||
[ center>> ] [ radius>> ] bi rot group boa ; inline
|
||||
|
||||
: make-group ( bound quot -- )
|
||||
swap >r { } make r> <group> ; inline
|
||||
swap [ { } make ] dip <group> ; inline
|
||||
|
||||
M: group intersect-scene ( hit ray group -- hit )
|
||||
[
|
||||
drop
|
||||
group-objs [ >r tuck r> intersect-scene swap ] each
|
||||
objs>> [ [ tuck ] dip intersect-scene swap ] each
|
||||
drop
|
||||
] if-ray-sphere ;
|
||||
|
||||
|
@ -88,30 +91,30 @@ M: group intersect-scene ( hit ray group -- hit )
|
|||
initial-hit -rot intersect-scene ; inline
|
||||
|
||||
: ray-o ( ray hit -- o )
|
||||
over ray-dir over hit-lambda v*n
|
||||
swap hit-normal delta v*n v+
|
||||
swap ray-orig v+ ; inline
|
||||
over dir>> over lambda>> v*n
|
||||
swap normal>> delta v*n v+
|
||||
swap orig>> v+ ; inline
|
||||
|
||||
: sray-intersect ( ray scene hit -- ray )
|
||||
swap >r ray-o light vneg <ray> r> initial-intersect ; inline
|
||||
swap [ ray-o light vneg <ray> ] dip initial-intersect ; inline
|
||||
|
||||
: ray-g ( hit -- g ) hit-normal light v. ; inline
|
||||
: ray-g ( hit -- g ) normal>> light v. ; inline
|
||||
|
||||
: cast-ray ( ray scene -- g )
|
||||
2dup initial-intersect dup hit-lambda 1.0/0.0 = [
|
||||
2dup initial-intersect dup lambda>> 1.0/0.0 = [
|
||||
3drop 0.0
|
||||
] [
|
||||
dup ray-g >r sray-intersect hit-lambda 1.0/0.0 =
|
||||
[ r> neg ] [ r> drop 0.0 ] if
|
||||
[ sray-intersect lambda>> 1.0/0.0 = ] keep swap
|
||||
[ ray-g neg ] [ drop 0.0 ] if
|
||||
] if ; inline
|
||||
|
||||
: create-center ( c r d -- c2 )
|
||||
>r 3.0 12.0 sqrt / * r> n*v v+ ; inline
|
||||
[ 3.0 12.0 sqrt / * ] dip n*v v+ ; inline
|
||||
|
||||
DEFER: create ( level c r -- scene )
|
||||
|
||||
: create-step ( level c r d -- scene )
|
||||
over >r create-center r> 2.0 / >r >r 1 - r> r> create ;
|
||||
over [ create-center ] dip 2.0 / [ 1 - ] 2dip create ;
|
||||
|
||||
: create-offsets ( quot -- )
|
||||
{
|
||||
|
@ -126,7 +129,7 @@ DEFER: create ( level c r -- scene )
|
|||
: create-group ( level c r -- scene )
|
||||
2dup create-bound [
|
||||
2dup <sphere> ,
|
||||
[ >r 3dup r> create-step , ] create-offsets 3drop
|
||||
[ [ 3dup ] dip create-step , ] create-offsets 3drop
|
||||
] make-group ;
|
||||
|
||||
: create ( level c r -- scene )
|
||||
|
@ -140,7 +143,7 @@ DEFER: create ( level c r -- scene )
|
|||
|
||||
: ray-grid ( point ss-grid -- ray-grid )
|
||||
[
|
||||
[ v+ normalize { 0.0 0.0 -4.0 } swap <ray> ] with map
|
||||
[ v+ normalize F{ 0.0 0.0 -4.0 } swap <ray> ] with map
|
||||
] with map ;
|
||||
|
||||
: ray-pixel ( scene point -- n )
|
||||
|
@ -164,7 +167,7 @@ DEFER: create ( level c r -- scene )
|
|||
pixel-grid [ [ ray-pixel ] with map ] with map ;
|
||||
|
||||
: run ( -- string )
|
||||
levels { 0.0 -1.0 0.0 } 1.0 create ray-trace [
|
||||
levels F{ 0.0 -1.0 0.0 } 1.0 create ray-trace [
|
||||
size size pgm-header
|
||||
[ [ oversampling sq / pgm-pixel ] each ] each
|
||||
] B{ } make ;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
! Copyright (C) 2007 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel macros sequences slots words classes.tuple ;
|
||||
USING: kernel macros sequences slots words classes.tuple
|
||||
quotations combinators ;
|
||||
IN: classes.tuple.lib
|
||||
|
||||
: reader-slots ( seq -- quot )
|
||||
[ slot-spec-reader ] map [ get-slots ] curry ;
|
||||
[ slot-spec-reader 1quotation ] map [ cleave ] curry ;
|
||||
|
||||
MACRO: >tuple< ( class -- )
|
||||
all-slots rest-slice reader-slots ;
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
USING: kernel generic sequences ;
|
||||
|
||||
IN: generic.lib
|
||||
|
||||
: chain ( seq -- object ) unclip swap [ tuck set-delegate ] each ;
|
|
@ -13,7 +13,7 @@ TUPLE: gesture-logger < gadget stream ;
|
|||
{ 100 100 } >>dim
|
||||
black solid-interior ;
|
||||
|
||||
M: gesture-logger handle-gesture*
|
||||
M: gesture-logger handle-gesture
|
||||
over T{ button-down } = [ dup request-focus ] when
|
||||
stream>> [ . ] with-output-stream*
|
||||
t ;
|
||||
|
|
|
@ -226,17 +226,6 @@ DEFER: _
|
|||
|
||||
\ new 1 [ ?wrapped empty-inverse ] define-pop-inverse
|
||||
|
||||
: writer>reader ( word -- word' )
|
||||
[ "writing" word-prop "slots" word-prop ] keep
|
||||
[ swap slot-spec-writer = ] curry find nip slot-spec-reader ;
|
||||
|
||||
: construct-inverse ( class setters -- quot )
|
||||
>r deconstruct-pred r>
|
||||
[ writer>reader ] map [ get-slots ] curry
|
||||
compose ;
|
||||
|
||||
\ construct 2 [ >r ?wrapped r> construct-inverse ] define-pop-inverse
|
||||
|
||||
! More useful inverse-based combinators
|
||||
|
||||
: recover-fail ( try fail -- )
|
||||
|
|
|
@ -168,7 +168,7 @@ M: key-caps-gadget graft*
|
|||
M: key-caps-gadget ungraft*
|
||||
alarm>> [ cancel-alarm ] when* ;
|
||||
|
||||
M: key-caps-gadget handle-gesture*
|
||||
M: key-caps-gadget handle-gesture
|
||||
drop [ key-down? ] [ key-up? ] bi or not ;
|
||||
|
||||
: key-caps ( -- )
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: sequences kernel math io calendar calendar.format
|
||||
calendar.model arrays models models.filter namespaces ui.gadgets
|
||||
ui.gadgets.labels ui.gadgets.theme ui ;
|
||||
USING: accessors sequences kernel math io calendar grouping
|
||||
calendar.format calendar.model arrays models models.filter
|
||||
namespaces ui.gadgets ui.gadgets.labels ui.gadgets.theme ui ;
|
||||
IN: lcd
|
||||
|
||||
: lcd-digit ( row digit -- str )
|
||||
|
@ -11,7 +11,7 @@ IN: lcd
|
|||
" | | | _| _| |_| |_ |_ | |_| |_| * "
|
||||
" |_| | |_ _| | _| |_| | |_| | * "
|
||||
" "
|
||||
} nth >r 4 * dup 4 + r> subseq ;
|
||||
} nth 4 <groups> nth ;
|
||||
|
||||
: lcd-row ( num row -- string )
|
||||
[ swap lcd-digit ] curry { } map-as concat ;
|
||||
|
@ -20,9 +20,8 @@ IN: lcd
|
|||
4 [ lcd-row ] with map "\n" join ;
|
||||
|
||||
: hh:mm:ss ( timestamp -- string )
|
||||
{
|
||||
timestamp-hour timestamp-minute timestamp-second
|
||||
} get-slots >fixnum 3array [ pad-00 ] map ":" join ;
|
||||
[ hour>> ] [ minute>> ] [ second>> >fixnum ] tri
|
||||
3array [ pad-00 ] map ":" join ;
|
||||
|
||||
: <time-display> ( timestamp -- gadget )
|
||||
[ hh:mm:ss lcd ] <filter> <label-control>
|
||||
|
|
|
@ -194,9 +194,9 @@ METHOD: n*M.M+n*M-in-place { number double-complex-blas-matrix double-complex-bl
|
|||
syntax:M: blas-matrix-base clone
|
||||
[
|
||||
[
|
||||
{ data>> ld>> cols>> element-type } get-slots
|
||||
heap-size * * memory>byte-array
|
||||
] [ { ld>> rows>> cols>> transpose>> } get-slots ] bi
|
||||
{ [ data>> ] [ ld>> ] [ cols>> ] [ element-type heap-size ] } cleave
|
||||
* * memory>byte-array
|
||||
] [ { [ ld>> ] [ rows>> ] [ cols>> ] [ transpose>> ] } cleave ] bi
|
||||
] keep (blas-matrix-like) ;
|
||||
|
||||
! XXX try rounding stride to next 128 bit bound for better vectorizin'
|
||||
|
@ -296,7 +296,7 @@ syntax:M: blas-matrix-rowcol-sequence nth-unsafe
|
|||
recip swap n*M ; inline
|
||||
|
||||
: Mtranspose ( matrix -- matrix^T )
|
||||
[ { data>> ld>> rows>> cols>> transpose>> } get-slots not ] keep (blas-matrix-like) ;
|
||||
[ { [ data>> ] [ ld>> ] [ rows>> ] [ cols>> ] [ transpose>> not ] } cleave ] keep (blas-matrix-like) ;
|
||||
|
||||
syntax:M: blas-matrix-base equal?
|
||||
{
|
||||
|
|
|
@ -49,10 +49,9 @@ SYMBOL: visited
|
|||
{ 0 0 } dup vertex (draw-maze)
|
||||
glEnd ;
|
||||
|
||||
TUPLE: maze ;
|
||||
TUPLE: maze < canvas ;
|
||||
|
||||
: <maze> ( -- gadget )
|
||||
<canvas> { set-delegate } maze construct ;
|
||||
: <maze> ( -- gadget ) maze new-canvas ;
|
||||
|
||||
: n ( gadget -- n ) rect-dim first2 min line-width /i ;
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ SYMBOL: key-value
|
|||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
M: processing-gadget handle-gesture* ( gadget gesture delegate -- ? )
|
||||
rot drop swap ! delegate gesture
|
||||
M: processing-gadget handle-gesture ( gesture gadget -- ? )
|
||||
swap
|
||||
{
|
||||
{
|
||||
[ dup key-down? ]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors assocs math kernel shuffle generalizations
|
||||
words quotations arrays combinators sequences math.vectors
|
||||
io.styles prettyprint vocabs sorting io generic locals.private
|
||||
|
@ -92,11 +94,11 @@ M: word noise badness 1 2array ;
|
|||
|
||||
M: wrapper noise wrapped>> noise ;
|
||||
|
||||
M: let noise let-body noise ;
|
||||
M: let noise body>> noise ;
|
||||
|
||||
M: wlet noise wlet-body noise ;
|
||||
M: wlet noise body>> noise ;
|
||||
|
||||
M: lambda noise lambda-body noise ;
|
||||
M: lambda noise body>> noise ;
|
||||
|
||||
M: object noise drop { 0 0 } ;
|
||||
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors assocs words sequences arrays compiler
|
||||
tools.time io.styles io prettyprint vocabs kernel sorting
|
||||
generator optimizer math math.order math.statistics combinators
|
||||
optimizer.debugger ;
|
||||
IN: report.optimizer
|
||||
|
||||
: table. ( alist -- )
|
||||
20 short tail*
|
||||
standard-table-style
|
||||
[
|
||||
[ [ [ pprint-cell ] each ] with-row ] each
|
||||
] tabular-output ;
|
||||
|
||||
: results ( results quot title -- )
|
||||
print
|
||||
[ second ] prepose
|
||||
[ [ compare ] curry sort table. ]
|
||||
[
|
||||
map
|
||||
[ "Mean: " write mean >float . ]
|
||||
[ "Median: " write median >float . ]
|
||||
[ "Standard deviation: " write std >float . ]
|
||||
tri
|
||||
] 2bi ; inline
|
||||
|
||||
: optimization-passes ( word -- n )
|
||||
word-dataflow nip 1 count-optimization-passes nip ;
|
||||
|
||||
: optimizer-measurements ( -- alist )
|
||||
all-words [ compiled>> ] filter
|
||||
[ dup [ optimization-passes ] benchmark 2array ] { } map>assoc ;
|
||||
|
||||
: optimizer-measurements. ( alist -- )
|
||||
{
|
||||
[ [ first ] "Optimizer passes:" results ]
|
||||
[ [ second ] "Compile times:" results ]
|
||||
} cleave ;
|
||||
|
||||
: optimizer-report ( -- )
|
||||
optimizer-measurements optimizer-measurements. ;
|
||||
|
||||
MAIN: optimizer-report
|
|
@ -1 +0,0 @@
|
|||
Eduardo Cavazos
|
|
@ -13,7 +13,15 @@ MIXIN: node
|
|||
TUPLE: concatenation seq ; INSTANCE: concatenation node
|
||||
TUPLE: alternation seq ; INSTANCE: alternation node
|
||||
TUPLE: kleene-star term ; INSTANCE: kleene-star node
|
||||
TUPLE: question term ; INSTANCE: question node
|
||||
|
||||
! !!!!!!!!
|
||||
TUPLE: possessive-question term ; INSTANCE: possessive-question node
|
||||
TUPLE: possessive-kleene-star term ; INSTANCE: possessive-kleene-star node
|
||||
|
||||
! !!!!!!!!
|
||||
TUPLE: reluctant-question term ; INSTANCE: reluctant-question node
|
||||
TUPLE: reluctant-kleene-star term ; INSTANCE: reluctant-kleene-star node
|
||||
|
||||
TUPLE: negation term ; INSTANCE: negation node
|
||||
TUPLE: constant char ; INSTANCE: constant node
|
||||
TUPLE: range from to ; INSTANCE: range node
|
||||
|
@ -21,7 +29,7 @@ TUPLE: lookahead term ; INSTANCE: lookahead node
|
|||
TUPLE: lookbehind term ; INSTANCE: lookbehind node
|
||||
TUPLE: capture-group term ; INSTANCE: capture-group node
|
||||
TUPLE: non-capture-group term ; INSTANCE: non-capture-group node
|
||||
TUPLE: independent-group term ; INSTANCE: independent-group node
|
||||
TUPLE: independent-group term ; INSTANCE: independent-group node ! atomic group
|
||||
TUPLE: character-class-range from to ; INSTANCE: character-class-range node
|
||||
SINGLETON: epsilon INSTANCE: epsilon node
|
||||
SINGLETON: any-char INSTANCE: any-char node
|
||||
|
@ -51,6 +59,11 @@ left-parenthesis pipe caret dash ;
|
|||
: get-unicode-case ( -- ? ) unicode-case get-option ;
|
||||
: get-reversed-regexp ( -- ? ) reversed-regexp get-option ;
|
||||
|
||||
: <possessive-kleene-star> ( obj -- kleene ) possessive-kleene-star boa ;
|
||||
: <reluctant-kleene-star> ( obj -- kleene ) reluctant-kleene-star boa ;
|
||||
: <possessive-question> ( obj -- kleene ) possessive-question boa ;
|
||||
: <reluctant-question> ( obj -- kleene ) reluctant-question boa ;
|
||||
|
||||
: <negation> ( obj -- negation ) negation boa ;
|
||||
: <concatenation> ( seq -- concatenation )
|
||||
>vector get-reversed-regexp [ reverse ] when
|
||||
|
@ -101,7 +114,6 @@ ERROR: unmatched-parentheses ;
|
|||
: make-negative-lookbehind ( string -- )
|
||||
<negation> lookbehind boa push-stack ;
|
||||
|
||||
DEFER: nested-parse-regexp
|
||||
: make-non-capturing-group ( string -- )
|
||||
non-capture-group boa push-stack ;
|
||||
|
||||
|
@ -112,6 +124,7 @@ ERROR: bad-option ch ;
|
|||
{ CHAR: i [ case-insensitive ] }
|
||||
{ CHAR: d [ unix-lines ] }
|
||||
{ CHAR: m [ multiline ] }
|
||||
{ CHAR: n [ multiline ] }
|
||||
{ CHAR: r [ reversed-regexp ] }
|
||||
{ CHAR: s [ dotall ] }
|
||||
{ CHAR: u [ unicode-case ] }
|
||||
|
@ -135,6 +148,7 @@ DEFER: (parse-regexp)
|
|||
|
||||
ERROR: bad-special-group string ;
|
||||
|
||||
DEFER: nested-parse-regexp
|
||||
: (parse-special-group) ( -- )
|
||||
read1 {
|
||||
{ [ dup CHAR: : = ]
|
||||
|
@ -146,9 +160,9 @@ ERROR: bad-special-group string ;
|
|||
{ [ dup CHAR: > = ]
|
||||
[ drop nested-parse-regexp pop-stack make-independent-group ] }
|
||||
{ [ dup CHAR: < = peek1 CHAR: = = and ]
|
||||
[ drop read1 drop nested-parse-regexp pop-stack make-positive-lookbehind ] }
|
||||
[ drop drop1 nested-parse-regexp pop-stack make-positive-lookbehind ] }
|
||||
{ [ dup CHAR: < = peek1 CHAR: ! = and ]
|
||||
[ drop read1 drop nested-parse-regexp pop-stack make-negative-lookbehind ] }
|
||||
[ drop drop1 nested-parse-regexp pop-stack make-negative-lookbehind ] }
|
||||
[
|
||||
":)" read-until
|
||||
[ swap prefix ] dip
|
||||
|
@ -162,16 +176,27 @@ ERROR: bad-special-group string ;
|
|||
|
||||
: handle-left-parenthesis ( -- )
|
||||
peek1 CHAR: ? =
|
||||
[ read1 drop (parse-special-group) ]
|
||||
[ drop1 (parse-special-group) ]
|
||||
[ nested-parse-regexp ] if ;
|
||||
|
||||
: handle-dot ( -- ) any-char push-stack ;
|
||||
: handle-pipe ( -- ) pipe push-stack ;
|
||||
: handle-star ( -- ) stack pop <kleene-star> push-stack ;
|
||||
: (handle-star) ( obj -- kleene-star )
|
||||
peek1 {
|
||||
{ CHAR: + [ drop1 <possessive-kleene-star> ] }
|
||||
{ CHAR: ? [ drop1 <reluctant-kleene-star> ] }
|
||||
[ drop <kleene-star> ]
|
||||
} case ;
|
||||
: handle-star ( -- ) stack pop (handle-star) push-stack ;
|
||||
: handle-question ( -- )
|
||||
stack pop epsilon 2array <alternation> push-stack ;
|
||||
stack pop peek1 {
|
||||
{ CHAR: + [ drop1 <possessive-question> ] }
|
||||
{ CHAR: ? [ drop1 <reluctant-question> ] }
|
||||
[ drop epsilon 2array <alternation> ]
|
||||
} case push-stack ;
|
||||
: handle-plus ( -- )
|
||||
stack pop dup <kleene-star> 2array <concatenation> push-stack ;
|
||||
stack pop dup (handle-star)
|
||||
2array <concatenation> push-stack ;
|
||||
|
||||
ERROR: unmatched-brace ;
|
||||
: parse-repetition ( -- start finish ? )
|
||||
|
@ -247,7 +272,7 @@ ERROR: expected-posix-class ;
|
|||
ERROR: bad-escaped-literals seq ;
|
||||
: parse-escaped-literals ( -- obj )
|
||||
"\\E" read-until [ bad-escaped-literals ] unless
|
||||
read1 drop
|
||||
drop1
|
||||
[ epsilon ] [
|
||||
[ <constant> ] V{ } map-as
|
||||
first|concatenation
|
||||
|
|
|
@ -180,58 +180,18 @@ IN: regexp2-tests
|
|||
[ t ] [ "aaaab" "a+ab" <regexp> matches? ] unit-test
|
||||
[ f ] [ "aaaxb" "a+ab" <regexp> matches? ] unit-test
|
||||
[ t ] [ "aaacb" "a+cb" <regexp> matches? ] unit-test
|
||||
[ f ] [ "aaaab" "a++ab" <regexp> matches? ] unit-test
|
||||
[ t ] [ "aaacb" "a++cb" <regexp> matches? ] unit-test
|
||||
|
||||
[ 3 ] [ "aaacb" "a*" <regexp> match-head ] unit-test
|
||||
[ 1 ] [ "aaacb" "a+?" <regexp> match-head ] unit-test
|
||||
[ 2 ] [ "aaacb" "aa?" <regexp> match-head ] unit-test
|
||||
[ 1 ] [ "aaacb" "aa??" <regexp> match-head ] unit-test
|
||||
[ 3 ] [ "aacb" "aa?c" <regexp> match-head ] unit-test
|
||||
[ 3 ] [ "aacb" "aa??c" <regexp> match-head ] unit-test
|
||||
|
||||
! [ t ] [ "aaa" "AAA" t <regexp> matches? ] unit-test
|
||||
! [ f ] [ "aax" "AAA" t <regexp> matches? ] unit-test
|
||||
! [ t ] [ "aaa" "A*" t <regexp> matches? ] unit-test
|
||||
! [ f ] [ "aaba" "A*" t <regexp> matches? ] unit-test
|
||||
! [ t ] [ "b" "[AB]" t <regexp> matches? ] unit-test
|
||||
! [ f ] [ "c" "[AB]" t <regexp> matches? ] unit-test
|
||||
! [ t ] [ "c" "[A-Z]" t <regexp> matches? ] unit-test
|
||||
! [ f ] [ "3" "[A-Z]" t <regexp> matches? ] unit-test
|
||||
|
||||
[ ] [
|
||||
"(0[lL]?|[1-9]\\d{0,9}(\\d{0,9}[lL])?|0[xX]\\p{XDigit}{1,8}(\\p{XDigit}{0,8}[lL])?|0[0-7]{1,11}([0-7]{0,11}[lL])?|([0-9]+\\.[0-9]*|\\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?|[0-9]+([eE][+-]?[0-9]+[fFdD]?|([eE][+-]?[0-9]+)?[fFdD]))"
|
||||
<regexp> drop
|
||||
] unit-test
|
||||
|
||||
[ "{Lower}" <regexp> ] [ invalid-range? ] must-fail-with
|
||||
|
||||
[ t ] [ "fxxbar" "(?!foo).{3}bar" <regexp> matches? ] unit-test
|
||||
[ f ] [ "foobar" "(?!foo).{3}bar" <regexp> matches? ] unit-test
|
||||
|
||||
! [ 3 ] [ "foobar" "foo(?=bar)" <regexp> match-head ] unit-test
|
||||
! [ f ] [ "foobxr" "foo(?=bar)" <regexp> match-head ] unit-test
|
||||
|
||||
! [ f ] [ "foobxr" "foo\\z" <regexp> match-head ] unit-test
|
||||
! [ 3 ] [ "foo" "foo\\z" <regexp> match-head ] unit-test
|
||||
|
||||
! [ 3 ] [ "foo bar" "foo\\b" <regexp> match-head ] unit-test
|
||||
! [ f ] [ "fooxbar" "foo\\b" <regexp> matches? ] unit-test
|
||||
! [ t ] [ "foo" "foo\\b" <regexp> matches? ] unit-test
|
||||
! [ t ] [ "foo bar" "foo\\b bar" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "fooxbar" "foo\\bxbar" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "foo" "foo\\bbar" <regexp> matches? ] unit-test
|
||||
|
||||
! [ f ] [ "foo bar" "foo\\B" <regexp> matches? ] unit-test
|
||||
! [ 3 ] [ "fooxbar" "foo\\B" <regexp> match-head ] unit-test
|
||||
! [ t ] [ "foo" "foo\\B" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "foo bar" "foo\\B bar" <regexp> matches? ] unit-test
|
||||
! [ t ] [ "fooxbar" "foo\\Bxbar" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "foo" "foo\\Bbar" <regexp> matches? ] unit-test
|
||||
|
||||
[ t ] [ "s@f" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
|
||||
[ f ] [ "a" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
|
||||
[ t ] [ ".o" "\\.[a-z]" <regexp> matches? ] unit-test
|
||||
[ t ] [ "aaa" "AAA" <iregexp> matches? ] unit-test
|
||||
[ f ] [ "aax" "AAA" <iregexp> matches? ] unit-test
|
||||
[ t ] [ "aaa" "A*" <iregexp> matches? ] unit-test
|
||||
[ f ] [ "aaba" "A*" <iregexp> matches? ] unit-test
|
||||
[ t ] [ "b" "[AB]" <iregexp> matches? ] unit-test
|
||||
[ f ] [ "c" "[AB]" <iregexp> matches? ] unit-test
|
||||
[ t ] [ "c" "[A-Z]" <iregexp> matches? ] unit-test
|
||||
[ f ] [ "3" "[A-Z]" <iregexp> matches? ] unit-test
|
||||
|
||||
[ t ] [ "a" "(?i)a" <regexp> matches? ] unit-test
|
||||
[ t ] [ "a" "(?i)a" <regexp> matches? ] unit-test
|
||||
|
@ -253,6 +213,50 @@ IN: regexp2-tests
|
|||
[ t ] [ "abc" <reversed> "a[bB][cC]" <rregexp> matches? ] unit-test
|
||||
[ t ] [ "adcbe" "a(?r)(bcd)(?-r)e" <rregexp> matches? ] unit-test
|
||||
|
||||
[ t ] [ "s@f" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
|
||||
[ f ] [ "a" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
|
||||
[ t ] [ ".o" "\\.[a-z]" <regexp> matches? ] unit-test
|
||||
|
||||
[ ] [
|
||||
"(0[lL]?|[1-9]\\d{0,9}(\\d{0,9}[lL])?|0[xX]\\p{XDigit}{1,8}(\\p{XDigit}{0,8}[lL])?|0[0-7]{1,11}([0-7]{0,11}[lL])?|([0-9]+\\.[0-9]*|\\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?|[0-9]+([eE][+-]?[0-9]+[fFdD]?|([eE][+-]?[0-9]+)?[fFdD]))"
|
||||
<regexp> drop
|
||||
] unit-test
|
||||
|
||||
|
||||
|
||||
|
||||
[ "{Lower}" <regexp> ] [ invalid-range? ] must-fail-with
|
||||
|
||||
[ 1 ] [ "aaacb" "a+?" <regexp> match-head ] unit-test
|
||||
[ 1 ] [ "aaacb" "aa??" <regexp> match-head ] unit-test
|
||||
[ f ] [ "aaaab" "a++ab" <regexp> matches? ] unit-test
|
||||
[ t ] [ "aaacb" "a++cb" <regexp> matches? ] unit-test
|
||||
[ 3 ] [ "aacb" "aa?c" <regexp> match-head ] unit-test
|
||||
[ 3 ] [ "aacb" "aa??c" <regexp> match-head ] unit-test
|
||||
|
||||
[ t ] [ "fxxbar" "(?!foo).{3}bar" <regexp> matches? ] unit-test
|
||||
[ f ] [ "foobar" "(?!foo).{3}bar" <regexp> matches? ] unit-test
|
||||
|
||||
[ 3 ] [ "foobar" "foo(?=bar)" <regexp> match-head ] unit-test
|
||||
[ f ] [ "foobxr" "foo(?=bar)" <regexp> match-head ] unit-test
|
||||
|
||||
! [ f ] [ "foobxr" "foo\\z" <regexp> match-head ] unit-test
|
||||
! [ 3 ] [ "foo" "foo\\z" <regexp> match-head ] unit-test
|
||||
|
||||
! [ 3 ] [ "foo bar" "foo\\b" <regexp> match-head ] unit-test
|
||||
! [ f ] [ "fooxbar" "foo\\b" <regexp> matches? ] unit-test
|
||||
! [ t ] [ "foo" "foo\\b" <regexp> matches? ] unit-test
|
||||
! [ t ] [ "foo bar" "foo\\b bar" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "fooxbar" "foo\\bxbar" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "foo" "foo\\bbar" <regexp> matches? ] unit-test
|
||||
|
||||
! [ f ] [ "foo bar" "foo\\B" <regexp> matches? ] unit-test
|
||||
! [ 3 ] [ "fooxbar" "foo\\B" <regexp> match-head ] unit-test
|
||||
! [ t ] [ "foo" "foo\\B" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "foo bar" "foo\\B bar" <regexp> matches? ] unit-test
|
||||
! [ t ] [ "fooxbar" "foo\\Bxbar" <regexp> matches? ] unit-test
|
||||
! [ f ] [ "foo" "foo\\Bbar" <regexp> matches? ] unit-test
|
||||
|
||||
! Bug in parsing word
|
||||
! [ t ] [ "a" R' a' matches? ] unit-test
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ IN: regexp2.utils
|
|||
: push1 ( obj -- ) input-stream get stream>> push ;
|
||||
: peek1 ( -- obj ) input-stream get stream>> [ f ] [ peek ] if-empty ;
|
||||
: pop3 ( seq -- obj1 obj2 obj3 ) [ pop ] [ pop ] [ pop ] tri spin ;
|
||||
: drop1 ( -- ) read1 drop ;
|
||||
|
||||
: stack ( -- obj ) current-regexp get stack>> ;
|
||||
: change-whole-stack ( quot -- )
|
||||
|
|
|
@ -82,7 +82,7 @@ M: bunny-dlist bunny-geom
|
|||
bunny-dlist-list glCallList ;
|
||||
|
||||
M: bunny-buffers bunny-geom
|
||||
dup { array>> element-array>> } get-slots [
|
||||
dup [ array>> ] [ element-array>> ] bi [
|
||||
{ GL_VERTEX_ARRAY GL_NORMAL_ARRAY } [
|
||||
GL_FLOAT 0 0 buffer-offset glNormalPointer
|
||||
[
|
||||
|
@ -99,7 +99,7 @@ M: bunny-dlist dispose
|
|||
list>> delete-dlist ;
|
||||
|
||||
M: bunny-buffers dispose
|
||||
{ array>> element-array>> } get-slots
|
||||
[ array>> ] [ element-array>> ] bi
|
||||
delete-gl-buffer delete-gl-buffer ;
|
||||
|
||||
: <bunny-geom> ( model -- geom )
|
|
@ -1 +0,0 @@
|
|||
Eduardo Cavazos
|
|
@ -1,94 +0,0 @@
|
|||
|
||||
USING: kernel
|
||||
io
|
||||
io.streams.duplex
|
||||
io.sockets
|
||||
io.server
|
||||
combinators continuations
|
||||
namespaces generic threads sequences arrays vars ;
|
||||
|
||||
IN: cabal
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
TUPLE: user name ;
|
||||
|
||||
: <user> ( client -- user )
|
||||
user construct-empty
|
||||
tuck set-delegate
|
||||
dup [ "name: " write flush readln ] with-stream* over set-user-name ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
VAR: users
|
||||
|
||||
: init-users ( -- ) V{ } clone >users ;
|
||||
|
||||
: show-users ( -- ) users> [ user-name print ] each flush ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
VAR: conversation
|
||||
|
||||
: init-conversation ( -- ) V{ } clone >conversation ;
|
||||
|
||||
: show-conversation ( -- ) conversation> [ print ] each flush ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
VARS: input user ;
|
||||
|
||||
: ((send-input)) ( other -- ) [ input> print flush ] with-stream* ;
|
||||
|
||||
: (send-input) ( other -- )
|
||||
[ ((send-input)) ] catch [ print dup dispose users> delete ] when ;
|
||||
|
||||
: send-input ( other -- )
|
||||
dup duplex-stream-closed? [ users> delete ] [ (send-input) ] if ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: tag-input ( -- ) user> user-name ": " input> 3append >input ;
|
||||
|
||||
: log-input ( -- ) input> conversation> push ;
|
||||
|
||||
! : send-message ( -- ) tag-input users> >array [ send-input ] each ;
|
||||
|
||||
: send-message ( -- ) tag-input log-input users> >array [ send-input ] each ;
|
||||
|
||||
: handle-user-loop ( -- )
|
||||
readln >input
|
||||
{ { [ input> f eq? ] [ user> users> delete ] }
|
||||
{ [ input> "/log" = ] [ show-conversation handle-user-loop ] }
|
||||
{ [ input> "/users" = ] [ show-users handle-user-loop ] }
|
||||
{ [ t ] [ send-message handle-user-loop ] } }
|
||||
cond ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
! : handle-client ( client -- ) <user> dup users> push
|
||||
! dup [ >user [ handle-user-loop ] with-stream* ] with-scope ;
|
||||
|
||||
: handle-client ( client -- )
|
||||
<user> dup users> push
|
||||
dup [ >user [ handle-user-loop ] with-stream ] with-scope ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: accept-client-loop ( server -- )
|
||||
[ accept [ handle-client ] curry in-thread ] keep
|
||||
accept-client-loop ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
! : start-cabal ( -- )
|
||||
! init-users
|
||||
! init-conversation
|
||||
! 8000 <server> accept-client-loop ;
|
||||
|
||||
: start-cabal ( -- )
|
||||
init-users
|
||||
init-conversation
|
||||
8000 internet-server [ inet4? ] find nip <server> accept-client-loop ;
|
||||
|
||||
MAIN: start-cabal
|
|
@ -1 +0,0 @@
|
|||
Minimalist chat server
|
|
@ -1,2 +0,0 @@
|
|||
Matthew Willis
|
||||
Eduardo Cavazos
|
|
@ -1 +0,0 @@
|
|||
Connects to a cabal server
|
|
@ -1,52 +0,0 @@
|
|||
USING: kernel
|
||||
io
|
||||
io.streams.duplex
|
||||
io.sockets
|
||||
namespaces sequences math math.parser threads quotations splitting
|
||||
ui
|
||||
ui.gadgets
|
||||
ui.gadgets.panes
|
||||
ui.gadgets.scrollers
|
||||
ui.gadgets.tracks
|
||||
ui.tools.interactor ;
|
||||
|
||||
IN: cabal.ui
|
||||
|
||||
TUPLE: cabal-gadget input output ;
|
||||
|
||||
: <cabal-input> ( -- gadget )
|
||||
gadget get cabal-gadget-output <pane-stream> <interactor> ;
|
||||
|
||||
: <cabal-gadget> ( -- gadget )
|
||||
cabal-gadget construct-empty
|
||||
dup
|
||||
[ <scrolling-pane> over dupd set-cabal-gadget-output <scroller> 5/6 track,
|
||||
<cabal-input> over dupd set-cabal-gadget-input <scroller> 1/6 track,
|
||||
drop ]
|
||||
curry
|
||||
{ 0 1 }
|
||||
build-track ;
|
||||
|
||||
M: cabal-gadget pref-dim* drop { 550 650 } ;
|
||||
|
||||
: cabal-stream ( cabal -- stream )
|
||||
dup cabal-gadget-input swap cabal-gadget-output <pane-stream>
|
||||
<duplex-stream> ;
|
||||
|
||||
: incoming-loop ( stream -- ) dup stream-readln print incoming-loop ;
|
||||
|
||||
: outgoing-loop ( stream -- )
|
||||
readln over stream-print dup stream-flush outgoing-loop ;
|
||||
|
||||
: cabal-thread ( -- )
|
||||
"cabal://" write readln
|
||||
":" split1 string>number <inet> <client>
|
||||
[ outgoing-loop ] in-thread incoming-loop ;
|
||||
|
||||
: cabal-client ( -- )
|
||||
<cabal-gadget> dup "Cabal Client" open-window
|
||||
cabal-stream [ [ cabal-thread ] with-stream ] in-thread drop ;
|
||||
|
||||
: cabal-client* ( -- ) [ cabal-client ] with-ui ;
|
||||
|
||||
MAIN: cabal-client*
|
|
@ -1 +0,0 @@
|
|||
Robbert van Dalen
|
|
@ -1,6 +0,0 @@
|
|||
! Copyright (C) 2007 Robbert van Dalen.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
USING: kernel sequences enchilada strings ;
|
||||
IN: temporary
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
! Copyright (C) 2007 Robbert van Dalen.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
IN: enchilada
|
||||
USING: generic kernel enchilada.engine enchilada.parser enchilada.printer prettyprint ;
|
||||
|
||||
|
||||
: (e-eval) ( e-expression -- )
|
||||
dup e-reducible? [ dup e-print . e-reduce (e-eval) ] [ e-print . ] if ;
|
||||
|
||||
: e-eval ( string -- )
|
||||
e-parse (e-eval) ;
|
|
@ -1,322 +0,0 @@
|
|||
! Copyright (C) 2007 Robbert van Dalen.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
IN: enchilada.engine
|
||||
USING: generic kernel math sequences isequences.interface isequences.base isequences.ops ;
|
||||
|
||||
! Provides Enchilada's rewriting expression engine.
|
||||
!
|
||||
|
||||
GENERIC: !! ( list -- list )
|
||||
GENERIC: \\ ( list -- list )
|
||||
|
||||
GENERIC: e-reducible? ( e -- ? )
|
||||
GENERIC: e-dyadic? ( o -- ? )
|
||||
GENERIC: e-operator? ( o -- ? )
|
||||
GENERIC: e-list? ( o -- ? )
|
||||
GENERIC: e-symbol? ( o -- ? )
|
||||
|
||||
GENERIC: e-m-operate ( v op -- e )
|
||||
GENERIC: e-d-operate ( v1 v2 op -- e )
|
||||
|
||||
GENERIC: e-reduce ( e -- e )
|
||||
GENERIC: free-symbols ( s -- symbols )
|
||||
|
||||
TUPLE: ireplace from to seq ;
|
||||
|
||||
: unpack-ireplace ( ireplace -- from to seq )
|
||||
dup ireplace-from swap dup ireplace-to swap ireplace-seq ; inline
|
||||
|
||||
GENERIC: e-replace ( from to sequence -- s )
|
||||
|
||||
: (ireplace1) ( from to seq -- ireplace )
|
||||
dup is-atom?
|
||||
[ pick over i-cmp 0 = [ drop nip ] [ nip nip ] if ]
|
||||
[ <ireplace> ] if ;
|
||||
|
||||
: <i-replace> ( from to seq -- ireplace )
|
||||
dup i-length dup 0 =
|
||||
[ 3drop drop 0 ]
|
||||
[ 1 = [ (ireplace1) ] [ <ireplace> ] if ]
|
||||
if ;
|
||||
|
||||
: ireplace-i-at ( s i -- v )
|
||||
swap dup ireplace-seq rot i-at dup >r swap dup ireplace-from rot i-cmp 0 =
|
||||
[ r> drop ireplace-to ]
|
||||
[ dup ireplace-from swap ireplace-to r> e-replace ]
|
||||
if ;
|
||||
|
||||
M: object e-replace <i-replace> ;
|
||||
M: integer e-replace -rot 2drop ;
|
||||
|
||||
M: ireplace i-length ireplace-seq i-length ;
|
||||
M: ireplace i-at ireplace-i-at ;
|
||||
M: ireplace ileft unpack-ireplace ileft e-replace ;
|
||||
M: ireplace iright unpack-ireplace iright e-replace ;
|
||||
M: ireplace ihead (ihead) ;
|
||||
M: ireplace itail (itail) ;
|
||||
M: ireplace $$ unpack-ireplace [ $$ ] 2apply rot $$ quick-hash quick-hash ;
|
||||
|
||||
TUPLE: esymbol seq ;
|
||||
|
||||
GENERIC: esymbol/i-cmp ( esymbol s -- i )
|
||||
|
||||
M: object esymbol/i-cmp 2drop -1 ;
|
||||
M: esymbol esymbol/i-cmp swap [ esymbol-seq ] 2apply i-cmp ;
|
||||
M: esymbol object/i-cmp 2drop 1 ;
|
||||
M: esymbol i-cmp swap esymbol/i-cmp ;
|
||||
|
||||
DEFER: (sunion)
|
||||
|
||||
: (sunion6) ( s1 s2 -- s )
|
||||
2dup [ 0 i-at ] 2apply i-cmp dup zero?
|
||||
[ 2drop ] [ 0 > [ swap ] when ++ ] if ; inline
|
||||
|
||||
: (sunion5) ( s1 s2 -- s )
|
||||
over ileft i-length pick swap i-at icut rot left-right
|
||||
swap roll (sunion) -rot swap (sunion) ++ ; inline
|
||||
|
||||
: (sunion4) ( s1 s2 -- s )
|
||||
2dup ifirst swap ilast i-cmp dup zero?
|
||||
[ drop 1 itail ++ ] [ 0 > [ ++ ] [ (sunion5) ] if ] if ; inline
|
||||
|
||||
: (sunion3) ( s1 s2 ls1 ls2 -- s )
|
||||
1 =
|
||||
[ 1 = [ (sunion6) ] [ (sunion4) ] if ]
|
||||
[ 1 = [ swap ] when (sunion4) ] if ; inline
|
||||
|
||||
: (sunion2) ( s1 s2 -- s )
|
||||
2dup [ i-length ] 2apply 2dup zero?
|
||||
[ 3drop drop ] [ zero? [ 2drop nip ] [ (sunion3) ] if ] if ; inline
|
||||
|
||||
: (sunion) ( s1 s2 -- s )
|
||||
2dup eq? [ drop ] [ (sunion2) ] if ; inline
|
||||
|
||||
: s-union ( s1 s2 -- s )
|
||||
(sunion) ; inline
|
||||
|
||||
: (free-symbols) ( s -- symbols )
|
||||
dup is-atom?
|
||||
[ dup e-symbol? [ drop 0 ] unless ]
|
||||
[ 0 i-at free-symbols ] if ;
|
||||
|
||||
M: object free-symbols
|
||||
dup i-length dup 0 =
|
||||
[ 2drop 0 ]
|
||||
[ 1 = [ (free-symbols) ] [ left-right [ free-symbols ] 2apply s-union ] if ] if ;
|
||||
|
||||
M: integer free-symbols drop 0 ;
|
||||
|
||||
M: object !!
|
||||
dup i-length dup 0 =
|
||||
[ 2drop 0 ]
|
||||
[ 1 = [ 0 i-at dup left-side swap right-side [ e-reduce ] 2apply <i-dual-sided> <i> ] [ left-right [ !! ] 2apply ++ ] if ] if ;
|
||||
|
||||
M: integer !! ;
|
||||
|
||||
|
||||
: (\\) ( expr -- list )
|
||||
dup i-length dup 0 =
|
||||
[ 2drop 0 ]
|
||||
[ 1 = [ <i> ] [ left-right [ (\\) ] 2apply ++ ] if ] if ;
|
||||
|
||||
M: object \\
|
||||
dup i-length dup 0 =
|
||||
[ 2drop 0 ]
|
||||
[ 1 = [ 0 i-at left-side (\\) ] [ left-right [ \\ ] 2apply ++ ] if ] if ;
|
||||
M: integer \\ ;
|
||||
|
||||
TUPLE: emacro symbols expr eager? ;
|
||||
|
||||
: symbol-list? ( symbols -- ? )
|
||||
i-sort dup free-symbols i-cmp 0 = ; inline
|
||||
|
||||
: full-reduce ( expr -- expr )
|
||||
dup e-reducible? [ e-reduce full-reduce ] when ;
|
||||
|
||||
: <e-macro> ( symbols expr eager? -- e-macro )
|
||||
dup [ swap full-reduce swap ] when
|
||||
>r swap dup symbol-list? [ swap r> <emacro> ] [ "illegal symbol list" throw ] if ;
|
||||
|
||||
M: emacro free-symbols dup emacro-expr free-symbols swap emacro-symbols i-diff ;
|
||||
|
||||
M: emacro e-replace
|
||||
pick over [ free-symbols ] 2apply i-intersect i-length 0 =
|
||||
[ -rot 2drop ]
|
||||
[ dup >r emacro-expr e-replace r> dup emacro-symbols swap emacro-eager? rot swap <e-macro> ] if ;
|
||||
|
||||
: eflatten ( s -- s )
|
||||
dup i-length dup zero?
|
||||
[ 2drop 0 ]
|
||||
[ 1 = [ 0 i-at left-side ] [ left-right [ eflatten ] 2apply ++ ] if ] if ; inline
|
||||
|
||||
TUPLE: c-op v d-op ;
|
||||
|
||||
M: object e-operator? drop f ;
|
||||
M: object e-list? dup e-operator? not swap e-symbol? not and ;
|
||||
M: object e-symbol? drop f ;
|
||||
M: object e-dyadic? drop f ;
|
||||
|
||||
M: esymbol e-symbol? drop t ;
|
||||
|
||||
M: c-op e-m-operate
|
||||
dup c-op-v swap c-op-d-op e-d-operate ;
|
||||
|
||||
TUPLE: .- ;
|
||||
M: .- e-m-operate drop -- <i> ;
|
||||
TUPLE: .` ;
|
||||
M: .` e-m-operate drop `` <i> ;
|
||||
TUPLE: .$ ;
|
||||
M: .$ e-m-operate drop $$ <i> ;
|
||||
TUPLE: .~ ;
|
||||
M: .~ e-m-operate drop ~~ <i> ;
|
||||
TUPLE: .: ;
|
||||
M: .: e-m-operate drop :: <i> ;
|
||||
TUPLE: .# ;
|
||||
M: .# e-m-operate drop ## <i> ;
|
||||
TUPLE: .^ ;
|
||||
M: .^ e-m-operate drop eflatten ;
|
||||
TUPLE: .! ;
|
||||
M: .! e-m-operate drop !! <i> ;
|
||||
TUPLE: .\ ;
|
||||
M: .\ e-m-operate drop \\ <i> ;
|
||||
|
||||
TUPLE: .+ ;
|
||||
M: .+ e-d-operate drop ++ <i> ;
|
||||
TUPLE: .* ;
|
||||
M: .* e-d-operate drop ** [ <i> ] 2apply ++ ;
|
||||
TUPLE: ./ ;
|
||||
M: ./ e-d-operate drop // [ <i> ] 2apply ++ ;
|
||||
TUPLE: .& ;
|
||||
M: .& e-d-operate drop && <i> ;
|
||||
TUPLE: .| ;
|
||||
M: .| e-d-operate drop || <i> ;
|
||||
TUPLE: .< ;
|
||||
M: .< e-d-operate drop << [ <i> ] 2apply ++ ;
|
||||
TUPLE: .> ;
|
||||
M: .> e-d-operate drop >> <i> ;
|
||||
TUPLE: .@ ;
|
||||
M: .@ e-d-operate >r swap 0 i-cmp 0 = [ dup eflatten swap <i> ++ r> ++ ] [ r> 2drop 0 ] if ;
|
||||
TUPLE: .? ;
|
||||
M: .? e-d-operate drop (i-eq?) [ 1 ] [ 0 ] if <i> ;
|
||||
TUPLE: .% ;
|
||||
M: .% e-d-operate drop %% [ <i> ] 2apply ++ ;
|
||||
|
||||
UNION: monadic-class c-op .- .` .$ .~ .: .# .^ .! .\ emacro ;
|
||||
UNION: dyadic-class .+ .* ./ .& .| .< .> .@ .? .% ;
|
||||
UNION: operator-class monadic-class dyadic-class ;
|
||||
|
||||
M: operator-class e-operator? drop t ;
|
||||
M: monadic-class e-dyadic? drop f ;
|
||||
M: dyadic-class e-dyadic? drop t ;
|
||||
|
||||
DEFER: +e+
|
||||
|
||||
: (e-reducible?) ( e -- ? )
|
||||
left-right 2dup [ e-reducible? ] either?
|
||||
[ 2drop t ] [ ifirst e-operator? swap ilast e-list? and ] if ; inline
|
||||
|
||||
M: object e-reducible?
|
||||
dup i-length 1 <= [ drop f ] [ (e-reducible?) ] if ;
|
||||
|
||||
: (e-reduce2) ( e1 e2 -- e )
|
||||
2dup ifirst swap ilast swap e-m-operate
|
||||
-rot 1 itail swap dup i-length 1- ihead rot ++ swap ++ ; inline
|
||||
|
||||
: (e-reduce) ( e -- e )
|
||||
left-right swap dup e-reducible? [ (e-reduce) swap ++ ]
|
||||
[ swap dup e-reducible? [ (e-reduce) ++ ] [ (e-reduce2) ] if ] if ; inline
|
||||
|
||||
M: object e-reduce
|
||||
dup e-reducible? [ (e-reduce) ] when ;
|
||||
|
||||
: (+e+2) ( e1 e2 -- e )
|
||||
2dup ifirst swap ilast swap <c-op>
|
||||
-rot 1 itail swap dup i-length 1- ihead rot ++ swap ++ ; inline
|
||||
|
||||
: (+e+1) ( e1 e2 -- e )
|
||||
2dup ifirst e-dyadic? swap ilast e-list? and
|
||||
[ (+e+2) ] [ ++g ] if ; inline
|
||||
|
||||
TUPLE: e-exp expr reducible ;
|
||||
|
||||
M: e-exp e-reducible? e-exp-reducible ;
|
||||
|
||||
: <expr> ( s -- e-exp )
|
||||
dup e-exp? [ dup e-reducible? <e-exp> ] unless ; inline
|
||||
|
||||
: +e+ ( e1 e2 -- e )
|
||||
2dup [ i-length 1 >= ] both?
|
||||
[ (+e+1) ] [ ++g ] if <expr> ; inline
|
||||
|
||||
: e-ipair ( e1 e2 -- e )
|
||||
<isequence> <expr> ; inline
|
||||
|
||||
M: c-op e-replace dup >r c-op-v e-replace r> c-op-d-op <c-op> ;
|
||||
|
||||
|
||||
GENERIC: e-exp/++ ( s e -- e )
|
||||
GENERIC: e-exp/ipair ( s e -- e )
|
||||
|
||||
M: e-exp ++ swap e-exp/++ ;
|
||||
M: e-exp ipair swap e-exp/ipair ;
|
||||
|
||||
M: object e-exp/++ swap +e+ ;
|
||||
M: object e-exp/ipair swap e-ipair ;
|
||||
|
||||
M: e-exp e-exp/++ swap +e+ ;
|
||||
M: e-exp e-exp/ipair swap e-ipair ;
|
||||
M: e-exp object/++ swap +e+ ;
|
||||
M: e-exp object/ipair swap e-ipair ;
|
||||
|
||||
M: operator-class ++ +e+ ;
|
||||
|
||||
M: e-exp i-length e-exp-expr i-length ;
|
||||
M: e-exp i-at swap e-exp-expr swap i-at ;
|
||||
M: e-exp ileft e-exp-expr ileft ;
|
||||
M: e-exp iright e-exp-expr iright ;
|
||||
M: e-exp ihead swap e-exp-expr swap ihead ;
|
||||
M: e-exp itail swap e-exp-expr swap itail ;
|
||||
M: e-exp $$ e-exp-expr $$ ;
|
||||
|
||||
M: e-exp e-replace
|
||||
dup i-length 1 =
|
||||
[ e-exp-expr e-replace ]
|
||||
[ 3dup iright e-replace >r ileft e-replace r> ++ ] if ;
|
||||
|
||||
TUPLE: ereplacement from to ;
|
||||
|
||||
: (ereplace) ( symbols from-symbol -- to-symbol )
|
||||
esymbol-seq dup ++ <esymbol> dup pick i-intersect i-length zero?
|
||||
[ nip ] [ (ereplace) ] if ; inline
|
||||
|
||||
: (replacements3) ( symbols from-symbol -- newsymbols replacement )
|
||||
2dup (ereplace) rot over i-union -rot <ereplacement> ; inline
|
||||
|
||||
: (replacements2) ( symbols intersect -- replacements )
|
||||
dup i-length zero?
|
||||
[ 2drop 0 ]
|
||||
[ dup >r ifirst (replacements3) swap r> 1 itail (replacements2) ++ ] if ;
|
||||
|
||||
: replace-s ( s replacements -- s )
|
||||
dup i-length dup zero?
|
||||
[ 2drop ]
|
||||
[ 1 = [ 0 i-at dup ereplacement-from swap ereplacement-to rot e-replace ] [ left-right >r replace-s r> replace-s ] if ] if ;
|
||||
|
||||
: (replacements) ( value macro -- replacements )
|
||||
dup emacro-expr free-symbols swap emacro-symbols -1 ++
|
||||
i-intersect tuck swap free-symbols i-intersect (replacements2) ; inline
|
||||
|
||||
: (replace-macro) ( replacements macro -- macro )
|
||||
2dup dup >r emacro-symbols swap replace-s swap emacro-expr rot replace-s r> emacro-eager? <e-macro> ;
|
||||
|
||||
: (eval-macro) ( value macro -- macro )
|
||||
dup >r emacro-symbols dup -1 ++ swap ilast rot <i> r> dup >r emacro-expr e-replace r> emacro-eager? <e-macro> ;
|
||||
|
||||
: eval-macro ( value macro -- s )
|
||||
2dup (replacements) swap (replace-macro) (eval-macro) ;
|
||||
|
||||
: emacro-e-m-operate ( value macro -- s )
|
||||
eval-macro dup emacro-symbols i-length zero? [ emacro-expr ] when ;
|
||||
|
||||
M: emacro e-m-operate emacro-e-m-operate ;
|
|
@ -1,139 +0,0 @@
|
|||
! Copyright (C) 2007 Robbert van Dalen.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
IN: enchilada.parser
|
||||
USING: strings sequences kernel promises lazy-lists parser-combinators parser-combinators.simple isequences.interface isequences.base enchilada.engine ;
|
||||
|
||||
USE: lazy-lists
|
||||
USE: parser-combinators
|
||||
|
||||
DEFER: e-expression
|
||||
|
||||
LAZY: e/- ( -- parser )
|
||||
"-" token [ drop <.-> ] <@ ;
|
||||
|
||||
LAZY: e/# ( -- parser )
|
||||
"#" token [ drop <.#> ] <@ ;
|
||||
|
||||
LAZY: e/^ ( -- parser )
|
||||
"^" token [ drop <.^> ] <@ ;
|
||||
|
||||
LAZY: e/` ( -- parser )
|
||||
"`" token [ drop <.`> ] <@ ;
|
||||
|
||||
LAZY: e/: ( -- parser )
|
||||
":" token [ drop <.:> ] <@ ;
|
||||
|
||||
LAZY: e/~ ( -- parser )
|
||||
"~" token [ drop <.~> ] <@ ;
|
||||
|
||||
LAZY: e/$ ( -- parser )
|
||||
"$" token [ drop <.$> ] <@ ;
|
||||
|
||||
LAZY: e/! ( -- parser )
|
||||
"!" token [ drop <.!> ] <@ ;
|
||||
|
||||
LAZY: e/\ ( -- parser )
|
||||
"\\" token [ drop <.\> ] <@ ;
|
||||
|
||||
LAZY: e/+ ( -- parser )
|
||||
"+" token [ drop <.+> ] <@ ;
|
||||
|
||||
LAZY: e/| ( -- parser )
|
||||
"|" token [ drop <.|> ] <@ ;
|
||||
|
||||
LAZY: e/& ( -- parser )
|
||||
"&" token [ drop <.&> ] <@ ;
|
||||
|
||||
LAZY: e/* ( -- parser )
|
||||
"*" token [ drop <.*> ] <@ ;
|
||||
|
||||
LAZY: e// ( -- parser )
|
||||
"/" token [ drop <./> ] <@ ;
|
||||
|
||||
LAZY: e/< ( -- parser )
|
||||
"<" token [ drop <.<> ] <@ ;
|
||||
|
||||
LAZY: e/> ( -- parser )
|
||||
">" token [ drop <.>> ] <@ ;
|
||||
|
||||
LAZY: e/@ ( -- parser )
|
||||
"@" token [ drop <.@> ] <@ ;
|
||||
|
||||
LAZY: e/? ( -- parser )
|
||||
"?" token [ drop <.?> ] <@ ;
|
||||
|
||||
LAZY: e/% ( -- parser )
|
||||
"%" token [ drop <.%> ] <@ ;
|
||||
|
||||
LAZY: e-monadic ( -- parser )
|
||||
e/- e/# <|> e/^ <|> e/` <|> e/: <|> e/~ <|> e/$ <|> e/! <|> e/\ <|> ;
|
||||
|
||||
LAZY: e-dyadic ( -- parser )
|
||||
e/+ e/* <|> e/& <|> e/| <|> e// <|> e/< <|> e/> <|> e/@ <|> e/? <|> e/% <|> ;
|
||||
|
||||
LAZY: e-number ( -- parser )
|
||||
'integer' ;
|
||||
|
||||
LAZY: e-letter ( -- parser )
|
||||
[ letter? ] satisfy [ 1 swap <string> ] <@ ;
|
||||
|
||||
LAZY: e-digit ( -- parser )
|
||||
[ digit? ] satisfy [ 1 swap <string> ] <@ ;
|
||||
|
||||
LAZY: e-alphanumeric-char ( -- parser )
|
||||
e-letter e-digit <|> ;
|
||||
|
||||
LAZY: e-alphanumeric-symbol ( -- parser )
|
||||
e-letter e-alphanumeric-char <!*> <&> [ dup first swap second "" [ append ] reduce append ] <@ ;
|
||||
|
||||
LAZY: e-symbol ( -- parser )
|
||||
e-alphanumeric-symbol 'string' <|> sp [ <esymbol> ] <@ ;
|
||||
|
||||
LAZY: e-symbol-list ( -- parser )
|
||||
e-symbol <!+> [ { } [ ++ ] reduce ] <@ ;
|
||||
|
||||
LAZY: e-macro-expression ( -- parser )
|
||||
"=" token "=" token <?> <&> sp e-expression <&> [ dup 1 tail swap first second [ t ] [ f ] if add ] <@ ;
|
||||
|
||||
LAZY: e-macro ( -- parser )
|
||||
"{" token sp e-symbol-list &> e-macro-expression <?> <&> "}" token sp <&
|
||||
[ dup first swap second dup [ first ] [ drop { 0 f } ] if dup first swap second <e-macro> ] <@ ;
|
||||
|
||||
LAZY: e-right-expression ( -- parser )
|
||||
"=" token e-expression &> ;
|
||||
|
||||
: create-e-item ( pair -- e-item )
|
||||
dup first swap second dup [ first ] [ drop 0 ] if <i-dual-sided> <i> ;
|
||||
|
||||
LAZY: e-item ( -- parser )
|
||||
e-expression e-right-expression <?> <&> [ create-e-item ] <@ ;
|
||||
|
||||
LAZY: e-rest ( -- parser )
|
||||
";" token sp e-item &> <!*> [ { } [ ++ ] reduce ] <@ ;
|
||||
|
||||
LAZY: e-contents ( -- parser )
|
||||
e-item e-rest <&> [ dup first swap second ++ ] <@ ;
|
||||
|
||||
LAZY: e-non-empty ( -- parser )
|
||||
"[" token e-contents &> "]" token sp <& ;
|
||||
|
||||
LAZY: e-empty ( -- parser )
|
||||
"[" token "]" token <&> [ drop 0 ] <@ ;
|
||||
|
||||
LAZY: e-sequence ( -- parser )
|
||||
e-empty e-non-empty <|> e-number <|> ;
|
||||
|
||||
LAZY: e-operand ( -- parser )
|
||||
"_" token <?> e-sequence <&> [ dup second swap first [ -- ] when <i> ] <@ ;
|
||||
|
||||
LAZY: e-operator ( -- parser )
|
||||
e-monadic e-dyadic <|> e-macro <|> ;
|
||||
|
||||
LAZY: e-element ( -- parser )
|
||||
e-operator e-operand <|> e-symbol <|> sp ;
|
||||
|
||||
LAZY: e-expression ( -- parser )
|
||||
e-element <!*> [ { } [ ++ ] reduce ] <@ ;
|
||||
|
||||
: e-parse ( string -- result ) e-expression parse car parse-result-parsed ;
|
|
@ -1,71 +0,0 @@
|
|||
! Copyright (C) 2007 Robbert van Dalen.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
IN: enchilada.printer
|
||||
USING: prettyprint strings generic kernel math math.parser sequences isequences.interface isequences.base enchilada.engine ;
|
||||
|
||||
: s-append ( s1 s2 s3 -- s )
|
||||
swap append append ;
|
||||
|
||||
DEFER: e-print
|
||||
DEFER: l-print
|
||||
|
||||
GENERIC: (e-print) ( op -- string )
|
||||
|
||||
M: .- (e-print) drop "-" ;
|
||||
M: .# (e-print) drop "#" ;
|
||||
M: .$ (e-print) drop "$" ;
|
||||
M: .^ (e-print) drop "^" ;
|
||||
M: .` (e-print) drop "`" ;
|
||||
M: .~ (e-print) drop "~" ;
|
||||
M: .: (e-print) drop ":" ;
|
||||
M: .! (e-print) drop "!" ;
|
||||
M: .\ (e-print) drop "\\" ;
|
||||
|
||||
M: .+ (e-print) drop "+" ;
|
||||
M: .* (e-print) drop "*" ;
|
||||
M: ./ (e-print) drop "/" ;
|
||||
M: .< (e-print) drop "<" ;
|
||||
M: .> (e-print) drop ">" ;
|
||||
M: .| (e-print) drop "|" ;
|
||||
M: .& (e-print) drop "&" ;
|
||||
M: .@ (e-print) drop "@" ;
|
||||
M: .? (e-print) drop "?" ;
|
||||
M: .% (e-print) drop "%" ;
|
||||
|
||||
: (eprint-macro-expr) ( emacro -- string )
|
||||
dup emacro-expr dup i-length 0 =
|
||||
[ 2drop "" ]
|
||||
[ e-print swap emacro-eager? [ "==" ] [ "=" ] if swap append ] if ;
|
||||
|
||||
: (l-print1) ( e-list -- string )
|
||||
0 i-at dup left-side swap right-side dup 0 =
|
||||
[ drop dup i-length 0 = [ drop " " ] [ e-print ] if ] [ e-print swap e-print swap "=" s-append ] if ;
|
||||
|
||||
: (l-print0) ( e-list -- string )
|
||||
left-right [ l-print ] 2apply ";" s-append ;
|
||||
|
||||
: l-print ( e-list -- string )
|
||||
dup i-length dup 0 =
|
||||
[ 2drop "0" ] [ 1 = [ (l-print1) ] [ (l-print0) ] if ] if ;
|
||||
|
||||
: prefix-neg ( s -- s prefix )
|
||||
dup i-length 0 < [ -- "_" ] [ "" ] if ;
|
||||
|
||||
: (e-print3) ( symbol -- string )
|
||||
esymbol-seq to-sequence >string ;
|
||||
|
||||
: (e-print2) ( e-list -- string )
|
||||
dup integer? [ prefix-neg swap number>string append ] [ prefix-neg "[" append swap l-print "]" append append ] if ;
|
||||
|
||||
: (e-print1) ( e-expression -- string )
|
||||
0 i-at dup e-operator? [ (e-print) ] [ dup e-symbol? [ (e-print3) ] [ (e-print2) ] if ] if ;
|
||||
|
||||
: e-print ( e-expression -- string )
|
||||
dup i-length dup 0 =
|
||||
[ 2drop "" ]
|
||||
[ 1 = [ (e-print1) ] [ left-right [ e-print ] 2apply " " s-append ] if ] if ;
|
||||
|
||||
M: c-op (e-print) dup c-op-d-op swap c-op-v (e-print2) swap (e-print) " " s-append ;
|
||||
M: emacro (e-print) "{" swap dup emacro-symbols e-print swap (eprint-macro-expr) "}" append append append ;
|
||||
|
|
@ -1 +0,0 @@
|
|||
Enchilada, a concatenative programming language
|
|
@ -1 +0,0 @@
|
|||
languages
|
|
@ -1,12 +0,0 @@
|
|||
! Copyright (C) 2006 Matthew Willis. All Rights Reserved.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
!
|
||||
|
||||
REQUIRES: libs/calendar libs/crypto libs/basic-authentication
|
||||
libs/furnace libs/serialize ;
|
||||
|
||||
PROVIDE: apps/furnace-onigiri
|
||||
{ +files+ {
|
||||
"onigiri.factor"
|
||||
"onigiri.facts"
|
||||
} } ;
|
|
@ -1,166 +0,0 @@
|
|||
! Copyright (C) 2006 Matthew Willis. All Rights Reserved.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
!
|
||||
|
||||
USING: httpd threads kernel namespaces furnace sequences
|
||||
html strings math assocs crypto io file-responder calendar
|
||||
prettyprint parser errors sha2 basic-authentication arrays
|
||||
serialize ;
|
||||
|
||||
IN: furnace:onigiri
|
||||
|
||||
TUPLE: entry title stub body created ;
|
||||
|
||||
TUPLE: user name password ;
|
||||
|
||||
TUPLE: meta key value ;
|
||||
|
||||
: title>stub ( title -- stub )
|
||||
! creates a url friendly name based on the title
|
||||
" " split [ [ alpha? ] subset ] map "" swap remove "-" join ;
|
||||
|
||||
C: entry ( title body stub -- entry )
|
||||
tuck set-entry-stub
|
||||
tuck set-entry-body
|
||||
dup entry-stub [ over title>stub over set-entry-stub ] unless
|
||||
now over set-entry-created tuck set-entry-title ;
|
||||
|
||||
C: user ( name password -- user )
|
||||
swap string>sha-256-string over set-user-password
|
||||
tuck set-user-name ;
|
||||
|
||||
: base-url ( -- url )
|
||||
"http://" "Host" "header" get at append ;
|
||||
|
||||
: action>url ( action -- url )
|
||||
"responder-url" get swap append ;
|
||||
|
||||
: stub>url ( stub -- url )
|
||||
"entry-show?stub=" swap append action>url ;
|
||||
|
||||
: stub>entry ( stub -- entry )
|
||||
entry get-global [ entry-stub = ] subset-with
|
||||
dup empty? [ drop f ] [ first ] if ;
|
||||
|
||||
: atom ( -- )
|
||||
"text/xml" serving-content
|
||||
[ f "atom" render-template ] with-html-stream ;
|
||||
|
||||
: sitemap ( -- )
|
||||
"text/xml" serving-content
|
||||
[ f "sitemap" render-template ] with-html-stream ;
|
||||
|
||||
: css-path ( -- path )
|
||||
! "text/css" serving-content
|
||||
"css" meta crud-lookup* meta-value
|
||||
[ "onigirihouse.css" ] unless* ;
|
||||
|
||||
DEFER: key>meta*
|
||||
: entry-list ( -- )
|
||||
"title" key>meta* meta-value
|
||||
serving-html [
|
||||
<furnace-model> "header" render-template
|
||||
entry get-global
|
||||
[ [ entry-created ] 2apply swap compare-timestamps ] sort
|
||||
[ "entry-show" render-template ] each
|
||||
f "footer" render-template
|
||||
] with-html-stream ;
|
||||
|
||||
DEFER: key>meta
|
||||
: entry-show ( stub -- )
|
||||
stub>entry
|
||||
[
|
||||
"title" key>meta* meta-value
|
||||
" - " pick entry-title 3append
|
||||
serving-html [
|
||||
<furnace-model> "header" render-template
|
||||
"entry-show" render-template
|
||||
f "footer" render-template
|
||||
] with-html-stream
|
||||
] [
|
||||
"title" key>meta* meta-value " - Entry not found" append
|
||||
serving-html [
|
||||
[
|
||||
<p> "The entry you are searching for could not be found" write </p>
|
||||
<p> [ entry-list ] "Back to " "title" key>meta
|
||||
[ meta-value ] [ "the main page" ] if* append render-link
|
||||
</p>
|
||||
] html-document
|
||||
] with-html-stream
|
||||
] if* ;
|
||||
|
||||
: entry-edit ( stub wiky -- )
|
||||
swap stub>entry dup [ entry-title ] [ f ] if*
|
||||
"title" key>meta* meta-value " - editing " rot 3append
|
||||
serving-html [
|
||||
<furnace-model> "header" render-template
|
||||
swap "entry-edit" "entry-edit-plain" ? render-template
|
||||
f "footer" render-template
|
||||
] with-html-stream ;
|
||||
|
||||
: entry-update ( title body stub -- )
|
||||
"onigiri-realm" [
|
||||
dup stub>entry [
|
||||
nip tuck set-entry-body tuck set-entry-title
|
||||
] [
|
||||
<entry> dup entry get-global swap add entry set-global
|
||||
] if* entry-stub entry-show
|
||||
] with-basic-authentication ;
|
||||
|
||||
: entry-delete ( stub -- )
|
||||
"onigiri-realm" [
|
||||
stub>entry entry get-global remove entry set-global entry-list
|
||||
] with-basic-authentication ;
|
||||
|
||||
DEFER: name>user
|
||||
: onigiri-realm ( name password -- bool )
|
||||
swap name>user [ user-password = ] [ drop f ] if*
|
||||
user get-global empty? or ;
|
||||
|
||||
: register-actions ( -- )
|
||||
\ entry-list { } define-action
|
||||
\ entry-show { { "stub" } } define-action
|
||||
\ entry-edit { { "stub" } { "wiky" f v-default } } define-action
|
||||
\ entry-update { { "title" } { "body" } { "stub" } } define-action
|
||||
\ entry-delete { { "stub" } } define-action
|
||||
\ atom { } define-action
|
||||
\ sitemap { } define-action
|
||||
"onigiri" "entry-list" "apps/furnace-onigiri/templates/" web-app
|
||||
"onigiri-resources" [
|
||||
[
|
||||
"apps/furnace-onigiri/resources/" resource-path "doc-root" set
|
||||
file-responder
|
||||
] with-scope
|
||||
] add-simple-responder
|
||||
[ onigiri-realm ] "onigiri-realm" add-realm
|
||||
! and finally, use scaffolding for metadata and user data
|
||||
[
|
||||
"furnace:onigiri" set-in
|
||||
meta "key" "onigiri-realm" scaffold
|
||||
user "name" "onigiri-realm" scaffold
|
||||
] with-scope ;
|
||||
|
||||
: onigiri ( -- )
|
||||
register-actions
|
||||
"default-responder" key>meta* meta-value
|
||||
[ "onigiri" set-default-responder ] when
|
||||
"port" key>meta* meta-value string>number [ 8888 ] unless*
|
||||
[ httpd ] in-thread drop ;
|
||||
|
||||
: onigiri-dump ( path -- )
|
||||
[
|
||||
[
|
||||
entry get-global serialize
|
||||
meta get-global serialize
|
||||
user get-global serialize
|
||||
] with-serialized
|
||||
] with-file-writer ;
|
||||
|
||||
: onigiri-boot ( path -- )
|
||||
<file-reader> [
|
||||
[
|
||||
deserialize entry set-global
|
||||
deserialize meta set-global
|
||||
deserialize user set-global
|
||||
] with-serialized
|
||||
] with-stream ;
|
|
@ -1,4 +0,0 @@
|
|||
Recent posts sidebar
|
||||
Links sidebar
|
||||
Widgets (Onigirihouse feels ...)
|
||||
Tagging*
|
|
@ -1,7 +0,0 @@
|
|||
body { font: 14px "Trebuchet MS", Arial, Helvetica, sans-serif; }
|
||||
h1, h2, h3, h4, h5, h6 { font-family: lucida grande ; }
|
||||
#header { text-align: center ; }
|
||||
#container { max-width: 720px ; margin: 0 auto; padding: 20px; }
|
||||
.entry { margin-bottom: 75px ; }
|
||||
a { color: #5C832F; text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
|
@ -1,15 +0,0 @@
|
|||
/* == wiky == */
|
||||
*.wiki blockquote { background:#ddd; border:solid 1px #999; margin-left:1em; padding:0.5em;}
|
||||
*.wiki table {
|
||||
border-collapse: collapse;
|
||||
empty-cells: show;
|
||||
}
|
||||
|
||||
*.wiki table td {
|
||||
border: solid 1px black;
|
||||
padding: 0.25em 0.5em 0.25em 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/*pre { font-size:100%; background: #eed; border:1px dotted #999; padding:0 0.5em; overflow:auto; }*/
|
||||
pre { font-family:courier new, monospace; overflow:auto; }
|
|
@ -1,373 +0,0 @@
|
|||
/* This work is licensed under Creative Commons GNU LGPL License.
|
||||
|
||||
License: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
|
||||
Author: Stefan Goessner/2005-06
|
||||
Web: http://goessner.net/
|
||||
*/
|
||||
var Wiky = {
|
||||
version: 0.95,
|
||||
blocks: null,
|
||||
rules: {
|
||||
all: [
|
||||
"Wiky.rules.pre",
|
||||
"Wiky.rules.nonwikiblocks",
|
||||
"Wiky.rules.wikiblocks",
|
||||
"Wiky.rules.post",
|
||||
],
|
||||
pre: [
|
||||
{ rex:/(\r?\n)/g, tmplt:"\xB6" }, // replace line breaks with '¶' ..
|
||||
],
|
||||
post: [
|
||||
{ rex:/(^\xB6)|(\xB6$)/g, tmplt:"" }, // .. remove linebreaks at BOS and EOS ..
|
||||
{ rex:/@([0-9]+)@/g, tmplt:function($0,$1){return Wiky.restore($1);} }, // resolve blocks ..
|
||||
{ rex:/\xB6/g, tmplt:"\n" } // replace '¶' with line breaks ..
|
||||
],
|
||||
nonwikiblocks: [
|
||||
{ rex:/\\([%])/g, tmplt:function($0,$1){return Wiky.store($1);} },
|
||||
{ rex:/\[(?:\{([^}]*)\})?(?:\(([^)]*)\))?%(.*?)%\]/g, tmplt:function($0,$1,$2,$3){return ":p]"+Wiky.store("<pre"+($2?(" lang=\"x-"+Wiky.attr($2)+"\""):"")+Wiky.style($1)+">" + Wiky.apply($3, $2?Wiky.rules.lang[Wiky.attr($2)]:Wiky.rules.code) + "</pre>")+"[p:";} } //programm code block
|
||||
],
|
||||
wikiblocks: [
|
||||
"Wiky.rules.nonwikiinlines",
|
||||
"Wiky.rules.escapes",
|
||||
{ rex:/(?:^|\xB6)(={1,6})(.*?)[=]*(?=\xB6|$)/g, tmplt:function($0,$1,$2){ var h=$1.length; return ":p]\xB6<h"+h+">"+$2+"</h"+h+">\xB6[p:";} }, // <h1> .. <h6>
|
||||
{ rex:/(?:^|\xB6)[-]{4}(?:\xB6|$)/g, tmplt:"\xB6<hr/>\xB6" }, // horizontal ruler ..
|
||||
{ rex:/\\\\([ \xB6])/g, tmplt:"<br/>$1" }, // forced line break ..
|
||||
{ rex:/(^|\xB6)([*01aAiIg]*[\.*])[ ]/g, tmplt:function($0,$1,$2){var state=$2.replace(/([*])/g,"u").replace(/([\.])/,"");return ":"+state+"]"+$1+"["+state+":";}},
|
||||
{ rex:/(?:^|\xB6);[ ](.*?):[ ]/g, tmplt:"\xB6:l][l:$1:d][d:"}, // ; term : definition
|
||||
{ rex:/\[(?:\{([^}]*)\})?(?:\(([^)]*)\))?\"/g, tmplt:function($0,$1,$2){return ":p]<blockquote"+Wiky.attr($2,"cite",0)+Wiky.attr($2,"title",1)+Wiky.style($1)+">[p:"; } }, // block quotation start
|
||||
{ rex:/\"\]/g, tmplt:":p]</blockquote>[p:" }, // block quotation end
|
||||
{ rex:/\[(\{[^}]*\})?\|/g, tmplt:":t]$1[r:" }, // .. start table ..
|
||||
{ rex:/\|\]/g, tmplt:":r][t:" }, // .. end table ..
|
||||
{ rex:/\|\xB6[ ]?\|/g, tmplt:":r]\xB6[r:" }, // .. end/start table row ..
|
||||
{ rex:/\|/g, tmplt:":c][c:" }, // .. end/start table cell ..
|
||||
{ rex:/^(.*)$/g, tmplt:"[p:$1:p]" }, // start paragraph '[p:' at BOS .. end paragraph ':p]' at EOS ..
|
||||
{ rex:/(([\xB6])([ \t\f\v\xB6]*?)){2,}/g, tmplt:":p]$1[p:" }, // .. separate paragraphs at blank lines ..
|
||||
{ rex:/\[([01AIacdgilprtu]+)[:](.*?)[:]([01AIacdgilprtu]+)\]/g, tmplt:function($0,$1,$2,$3){return Wiky.sectionRule($1==undefined?"":$1,"",Wiky.apply($2,Wiky.rules.wikiinlines),!$3?"":$3);} },
|
||||
{ rex:/\[[01AIacdgilprtu]+[:]|[:][01AIacdgilprtu]+\]/g, tmplt:"" }, // .. remove singular section delimiters (they frequently exist with incomplete documents while typing) ..
|
||||
{ rex:/<td>(?:([0-9]*)[>])?([ ]?)(.*?)([ ]?)<\/td>/g, tmplt:function($0,$1,$2,$3,$4){return "<td"+($1?" colspan=\""+$1+"\"":"")+($2==" "?(" style=\"text-align:"+($2==$4?"center":"right")+";\""):($4==" "?" style=\"text-align:left;\"":""))+">"+$2+$3+$4+"</td>";} },
|
||||
{ rex:/<(p|table)>(?:\xB6)?(?:\{(.*?)\})/g, tmplt:function($0,$1,$2){return "<"+$1+Wiky.style($2)+">";} },
|
||||
{ rex:/<p>([ \t\f\v\xB6]*?)<\/p>/g, tmplt:"$1" }, // .. remove empty paragraphs ..
|
||||
"Wiky.rules.shortcuts"
|
||||
],
|
||||
nonwikiinlines: [
|
||||
{ rex:/%(?:\{([^}]*)\})?(?:\(([^)]*)\))?(.*?)%/g, tmplt:function($0,$1,$2,$3){return Wiky.store("<code"+($2?(" lang=\"x-"+Wiky.attr($2)+"\""):"")+Wiky.style($1)+">" + Wiky.apply($3, $2?Wiky.rules.lang[Wiky.attr($2)]:Wiky.rules.code) + "</code>");} }, // inline code
|
||||
{ rex:/%(.*?)%/g, tmplt:function($0,$1){return Wiky.store("<code>" + Wiky.apply($2, Wiky.rules.code) + "</code>");} }
|
||||
],
|
||||
wikiinlines: [
|
||||
{ rex:/\*([^*]+)\*/g, tmplt:"<strong>$1</strong>" }, // .. strong ..
|
||||
{ rex:/_([^_]+)_/g, tmplt:"<em>$1</em>" },
|
||||
{ rex:/\^([^^]+)\^/g, tmplt:"<sup>$1</sup>" },
|
||||
{ rex:/~([^~]+)~/g, tmplt:"<sub>$1</sub>" },
|
||||
{ rex:/\(-(.+?)-\)/g, tmplt:"<del>$1</del>" },
|
||||
{ rex:/\?([^ \t\f\v\xB6]+)\((.+)\)\?/g, tmplt:"<abbr title=\"$2\">$1</abbr>" }, // .. abbreviation ..
|
||||
{ rex:/\[(?:\{([^}]*)\})?[Ii]ma?ge?\:([^ ,\]]*)(?:[, ]([^\]]*))?\]/g, tmplt:function($0,$1,$2,$3){return Wiky.store("<img"+Wiky.style($1)+" src=\""+$2+"\" alt=\""+($3?$3:$2)+"\" title=\""+($3?$3:$2)+"\"/>");} }, // wikimedia image style ..
|
||||
{ rex:/\[([^ ,]+)[, ]([^\]]*)\]/g, tmplt:function($0,$1,$2){return Wiky.store("<a href=\""+$1+"\">"+$2+"</a>");}}, // wiki block style uri's ..
|
||||
{ rex:/(((http(s?))\:\/\/)?[A-Za-z0-9\._\/~\-:]+\.(?:png|jpg|jpeg|gif|bmp))/g, tmplt:function($0,$1,$2){return Wiky.store("<img src=\""+$1+"\" alt=\""+$1+"\"/>");} }, // simple images ..
|
||||
{ rex:/((mailto\:|javascript\:|(news|file|(ht|f)tp(s?))\:\/\/)[A-Za-z0-9\.:_\/~%\-+&#?!=()@\x80-\xB5\xB7\xFF]+)/g, tmplt:"<a href=\"$1\">$1</a>" } // simple uri's ..
|
||||
],
|
||||
escapes: [
|
||||
{ rex:/\\([|*_~\^])/g, tmplt:function($0,$1){return Wiky.store($1);} },
|
||||
{ rex:/\\&/g, tmplt:"&" },
|
||||
{ rex:/\\>/g, tmplt:">" },
|
||||
{ rex:/\\</g, tmplt:"<" }
|
||||
],
|
||||
shortcuts: [
|
||||
{ rex:/---/g, tmplt:"—" }, // —
|
||||
{ rex:/--/g, tmplt:"–" }, // –
|
||||
{ rex:/[\.]{3}/g, tmplt:"…"}, // …
|
||||
{ rex:/<->/g, tmplt:"↔"}, // $harr;
|
||||
{ rex:/<-/g, tmplt:"←"}, // ←
|
||||
{ rex:/->/g, tmplt:"→"}, //→
|
||||
],
|
||||
code: [
|
||||
{ rex:/&/g, tmplt:"&"},
|
||||
{ rex:/</g, tmplt:"<"},
|
||||
{ rex:/>/g, tmplt:">"}
|
||||
],
|
||||
lang: {}
|
||||
},
|
||||
|
||||
inverse: {
|
||||
all: [
|
||||
"Wiky.inverse.pre",
|
||||
"Wiky.inverse.nonwikiblocks",
|
||||
"Wiky.inverse.wikiblocks",
|
||||
"Wiky.inverse.post"
|
||||
],
|
||||
pre: [
|
||||
{ rex:/(\r?\n)/g, tmplt:"\xB6" } // replace line breaks with '¶' ..
|
||||
],
|
||||
post: [
|
||||
{ rex:/@([0-9]+)@/g, tmplt:function($0,$1){return Wiky.restore($1);} }, // resolve blocks ..
|
||||
{ rex:/\xB6/g, tmplt:"\n" } // replace '¶' with line breaks ..
|
||||
],
|
||||
nonwikiblocks: [
|
||||
{ rex:/<pre([^>]*)>(.*?)<\/pre>/mgi, tmplt:function($0,$1,$2){return Wiky.store("["+Wiky.invStyle($1)+Wiky.invAttr($1,["lang"]).replace(/x\-/,"")+"%"+Wiky.apply($2, Wiky.hasAttr($1,"lang")?Wiky.inverse.lang[Wiky.attrVal($1,"lang").substr(2)]:Wiky.inverse.code)+"%]");} } //code block
|
||||
],
|
||||
wikiblocks: [
|
||||
"Wiky.inverse.nonwikiinlines",
|
||||
"Wiky.inverse.escapes",
|
||||
"Wiky.inverse.wikiinlines",
|
||||
{ rex:/<h1>(.*?)<\/h1>/mgi, tmplt:"=$1=" },
|
||||
{ rex:/<h2>(.*?)<\/h2>/mgi, tmplt:"==$1==" },
|
||||
{ rex:/<h3>(.*?)<\/h3>/mgi, tmplt:"===$1===" },
|
||||
{ rex:/<h4>(.*?)<\/h4>/mgi, tmplt:"====$1====" },
|
||||
{ rex:/<h5>(.*?)<\/h5>/mgi, tmplt:"=====$1=====" },
|
||||
{ rex:/<h6>(.*?)<\/h6>/mgi, tmplt:"======$1======" },
|
||||
{ rex:/<(p|table)[^>]+(style=\"[^\"]*\")[^>]*>/mgi, tmplt:function($0,$1,$2){return "<"+$1+">"+Wiky.invStyle($2);} },
|
||||
{ rex:/\xB6{2}<li/mgi, tmplt:"\xB6<li" }, // ie6 only ..
|
||||
{ rex:/<li class=\"?([^ >\"]*)\"?[^>]*?>([^<]*)/mgi, tmplt:function($0,$1,$2){return $1.replace(/u/g,"*").replace(/([01aAiIg])$/,"$1.")+" "+$2;}}, // list items ..
|
||||
{ rex:/(^|\xB6)<(u|o)l[^>]*?>\xB6/mgi, tmplt:"$1" }, // only outer level list start at BOL ...
|
||||
{ rex:/(<\/(?:dl|ol|ul|p)>[ \xB6]*<(?:p)>)/gi, tmplt:"\xB6\xB6" },
|
||||
{ rex:/<dt>(.*?)<\/dt>[ \f\n\r\t\v]*<dd>/mgi, tmplt:"; $1: " },
|
||||
{ rex:/<blockquote([^>]*)>/mgi, tmplt:function($0,$1){return Wiky.store("["+Wiky.invStyle($1)+Wiky.invAttr($1,["cite","title"])+"\"");} },
|
||||
{ rex:/<\/blockquote>/mgi, tmplt:"\"]" },
|
||||
{ rex:/<td class=\"?lft\"?>\xB6*[ ]?|<\/tr>/mgi, tmplt:"|" }, // ie6 only ..
|
||||
{ rex:/\xB6<tr(?:[^>]*?)>/mgi, tmplt:"\xB6" },
|
||||
{ rex:/<td colspan=\"([0-9]+)\"(?:[^>]*?)>/mgi, tmplt:"|$1>" },
|
||||
{ rex:/<td(?:[^>]*?)>/mgi, tmplt:"|" },
|
||||
{ rex:/<table>/mgi, tmplt:"[" },
|
||||
{ rex:/<\/table>/mgi, tmplt:"]" },
|
||||
{ rex:/<tr(?:[^>]*?)>\xB6*|<\/td>\xB6*|<tbody>\xB6*|<\/tbody>/mgi, tmplt:"" },
|
||||
{ rex:/<hr\/?>/mgi, tmplt:"----" },
|
||||
{ rex:/<br\/?>/mgi, tmplt:"\\\\" },
|
||||
{ rex:/(<p>|<(d|o|u)l[^>]*>|<\/(dl|ol|ul|p)>|<\/(li|dd)>)/mgi, tmplt:"" },
|
||||
"Wiky.inverse.shortcuts"
|
||||
],
|
||||
nonwikiinlines: [
|
||||
{ rex:/<code>(.*?)<\/code>/g, tmplt:function($0,$1){return Wiky.store("%"+Wiky.apply($1, Wiky.inverse["code"])+"%");} }
|
||||
],
|
||||
wikiinlines: [
|
||||
{ rex:/<strong[^>]*?>(.*?)<\/strong>/mgi, tmplt:"*$1*" },
|
||||
{ rex:/<b[^>]*?>(.*?)<\/b>/mgi, tmplt:"*$1*" },
|
||||
{ rex:/<em[^>]*?>(.*?)<\/em>/mgi, tmplt:"_$1_" },
|
||||
{ rex:/<i[^>]*?>(.*?)<\/i>/mgi, tmplt:"_$1_" },
|
||||
{ rex:/<sup[^>]*?>(.*?)<\/sup>/mgi, tmplt:"^$1^" },
|
||||
{ rex:/<sub[^>]*?>(.*?)<\/sub>/mgi, tmplt:"~$1~" },
|
||||
{ rex:/<del[^>]*?>(.*?)<\/del>/mgi, tmplt:"(-$1-)" },
|
||||
{ rex:/<abbr title=\"([^\"]*)\">(.*?)<\/abbr>/mgi, tmplt:"?$2($1)?" },
|
||||
{ rex:/<a href=\"([^\"]*)\"[^>]*?>(.*?)<\/a>/mgi, tmplt:function($0,$1,$2){return $1==$2?$1:"["+$1+","+$2+"]";}},
|
||||
{ rex:/<img([^>]*)\/>/mgi, tmplt:function($0,$1){var a=Wiky.attrVal($1,"alt"),h=Wiky.attrVal($1,"src"),t=Wiky.attrVal($1,"title"),s=Wiky.attrVal($1,"style");return s||(t&&h!=t)?("["+Wiky.invStyle($1)+"img:"+h+(t&&(","+t))+"]"):h;}},
|
||||
],
|
||||
escapes: [
|
||||
{ rex:/([|*_~%\^])/g, tmplt:"\\$1" },
|
||||
{ rex:/&/g, tmplt:"\\&" },
|
||||
{ rex:/>/g, tmplt:"\\>" },
|
||||
{ rex:/</g, tmplt:"\\<" }
|
||||
],
|
||||
shortcuts: [
|
||||
{ rex:/–|\u2013/g, tmplt:"--"},
|
||||
{ rex:/—|\u2014/g, tmplt:"---"},
|
||||
{ rex:/…|\u2026/g, tmplt:"..."},
|
||||
{ rex:/↔|\u2194/g, tmplt:"<->"},
|
||||
{ rex:/←|\u2190/g, tmplt:"<-"},
|
||||
{ rex:/→|\u2192/g, tmplt:"->"}
|
||||
],
|
||||
code: [
|
||||
{ rex:/&/g, tmplt:"&"},
|
||||
{ rex:/</g, tmplt:"<"},
|
||||
{ rex:/>/g, tmplt:">"}
|
||||
],
|
||||
lang: {}
|
||||
},
|
||||
|
||||
toHtml: function(str) {
|
||||
Wiky.blocks = [];
|
||||
return Wiky.apply(str, Wiky.rules.all);
|
||||
},
|
||||
|
||||
toWiki: function(str) {
|
||||
Wiky.blocks = [];
|
||||
return Wiky.apply(str, Wiky.inverse.all);
|
||||
},
|
||||
|
||||
apply: function(str, rules) {
|
||||
if (str && rules)
|
||||
for (var i in rules) {
|
||||
if (typeof(rules[i]) == "string")
|
||||
str = Wiky.apply(str, eval(rules[i]));
|
||||
else
|
||||
str = str.replace(rules[i].rex, rules[i].tmplt);
|
||||
}
|
||||
return str;
|
||||
},
|
||||
store: function(str, unresolved) {
|
||||
return unresolved ? "@" + (Wiky.blocks.push(str)-1) + "@"
|
||||
: "@" + (Wiky.blocks.push(str.replace(/@([0-9]+)@/g, function($0,$1){return Wiky.restore($1);}))-1) + "@";
|
||||
},
|
||||
restore: function(idx) {
|
||||
return Wiky.blocks[idx];
|
||||
},
|
||||
attr: function(str, name, idx) {
|
||||
var a = str && str.split(",")[idx||0];
|
||||
return a ? (name ? (" "+name+"=\""+a+"\"") : a) : "";
|
||||
},
|
||||
hasAttr: function(str, name) {
|
||||
return new RegExp(name+"=").test(str);
|
||||
},
|
||||
attrVal: function(str, name) {
|
||||
return str.replace(new RegExp("^.*?"+name+"=\"(.*?)\".*?$"), "$1");
|
||||
},
|
||||
invAttr: function(str, names) {
|
||||
var a=[], x;
|
||||
for (var i in names)
|
||||
if (str.indexOf(names[i]+"=")>=0)
|
||||
a.push(str.replace(new RegExp("^.*?"+names[i]+"=\"(.*?)\".*?$"), "$1"));
|
||||
return a.length ? ("("+a.join(",")+")") : "";
|
||||
},
|
||||
style: function(str) {
|
||||
var s = str && str.split(/,|;/), p, style = "";
|
||||
for (var i in s) {
|
||||
p = s[i].split(":");
|
||||
if (p[0] == ">") style += "margin-left:4em;";
|
||||
else if (p[0] == "<") style += "margin-right:4em;";
|
||||
else if (p[0] == ">>") style += "float:right;";
|
||||
else if (p[0] == "<<") style += "float:left;";
|
||||
else if (p[0] == "=") style += "display:block;margin:0 auto;";
|
||||
else if (p[0] == "_") style += "text-decoration:underline;";
|
||||
else if (p[0] == "b") style += "border:solid 1px;";
|
||||
else if (p[0] == "c") style += "color:"+p[1]+";";
|
||||
else if (p[0] == "C") style += "background:"+p[1]+";";
|
||||
else if (p[0] == "w") style += "width:"+p[1]+";";
|
||||
else style += p[0]+":"+p[1]+";";
|
||||
}
|
||||
return style ? " style=\""+style+"\"" : "";
|
||||
},
|
||||
invStyle: function(str) {
|
||||
var s = /style=/.test(str) ? str.replace(/^.*?style=\"(.*?)\".*?$/, "$1") : "",
|
||||
p = s && s.split(";"), pi, prop = [];
|
||||
for (var i in p) {
|
||||
pi = p[i].split(":");
|
||||
if (pi[0] == "margin-left" && pi[1]=="4em") prop.push(">");
|
||||
else if (pi[0] == "margin-right" && pi[1]=="4em") prop.push("<");
|
||||
else if (pi[0] == "float" && pi[1]=="right") prop.push(">>");
|
||||
else if (pi[0] == "float" && pi[1]=="left") prop.push("<<");
|
||||
else if (pi[0] == "margin" && pi[1]=="0 auto") prop.push("=");
|
||||
else if (pi[0] == "display" && pi[1]=="block") ;
|
||||
else if (pi[0] == "text-decoration" && pi[1]=="underline") prop.push("_");
|
||||
else if (pi[0] == "border" && pi[1]=="solid 1px") prop.push("b");
|
||||
else if (pi[0] == "color") prop.push("c:"+pi[1]);
|
||||
else if (pi[0] == "background") prop.push("C:"+pi[1]);
|
||||
else if (pi[0] == "width") prop.push("w:"+pi[1]);
|
||||
else if (pi[0]) prop.push(pi[0]+":"+pi[1]);
|
||||
}
|
||||
return prop.length ? ("{" + prop.join(",") + "}") : "";
|
||||
},
|
||||
sectionRule: function(fromLevel, style, content, toLevel) {
|
||||
var trf = { p_p: "<p>$1</p>",
|
||||
p_u: "<p>$1</p><ul$3>",
|
||||
p_o: "<p>$1</p><ol$3>",
|
||||
// p - ul
|
||||
// ul - p
|
||||
u_p: "<li$2>$1</li></ul>",
|
||||
u_c: "<li$2>$1</li></ul></td>",
|
||||
u_r: "<li$2>$1</li></ul></td></tr>",
|
||||
uu_p: "<li$2>$1</li></ul></li></ul>",
|
||||
uo_p: "<li$2>$1</li></ol></li></ul>",
|
||||
uuu_p: "<li$2>$1</li></ul></li></ul></li></ul>",
|
||||
uou_p: "<li$2>$1</li></ul></li></ol></li></ul>",
|
||||
uuo_p: "<li$2>$1</li></ol></li></ul></li></ul>",
|
||||
uoo_p: "<li$2>$1</li></ol></li></ol></li></ul>",
|
||||
// ul - ul
|
||||
u_u: "<li$2>$1</li>",
|
||||
uu_u: "<li$2>$1</li></ul></li>",
|
||||
uo_u: "<li$2>$1</li></ol></li>",
|
||||
uuu_u: "<li$2>$1</li></ul></li></ul></li>",
|
||||
uou_u: "<li$2>$1</li></ul></li></ol></li>",
|
||||
uuo_u: "<li$2>$1</li></ol></li></ul></li>",
|
||||
uoo_u: "<li$2>$1</li></ol></li></ol></li>",
|
||||
u_uu: "<li$2>$1<ul$3>",
|
||||
// ul - ol
|
||||
u_o: "<li$2>$1</li></ul><ol$3>",
|
||||
uu_o: "<li$2>$1</li></ul></li></ul><ol$3>",
|
||||
uo_o: "<li$2>$1</li></ol></li></ul><ol$3>",
|
||||
uuu_o: "<li$2>$1</li></ul></li></ul></li></ul><ol$3>",
|
||||
uou_o: "<li$2>$1</li></ul></li></ol></li></ul><ol$3>",
|
||||
uuo_o: "<li$2>$1</li></ol></li></ul></li></ul><ol$3>",
|
||||
uoo_o: "<li$2>$1</li></ol></li></ol></li></ul><ol$3>",
|
||||
u_uo: "<li$2>$1<ol$3>",
|
||||
// ol - p
|
||||
o_p: "<li$2>$1</li></ol>",
|
||||
oo_p: "<li$2>$1</li></ol></li></ol>",
|
||||
ou_p: "<li$2>$1</li></ul></li></ol>",
|
||||
ooo_p: "<li$2>$1</li></ol></li></ol>",
|
||||
ouo_p: "<li$2>$1</li></ol></li></ul></li></ol>",
|
||||
oou_p: "<li$2>$1</li></ul></li></ol></li></ol>",
|
||||
ouu_p: "<li$2>$1</li></ul></li></ul></li></ol>",
|
||||
// ol - ul
|
||||
o_u: "<li$2>$1</li></ol><ul$3>",
|
||||
oo_u: "<li$2>$1</li></ol></li></ol><ul$3>",
|
||||
ou_u: "<li$2>$1</li></ul></li></ol><ul$3>",
|
||||
ooo_u: "<li$2>$1</li></ol></li></ol></li></ol><ul$3>",
|
||||
ouo_u: "<li$2>$1</li></ol></li></ul></li></ol><ul$3>",
|
||||
oou_u: "<li$2>$1</li></ul></li></ol></li></ol><ul$3>",
|
||||
ouu_u: "<li$2>$1</li></ul></li></ul></li></ol><ul$3>",
|
||||
o_ou: "<li$2>$1<ul$3>",
|
||||
// -- ol - ol --
|
||||
o_o: "<li$2>$1</li>",
|
||||
oo_o: "<li$2>$1</li></ol></li>",
|
||||
ou_o: "<li$2>$1</li></ul></li>",
|
||||
ooo_o: "<li$2>$1</li></ol></li></ol></li>",
|
||||
ouo_o: "<li$2>$1</li></ol></li></ul></li>",
|
||||
oou_o: "<li$2>$1</li></ul></li></ol></li>",
|
||||
ouu_o: "<li$2>$1</li></ul></li></ul></li>",
|
||||
o_oo: "<li$2>$1<ol$3>",
|
||||
// -- dl --
|
||||
l_d: "<dt>$1</dt>",
|
||||
d_l: "<dd>$1</dd>",
|
||||
d_u: "<dd>$1</dd></dl><ul>",
|
||||
d_o: "<dd>$1</dd></dl><ol>",
|
||||
p_l: "<p>$1</p><dl>",
|
||||
u_l: "<li$2>$1</li></ul><dl>",
|
||||
o_l: "<li$2>$1</li></ol><dl>",
|
||||
uu_l: "<li$2>$1</li></ul></li></ul><dl>",
|
||||
uo_l: "<li$2>$1</li></ol></li></ul><dl>",
|
||||
ou_l: "<li$2>$1</li></ul></li></ol><dl>",
|
||||
oo_l: "<li$2>$1</li></ol></li></ol><dl>",
|
||||
d_p: "<dd>$1</dd></dl>",
|
||||
// -- table --
|
||||
p_t: "<p>$1</p><table>",
|
||||
p_r: "<p>$1</p></td></tr>",
|
||||
p_c: "<p>$1</p></td>",
|
||||
t_p: "</table><p>$1</p>",
|
||||
r_r: "<tr><td>$1</td></tr>",
|
||||
r_p: "<tr><td><p>$1</p>",
|
||||
r_c: "<tr><td>$1</td>",
|
||||
r_u: "<tr><td>$1<ul>",
|
||||
c_p: "<td><p>$1</p>",
|
||||
c_r: "<td>$1</td></tr>",
|
||||
c_c: "<td>$1</td>",
|
||||
// c_u: "<td>$1<ul>",
|
||||
u_t: "<li$2>$1</li></ul><table>",
|
||||
o_t: "<li$2>$1</li></ol><table>",
|
||||
d_t: "<dd>$1</dd></dl><table>",
|
||||
t_u: "</table><p>$1</p><ul>",
|
||||
t_o: "</table><p>$1</p><ol>",
|
||||
t_l: "</table><p>$1</p><dl>"
|
||||
};
|
||||
var type = { "0": "decimal-leading-zero",
|
||||
"1": "decimal",
|
||||
"a": "lower-alpha",
|
||||
"A": "upper-alpha",
|
||||
"i": "lower-roman",
|
||||
"I": "upper-roman",
|
||||
"g": "lower-greek" };
|
||||
|
||||
var from = "", to = "", maxlen = Math.max(fromLevel.length, toLevel.length), sync = true, sectiontype = type[toLevel.charAt(toLevel.length-1)], transition;
|
||||
|
||||
for (var i=0; i<maxlen; i++)
|
||||
if (fromLevel.charAt(i+1) != toLevel.charAt(i+1) || !sync || i == maxlen-1)
|
||||
{
|
||||
from += fromLevel.charAt(i) == undefined ? " " : fromLevel.charAt(i);
|
||||
to += toLevel.charAt(i) == undefined ? " " : toLevel.charAt(i);
|
||||
sync = false;
|
||||
}
|
||||
transition = (from + "_" + to).replace(/([01AIagi])/g, "o");
|
||||
return !trf[transition] ? ("?(" + transition + ")") // error string !
|
||||
: trf[transition].replace(/\$2/, " class=\"" + fromLevel + "\"")
|
||||
.replace(/\$3/, !sectiontype ? "" : (" style=\"list-style-type:" + sectiontype + ";\""))
|
||||
.replace(/\$1/, content)
|
||||
.replace(/<p><\/p>/, "");
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
pre.syntax { font-size:100%; background: #eed; border:1px dotted #999; padding:0 0.5em; overflow:auto; }
|
||||
span.cmt { font-style: italic; color: green; }
|
||||
span.str { font-style: italic; color: darkred; }
|
||||
span.kwd { color: blue; }
|
||||
span.obj { color: purple; }
|
||||
span.mbr { color: gray; }
|
||||
span.xtag { color: blue; }
|
||||
span.xnam { color: purple; }
|
||||
span.xval { font-style: italic; color: darkred; }
|
|
@ -1,40 +0,0 @@
|
|||
/* This work is licensed under Creative Commons GNU LGPL License.
|
||||
|
||||
License: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
|
||||
Author: Stefan Goessner/2005-06
|
||||
Web: http://goessner.net/
|
||||
|
||||
credits: http://www.regular-expressions.info/examplesprogrammer.html
|
||||
*/
|
||||
Wiky.rules.lang.js = [
|
||||
"Wiky.rules.code",
|
||||
{ rex:/"([^"\\\xB6]*(\\.[^"\\\xB6]*)*)"/g, tmplt:function($0,$1){return Wiky.store("<span class=\"str\">\""+$1+"\"</span>");}}, // string delimited by '"' with '\"' allowed ..
|
||||
{ rex:/'([^'\\\xB6]*(\\.[^'\\\xB6]*)*)'/g, tmplt:function($0,$1){return Wiky.store("<span class=\"str\">\'"+$1+"\'</span>");}}, // string delimited by "'" with "\'" allowed ..
|
||||
{ rex:/\/\/(.*?)(?:\xB6|$)/g, tmplt:function($0,$1){return Wiky.store("<span class\=\"cmt\">//"+$1+"</span>\xB6");}}, // single line comment
|
||||
{ rex:/\/\*(.*?)\*\//g, tmplt:function($0,$1){return Wiky.store("<span class\=\"cmt\">\/*"+$1+"*\/</span>");}}, // multi-line comment
|
||||
// { rex:/([\]\[\-+\|*!%<>=\{\}?:,\)\(]+)|("|/|=)+/g, tmplt:"<span class=\"op\">$1</span>"}, // operators
|
||||
{ rex:/\b(break|case|catch|continue|do|else|false|for|function|if|in|new|return|switch|this|throw|true|try|var|while|with)\b/g, tmplt:"<span class=\"kwd\">$1</span>" }, // keywords
|
||||
{ rex:/\b(arguments|Array|Boolean|Date|Error|Function|Global|Math|Number|Object|RegExp|String)\b/g, tmplt:"<span class=\"obj\">$1</span>" }, // objects
|
||||
{ rex:/\.(abs|acos|anchor|arguments|asin|atan|atan2|big|blink|bold|callee|caller|ceil|charAt|charCodeAt|concat|constructor|cos|E|escape|eval|exp|fixed|floor|fontcolor|fontsize|fromCharCode|getDate|getDay|getFullYear|getHours|getMilliseconds|getMinutes|getMonth|getSeconds|getTime|getTimezoneOffset|getUTCDate|getUTCDay|getUTCFullYear|getUTCHours|getUTCMilliseconds|getUTCMinutes|getUTCMonth|getUTCSeconds|getVarDate|getYear|index|indexOf|Infinity|input|isFinite|isNaN|italics|join|lastIndex|lastIndexOf|lastMatch|lastParen|leftContext|length|link|LN10|LN2|log|LOG10E|LOG2E|match|max|MAX_VALUE|min|MIN_VALUE|NaN|NaN|NEGATIVE_INFINITY|parse|parseFloat|parseInt|PI|pop|POSITIVE_INFINITY|pow|prototype|push|random|replace|reverse|rightContext|round|search|setDate|setFullYear|setHours|setMilliseconds|setMinutes|setMonth|setSeconds|setTime|setUTCDate|setUTCFullYear|setUTCHours|setUTCMilliseconds|setUTCMinutes|setUTCMonth|setUTCSeconds|setYear|shift|sin|slice|slice|small|sort|splice|split|sqrt|SQRT1_2|SQRT2|strike|sub|substr|substring|sup|tan|toGMTString|toLocaleString|toLowerCase|toString|toUpperCase|toUTCString|unescape|unshift|UTC|valueOf)\b/g, tmplt:".<span class=\"mbr\">$1</span>" }, // members
|
||||
];
|
||||
Wiky.rules.lang.xml = [
|
||||
{ rex:/<script([^>]*)>(.*?)<\/script>/g, tmplt:function($0,$1,$2){return "<script"+$1+">"+Wiky.store(Wiky.apply($2, Wiky.rules.lang.js))+"</script>";} }, // script blocks ..
|
||||
{ rex:/<!\[CDATA\[(.*?)\]\]>/g, tmplt:function($0,$1){return Wiky.store("<![CDATA["+$1+"]]>");} }, // CDATA sections, ..
|
||||
{ rex:/<!(.*?)>/g, tmplt:function($0,$1){return Wiky.store("<span class=\"cmt\"><!"+$1+"></span>");} }, // inline xml comments, doctypes, ..
|
||||
{ rex:/</g, tmplt:"\xAB"}, // replace '<' by '«'
|
||||
{ rex:/>/g, tmplt:"\xBB"}, // replace '>' by '»'
|
||||
{ rex:/([-A-Za-z0-9_:]+)[ ]*=[ ]*\"(.*?)\"/g, tmplt:"<span class=\"xnam\">$1</span>=<span class=\"xval\">"$2"</span>"}, // "xml attribute value strings ..
|
||||
{ rex:/(\xAB[\/]?)([-A-Za-z0-9_:]+)/g, tmplt:"$1<span class=\"xtag\">$2</span>"}, // "xml tag ..
|
||||
{ rex:/\xAB/g, tmplt:"<"}, // replace '«' by '<'
|
||||
{ rex:/\xBB/g, tmplt:">"}, // replace '»' by '>'
|
||||
];
|
||||
Wiky.inverse.lang.js = [
|
||||
{ rex:/<span class=\"?(cmt|kwd|mbr|obj|str)\"?>|<\/span>/mgi, tmplt:"" },
|
||||
{ rex:/<strong>(.*?)<\/strong>/mgi, tmplt:"[*$1*]" },
|
||||
"Wiky.inverse.code"
|
||||
];
|
||||
Wiky.inverse.lang.xml = [
|
||||
{ rex:/<span class=\"?(cmt|xtag|xnam|xval)\"?>|<\/span>/mgi, tmplt:"" },
|
||||
"Wiky.inverse.lang.js"
|
||||
];
|
|
@ -1,88 +0,0 @@
|
|||
/* math */
|
||||
dfn, div.eq {
|
||||
white-space: nowrap;
|
||||
font-family: sans-serif;
|
||||
font-style: normal;
|
||||
color: navy;
|
||||
}
|
||||
div.eq {
|
||||
margin-left: 3em;
|
||||
margin-right: 1em;
|
||||
}
|
||||
div.eq a {float:right}
|
||||
|
||||
span.h { /* huge */
|
||||
font-size:150%;
|
||||
}
|
||||
|
||||
span.o, span.s, span.f {
|
||||
display:-moz-inline-box;
|
||||
-moz-box-orient:vertical;
|
||||
display:inline-block;
|
||||
vertical-align:middle;
|
||||
margin:0 0.2em;
|
||||
}
|
||||
|
||||
span.x, span.i, span.d, span.n, span.o span {
|
||||
display: block;
|
||||
}
|
||||
|
||||
span.x, span.d, span.n, span.s, span.o span {
|
||||
text-align:center;
|
||||
margin:0 0.2em;
|
||||
}
|
||||
|
||||
span.n, span.d {
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
span.i {
|
||||
text-align: left;
|
||||
margin:0 0.2em 0 0;
|
||||
}
|
||||
span.b {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.x, span.i, span.f span.f {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
span.n {
|
||||
border-bottom:solid 1px navy;
|
||||
}
|
||||
|
||||
span.v, span.m {
|
||||
display:-moz-inline-box;
|
||||
-moz-box-orient:vertical;
|
||||
display:inline-block;
|
||||
vertical-align:middle;
|
||||
}
|
||||
span.v span.e, span.m span.e {
|
||||
font-size: 90%;
|
||||
white-space:nowrap;
|
||||
display: block;
|
||||
text-align:center;
|
||||
margin:0.2em;
|
||||
}
|
||||
/*span.m > span.e { height:2em; }*/ /* hide ie 6 */
|
||||
|
||||
span.lb, span.rb {
|
||||
margin:0;
|
||||
padding:0;
|
||||
vertical-align: middle;
|
||||
border-top:1px solid navy;
|
||||
border-bottom:1px solid navy;
|
||||
}
|
||||
span.lb {
|
||||
border-left:1px solid navy;
|
||||
}
|
||||
span.rb {
|
||||
border-right:1px solid navy;
|
||||
}
|
||||
span.lbrk2, span.rbrk2 {
|
||||
font-size:200%;
|
||||
}
|
||||
span.lbrk3, span.rbrk3 {
|
||||
font-size:300%;
|
||||
}
|
|
@ -1,374 +0,0 @@
|
|||
/* This work is licensed under Creative Commons GNU LGPL License.
|
||||
|
||||
License: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
|
||||
Author: Stefan Goessner/2005-06
|
||||
Web: http://goessner.net/
|
||||
inspired by: http://xml-maiden.com/
|
||||
*/
|
||||
Wiky.rules.math = {
|
||||
version: 0.95,
|
||||
preshortcuts: [
|
||||
// { rex:/[ ]/g, tmplt:"`"}, // omit due to charset support ie6
|
||||
{ rex:/\+\-/g, tmplt:"±"},
|
||||
{ rex:/\/O|\\Oslash/g, tmplt:"Ø"},
|
||||
{ rex:/\/o|\\oslash/g, tmplt:"ø"},
|
||||
{ rex:/<->|\\harr/g, tmplt:"↔"},
|
||||
{ rex:/<-|\\larr/g, tmplt:"←"},
|
||||
{ rex:/->|\\rarr/g, tmplt:"→"},
|
||||
{ rex:/<=>|\\hArr/g, tmplt:"⇔"},
|
||||
{ rex:/=>|\\rArr/g, tmplt:"⇒"},
|
||||
{ rex:/-=|\\equiv/g, tmplt:"≡"},
|
||||
{ rex:/<=|\\le/g, tmplt:"≤"},
|
||||
{ rex:/>=|\\ge/g, tmplt:"≥"},
|
||||
{ rex:/</g, tmplt:"<"},
|
||||
{ rex:/>/g, tmplt:">"}
|
||||
],
|
||||
postshortcuts: [
|
||||
{ rex:/\*|\\middot/g, tmplt:"·"},
|
||||
{ rex:/\\x|\\times/g, tmplt:"×"},
|
||||
{ rex:/~=|\\cong/g, tmplt:"≅"},
|
||||
{ rex:/~~|\\asymp/g, tmplt:"≈"},
|
||||
{ rex:/~|\\sim/g, tmplt:"∼"},
|
||||
{ rex:/!=|\\neq|\\ne/g, tmplt:"≠"},
|
||||
{ rex:/\.\.\.|\\ldots/g, tmplt:"…"},
|
||||
{ rex:/\\in|\\isin/g, tmplt:"∈"},
|
||||
{ rex:/([0-9])x([0-9])/g, tmplt:"$1×$2"},
|
||||
{ rex:/([A-Za-z]) x ([A-Za-z])/g, tmplt:"$1×$2"},
|
||||
// { rex:/[`]{4}/g, tmplt:" "}, // omit due to charset support ie6
|
||||
// { rex:/[`]{3}/g, tmplt:" "},
|
||||
// { rex:/[`]{2}/g, tmplt:" "},
|
||||
// { rex:/[`]/g, tmplt:" "},
|
||||
{ rex:/\{/g, tmplt:"‎"}, // unvisible left-to-right mark,
|
||||
{ rex:/\}/g, tmplt:"‏"} // unvisible right-to-left mark,
|
||||
],
|
||||
expr: [
|
||||
{ rex:/\^\^/g, tmplt:"^^"}, // ^ overindex
|
||||
{ rex:/(\\sum|\\prod|\\int)_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span class=\"x\">$3</span>$1<span class=\"x\">$2</span></span>"}, // over-/underscript (\sum, \prod, \int)
|
||||
{ rex:/(\\sum|\\prod|\\int)\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span class=\"x\">$2</span>$1<span> </span></span>"},
|
||||
{ rex:/(\\sum|\\prod|\\int)_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span> </span>$1<span class=\"x\">$2</span></span>"},
|
||||
{ rex:/_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"s\"><span class=\"i\">$2</span><span class=\"i\">$1</span></span>"}, // over-/underindex
|
||||
{ rex:/\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sup class=\"i\">$1</sup>"}, // overindex
|
||||
{ rex:/_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sub class=\"i\">$1</sub>"}, // underindex
|
||||
{ rex:/-/g, tmplt:"−"},
|
||||
{ rex:/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"f\"><span class=\"n\">$1</span><span class=\"d\">$2</span></span>"}, // fraction
|
||||
{ rex:/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\/\/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sup>$1</sup>⁄<sub>$2</sub>"}, // fraction
|
||||
{ rex:/\[((\[(([^,\]]+[,]){1,}[^\]]+)\][ \n]*){1,})\]/g, tmplt:function($0,$1){var m=Wiky.math.transpose($1.replace(/(^\[|\]$)/g,"").replace(/(\][ \n]*\[)/g,"|").split("|")),sz=" style=\"font-size:"+(m.len)+"00%;\"";/*alert("{("+m.mat.join(")}\n{(").split(",").join(")(")+")}");*/ return "<span class=\"lb\""+sz+">"+Wiky.math.fence()+"</span><span class=\"m\"><span class=\"e\">"+m.mat.join("</span></span>\n<span class=\"m\"><span class=\"e\">").split(",").join("</span><span class=\"e\">")+"</span></span><span class=\"rb\""+sz+">"+Wiky.math.fence()+"</span>";}}, // matrix
|
||||
{ rex:/\[((?:[^,\]]){1,}[^\]]+)\]/g, tmplt:function($0,$1){var v=$1.split(","),sz=" style=\"font-size:"+v.length+"00%;\""; return "<span class=\"lb\""+sz+">"+Wiky.math.fence()+"</span><span class=\"v\"><span class=\"e\">"+v.join("</span><span class=\"e\">")+"</span></span><span class=\"rb\""+sz+">"+Wiky.math.fence()+"</span>";}}, // vector
|
||||
{ rex:/!([a-zA-Z0-9\.&;]+)/g, tmplt:"<span class=\"b\">$1</span>" }, // bold vector symbol ..
|
||||
{ rex:/\\prod/g, tmplt:"<span class=\"h\">∏</span>"},
|
||||
{ rex:/\\sum/g, tmplt:"<span class=\"h\">∑</span>"},
|
||||
{ rex:/\\int/g, tmplt:"<span class=\"h\">∫</span>"},
|
||||
"Wiky.rules.math.postshortcuts"
|
||||
],
|
||||
symbols: [
|
||||
{ rex:/\\Alpha/g, tmplt:"Α"},
|
||||
{ rex:/\\Beta/g, tmplt:"Β"},
|
||||
{ rex:/\\Gamma/g, tmplt:"Γ"},
|
||||
{ rex:/\\Delta/g, tmplt:"Δ"},
|
||||
{ rex:/\\Epsilon/g, tmplt:"Ε"},
|
||||
{ rex:/\\Zeta/g, tmplt:"Ζ"},
|
||||
{ rex:/\\Eta/g, tmplt:"Η"},
|
||||
{ rex:/\\Theta/g, tmplt:"Θ"},
|
||||
{ rex:/\\Iota/g, tmplt:"Ι"},
|
||||
{ rex:/\\Kappa/g, tmplt:"Κ"},
|
||||
{ rex:/\\Lambda/g, tmplt:"Λ"},
|
||||
{ rex:/\\Mu/g, tmplt:"Μ"},
|
||||
{ rex:/\\Nu/g, tmplt:"Ν"},
|
||||
{ rex:/\\Xi/g, tmplt:"Ξ"},
|
||||
{ rex:/\\Omicron/g, tmplt:"Ο"},
|
||||
{ rex:/\\Pi/g, tmplt:"Π"},
|
||||
{ rex:/\\Rho/g, tmplt:"Ρ"},
|
||||
{ rex:/\\Sigma/g, tmplt:"Σ"},
|
||||
{ rex:/\\Tau/g, tmplt:"Τ"},
|
||||
{ rex:/\\Upsilon/g, tmplt:"Υ"},
|
||||
{ rex:/\\Phi/g, tmplt:"Φ"},
|
||||
{ rex:/\\Chi/g, tmplt:"Χ"},
|
||||
{ rex:/\\Psi/g, tmplt:"Ψ"},
|
||||
{ rex:/\\Omega/g, tmplt:"Ω"},
|
||||
{ rex:/\\alpha/g, tmplt:"α"},
|
||||
{ rex:/\\beta/g, tmplt:"β"},
|
||||
{ rex:/\\gamma/g, tmplt:"γ"},
|
||||
{ rex:/\\delta/g, tmplt:"δ"},
|
||||
{ rex:/\\epsilon/g, tmplt:"ε"},
|
||||
{ rex:/\\zeta/g, tmplt:"ζ"},
|
||||
{ rex:/\\eta/g, tmplt:"η"},
|
||||
{ rex:/\\thetasym/g, tmplt:"ϑ"},
|
||||
{ rex:/\\theta/g, tmplt:"θ"},
|
||||
{ rex:/\\iota/g, tmplt:"ι"},
|
||||
{ rex:/\\kappa/g, tmplt:"κ"},
|
||||
{ rex:/\\lambda/g, tmplt:"λ"},
|
||||
{ rex:/\\mu/g, tmplt:"μ"},
|
||||
{ rex:/\\nu/g, tmplt:"ν"},
|
||||
{ rex:/\\xi/g, tmplt:"ξ"},
|
||||
{ rex:/\\omicron/g, tmplt:"ο"},
|
||||
{ rex:/\\piv/g, tmplt:"ϖ"},
|
||||
{ rex:/\\pi/g, tmplt:"π"},
|
||||
{ rex:/\\rho/g, tmplt:"ρ"},
|
||||
{ rex:/\\sigmaf/g, tmplt:"ς"},
|
||||
{ rex:/\\sigma/g, tmplt:"σ"},
|
||||
{ rex:/\\tau/g, tmplt:"τ"},
|
||||
{ rex:/\\upsilon/g, tmplt:"υ"},
|
||||
{ rex:/\\phi/g, tmplt:"φ"},
|
||||
{ rex:/\\chi/g, tmplt:"χ"},
|
||||
{ rex:/\\psi/g, tmplt:"ψ"},
|
||||
{ rex:/\\omega/g, tmplt:"ω"},
|
||||
{ rex:/\\upsih/g, tmplt:"ϒ"},
|
||||
// miscellaneous symbols
|
||||
{ rex:/\\bull/g, tmplt:"•"},
|
||||
{ rex:/\\uarr/g, tmplt:"↑"},
|
||||
{ rex:/\\darr/g, tmplt:"↓"},
|
||||
{ rex:/\\crarr/g, tmplt:"↵"},
|
||||
{ rex:/\\lArr/g, tmplt:"⇐"},
|
||||
{ rex:/\\uArr/g, tmplt:"⇑"},
|
||||
{ rex:/\\dArr/g, tmplt:"⇓"},
|
||||
{ rex:/\\forall/g, tmplt:"∀"},
|
||||
{ rex:/\\part/g, tmplt:"∂"},
|
||||
{ rex:/\\exist/g, tmplt:"∃"},
|
||||
{ rex:/\\empty/g, tmplt:"∅"},
|
||||
{ rex:/\\nabla/g, tmplt:"∇"},
|
||||
{ rex:/\\notin/g, tmplt:"∉"},
|
||||
{ rex:/\\ni/g, tmplt:"∋"},
|
||||
{ rex:/\\minus/g, tmplt:"−"},
|
||||
{ rex:/\\lowast/g, tmplt:"∗"},
|
||||
{ rex:/\\sqrt|\\radic/g, tmplt:"√"},
|
||||
{ rex:/\\prop/g, tmplt:"∝"},
|
||||
{ rex:/\\infin/g, tmplt:"∞"},
|
||||
{ rex:/\\ang/g, tmplt:"∠"},
|
||||
{ rex:/\\and/g, tmplt:"∧"},
|
||||
{ rex:/\\or/g, tmplt:"∨"},
|
||||
{ rex:/\\cap/g, tmplt:"∩"},
|
||||
{ rex:/\\cup/g, tmplt:"∪"},
|
||||
{ rex:/\\there4/g, tmplt:"∴"},
|
||||
{ rex:/\\sub/g, tmplt:"⊂"},
|
||||
{ rex:/\\sup/g, tmplt:"⊃"},
|
||||
{ rex:/\\nsub/g, tmplt:"⊄"},
|
||||
{ rex:/\\sube/g, tmplt:"⊆"},
|
||||
{ rex:/\\supe/g, tmplt:"⊇"},
|
||||
{ rex:/\\oplus/g, tmplt:"⊕"},
|
||||
{ rex:/\\otimes/g, tmplt:"⊗"},
|
||||
{ rex:/\\perp/g, tmplt:"⊥"},
|
||||
{ rex:/\\sdot/g, tmplt:"⋅"}
|
||||
]
|
||||
};
|
||||
|
||||
Wiky.inverse.math = {
|
||||
pre: [
|
||||
{ rex:/−|\u2212/g, tmplt:"-"},
|
||||
{ rex:/ |\u2009/g, tmplt:" "},
|
||||
{ rex:/‎|\u200E/g, tmplt:"{"},
|
||||
{ rex:/‏|\u200F/g, tmplt:"}"}
|
||||
],
|
||||
post: [
|
||||
// { rex:/([$])/g, tmplt:"\\$1" },
|
||||
{ rex:/^|\x5E/g, tmplt:"^"},
|
||||
{ rex:/</g, tmplt:"<"},
|
||||
{ rex:/>/g, tmplt:">"}
|
||||
],
|
||||
shortcuts: [
|
||||
// { rex:/ |\u2003/g, tmplt:" "}, // omit due to charset support ie6
|
||||
// { rex:/ |\u2002/g, tmplt:" "},
|
||||
// { rex:/ |\u2009/g, tmplt:" "},
|
||||
{ rex:/±|\xB1/g, tmplt:"+-"},
|
||||
{ rex:/·|\xB7/g, tmplt:"*"},
|
||||
{ rex:/×|\xD7/g, tmplt:"\\x"},
|
||||
{ rex:/Ø|\xD8/g, tmplt:"/O"},
|
||||
{ rex:/ø|\xF8/g, tmplt:"/o"},
|
||||
{ rex:/←|\u2190/g, tmplt:"<-"},
|
||||
{ rex:/→|\u2192/g, tmplt:"->"},
|
||||
{ rex:/↔|\u2194/g, tmplt:"<->"},
|
||||
{ rex:/⇒|\u21D2/g, tmplt:"=>"},
|
||||
{ rex:/⇔|\u21D4/g, tmplt:"<=>"},
|
||||
{ rex:/∼|\u223C/g, tmplt:"~"},
|
||||
{ rex:/≅|\u2245/g, tmplt:"~="},
|
||||
{ rex:/≈|\u2248/g, tmplt:"~~"},
|
||||
{ rex:/≠|\u2260/g, tmplt:"!="},
|
||||
{ rex:/…/g, tmplt:"..."},
|
||||
{ rex:/≡|\u2261/g, tmplt:"-="},
|
||||
{ rex:/≤|\u2264/g, tmplt:"<="},
|
||||
{ rex:/≥|\u2265/g, tmplt:">="}
|
||||
],
|
||||
expr: [
|
||||
{ rex:/<span class=\"s\"><span class=\"i\">(\{?@[0-9]+@\}?)<\/span><span class="i">(\{?@[0-9]+@\}?)<\/span><\/span>/g, tmplt:"_$2^$1"}, // superscript + subscript
|
||||
{ rex:/<span class=\"o\"><span class=\"x\">(\{?@[0-9]+@\}?)<\/span>(\\prod|\\sum|\\int)<span class=\"x\">(\{?@[0-9]+@\}?)<\/span><\/span>/g, tmplt:"$2_$3^$1"}, // overscript + underscript
|
||||
{ rex:/<span class=\"o\"><span>@[0-9]+@<\/span>(\\prod|\\sum|\\int)<span class=\"x\">(\{?@[0-9]+@\}?)<\/span><\/span>/mgi, tmplt:"$1_$2", dbg:true}, // underscript
|
||||
{ rex:/<span class=\"o\"><span class=\"x\">(\{?@[0-9]+@\}?)<\/span>(\\prod|\\sum|\\int)<span>@[0-9]+@<\/span><\/span>/mgi, tmplt:"$2^$1"}, // overscript
|
||||
{ rex:/<span class=\"f\"><span class=\"n\">(\{?@[0-9]+@\}?)<\/span><span class="d">(\{?@[0-9]+@\}?)<\/span><\/span>/mgi, tmplt:"$1/$2"}, // fraction
|
||||
{ rex:/<span class=\"lb\"[^>]*>&[^;]+;<\/span><span class=\"v\">((?:<span class=\"e\">[^>]*<\/span>){2,})<\/span><span class=\"rb\"[^>]*>&[^;]+;<\/span>/mgi, tmplt:function($0,$1){return "["+$1.replace(/(?:^<span class=\"e\">|<\/span>$)/g,"").replace(/<\/span><span class=\"e\">/g,",")+"]";}}, // vector ..
|
||||
{ rex:/<span class=\"lb\"[^>]*>&[^;]+;<\/span>((?:<span class=\"m\">(?:(?:<span class=\"e\">[^>]*<\/span>){2,})<\/span>[^>]*){2,})<span class=\"rb\"[^>]*>&[^;]+;<\/span>/mgi, tmplt:function($0,$1){return "[["+Wiky.math.transpose($1.replace(/(?:^<span class=\"m\"><span class=\"e\">|<\/span><\/span>$)/g,"").replace(/<\/span><span class=\"e\">/g,",").replace(/<\/span><\/span>[^>]*<span class=\"m\"><span class=\"e\">/g,"|").split("|")).mat.join("][")+"]]";}}, // matrix ..
|
||||
{ rex:/<span class=\"b\">(@[0-9]+@)<\/span>/mgi, tmplt:"!$1"}, // bold vector ..
|
||||
{ rex:/<sup>(\{?@[0-9]+@\}?)<\/sup>⁄<sub>(\{?@[0-9]+@\}?)<\/sub>/mgi, tmplt:"$1//$2"},
|
||||
{ rex:/<sup class=\"i\">(\{?@[0-9]+@\}?)<\/sup>/mgi, tmplt:"^$1" },
|
||||
{ rex:/<sub class=\"i\">(\{?@[0-9]+@\}?)<\/sub>/mgi, tmplt:"_$1" }
|
||||
],
|
||||
symbols: [
|
||||
// greek symbols
|
||||
{ rex:/Α|\u391/g, tmplt:"\\Alpha"},
|
||||
{ rex:/Β|\u392/g, tmplt:"\\Beta"},
|
||||
{ rex:/Γ|\u393/g, tmplt:"\\Gamma"},
|
||||
{ rex:/Δ|\u394/g, tmplt:"\\Delta"},
|
||||
{ rex:/Ε|\u395/g, tmplt:"\\Epsilon"},
|
||||
{ rex:/Ζ|\u396/g, tmplt:"\\Zeta"},
|
||||
{ rex:/Η|\u397/g, tmplt:"\\Eta"},
|
||||
{ rex:/Θ|\u398/g, tmplt:"\\Theta"},
|
||||
{ rex:/Ι|\u399/g, tmplt:"\\Iota"},
|
||||
{ rex:/Κ|\u39A/g, tmplt:"\\Kappa"},
|
||||
{ rex:/Λ|\u39B/g, tmplt:"\\Lambda"},
|
||||
{ rex:/Μ|\u39C/g, tmplt:"\\Mu"},
|
||||
{ rex:/Ν|\u39D/g, tmplt:"\\Nu"},
|
||||
{ rex:/Ξ|\u39E/g, tmplt:"\\Xi"},
|
||||
{ rex:/Ο|\u39F/g, tmplt:"\\Omicron"},
|
||||
{ rex:/Π|\u3A0/g, tmplt:"\\Pi"},
|
||||
{ rex:/Ρ|\u3A1/g, tmplt:"\\Rho"},
|
||||
{ rex:/Σ|\u3A3/g, tmplt:"\\Sigma"},
|
||||
{ rex:/Τ|\u3A4/g, tmplt:"\\Tau"},
|
||||
{ rex:/Υ|\u3A5/g, tmplt:"\\Upsilon"},
|
||||
{ rex:/Φ|\u3A6/g, tmplt:"\\Phi"},
|
||||
{ rex:/Χ|\u3A7/g, tmplt:"\\Chi"},
|
||||
{ rex:/Ψ|\u3A8/g, tmplt:"\\Psi"},
|
||||
{ rex:/Ω|\u3A9/g, tmplt:"\\Omega"},
|
||||
{ rex:/α|\u3B1/g, tmplt:"\\alpha"},
|
||||
{ rex:/β|\u3B2/g, tmplt:"\\beta"},
|
||||
{ rex:/γ|\u3B3/g, tmplt:"\\gamma"},
|
||||
{ rex:/δ|\u3B4/g, tmplt:"\\delta"},
|
||||
{ rex:/ε|\u3B5/g, tmplt:"\\epsilon"},
|
||||
{ rex:/ζ|\u3B6/g, tmplt:"\\zeta"},
|
||||
{ rex:/η|\u3B7/g, tmplt:"\\eta"},
|
||||
{ rex:/ϑ|\u3D1/g, tmplt:"\\thetasym"},
|
||||
{ rex:/θ|\u3B8/g, tmplt:"\\theta"},
|
||||
{ rex:/ι|\u3B9/g, tmplt:"\\iota"},
|
||||
{ rex:/κ|\u3BA/g, tmplt:"\\kappa"},
|
||||
{ rex:/λ|\u3BB/g, tmplt:"\\lambda"},
|
||||
{ rex:/μ|\u3BC/g, tmplt:"\\mu"},
|
||||
{ rex:/ν|\u3BD/g, tmplt:"\\nu"},
|
||||
{ rex:/ξ|\u3BE/g, tmplt:"\\xi"},
|
||||
{ rex:/ο|\u3BF/g, tmplt:"\\omicron"},
|
||||
{ rex:/π|\u3C0/g, tmplt:"\\pi"},
|
||||
{ rex:/ρ|\u3C1/g, tmplt:"\\rho"},
|
||||
{ rex:/ς|\u3C2/g, tmplt:"\\sigmaf"},
|
||||
{ rex:/σ|\u3C3/g, tmplt:"\\sigma"},
|
||||
{ rex:/τ|\u3C4/g, tmplt:"\\tau"},
|
||||
{ rex:/υ|\u3C5/g, tmplt:"\\upsilon"},
|
||||
{ rex:/φ|\u3C6/g, tmplt:"\\phi"},
|
||||
{ rex:/χ|\u3C7/g, tmplt:"\\chi"},
|
||||
{ rex:/ψ|\u3C8/g, tmplt:"\\psi"},
|
||||
{ rex:/ω|\u3C9/g, tmplt:"\\omega"},
|
||||
// miscellaneous symbols
|
||||
{ rex:/ϒ|\u3D2/g, tmplt:"\\upsih"},
|
||||
{ rex:/ϖ|\u3D6/g, tmplt:"\\piv"},
|
||||
{ rex:/•|\u2022/g, tmplt:"\\bull"},
|
||||
{ rex:/↑|\u2191/g, tmplt:"\\uarr"},
|
||||
{ rex:/↓|\u2193/g, tmplt:"\\darr"},
|
||||
{ rex:/↵|\u21B5/g, tmplt:"\\crarr"},
|
||||
{ rex:/⇐|\u21D0/g, tmplt:"\\lArr"},
|
||||
{ rex:/⇑|\u21D1/g, tmplt:"\\uArr"},
|
||||
{ rex:/⇓|\u21D3/g, tmplt:"\\dArr"},
|
||||
{ rex:/∀|\u2200/g, tmplt:"\\forall"},
|
||||
{ rex:/∂|\u2202/g, tmplt:"\\part"},
|
||||
{ rex:/∃|\u2203/g, tmplt:"\\exist"},
|
||||
{ rex:/∅|\u2205/g, tmplt:"\\empty"},
|
||||
{ rex:/∇|\u2207/g, tmplt:"\\nabla"},
|
||||
{ rex:/∈|\u2208/g, tmplt:"\\isin"},
|
||||
{ rex:/∉|\u2209/g, tmplt:"\\notin"},
|
||||
{ rex:/∋|\u220B/g, tmplt:"\\ni"},
|
||||
{ rex:/<span class=\"h\">(∏|\u220F)<\/span>/g, tmplt:"\\prod"},
|
||||
{ rex:/<span class=\"h\">(∑|\u2211)<\/span>/g, tmplt:"\\sum"},
|
||||
{ rex:/∗|\u2217/g, tmplt:"\\lowast"},
|
||||
{ rex:/√|\u221A/g, tmplt:"\\sqrt"},
|
||||
{ rex:/∝|\u221D/g, tmplt:"\\prop"},
|
||||
{ rex:/∞|\u221E/g, tmplt:"\\infin"},
|
||||
{ rex:/∠|\u2220/g, tmplt:"\\ang"},
|
||||
{ rex:/∧|\u2227/g, tmplt:"\\and"},
|
||||
{ rex:/∨|\u2228/g, tmplt:"\\or"},
|
||||
{ rex:/∩|\u2229/g, tmplt:"\\cap"},
|
||||
{ rex:/∪|\u222A/g, tmplt:"\\cup"},
|
||||
{ rex:/<span class=\"h\">(?:∫|\u222B)<\/span>/g, tmplt:"\\int"},
|
||||
{ rex:/∴|\u2234/g, tmplt:"\\there4"},
|
||||
{ rex:/⊂|\u2282/g, tmplt:"\\sub"},
|
||||
{ rex:/⊃|\u2283/g, tmplt:"\\sup"},
|
||||
{ rex:/⊄|\u2284/g, tmplt:"\\nsub"},
|
||||
{ rex:/⊆|\u2286/g, tmplt:"\\sube"},
|
||||
{ rex:/⊇|\u2287/g, tmplt:"\\supe"},
|
||||
{ rex:/⊕|\u2295/g, tmplt:"\\oplus"},
|
||||
{ rex:/⊗|\u2297/g, tmplt:"\\otimes"},
|
||||
{ rex:/⊥|\u22A5/g, tmplt:"\\perp"},
|
||||
{ rex:/⋅|\u22C5/g, tmplt:"\\sdot"}
|
||||
]
|
||||
};
|
||||
|
||||
Wiky.math = {
|
||||
toHtml: function(str) {
|
||||
var expr = function(itr) { // region from "{" to "}", nesting allowed ..
|
||||
var s = "";
|
||||
for (var c = itr.str.charAt(itr.pos++); itr.pos <= itr.str.length && c != "}"; c = itr.str.charAt(itr.pos++))
|
||||
s += (c == "{") ? ("{"+expr(itr)+"}") : c;
|
||||
return Wiky.store(Wiky.apply(s, Wiky.rules.math.expr));
|
||||
};
|
||||
str = Wiky.apply(str, Wiky.rules.math.preshortcuts);
|
||||
str = Wiky.apply(str, Wiky.rules.math.symbols);
|
||||
str = expr({str:str,pos:0});
|
||||
return str;
|
||||
},
|
||||
toWiki: function(str) {
|
||||
var parseTree = function(itr, endtag) {
|
||||
var c, s="",gt,nam,idxof=function(s,c,p){var i=s.indexOf(c,p);return i>=0?i:s.length;}
|
||||
for (itr.buf=itr.str.substr(itr.pos,endtag.length);
|
||||
itr.pos<itr.str.length && (!endtag || itr.buf!=endtag);
|
||||
itr.buf=itr.str.substr(++itr.pos,endtag.length)) {
|
||||
if ((c=itr.str.charAt(itr.pos))=="<" && (gt=idxof(itr.str,">",itr.pos)) < idxof(itr.str,"/",itr.pos)) { // start tags .. no empty elements or endtags ..
|
||||
nam = itr.str.substring(itr.pos+1,Math.min(idxof(itr.str," ",itr.pos),gt));
|
||||
s += itr.str.substring(itr.pos,itr.pos=gt+1) + parseTree(itr, "</" + nam + ">") + "</" + nam + ">";
|
||||
itr.pos += nam.length+3;
|
||||
}
|
||||
else
|
||||
s += c;
|
||||
}
|
||||
itr.pos--;
|
||||
return Wiky.store(s, true);
|
||||
};
|
||||
str = Wiky.apply(str, Wiky.inverse.math.pre);
|
||||
str = Wiky.apply(str, Wiky.inverse.math.symbols);
|
||||
str = parseTree({str:str,pos:0,buf:null}, "");
|
||||
while (str.match(/@[0-9]+@/g) != null)
|
||||
str = Wiky.apply(str.replace(/@([0-9]+)@/g, function($0,$1){return Wiky.restore($1);}), Wiky.inverse.math.expr);
|
||||
str = Wiky.apply(str, Wiky.inverse.math.shortcuts);
|
||||
str = Wiky.apply(str, Wiky.inverse.math.post);
|
||||
return str;
|
||||
},
|
||||
fence: function(str) {
|
||||
return window && window.ActiveXObject ? " " : " ";
|
||||
},
|
||||
transpose: function (m) {
|
||||
var t=[];
|
||||
for (var i in m) {
|
||||
m[i] = m[i].split(",");
|
||||
for (var j in m[i]) {
|
||||
if (!t[j]) t[j]=[];
|
||||
t[j][i] = m[i][j];
|
||||
}
|
||||
}
|
||||
for (var i in t)
|
||||
t[i] = t[i].join(",");
|
||||
return {mat:t, len:m.length};
|
||||
}
|
||||
};
|
||||
|
||||
Wiky.rules.pre = Wiky.rules.pre.concat({ rex:/\\([$])/g, tmplt:function($0,$1){return Wiky.store($1);} });
|
||||
Wiky.rules.nonwikiblocks = Wiky.rules.nonwikiblocks.concat(
|
||||
[
|
||||
{ rex:/\[\(([a-zA-Z0-9\.-]+)\)\$([^$]*)\$\]/g, tmplt:function($0,$1,$2){return ":p]<div class=\"eq\"><a name=\"eq"+$1+"\">("+$1+")</a>" + Wiky.math.toHtml($2) + "</div>[p:";} }, // numbered equation
|
||||
{ rex:/\[\$([^$]*)\$\]/g, tmplt:function($0,$1){return ":p]<div class=\"eq\">" + Wiky.math.toHtml($1) + "</div>[p:";} }, // equation
|
||||
]);
|
||||
Wiky.rules.nonwikiinlines = Wiky.rules.nonwikiinlines.concat(
|
||||
{ rex:/\$([^$]*)\$/g, tmplt:function($0,$1){return "<dfn>" + Wiky.math.toHtml($1) + "</dfn>";} } // inline equation
|
||||
);
|
||||
|
||||
Wiky.inverse.pre = Wiky.inverse.pre.concat({ rex:/([\$])/g, tmplt:"\\$1" });
|
||||
Wiky.inverse.nonwikiblocks = Wiky.inverse.nonwikiblocks.concat(
|
||||
[
|
||||
{ rex:/<div class=\"eq\"><a name=\"eq([0-9]+)\">(?:.*?)<\/a>(.*?)<\/div>/g, tmplt:function($0,$1,$2){return Wiky.store("[("+$1+")$"+Wiky.math.toWiki($2)+"$]");} }, // numbered equation
|
||||
{ rex:/<div class=\"eq\">(.*?)<\/div>/g, tmplt:function($0,$1){return Wiky.store("[$"+Wiky.math.toWiki($1)+"$]");} }, // equation
|
||||
]);
|
||||
Wiky.inverse.nonwikiinlines = Wiky.inverse.nonwikiinlines.concat(
|
||||
{ rex:/<dfn>(.*?)<\/dfn>/g, tmplt:function($0,$1){return Wiky.store("$"+Wiky.math.toWiki($1)+"$");} } // inline equation
|
||||
);
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<% USING: io namespaces furnace:onigiri html
|
||||
math kernel sequences hashtables calendar ; %>
|
||||
<title><% "title" key>meta* meta-value [ "an onigiri weblog" ] unless* write %></title>
|
||||
<link rel="self" href="<% base-url write "atom" action>url write %>"/>
|
||||
<author>
|
||||
<name><% "author" key>meta* meta-value [ "anonymous" ] unless* write %></name>
|
||||
</author>
|
||||
<id><% base-url write "atom" action>url write %></id>
|
||||
<% entry get
|
||||
[ [ entry-created ] 2apply compare-timestamps neg ] sort
|
||||
dup empty? [ %>
|
||||
<updated><% dup first entry-created timestamp>rfc3339 write %></updated><% ] unless
|
||||
[ %>
|
||||
<entry>
|
||||
<title><% dup entry-title write %></title>
|
||||
<id><% dup entry-stub stub>url dup base-url write write %></id>
|
||||
<updated><% over entry-created timestamp>rfc3339 write %></updated>
|
||||
<link href="<% base-url write write %>"/>
|
||||
<summary><% entry-body write-html %></summary>
|
||||
</entry><% ] each %>
|
||||
</feed>
|
|
@ -1,19 +0,0 @@
|
|||
<% USING: namespaces io kernel sequences furnace:onigiri html
|
||||
furnace ; %>
|
||||
|
||||
<p><% "stub" get [ "true" entry-edit ] curry "Edit with Wiky" render-link %></p>
|
||||
|
||||
<form method="post" action="entry-update">
|
||||
<% "stub" get [ %><input type="hidden" name="stub" value="<% "stub" get write %>"/><% ] when %>
|
||||
<table><tr><td>Title:</td><td><input type="text" name="title" value="<% "title" get write %>"/></td></tr>
|
||||
<tr><td>Body:</td><td><textarea id="body" rows="10" cols="60" name="body" onKeyUp="$('preview').innerHTML=$('body').value;"><% "body" get write %></textarea></td></tr>
|
||||
<tr><td></td><td><input type="submit" name="post" value="<% "stub" get "update" "post" ? write %>"/>
|
||||
|
||||
<% "stub" get [ [ entry-delete ] curry "Delete" render-link ] when* %>(preview below)</td></tr>
|
||||
<tr><td></td><td><div id="preview"></div></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$('preview').innerHTML=$('body').value;
|
||||
</script>
|
|
@ -1,34 +0,0 @@
|
|||
<% USING: namespaces io kernel sequences furnace:onigiri html
|
||||
furnace ; %>
|
||||
|
||||
<script type="text/javascript">
|
||||
function transformWiky() {
|
||||
var wiky = $('wiky').value;
|
||||
var html = Wiky.toHtml(wiky);
|
||||
$('html').value = html;
|
||||
$('preview').innerHTML = html;
|
||||
}
|
||||
function transformHtml() {
|
||||
var html = $('preview').innerHTML;
|
||||
var wiky = Wiky.toWiki(html);
|
||||
$('wiky').value = wiky;
|
||||
$('html').value = html;
|
||||
}
|
||||
</script>
|
||||
|
||||
<p><% "stub" get [ f entry-edit ] curry "Edit in non-Wiky editor" render-link %></p>
|
||||
|
||||
<form method="post" action="entry-update">
|
||||
<% "stub" get [ %><input type="hidden" name="stub" value="<% "stub" get write %>"/><% ] when %>
|
||||
<table><tr><td>Title:</td><td><input type="text" name="title" value="<% "title" get write %>"/></td></tr>
|
||||
<tr><td>Body:</td><td><textarea id="wiky" rows="10" cols="60" name="wiky" onkeyup="transformWiky();"></textarea></td></tr>
|
||||
<tr><td></td><td><input type="submit" name="post" value="<% "stub" get "update" "post" ? write %>"/>
|
||||
|
||||
<% "stub" get [ [ entry-delete ] curry "Delete" render-link ] when* %>
|
||||
(preview below)</td></tr>
|
||||
<tr><td></td><td><input id="html" type="hidden" name="body" value=""/><div id="preview"><% "body" get [ write-html ] when* %></div></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
transformHtml();
|
||||
</script>
|
|
@ -1,9 +0,0 @@
|
|||
<% USING: furnace:onigiri io namespaces math calendar html kernel furnace ; %>
|
||||
|
||||
<div class="entry">
|
||||
<h2><a href="<% "entry-show" action>url write %>?stub=<% "stub" get write %>"><% "title" get write %></a></h2>
|
||||
|
||||
<p>posted <% "created" get timestamp>string write %> <% "stub" get [ entry-edit ] curry "(edit)" render-link %></p>
|
||||
|
||||
<% "body" get write-html %>
|
||||
</div>
|
|
@ -1,16 +0,0 @@
|
|||
<% USING: io kernel namespaces hashtables furnace:onigiri ; %>
|
||||
|
||||
<% "analytics" key>meta* meta-value [ %>
|
||||
|
||||
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
_uacct = "<% write %>";
|
||||
urchinTracker();
|
||||
</script>
|
||||
|
||||
<% ] when* %>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<% USING: namespaces io kernel hashtables furnace:onigiri furnace sequences ; %>
|
||||
<title><% "model" get write %></title>
|
||||
<link rel='stylesheet' type='text/css' href='/responder/onigiri-resources/<% css-path write %>'/>
|
||||
<link rel='stylesheet' type='text/css' href='/responder/onigiri-resources/wiky/wiky.css'/>
|
||||
<link rel='stylesheet' type='text/css' href='/responder/onigiri-resources/wiky/wiky.lang.css'/>
|
||||
<link rel='stylesheet' type='text/css' href='/responder/onigiri-resources/wiky/wiky.math.css'/>
|
||||
<script type='text/javascript' src='/responder/onigiri-resources/wiky/wiky.js'></script>
|
||||
<script type='text/javascript' src='/responder/onigiri-resources/wiky/wiky.lang.js'></script>
|
||||
<script type='text/javascript' src='/responder/onigiri-resources/wiky/wiky.math.js'></script>
|
||||
<script type='text/javascript' src='/responder/resources/prototype.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="header">
|
||||
<h1><a href="<% "" action>url write %>"><% "title" key>meta* meta-value write %></a></h1>
|
||||
|
||||
<p>Proudly running on <a href="http://factorcode.org">Factor <% version write %></a></p>
|
||||
|
||||
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0 Strict</a> | <a href="<% "atom" action>url write %>">Subscribe to <% "title" key>meta [ meta-value ] [ "this weblog" ] if* write %></a> | <% [ meta-list ] "Admin" render-link %> | <% [ f entry-edit ] "Post" render-link %></p>
|
||||
</div>
|
||||
|
||||
<div id="container">
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
|
||||
<% USING: namespaces furnace:onigiri sequences io ; %>
|
||||
<url>
|
||||
<loc><% base-url write "" action>url write %></loc>
|
||||
</url>
|
||||
<% entry get [ %>
|
||||
<url>
|
||||
<loc><% entry-stub base-url write stub>url write %></loc>
|
||||
</url>
|
||||
<% ] each %>
|
||||
</urlset>
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue