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

pygments syntax: improve cylc lexer #2274

Merged

Conversation

oliver-sanders
Copy link
Member

@oliver-sanders oliver-sanders commented Jan 7, 2019

Support additional features of the Cylc suite.rc language to permit use in the Cylc documentation (cylc/cylc-flow#2910).

Adds support for the following (see table in cylc/cylc-flow#2752):

  • Inter-Suite
  • Include files
  • xtriggers
  • empy

Fixes:

  • Line continuation characters in headings
     [foo, \
     bar]
    
  • Cycle points in inter-cycle offsets

Copy link
Member

@matthewrmshin matthewrmshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good by eyeballs 👀 (+ 👓 in my case). Do we need some automated tests?

@oliver-sanders
Copy link
Member Author

oliver-sanders commented Jan 7, 2019

Automated testing for syntax files, hmmm, that might be a tricky one.

The simplest thing I can think of doing would be to come up with some devilishly convoluted examples to run through each editor in turn, then perform a visual diff on before and after screenshots. We need to look into this stuff anyway for future GUI development ...

Copy link
Member

@matthewrmshin matthewrmshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a way to test by giving the lexical analyser some suite.rc fragments and see what tokens come out on the other side, then we should try that. Otherwise, change looks OK.

@oliver-sanders
Copy link
Member Author

If there is a way to test by giving the lexical analyser some suite.rc fragments and see what tokens come out on the other side

For pygments, yes.
For vim, possibly.
For gedit god knows.

See cylc/cylc-flow#2915 for a discussion on testing approaches for syntax files.

@oliver-sanders
Copy link
Member Author

Have added standard reference files for testing lexers in cylc/cylc-flow#2916.

PS/ Spotted an edge case with empy (@[if []]).

(r'\s', Text),
(r'=>', Operator),
(r'[\&\|\!]', Operator),
(r'[\&\|]', Operator),
(r'[\(\)]', Punctuation),
(r'\[', Text, 'intercycle-offset'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed one omission. Dependencies on specific cycle points e.g. graph = "red[2019] => blue" are supported as valid specification within square brackets in a graph string, where only intercycle offsets appear to be recognised by the lexer as-is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drat.

Turns out you can also do arithmetic (e.g. [^ + P1D]) which I didn't know. This is going to be a little trickier to support whilst maintaining error checking.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The good news is the lexer is now so water-tight it picked up on several missing markers in some of the Cylc documentation code excerpts. It's nearly there 👏

@oliver-sanders oliver-sanders removed the request for review from wxtim January 11, 2019 17:13
Copy link
Contributor

@sadielbartholomew sadielbartholomew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Very sorry for the delay in re-reviewing, I didn't realise commented reviews took PRs off the GitHub 'review requests' listing.)

Works as described. Lack of associated tests justified by comment.

To note: dependencies on specific cycle points are recognised after merge of this PR, but cycle point arithmetic has not been included in the PR domain & should eventually be incorporated:

syntax_highl

@sadielbartholomew sadielbartholomew merged commit b3191eb into metomi:master Jan 25, 2019
@oliver-sanders
Copy link
Member Author

oliver-sanders commented Jan 25, 2019

cycle point arithmetic has not been included

Arithmetic is fine but arbitrary whitespace is not supported.

Table updated accordingly

@sadielbartholomew
Copy link
Contributor

Arithmetic is fine but arbitrary whitespace is not supported.

Oh, fair enough, I simply used the example you provided in your original comment, assuming it was valid. Good!

@oliver-sanders oliver-sanders deleted the pygments-lexer-imprevements branch January 25, 2019 14:25
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