Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PortugolLexer #2300

Merged
merged 2 commits into from
Dec 10, 2022

Conversation

LorhanSohaky
Copy link
Contributor

@LorhanSohaky LorhanSohaky commented Dec 6, 2022

Portugol don't have a extensive documentation, so I based on Pascal lexer and the manual of Visualg that is a program that's implements the Portugol.

issue #2299

@jeanas
Copy link
Contributor

jeanas commented Dec 6, 2022

This looks like lots of copy/paste from DelphiLexer, can you merge it into it by introducing a new boolean option to the lexer similar to turbopascal and freepascal?

@LorhanSohaky
Copy link
Contributor Author

This looks like lots of copy/paste from DelphiLexer, can you merge it into it by introducing a new boolean option to the lexer similar to turbopascal and freepascal?

It's because Portugol doesn't understand Delphi's or Pascal's reserved words

@jeanas
Copy link
Contributor

jeanas commented Dec 7, 2022

That should not be a problem. Just change DelphiLexer.__init__ so the lexer's keyword data is what you want if portugol=True is passed.

@LorhanSohaky
Copy link
Contributor Author

Some differences:

  • hex and char types are not supported
  • there are no classes
  • only single comments are supported
  • the operators ; @ and ^ are not supported
  • portugol has the operator <-
  • asm is not supported
  • label and goto are not supported
  • function modifiers are not supported
  • strings only with double quotes

Still do you think it's better to put portugol in DelphiLexer? A bit afraid is to appear several if portugol in the code or stylize tokens that shouldn't.

@jeanas
Copy link
Contributor

jeanas commented Dec 7, 2022

Yes, this is a lot of code duplication and I'd really prefer not to.

if portugol is not a problem.

You can use if portugol if needed to prevent tokens from being styled if they don't have a meaning in Portugol. Keep in mind that it's a non-goal for Pygments to validate the input, so this will only be necessary if valid Portugol code would be highlighted wrongly.

@LorhanSohaky
Copy link
Contributor Author

@jean-abou-samra , ok. How can I pass this parameter to the Lexer

image

@jeanas
Copy link
Contributor

jeanas commented Dec 10, 2022

lexer = DelphiLexer(portugol=True)

@LorhanSohaky
Copy link
Contributor Author

lexer = DelphiLexer(portugol=True)

It's because when running the tests I don't know how to pass this parameter.

python -m pygments -x -l pygments/lexers/pascal.py:DelphiLexer tests/examplefiles/delphi/example.alg

And every time the user uses it, will he have to pass this parameter? For example, in mkdocs material

```portugol(portugol=true)

// My code
```

https://squidfunk.github.io/mkdocs-material/reference/code-blocks/

@jeanas
Copy link
Contributor

jeanas commented Dec 10, 2022

Well, that's true. OTOH, you can do

class PortugolLexer:
    name = 'Portugol'
    aliases = ['portugol']
    # etc. (mimetypes, filenames)
    def __new__(cls, *args, **kwargs):
        return DelphiLexer(*args, **kwargs, portugol=True)

and that will make the lexer available as a normal lexer class and enable the ```portugol syntax in mkdocs/whatever.

@LorhanSohaky
Copy link
Contributor Author

Perfect! Do you recommend me putting it in the same file or creating a file just for Portugol Lexer as a Delphi inheritor?

@jeanas
Copy link
Contributor

jeanas commented Dec 10, 2022

In the same file, as it's just a wrapper.

@LorhanSohaky
Copy link
Contributor Author

@jean-abou-samra , thanks!

@jeanas jeanas merged commit 478318b into pygments:master Dec 10, 2022
@jeanas
Copy link
Contributor

jeanas commented Dec 10, 2022

Thanks for the update, looks much better now. I'll do some touch-ups.

@LorhanSohaky
Copy link
Contributor Author

Thanks for the update, looks much better now. I'll do some touch-ups.

I thank you. Can you tell me when the next release will be? I'm very excited to use

@jeanas
Copy link
Contributor

jeanas commented Dec 10, 2022

I don't think there is a date set in stone yet.

You can always install the latest version from source using

pip install https://github.com/pygments/pygments/archive/master.zip

@Anteru Anteru added this to the 2.14.0 milestone Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants