##// END OF EJS Templates
A few parser fixes
naryl -
r13:f0a3bfeb default
parent child Browse files
Show More
@@ -35,10 +35,10 b' 1. **\xd0\x9f\xd1\x80\xd0\xbe\xd1\x81\xd1\x82\xd0\xbe \xd1\x81\xd0\xbe\xd0\xb1\xd0\xb5\xd1\x80\xd0\xb8 \xd0\xbc\xd0\xbd\xd0\xb5 \xd0\xb8\xd0\xb3\xd1\x80\xd1\x83**:<br/>'
35 35
36 36 2. **Я знаю что делаю**:<br/>
37 37 `sugar-qsp game.txt -o game.html --body body.html --js jquery.js my-js-library.js --css styles/*.css`<br/>
38 Если вы знаете что делаете, то для вас смысл опций очевиден. `body.html`
39 по-умолчанию лежит в каталоге `extras`.
38 Если вы знаете что делаете, то для вас смысл опций очевиден. `body.html` и `default.css`
39 лежат в каталоге `extras`.
40 40
41 41 3. **Я - фронтендер!**<br/>
42 42 `sugar-qsp game.txt -c -o game.js`<br/>
43 43 Просто соберёт игру в Javascript файл который вы можете разместить на своём
44 сайте как вам угодно. Для запуска игры вызовите `SugarQSP.start()`.
44 сайте как вам угодно.
@@ -37,10 +37,14 b''
37 37 `(funcall (root lib rand) 1 1000))
38 38
39 39 (ps:defpsmacro qspmax (&rest args)
40 `(max ,@args))
40 (if (= 1 (length args))
41 `(*math.max.apply nil ,@args)
42 `(*math.max ,@args)))
41 43
42 44 (ps:defpsmacro qspmin (&rest args)
43 `(min ,@args))
45 (if (= 1 (length args))
46 `(*math.min.apply nil ,@args)
47 `(*math.min ,@args)))
44 48
45 49 ;;; 5arrays
46 50
@@ -103,13 +103,18 b''
103 103 ;;; Identifiers
104 104
105 105 ;; From the official docs
106 (defparameter *keywords* '(act addlib addobj addqst and arrcomp arrpos arrsize cla clear *clear close clr *clr cls cmdclear cmdclr copyarr $counter countobj $curacts curloc debug delact dellib delobj desc disablescroll disablesubex dynamic dyneval else elseif end exit fcolor $fname freelib fsize func getobj gosub goto gs gt if iif inclib input instr isnum isplay jump killall killobj killqst killvar lcase lcolor len let loc $maintxt max menu mid min mod msecscount msg nl *nl no nosave obj $onactsel $ongload $ongsave $onnewloc $onobjadd $onobjdel $onobjsel opengame openqst or p *p pl *pl play qspver rand refint replace rgb rnd savegame selact selobj set settimer showacts showinput showobjs showstat $stattxt str strcomp strfind strpos trim ucase unsel unselect $usercom user_text usrtxt val view wait xgoto xgt))
106 (defparameter *keywords* '(act addlib addobj addqst and arrcomp arrpos arrsize cla clear *clear close clr *clr cls cmdclear cmdclr copyarr counter countobj curacts curloc debug delact dellib delobj desc disablescroll disablesubex dynamic dyneval else elseif end exit fcolor fname freelib fsize func getobj gosub goto gs gt if iif inclib input instr isnum isplay jump killall killobj killqst killvar lcase lcolor len let loc maintxt max menu mid min mod msecscount msg nl *nl no nosave obj onactsel ongload ongsave onnewloc onobjadd onobjdel onobjsel opengame openqst or p *p pl *pl play qspver rand refint replace rgb rnd savegame selact selobj set settimer showacts showinput showobjs showstat stattxt str strcomp strfind strpos trim ucase unsel unselect usercom user_text usrtxt val view wait xgoto xgt))
107
108 (defun trim-$ (str)
109 (if (char= #\$ (elt str 0))
110 (subseq str 1)
111 str))
107 112
108 113 (defun qsp-keyword-p (id)
109 (member (intern (string-upcase id)) *keywords*))
114 (member (intern (trim-$ (string-upcase id))) *keywords*))
110 115
111 116 (defun not-qsp-keyword-p (id)
112 (not (member (intern (string-upcase id)) *keywords*)))
117 (not (member (intern (trim-$ (string-upcase id))) *keywords*)))
113 118
114 119 (p:defrule qsp-keyword (qsp-keyword-p identifier-raw))
115 120
@@ -118,10 +123,7 b''
118 123 (digit-char-p character)))
119 124 (p:defrule identifier-raw (and id-first (* id-next))
120 125 (:lambda (list)
121 (let ((id (p:text list)))
122 (when (member id *keywords*)
123 (error "~A is a keyword" id))
124 (intern (string-upcase id)))))
126 (intern (string-upcase (p:text list)))))
125 127
126 128 (p:defrule identifier (not-qsp-keyword-p identifier-raw))
127 129
@@ -250,7 +252,10 b''
250 252 (:lambda (list)
251 253 (intern (string (second list)) :keyword)))
252 254
253 (p:defrule comment (and #\! (* (or text-spaces qsp-string brace-string not-newline)))
255 (p:defrule comment (and #\! (* (or qsp-string brace-comment text-spaces not-newline)))
256 (:constant nil))
257
258 (p:defrule brace-comment (and #\{ (* (not-brace character)) #\})
254 259 (:constant nil))
255 260
256 261 ;;; Blocks
@@ -346,11 +351,15 b''
346 351 (:function third))
347 352 (p:defrule plain-arguments (and spaces base-arguments)
348 353 (:function second))
349 (p:defrule no-arguments (or spaces (p:& #\newline) (p:& #\&))
354 (p:defrule no-arguments (or (and spaces? (p:& #\newline))
355 (and spaces? (p:& #\&))
356 spaces?)
350 357 (:constant nil))
351 (p:defrule base-arguments (and first-argument (* next-argument))
352 (:destructure (first rest)
353 (list* first rest)))
358 (p:defrule base-arguments (or (and first-argument (* next-argument)) spaces?)
359 (:lambda (list)
360 (if (null list)
361 nil
362 (list* (first list) (second list)))))
354 363
355 364 ;;; Intrinsics
356 365
@@ -437,17 +446,17 b''
437 446 (dynamic nil 1 10)
438 447 (dyneval t 1 10)
439 448 ;; Main window
440 (main-p nil 1 1 "*p")
441 449 (main-pl nil 1 1 "*pl")
442 450 (main-nl nil 0 1 "*nl")
451 (main-p nil 1 1 "*p")
443 452 (maintxt t 0 0)
444 453 (desc t 1 1)
445 454 (main-clear nil 0 0 "*clear" "*clr")
446 455 ;; Aux window
447 456 (showstat nil 1 1)
448 (stat-p nil 1 1 "p")
449 457 (stat-pl nil 1 1 "pl")
450 458 (stat-nl nil 0 1 "nl")
459 (stat-p nil 1 1 "p")
451 460 (stattxt t 0 0)
452 461 (stat-clear nil 0 0 "clear" "clr")
453 462 (cls nil 0 0)
@@ -503,17 +512,11 b''
503 512 (p:defrule and-expr (and eq-expr (* (and spaces? and-op spaces? eq-expr)))
504 513 (:function do-binop))
505 514
506 (p:defrule eq-expr (and cat-expr (* (and spaces? (or "<>" "<=" ">=" "=<" "=>"
507 #\= #\< #\> #\!)
515 (p:defrule eq-expr (and sum-expr (* (and spaces? (or "<=" ">=" "=<" "=>" "<>"
516 "=" "<" ">" "!")
508 517 spaces? cat-expr)))
509 518 (:function do-binop))
510 519
511 (p:defrule cat-expr (and sum-expr (* (and spaces? #\& spaces? (p:! expr-stopper) sum-expr)))
512 (:lambda (list)
513 (do-binop (list (first list) (mapcar (lambda (l)
514 (remove-nth l 3))
515 (second list))))))
516
517 520 (p:defrule sum-expr (and mod-expr (* (and spaces? (or #\+ #\-) spaces? mod-expr)))
518 521 (:function do-binop))
519 522
@@ -552,15 +555,21 b''
552 555 (:lambda (list)
553 556 (or (third list) :end)))
554 557
555 (p:defrule assignment (or kw-assignment plain-assignment)
558 (p:defrule assignment (or kw-assignment plain-assignment op-assignment)
556 559 (:destructure (var eq expr)
557 560 (declare (ignore eq))
558 561 (list 'set var expr)))
559 562
563 (p:defrule kw-assignment (and (or (p:~ "let") (p:~ "set")) spaces? (or op-assignment plain-assignment))
564 (:function third))
565
566 (p:defrule op-assignment (and variable spaces? (or "+" "-" "*" "/") #\= spaces? expression)
567 (:destructure (var ws1 op eq ws2 expr)
568 (declare (ignore ws1 ws2))
569 (list var eq (intern-first (list op var expr)))))
570
560 571 (p:defrule plain-assignment (and variable spaces? #\= spaces? expression)
561 572 (:function remove-nil))
562 (p:defrule kw-assignment (and (or (p:~ "let") (p:~ "set")) spaces? plain-assignment)
563 (:function third))
564 573
565 574 ;;; Non-string literals
566 575
General Comments 0
You need to be logged in to leave comments. Login now