Comments (7)
As far as I understood, you want to manually make parser fail on unsupported language elements for a selected dialect, right?
It is not difficult to implement. I think, the easiest way to do that is to inherit TPasSyntaxTreeBuilder class.
For example:
TPasSyntaxTreeBuilderD7 = class(TPasSyntaxTreeBuilder)
protected
procedure TypeArgs; override;
// etc..
end;
procedure TPasSyntaxTreeBuilderD7.TypeArgs;
begin
raise ENotSupported.Create('Not supported in D7: TypeArgs');
end;
// etc...
So it's doable. Is this what you need?
from delphiast.
This is a good idea, especially given that we have at our disposal a list of all language features, when they were added, when they were improved, and anything that was removed.
To have these as an enumerated set would be very handy, then to have a set of constants defined for specific versions would make it trivial to for an implementing developer to use.
It would also enable IDE extensions to be able to warn third-party tools/components/library developers when they're using features that are only available within a particular range of Delphi versions (can't tell you how much time that would've saved me over the last 5+ years).
from delphiast.
Yes that was what I had in mind.
For instance, let's say I want to use DAST to generate JS compatible code, where a code-generator is written to handle the node-tree directly (or through an XML import).
I would then disable pointer-support, library-support, message support etc., forcing the user to write plain, vanilla "safe" object pascal. DelphiAST would then function as a parser and method of making sure the syntax is correct. The codegen's job would be to reflect everything in the target language as best it can.
If anyone tries to use those features while these options are enabled, we could either throw an exception or (perhaps) signal an event.
Something like:
Raise EDASTDialectError('Pointers are not allowed for the present dialect');
Like LAKraven says, this makes it possible to have "default" settings which mimics the evolution of Delphi, from the older Delphi-7 dialect through the more modern phases up to XE7.
Hopefully we could also add support for some of the Smart Pascal dialect features, like lambdas, shortcut properties, ++ / -- operators and array helpers. That way we would have the proverbial sauron's ring in terms of AST support.
SMS has a few interesting dialect changes, for instance:
Type
TMyObject = Class(TObject)
published
Property Name:String;
Property Value:variant;
end;
And shorthand operators like:
FValue ++; // Inc by 1
FValue --; // dec by 1
FValue +=12; //add 12
Also, all arrays have more or less all the methods you would expect from a TList.
var
mBuffer: Array of Integer;
Begin
mBuffer.add(12);
mbuffer.insert(0,13);
mBuffer.delete(0,1);
mBuffer.sort;
mBuffer.clear;
end;
I would add this myself, but i have to spend some time with pasParse before i jump in. ++/--/+= operators requires two reads as opposed to the standard single char operator, do we have a "peek next token" somewhere?
e.g:
previous token was a variable
current token is "+"
next token is "+"
next next token is ";"
At which point we know it's an inc operation.
I had a round with castalia a couple of years back, but have focused completely on DWScript - since that's where 90% of my free time goes these days.
from delphiast.
If we are going to support alternative dialects (like FreePascal, or SMS, or DWScript), we have to consider some form of class inheritance or dependency injection. Supporting all dialects in a single class will make it overcomplicated...
I would add this myself, but i have to spend some time with pasParse before i jump in. ++/--/+= operators requires two reads as opposed to the standard single char operator, do we have a "peek next token" somewhere?
You can take a look at >=, <=, <> operators implementation. They require two reads too. Just do a search for "ptGreaterEqual" substring. But adding new operators is not as easy as it could be: you have to add a support for a new operator to lexer, then to parser, and finally to AST builder. To all three layers of logic.
from delphiast.
var
mBuffer: Array of Integer;
Begin
mBuffer.add(12);
mbuffer.insert(0,13);
mBuffer.delete(0,1);
mBuffer.sort;
mBuffer.clear;
end;
This will be parsed without any problems :) Parser doesn't do type check.
from delphiast.
Those methods are "magic" methods, meaning they should be known to the parser, as they are not defined anywhere. Does castalia do symbol checks? Meaning - checking that a class actually have a member or a record/datatype have members?
from delphiast.
Syntactically, the code above is absolutely correct. Parser checks syntax only, nothing else. @LaKraven was going to start developing a symbol table builder on the top of existing AST. This will make such checks possible.
from delphiast.
Related Issues (20)
- Can't parse System.Classes.pas HOT 2
- Can't parse Posix.SysSocket.pas
- Can't parse System.Internal.Unwinder.pas
- Attributes for variant record fields missing HOT 2
- How to compile in Lazarus v2.0.6 HOT 2
- Need list of all comments HOT 10
- Need feature to REMOVE all elements of a specific type from the source HOT 1
- Get the end_line and end_col of a multi-line comment? HOT 3
- Lexer does not fully initializes its state HOT 1
- Possible string mismatch? HOT 2
- Lexer does not parse Unicode characters
- Procedure declaration with varargs directive is not fully supported
- {$I ..\file.inc} is not proceed correctly
- delphi2007 compile failed HOT 1
- Cannot parse System.SysUtils in 10.4.2 - should there be a default set of defines? HOT 7
- FreePascal demo is not working HOT 2
- Lexer failes parsing generic types with default value without spacecing inbetween
- Error when assigning a initial value to generic "global" variable in a specific way. HOT 1
- Should an empty begin/end block be classified as `ntEmptyStatement` ? HOT 1
- Bing chat claims: DelphiAST.Helpers file exist but it's not there ? What is going on ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from delphiast.