~ubuntu-branches/ubuntu/vivid/tidy/vivid-updates

« back to all changes in this revision

Viewing changes to src/lexer.h

  • Committer: Bazaar Package Importer
  • Author(s): Jason Thomas
  • Date: 2008-01-20 21:46:03 UTC
  • mfrom: (0.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080120214603-oqicq5jwr1exrm55
Tags: 20080116cvs-2
* debian/control: build depends on xsltproc
  (closes: #461608)
* debian/tidy.preinst,postinst: add code to move old config file
  (closes: #461623)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
/* lexer.h -- Lexer for html parser
5
5
  
6
 
   (c) 1998-2005 (W3C) MIT, ERCIM, Keio University
 
6
   (c) 1998-2007 (W3C) MIT, ERCIM, Keio University
7
7
   See tidy.h for the copyright notice.
8
8
  
9
9
   CVS Info:
10
10
    $Author: arnaud02 $ 
11
 
    $Date: 2005/08/26 16:08:45 $ 
12
 
    $Revision: 1.30 $ 
 
11
    $Date: 2007/01/17 10:51:18 $ 
 
12
    $Revision: 1.40 $ 
13
13
 
14
14
*/
15
15
 
45
45
 
46
46
/* lexer character types
47
47
*/
48
 
#define digit       1
49
 
#define letter      2
50
 
#define namechar    4
51
 
#define white       8
52
 
#define newline     16
53
 
#define lowercase   32
54
 
#define uppercase   64
 
48
#define digit       1u
 
49
#define letter      2u
 
50
#define namechar    4u
 
51
#define white       8u
 
52
#define newline     16u
 
53
#define lowercase   32u
 
54
#define uppercase   64u
 
55
#define digithex    128u
55
56
 
56
57
 
57
58
/* node->type is one of these values
359
360
    uint txtend;            /* end of current node */
360
361
    LexerState state;       /* state of lexer's finite state machine */
361
362
 
362
 
    Node* token;            /* current parse point */
 
363
    Node* token;            /* last token returned by GetToken() */
 
364
    Node* itoken;           /* last duplicate inline returned by GetToken() */
363
365
    Node* root;             /* remember root node of the document */
364
366
    Node* parent;           /* remember parent node for CDATA elements */
365
367
    
389
391
 
390
392
    TagStyle *styles;          /* used for cleaning up presentation markup */
391
393
 
 
394
    TidyAllocator* allocator; /* allocator */
 
395
 
392
396
#if 0
393
397
    TidyDocImpl* doc;       /* Pointer back to doc for error reporting */
394
398
#endif 
397
401
 
398
402
/* Lexer Functions
399
403
*/
400
 
Node *CommentToken( Lexer *lexer );
401
404
 
402
405
/* choose what version to use for new doctype */
403
 
int HTMLVersion( TidyDocImpl* doc );
404
 
 
405
 
ctmbstr GetFPIFromVers(uint vers);
 
406
int TY_(HTMLVersion)( TidyDocImpl* doc );
406
407
 
407
408
/* everything is allowed in proprietary version of HTML */
408
409
/* this is handled here rather than in the tag/attr dicts */
409
410
 
410
 
void ConstrainVersion( TidyDocImpl* doc, uint vers );
411
 
 
412
 
Bool IsWhite(uint c);
413
 
Bool IsDigit(uint c);
414
 
Bool IsLetter(uint c);
415
 
Bool IsNewline(uint c);
416
 
Bool IsNamechar(uint c);
417
 
Bool IsXMLLetter(uint c);
418
 
Bool IsXMLNamechar(uint c);
419
 
 
420
 
Bool IsLower(uint c);
421
 
Bool IsUpper(uint c);
422
 
uint ToLower(uint c);
423
 
uint ToUpper(uint c);
424
 
 
425
 
char FoldCase( TidyDocImpl* doc, tmbchar c, Bool tocaps );
426
 
 
427
 
 
428
 
Lexer* NewLexer( TidyDocImpl* doc );
429
 
Bool EndOfInput( TidyDocImpl* doc );
430
 
void FreeLexer( TidyDocImpl* doc );
 
411
void TY_(ConstrainVersion)( TidyDocImpl* doc, uint vers );
 
412
 
 
413
Bool TY_(IsWhite)(uint c);
 
414
Bool TY_(IsDigit)(uint c);
 
415
Bool TY_(IsLetter)(uint c);
 
416
Bool TY_(IsNewline)(uint c);
 
417
Bool TY_(IsNamechar)(uint c);
 
418
Bool TY_(IsXMLLetter)(uint c);
 
419
Bool TY_(IsXMLNamechar)(uint c);
 
420
 
 
421
/* Bool IsLower(uint c); */
 
422
Bool TY_(IsUpper)(uint c);
 
423
uint TY_(ToLower)(uint c);
 
424
uint TY_(ToUpper)(uint c);
 
425
 
 
426
Lexer* TY_(NewLexer)( TidyDocImpl* doc );
 
427
void TY_(FreeLexer)( TidyDocImpl* doc );
431
428
 
432
429
/* store character c as UTF-8 encoded byte stream */
433
 
void AddCharToLexer( Lexer *lexer, uint c );
 
430
void TY_(AddCharToLexer)( Lexer *lexer, uint c );
434
431
 
435
432
/*
436
433
  Used for elements and text nodes
445
442
  list of AttVal nodes which hold the
446
443
  strings for attribute/value pairs.
447
444
*/
448
 
Node* NewNode( Lexer* lexer );
 
445
Node* TY_(NewNode)( TidyAllocator* allocator, Lexer* lexer );
449
446
 
450
447
 
451
448
/* used to clone heading nodes when split by an <HR> */
452
 
Node *CloneNode( TidyDocImpl* doc, Node *element );
 
449
Node* TY_(CloneNode)( TidyDocImpl* doc, Node *element );
453
450
 
454
451
/* free node's attributes */
455
 
void FreeAttrs( TidyDocImpl* doc, Node *node );
 
452
void TY_(FreeAttrs)( TidyDocImpl* doc, Node *node );
456
453
 
457
454
/* doesn't repair attribute list linkage */
458
 
void FreeAttribute( TidyDocImpl* doc, AttVal *av );
 
455
void TY_(FreeAttribute)( TidyDocImpl* doc, AttVal *av );
459
456
 
460
457
/* detach attribute from node */
461
 
void DetachAttribute( Node *node, AttVal *attr );
 
458
void TY_(DetachAttribute)( Node *node, AttVal *attr );
462
459
 
463
460
/* detach attribute from node then free it
464
461
*/
465
 
void RemoveAttribute( TidyDocImpl* doc, Node *node, AttVal *attr );
 
462
void TY_(RemoveAttribute)( TidyDocImpl* doc, Node *node, AttVal *attr );
466
463
 
467
464
/*
468
465
  Free document nodes by iterating through peers and recursing
469
466
  through children. Set next to NULL before calling FreeNode()
470
467
  to avoid freeing peer nodes. Doesn't patch up prev/next links.
471
468
 */
472
 
void FreeNode( TidyDocImpl* doc, Node *node );
 
469
void TY_(FreeNode)( TidyDocImpl* doc, Node *node );
473
470
 
474
 
Node* TextToken( Lexer *lexer );
 
471
Node* TY_(TextToken)( Lexer *lexer );
475
472
 
476
473
/* used for creating preformatted text from Word2000 */
477
 
Node *NewLineNode( Lexer *lexer );
 
474
Node* TY_(NewLineNode)( Lexer *lexer );
478
475
 
479
476
/* used for adding a &nbsp; for Word2000 */
480
 
Node *NewLiteralTextNode(Lexer *lexer, ctmbstr txt );
481
 
 
482
 
Node* CommentToken(Lexer *lexer);
483
 
Node* GetCDATA( TidyDocImpl* doc, Node *container );
484
 
 
485
 
void AddByte( Lexer *lexer, tmbchar c );
486
 
void AddStringLiteral( Lexer* lexer, ctmbstr str );
487
 
void AddStringLiteralLen( Lexer* lexer, ctmbstr str, int len );
 
477
Node* TY_(NewLiteralTextNode)(Lexer *lexer, ctmbstr txt );
 
478
 
 
479
void TY_(AddStringLiteral)( Lexer* lexer, ctmbstr str );
 
480
/* void AddStringLiteralLen( Lexer* lexer, ctmbstr str, int len ); */
488
481
 
489
482
/* find element */
490
 
Node* FindDocType( TidyDocImpl* doc );
491
 
Node* FindHTML( TidyDocImpl* doc );
492
 
Node* FindHEAD( TidyDocImpl* doc );
493
 
Node* FindTITLE(TidyDocImpl* doc);
494
 
Node* FindBody( TidyDocImpl* doc );
495
 
Node* FindXmlDecl(TidyDocImpl* doc);
 
483
Node* TY_(FindDocType)( TidyDocImpl* doc );
 
484
Node* TY_(FindHTML)( TidyDocImpl* doc );
 
485
Node* TY_(FindHEAD)( TidyDocImpl* doc );
 
486
Node* TY_(FindTITLE)(TidyDocImpl* doc);
 
487
Node* TY_(FindBody)( TidyDocImpl* doc );
 
488
Node* TY_(FindXmlDecl)(TidyDocImpl* doc);
496
489
 
497
490
/* Returns containing block element, if any */
498
 
Node* FindContainer( Node* node );
 
491
Node* TY_(FindContainer)( Node* node );
499
492
 
500
493
/* add meta element for Tidy */
501
 
Bool AddGenerator( TidyDocImpl* doc );
502
 
 
503
 
/* examine <!DOCTYPE> to identify version */
504
 
uint FindGivenVersion( TidyDocImpl* doc, Node* doctype );
505
 
uint ApparentVersion( TidyDocImpl* doc );
506
 
 
507
 
 
508
 
Bool CheckDocTypeKeyWords(Lexer *lexer, Node *doctype);
509
 
 
510
 
ctmbstr HTMLVersionName( TidyDocImpl* doc );
511
 
ctmbstr HTMLVersionNameFromCode( uint vers, Bool isXhtml );
512
 
 
513
 
Bool SetXHTMLDocType( TidyDocImpl* doc );
 
494
Bool TY_(AddGenerator)( TidyDocImpl* doc );
 
495
 
 
496
uint TY_(ApparentVersion)( TidyDocImpl* doc );
 
497
 
 
498
ctmbstr TY_(HTMLVersionNameFromCode)( uint vers, Bool isXhtml );
 
499
 
 
500
Bool TY_(WarnMissingSIInEmittedDocType)( TidyDocImpl* doc );
 
501
 
 
502
Bool TY_(SetXHTMLDocType)( TidyDocImpl* doc );
514
503
 
515
504
 
516
505
/* fixup doctype if missing */
517
 
Bool FixDocType( TidyDocImpl* doc );
 
506
Bool TY_(FixDocType)( TidyDocImpl* doc );
518
507
 
519
508
/* ensure XML document starts with <?xml version="1.0"?> */
520
509
/* add encoding attribute if not using ASCII or UTF-8 output */
521
 
Bool FixXmlDecl( TidyDocImpl* doc );
522
 
 
523
 
Node* InferredTag(TidyDocImpl* doc, TidyTagId id);
524
 
 
525
 
Bool ExpectsContent(Node *node);
526
 
 
527
 
 
528
 
void UngetToken( TidyDocImpl* doc );
 
510
Bool TY_(FixXmlDecl)( TidyDocImpl* doc );
 
511
 
 
512
Node* TY_(InferredTag)(TidyDocImpl* doc, TidyTagId id);
 
513
 
 
514
void TY_(UngetToken)( TidyDocImpl* doc );
529
515
 
530
516
 
531
517
/*
535
521
  Preformatted   -- white space preserved as is
536
522
  IgnoreMarkup   -- for CDATA elements such as script, style
537
523
*/
538
 
#define IgnoreWhitespace    0
539
 
#define MixedContent        1
540
 
#define Preformatted        2
541
 
#define IgnoreMarkup        3
542
 
#define CdataContent        4
543
 
 
544
 
Node* GetToken( TidyDocImpl* doc, uint mode );
545
 
 
546
 
void InitMap(void);
547
 
 
548
 
Bool IsValidAttrName( ctmbstr attr );
 
524
typedef enum
 
525
{
 
526
  IgnoreWhitespace,
 
527
  MixedContent,
 
528
  Preformatted,
 
529
  IgnoreMarkup,
 
530
  CdataContent
 
531
} GetTokenMode;
 
532
 
 
533
Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode );
 
534
 
 
535
void TY_(InitMap)(void);
549
536
 
550
537
 
551
538
/* create a new attribute */
552
 
AttVal *NewAttribute(void);
 
539
AttVal* TY_(NewAttribute)( TidyDocImpl* doc );
553
540
 
554
541
/* create a new attribute with given name and value */
555
 
AttVal *NewAttributeEx( TidyDocImpl* doc, ctmbstr name, ctmbstr value,
556
 
                        int delim );
 
542
AttVal* TY_(NewAttributeEx)( TidyDocImpl* doc, ctmbstr name, ctmbstr value,
 
543
                             int delim );
557
544
 
558
545
/* insert attribute at the end of attribute list of a node */
559
 
void InsertAttributeAtEnd( Node *node, AttVal *av );
 
546
void TY_(InsertAttributeAtEnd)( Node *node, AttVal *av );
560
547
 
561
548
/* insert attribute at the start of attribute list of a node */
562
 
void InsertAttributeAtStart( Node *node, AttVal *av );
 
549
void TY_(InsertAttributeAtStart)( Node *node, AttVal *av );
563
550
 
564
551
/*************************************
565
552
  In-line Stack functions
567
554
 
568
555
 
569
556
/* duplicate attributes */
570
 
AttVal* DupAttrs( TidyDocImpl* doc, AttVal* attrs );
 
557
AttVal* TY_(DupAttrs)( TidyDocImpl* doc, AttVal* attrs );
571
558
 
572
559
/*
573
560
  push a copy of an inline node onto stack
585
572
      <p><em>text</em></p>
586
573
      <p><em><em>more text</em></em>
587
574
*/
588
 
void PushInline( TidyDocImpl* doc, Node* node );
 
575
void TY_(PushInline)( TidyDocImpl* doc, Node* node );
589
576
 
590
577
/* pop inline stack */
591
 
void PopInline( TidyDocImpl* doc, Node* node );
 
578
void TY_(PopInline)( TidyDocImpl* doc, Node* node );
592
579
 
593
 
Bool IsPushed( TidyDocImpl* doc, Node* node );
 
580
Bool TY_(IsPushed)( TidyDocImpl* doc, Node* node );
 
581
Bool TY_(IsPushedLast)( TidyDocImpl* doc, Node *element, Node *node );
594
582
 
595
583
/*
596
584
  This has the effect of inserting "missing" inline
609
597
  where it gets tokens from the inline stack rather than
610
598
  from the input stream.
611
599
*/
612
 
int InlineDup( TidyDocImpl* doc, Node *node );
 
600
int TY_(InlineDup)( TidyDocImpl* doc, Node *node );
613
601
 
614
602
/*
615
603
 defer duplicates when entering a table or other
616
604
 element where the inlines shouldn't be duplicated
617
605
*/
618
 
void DeferDup( TidyDocImpl* doc );
619
 
Node *InsertedToken( TidyDocImpl* doc );
 
606
void TY_(DeferDup)( TidyDocImpl* doc );
 
607
Node* TY_(InsertedToken)( TidyDocImpl* doc );
 
608
 
 
609
/* stack manipulation for inline elements */
 
610
Bool TY_(SwitchInline)( TidyDocImpl* doc, Node* element, Node* node );
 
611
Bool TY_(InlineDup1)( TidyDocImpl* doc, Node* node, Node* element );
620
612
 
621
613
#ifdef __cplusplus
622
614
}