Add Multi threading

This commit is contained in:
2019-04-15 19:27:49 +03:00
parent 67bb7b5fed
commit 94d7217bbe
5 changed files with 619 additions and 666 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -4,50 +4,63 @@ Tokenizer Library for Delphi/FPC. Based on [PyPascalTokenizer](https://github.co
## API
### TToken struct
### TAGToken struct
TToken is a `record` type of:
TAGToken is a `record` type of:
* Text: `string` with token text.
* &begin: `TTokenizerPos` with start position of token.
* &end: `TTokenizerPos` with end position of token.
* &begin: `TAGTokenizerPos` with start position of token.
* &end: `TAGTokenizerPos` with end position of token.
* ended: `boolean` flag, true if it was the last token.
Has Create constructor with all values.
### TTokenizerPos
### TAGTokenizerPos
`record`, saves position of token if format:
* x: `integer` platform-depend-base (`NEXTGEN`) character index in line.
* y: `integer` 0-based line index.
### `Class` PasTokenizer
### `Class` TAGPasTokenizer
Main class of tokenizer.
* s: `TStrings` private, use constructor. List of source code strings.
* get_next(): function, returns `TToken`. Get next token and change end pos
* read_next(): function, not implemented, get next token, but don't change end pos.
* is_ended(): function, not implemented, check if text ended.
* get_next(): `TAGToken` function, returns. Get next token and change pos
* pos: `TAGTokenizerPos` property, containing position whear tokenizer was stoped after last get_next(), writeble.
* is_ended: `boolean` property, check if text ended.
Has constructor Create with `s` param.
Has constructor Create with `input`: `TStrings` param.
### `Class` PasTokenizerStack
### `Class` TAGPasTokenizerStack
Not implemented.
Stack of tokens automaticaly filled from input.
### `Class` PasTokenizerParallelStack
* Push(t: `TAGToken`) push token to stack.
* Pop(): `TAGToken` pop token from stack.
* Last: `TAGToken` property, seek stask head.
* ended: `boolean` property, check if text ended.
Not implemented.
Has constructor Create with input: `TStrings` and GetComments: `boolean=True` param.
### `Class` TAGPasTokenizerParallelStack
Stack of tokens automaticaly filled from input(in second tread).
* Push(t: `TAGToken`) push token to stack.
* Pop(): `TAGToken` pop token from stack.
* Last: `TAGToken` property, seek stask head.
* ended: `boolean` property, check if text ended.
Has constructor Create with input: `TStrings`, GetComments: `boolean=True` and stackMax:`integer=1000` param.
## Utils
Helper functions to analyze token text.
* is_name(s: `string`): `boolean` Check for valid identifier (can be reserved word too).
* is_comment(s: `string`): `boolean` Check for valid comment.
* is_string(s: `string`): `boolean` Check for string constant.
* IsName(s: `string`): `boolean` Check for valid identifier (can be reserved word too).
* IsComment(s: `string`): `boolean` Check for valid comment.
* IsString(s: `string`): `boolean` Check for string constant.
## Author

View File

@@ -1,53 +1,66 @@
# AGPascalTokenizer
# AGPascalTokenizer
Библиотека токенайзер для Delphi/FPC. Основана на работе [PyPascalTokenizer](https://github.com/Artem3213212/PyPascalTokenizer) [Артёма Гаврилова](https://github.com/Artem3213212).
## API
### TToken
### TAGToken
TToken это тип `record` из:
TAGToken это тип `record` из:
* Text: `string` с текстом токена.
* &begin: `TTokenizerPos` со стартовой позицией токена.
* &end: `TTokenizerPos` с конечной позицией токена.
* &begin: `TAGTokenizerPos` со стартовой позицией токена.
* &end: `TAGTokenizerPos` с конечной позицией токена.
* ended: `boolean` Истина, если это был постедний токен.
Имеет конструктор Create с перечисленными переменными.
### TTokenizerPos
### TAGTokenizerPos
тип `record`, сохраняет позицию в формате:
* x: `integer` начало зависит от платформы (`NEXTGEN`), индекс символа в строке.
* y: `integer` начало с 0, номер строки.
### `Class` PasTokenizer
### `Class` TAGPasTokenizer
Главный класс токенайзера.
* s: `TStrings` приватная, используйте конструктор. Список строк исходного кода.
* get_next(): функция, возвращает `TToken`. Возвращает следующий токен и изменяет свою позицию.
* read_next(): функция, не имплементированно, Возвращает следующий токен, не изменяя свою позицию.
* is_ended(): функция, не имплементированно, проверка что текст закончился.
* get_next(): функция, возвращает `TAGToken`. Возвращает следующий токен и изменяет позицию.
* pos: `TAGTokenizerPos` свойство, содержит позицию где токенайзер .
* is_ended: `boolean` свойство, проверка что текст закончился.
Имеет конструктор Create с параметром `s`.
Имеет конструктор Create с параметром `input`: `TStrings`.
### `Class` PasTokenizerStack
### `Class` TAGPasTokenizerStack
Не имплементированно.
Стек из токенов автоматически заполняется из input'а.
### `Class` PasTokenizerParallelStack
* Push(t: `TAGToken`) кладёт токен в стек.
* Pop(): `TAGToken` достать токен из стека.
* Last: `TAGToken` свойство, выдающееся вершина стека.
* is_ended: `boolean` свойство, проверка конца текста.
Не имплементированно.
Имеет конструктор Create с параметрами `input`: `TStrings` и GetComments: `boolean=True`.
### `Class` TAGPasTokenizerParallelStack
Стек из токенов автоматически заполняется из input'а(во втором потоке).
* Push(t: `TAGToken`) кладёт токен в стек.
* Pop(): `TAGToken` достать токен из стека.
* Last: `TAGToken` свойство, выдающееся вершина стека.
* ended: `boolean` свойство, проверка конца текста.
Имеет конструктор Create с параметрами input: `TStrings`, GetComments: `boolean=True` и stackMax:`integer=1000`.
## Утилиты
Вспомогательные функции для анализа текста.
* is_name(s: `string`): `boolean` Проверка что идентификатор правильный.
* is_comment(s: `string`): `boolean` Проверка что комментарий правильный.
* is_string(s: `string`): `boolean` Проверка что это строковое значение.
* IsName(s: `string`): `boolean` Проверка что идентификатор правильный.
* IsComment(s: `string`): `boolean` Проверка что комментарий правильный.
* IsString(s: `string`): `boolean` Проверка что это строковое значение.
## Авторы

View File

@@ -11,7 +11,7 @@ program Demo;
uses
{$IF not defined(FPC)}
FastMM4,
//FastMM4,
{$endif}
SysUtils,
Classes,

View File

@@ -13,11 +13,6 @@
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Android' and '$(Base)'=='true') or '$(Base_Android)'!=''">
<Base_Android>true</Base_Android>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
@@ -55,19 +50,6 @@
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<SanitizedProjectName>Demo</SanitizedProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Android)'!=''">
<DCC_UsePackage>DBXSqliteDriver;RESTComponents;DBXInterBaseDriver;emsclientfiredac;DataSnapFireDAC;tethering;bindcompfmx;FmxTeeUI;FireDACIBDriver;fmx;FireDACDBXDriver;dbexpress;IndyCore;dsnap;DataSnapCommon;emsclient;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;DataSnapClient;inet;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;FMXTee;soaprtl;DbxCommonDriver;xmlrtl;soapmidas;DataSnapNativeClient;FireDACDSDriver;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;$(DCC_UsePackage)</DCC_UsePackage>
<Android_LauncherIcon36>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_36x36.png</Android_LauncherIcon36>
<Android_LauncherIcon48>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_48x48.png</Android_LauncherIcon48>
<Android_LauncherIcon72>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_72x72.png</Android_LauncherIcon72>
<Android_LauncherIcon96>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_96x96.png</Android_LauncherIcon96>
<Android_LauncherIcon144>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_144x144.png</Android_LauncherIcon144>
<Android_SplashImage426>$(BDS)\bin\Artwork\Android\FM_SplashImage_426x320.png</Android_SplashImage426>
<Android_SplashImage470>$(BDS)\bin\Artwork\Android\FM_SplashImage_470x320.png</Android_SplashImage470>
<Android_SplashImage640>$(BDS)\bin\Artwork\Android\FM_SplashImage_640x480.png</Android_SplashImage640>
<Android_SplashImage960>$(BDS)\bin\Artwork\Android\FM_SplashImage_960x720.png</Android_SplashImage960>
<EnabledSysJars>android-support-v4.dex.jar;cloud-messaging.dex.jar;fmx.dex.jar;google-analytics-v2.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar;google-play-services-ads-7.0.0.dex.jar;google-play-services-analytics-7.0.0.dex.jar;google-play-services-base-7.0.0.dex.jar;google-play-services-gcm-7.0.0.dex.jar;google-play-services-identity-7.0.0.dex.jar;google-play-services-maps-7.0.0.dex.jar;google-play-services-panorama-7.0.0.dex.jar;google-play-services-plus-7.0.0.dex.jar;google-play-services-wallet-7.0.0.dex.jar</EnabledSysJars>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<DCC_UsePackage>DBXSqliteDriver;RESTComponents;DataSnapServerMidas;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;emsclientfiredac;DataSnapFireDAC;svnui;tethering;JvGlobus;FireDACADSDriver;JvPluginSystem;DBXMSSQLDriver;JvMM;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;JvBands;vcldb;bindcompfmx;svn;JvJans;DBXOracleDriver;JvNet;inetdb;JvAppFrm;VirtualTreesDR;FmxTeeUI;emsedge;JvDotNetCtrls;FireDACIBDriver;fmx;fmxdae;JvWizards;FireDACDBXDriver;dbexpress;IndyCore;vclx;JvPageComps;dsnap;DataSnapCommon;emsclient;FireDACCommon;JvDB;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;JclDeveloperTools;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;CloudService;FireDACMySQLDriver;DBXFirebirdDriver;JvCmp;JvHMI;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;OverbyteIcsD103Run;bindcompdbx;IndyIPCommon;JvCustom;vcl;DBXSybaseASEDriver;IndyIPServer;JvXPCtrls;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;FireDAC;GrtPanelPackage;Jcl;JvCore;emshosting;JvCrypt;FireDACSqliteDriver;FireDACPgDriver;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;JvDlgs;JvRuntimeDesign;JvManagedThreads;Tee;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;emsserverresource;DbxClientDriver;JvTimeFramework;DBXSybaseASADriver;CustomIPTransport;vcldsnap;JvSystem;JvStdCtrls;FrameViewerXE9;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;SynEdit_R;TeeUI;JvDocking;dbxcds;VclSmp;JvPascalInterpreter;adortl;FireDACODBCDriver;JclVcl;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;IndyProtocols;JvControls;JvPrintPreview;JclContainers;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
@@ -139,13 +121,24 @@
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="OSX32">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\Demo.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>Demo.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\osx64\libcgsqlite3.dylib" Class="DependencyModule">
<Platform Name="OSX64">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="OSX32">
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libPCRE.dylib" Class="DependencyModule">
<Platform Name="iOSSimulator">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
@@ -164,12 +157,6 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\Demo.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>Demo.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployClass Name="AdditionalDebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>
@@ -179,6 +166,7 @@
<Operation>1</Operation>
</Platform>
<Platform Name="Win32">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>0</Operation>
</Platform>
</DeployClass>
@@ -314,11 +302,6 @@
<Operation>1</Operation>
<Extensions>.framework</Extensions>
</Platform>
<Platform Name="OSX64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.framework</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
@@ -341,11 +324,6 @@
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="OSX64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
@@ -369,11 +347,6 @@
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="OSX64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.bpl</Extensions>
@@ -396,10 +369,6 @@
<RemoteDir>Contents\Resources\StartUp\</RemoteDir>
<Operation>0</Operation>
</Platform>
<Platform Name="OSX64">
<RemoteDir>Contents\Resources\StartUp\</RemoteDir>
<Operation>0</Operation>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
@@ -547,30 +516,18 @@
<RemoteDir>..\</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSX64">
<RemoteDir>..\</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXInfoPList">
<Platform Name="OSX32">
<RemoteDir>Contents</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSX64">
<RemoteDir>Contents</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXResource">
<Platform Name="OSX32">
<RemoteDir>Contents\Resources</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSX64">
<RemoteDir>Contents\Resources</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Required="true" Name="ProjectOutput">
<Platform Name="Android">
@@ -593,10 +550,6 @@
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSX64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
@@ -640,7 +593,6 @@
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
</Deployment>
<Platforms>
<Platform value="Android">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>