1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
%{
{
Copyright (c) 2008 by Felipe Monteiro de Carvalho
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************}
unit fmlscan;
{$ifdef fpc}
{$mode delphi}
{$endif}
interface
uses
strings, sysutils, lexlib;
type
TFMLBlock = (fbStructure, fbText);
TFMLScannerDelegate = class
public
procedure DoAddTopic(aTopic: string); virtual; abstract;
procedure DoSetTextColor(aColor: string); virtual; abstract;
procedure DoSetTitle(aTitle: string); virtual; abstract;
procedure DoWriteChars(aChars: string); virtual; abstract;
end;
const
currentBlock: TFMLBlock = fbStructure;
var
scannerDelegate: TFMLScannerDelegate;
function yylex : integer;
function act_token : string;
implementation
%}
DIGIT [0-9]
LETTER [a-zA-Z]
NOTLETTER ^[a-zA-Z]
%%
(\{title\}).*\n
if currentBlock = fbStructure then
begin
scannerDelegate.DoSetTitle(System.Copy(yytext, 8, Length(yytext) - 8));
end
else raise Exception.Create('Tag {title} in invalid document position');
(\{topic\}).*\n
if currentBlock = fbStructure then
begin
scannerDelegate.DoAddTopic(System.Copy(yytext, 8, Length(yytext) - 8));
end
else raise Exception.Create('Tag {topic} in invalid document position');
\{color=LETTER*\}
if currentBlock = fbText then
begin
scannerDelegate.DoSetTextColor(yytext);
end;
.
if currentBlock = fbText then
begin
scannerDelegate.DoWriteChars(yytext);
end;
%%
function act_token: string;
begin
Result := yytext;
end;
{ Overrides the default yywrap function to avoid having the input
file being closed. Returns True to indicate that yylex should
terminate when the end-of-file marker is found }
function fml_yywrap(): Boolean;
begin
Result := True;
end;
initialization
lexlib.yywrap := @fml_yywrap;
end.
|