Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/parsexml.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH library - PARSE XML - Copyright 2008 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

[UNDEFINED] skip-tag [IF]
[UNDEFINED] COMPARE [IF]
[NEEDS lib/compare.4th]
[THEN]

[UNDEFINED] 2OVER [IF]
[NEEDS lib/2rotover.4th]
[THEN]

char > constant '>'                    \ > character
char < constant '<'                    \ < character

: parse-tag                            ( -- a n)
  bl omit >in @ >r '>' parse dup
  if over c@ '<' = if 1+ else 2drop r@ >in ! '<' parse -1 >in +! then then
  r> drop
;                                      \ parse a tag
                                       ( -- a n)
: next-tag begin parse-tag dup if exit then refill while 2drop repeat ;
                                       \ check for a tag
: check-tag                            ( a n --)
  next-tag 2dup 2>r compare
  if cout stdout use 2r> type ."  not expected here" cr use else 2r> 2drop then
;
                                       \ find a tag
: search-tag                           ( a n --)
  begin next-tag dup while 2over 2over compare while 2drop repeat 2drop 2drop
;
                                       \ check whether a tag is there
: expect-tag next-tag compare 0= ;     ( a n -- f)
: skip-tag next-tag 2drop ;            ( --)
                                       \ skip a tag
[DEFINED] 4TH# [IF]
hide parse-tag
[THEN]
[THEN]

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].