JWM Source Documentation
Functions | Variables
lex.c File Reference

XML lexer functions. More...

#include "jwm.h"
#include "lex.h"
#include "error.h"
#include "misc.h"

Go to the source code of this file.

Functions

static TokenNodeCreateNode (TokenNode *current, const char *file, unsigned int line)
 Create an empty XML tag node.
 
static AttributeNodeCreateAttribute (TokenNode *np)
 Create an empty XML attribute node.
 
static char IsElementEnd (char ch)
 Determine if ch is the end of a tag/attribute name.
 
static char IsValueEnd (char ch)
 Determine if ch is the end of tag data.
 
static char IsAttributeEnd (char ch)
 Determine if ch is the end of an attribute value.
 
static char * ReadElementName (const char *line)
 Get the name of the next element.
 
static char * ReadValue (const char *line, const char *file, char(*IsEnd)(char), unsigned int *offset, unsigned int *lineNumber)
 Read the value of an element or attribute.
 
static char * ReadElementValue (const char *line, const char *file, unsigned int *offset, unsigned int *lineNumber)
 Get the value of the current element.
 
static char * ReadAttributeValue (const char *line, const char *file, unsigned int *offset, unsigned int *lineNumber)
 Get the value of the current attribute.
 
static int ParseEntity (const char *entity, char *ch, const char *file, unsigned int line)
 Parse an entity reference.
 
static TokenType LookupType (const char *name, TokenNode *np)
 Get the token for a tag name.
 
TokenNodeTokenize (const char *line, const char *fileName)
 Tokenize data.
 
const char * GetTokenName (const TokenNode *tp)
 Get a string representation of a token.
 
const char * GetTokenTypeName (TokenType type)
 Get the string representation of a token.
 
void ReleaseTokens (TokenNode *np)
 Release a token list.
 

Variables

static const int BLOCK_SIZE = 16
 Amount to increase allocations by when reading text.
 
static const StringMappingType TOKEN_MAP []
 Mapping between token names and tokens.
 
static const unsigned int TOKEN_MAP_COUNT = sizeof(TOKEN_MAP) / sizeof(TOKEN_MAP[0])
 
static TokenNodehead
 

Detailed Description

XML lexer functions.

Author
Joe Wingbermuehle
Date
2004-2014

Definition in file lex.c.

Function Documentation

AttributeNode * CreateAttribute ( TokenNode np)
static

Create an empty XML attribute node.

Definition at line 586 of file lex.c.

References Allocate, TokenNode::attributes, AttributeNode::name, AttributeNode::next, and AttributeNode::value.

Referenced by Tokenize().

TokenNode * CreateNode ( TokenNode current,
const char *  file,
unsigned int  line 
)
static
const char* GetTokenName ( const TokenNode tp)

Get a string representation of a token.

Get a string represention of a token.

Definition at line 523 of file lex.c.

References GetTokenTypeName(), TokenNode::invalidName, and TokenNode::type.

Referenced by InvalidTag(), Parse(), ParseMenuItem(), ParseTokenValue(), and Tokenize().

const char* GetTokenTypeName ( TokenType  type)

Get the string representation of a token.

Get a string represention of a token.

Definition at line 533 of file lex.c.

References FindKey(), and TOKEN_MAP_COUNT.

Referenced by GetTokenName(), and InvalidTag().

char IsAttributeEnd ( char  ch)
static

Determine if ch is the end of an attribute value.

Definition at line 396 of file lex.c.

Referenced by ReadAttributeValue().

char IsElementEnd ( char  ch)
static

Determine if ch is the end of a tag/attribute name.

Definition at line 376 of file lex.c.

Referenced by ReadElementName().

char IsValueEnd ( char  ch)
static

Determine if ch is the end of tag data.

Definition at line 408 of file lex.c.

Referenced by ReadElementValue().

TokenType LookupType ( const char *  name,
TokenNode np 
)
static

Get the token for a tag name.

Definition at line 503 of file lex.c.

References CopyString(), FindValue(), TokenNode::invalidName, JUNLIKELY, TOK_INVALID, TOKEN_MAP_COUNT, and TokenNode::type.

Referenced by Tokenize().

int ParseEntity ( const char *  entity,
char *  ch,
const char *  file,
unsigned int  line 
)
static

Parse an entity reference.

The entity value is returned in ch and the length of the entity is returned as the value of the function.

Definition at line 326 of file lex.c.

References _, AllocateStack, ReleaseStack, and Warning().

Referenced by ReadValue().

char * ReadAttributeValue ( const char *  line,
const char *  file,
unsigned int *  offset,
unsigned int *  lineNumber 
)
static

Get the value of the current attribute.

Definition at line 494 of file lex.c.

References IsAttributeEnd(), and ReadValue().

Referenced by Tokenize().

char * ReadElementName ( const char *  line)
static

Get the name of the next element.

Definition at line 420 of file lex.c.

References Allocate, and IsElementEnd().

Referenced by Tokenize().

char * ReadElementValue ( const char *  line,
const char *  file,
unsigned int *  offset,
unsigned int *  lineNumber 
)
static

Get the value of the current element.

Definition at line 485 of file lex.c.

References IsValueEnd(), and ReadValue().

Referenced by Tokenize().

char * ReadValue ( const char *  line,
const char *  file,
char(*)(char)  IsEnd,
unsigned int *  offset,
unsigned int *  lineNumber 
)
static

Read the value of an element or attribute.

Definition at line 439 of file lex.c.

References _, Allocate, BLOCK_SIZE, FatalError(), JUNLIKELY, ParseEntity(), Reallocate, and Trim().

Referenced by ReadAttributeValue(), and ReadElementValue().

void ReleaseTokens ( TokenNode np)
TokenNode* Tokenize ( const char *  line,
const char *  fileName 
)

Variable Documentation

const int BLOCK_SIZE = 16
static

Amount to increase allocations by when reading text.

Definition at line 16 of file lex.c.

Referenced by ReadFile(), and ReadValue().

TokenNode* head
static

Definition at line 96 of file lex.c.

Referenced by CreateNode(), and Tokenize().

const StringMappingType TOKEN_MAP[]
static

Mapping between token names and tokens.

These must be sorted.

Definition at line 21 of file lex.c.

const unsigned int TOKEN_MAP_COUNT = sizeof(TOKEN_MAP) / sizeof(TOKEN_MAP[0])
static

Definition at line 94 of file lex.c.

Referenced by GetTokenTypeName(), and LookupType().

joewing.net / Projects / JWM