Giter Club home page Giter Club logo

Comments (7)

RomanYankovsky avatar RomanYankovsky commented on June 12, 2024

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.

 avatar commented on June 12, 2024

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.

quartexNOR avatar quartexNOR commented on June 12, 2024

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.

RomanYankovsky avatar RomanYankovsky commented on June 12, 2024

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.

RomanYankovsky avatar RomanYankovsky commented on June 12, 2024
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.

quartexNOR avatar quartexNOR commented on June 12, 2024

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.

RomanYankovsky avatar RomanYankovsky commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.