You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
4.8 KiB
190 lines
4.8 KiB
//*****************************************************************
|
|
//
|
|
// $file: scanner.h $
|
|
// $author: Martin Fouilleul $
|
|
// $date: 24/12/2017 $
|
|
//
|
|
//*****************************************************************
|
|
|
|
/*
|
|
------------------------------------------------------------------------------
|
|
This software is available under 2 licenses -- choose whichever you prefer.
|
|
------------------------------------------------------------------------------
|
|
ALTERNATIVE A - MIT License
|
|
Copyright (c) 2017 Martin Fouilleul
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
the Software without restriction, including without limitation the rights to
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
of the Software, and to permit persons to whom the Software is furnished to do
|
|
so, subject to the following conditions:
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
------------------------------------------------------------------------------
|
|
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
|
This is free and unencumbered software released into the public domain.
|
|
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
|
software, either in source code form or as a compiled binary, for any purpose,
|
|
commercial or non-commercial, and by any means.
|
|
In jurisdictions that recognize copyright laws, the author or authors of this
|
|
software dedicate any and all copyright interest in the software to the public
|
|
domain. We make this dedication for the benefit of the public at large and to
|
|
the detriment of our heirs and successors. We intend this dedication to be an
|
|
overt act of relinquishment in perpetuity of all present and future rights to
|
|
this software under copyright law.
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
------------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
#ifndef __SCANNER_H_
|
|
#define __SCANNER_H_
|
|
|
|
enum{MODE_TEXT, MODE_MATHS_INLINE, MODE_MATHS_BLOCK, MODE_CODE_INLINE, MODE_CODE_BLOCK, MODE_HTML};
|
|
|
|
const int MAX_HTML_TAG_LENGTH = 1023;
|
|
const int MAX_MARKUP_TAG_LENGTH = 1023;
|
|
|
|
struct html_tag
|
|
{
|
|
char text[MAX_HTML_TAG_LENGTH+1];
|
|
};
|
|
|
|
typedef enum {MATHS_INLINE_START,
|
|
MATHS_INLINE_STOP,
|
|
MATHS_BLOCK_START,
|
|
MATHS_BLOCK_STOP,
|
|
CODE_INLINE_START,
|
|
CODE_INLINE_STOP,
|
|
CODE_BLOCK_START,
|
|
CODE_BLOCK_STOP,
|
|
HTML_BLOCK_START,
|
|
HTML_BLOCK_STOP,
|
|
URL_START,
|
|
URL_STOP,
|
|
IMG,
|
|
SECTION,
|
|
UNDERLINE,
|
|
BOLD,
|
|
ITALIC,
|
|
REGULAR,
|
|
LIST,
|
|
SUBSCRIPT,
|
|
SUPERSCRIPT,
|
|
VECTOR,
|
|
SQRT,
|
|
FRACTION,
|
|
NSUM,
|
|
NPRODUCT } markup_type;
|
|
|
|
struct markup_tag
|
|
{
|
|
markup_type type;
|
|
union
|
|
{
|
|
int value;
|
|
char text[MAX_MARKUP_TAG_LENGTH+1];
|
|
};
|
|
};
|
|
|
|
typedef enum { MULTIPLY,
|
|
DIVIDE,
|
|
SUBSTRACT,
|
|
STAR,
|
|
LOSTAR,
|
|
CDOT,
|
|
OTIMES,
|
|
LEQ,
|
|
GEQ,
|
|
INF,
|
|
LARR,
|
|
RARR,
|
|
EMDASH,
|
|
LINE,
|
|
THINSPACE,
|
|
ALPHA,
|
|
BETA,
|
|
GAMMA,
|
|
DELTA,
|
|
EPSILON,
|
|
ZETA,
|
|
ETA,
|
|
THETA,
|
|
IOTA,
|
|
KAPPA,
|
|
LAMBDA,
|
|
MU,
|
|
NU,
|
|
XI,
|
|
OMICRON,
|
|
PI,
|
|
RHO,
|
|
SIGMA,
|
|
TAU,
|
|
UPSILON,
|
|
PHI,
|
|
CHI,
|
|
PSI,
|
|
OMEGA,
|
|
ALPHA_UPPER,
|
|
BETA_UPPER,
|
|
GAMMA_UPPER,
|
|
DELTA_UPPER,
|
|
EPSILON_UPPER,
|
|
ZETA_UPPER,
|
|
ETA_UPPER,
|
|
THETA_UPPER,
|
|
IOTA_UPPER,
|
|
KAPPA_UPPER,
|
|
LAMBDA_UPPER,
|
|
MU_UPPER,
|
|
NU_UPPER,
|
|
XI_UPPER,
|
|
OMICRON_UPPER,
|
|
PI_UPPER,
|
|
RHO_UPPER,
|
|
SIGMA_UPPER,
|
|
TAU_UPPER,
|
|
UPSILON_UPPER,
|
|
PHI_UPPER,
|
|
CHI_UPPER,
|
|
PSI_UPPER,
|
|
OMEGA_UPPER } symbol_code;
|
|
|
|
struct markup_symbol
|
|
{
|
|
symbol_code code;
|
|
};
|
|
|
|
typedef enum { CHAR, SYMBOL, ESC, ENDL, ENDF, MARKUP, HTML_TAG} token_type;
|
|
|
|
struct token
|
|
{
|
|
token_type type;
|
|
int line;
|
|
int col;
|
|
union
|
|
{
|
|
char c;
|
|
html_tag html;
|
|
markup_tag markup;
|
|
markup_symbol symbol;
|
|
};
|
|
};
|
|
|
|
void GetNextToken(FILE* input, token* t);
|
|
void ResetScanMode();
|
|
|
|
#endif //__SCANNER_H_
|
|
|