Skip to content

Commit

Permalink
improved do statements and if statements
Browse files Browse the repository at this point in the history
fixes #14
  • Loading branch information
315234 committed Jun 21, 2016
1 parent 9deb5aa commit 0446aee
Showing 1 changed file with 67 additions and 8 deletions.
75 changes: 67 additions & 8 deletions grammars/FortranModern.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ variables:
{{entity_decl_list}}
)
construct_name: (?xi:{{ident}} \s* (?=:)) # do/if statement label (a valid identifier followed by colon)
stmt_label: (?xi:\b \d+ \b) # a statement label (a number)



Expand Down Expand Up @@ -397,24 +399,81 @@ contexts:
flow-control:
# do loop (with optional label and number)
# do_while_statement (must come before do_statement)
- match: |
(?xi)
(?:^ \s*
(?:(\w+):\s*)? (do \s+ concurrent|do) \b
(\s+\d+\s+)?
\s*
(?: ({{construct_name}}) : )? # 1 optional do statement label
\s* \b (do) \b # 2 do keyword
\s* ({{stmt_label}})? # 3 statement label with comma
\s* ,? # optional comma
\s* \b (while) \b # 4 while keyword
(?= \s* \( ) # lookahead to expect opening parenthesis
# Can't use this stuff:
# \s* \( # opening parenthesis
# .* # logical scalar expression
# \s* \) # closing parenthesis
)
scope: meta.do_while_statement.fortran
captures:
1: entity.name.tag.do-loop-label.fortran
1: entity.name.tag.construct_name.fortran
2: keyword.control.fortran
3: entity.name.statement-label.fortran
3: entity.name.statement-label.fortran constant.numeric
4: keyword.control.fortran
# do_statement
- match: |
(?xi)
(?:^ \s*
(?: ({{construct_name}}) : )? # optional do statement label
\s* \b (do|do \s+ concurrent) \b # do keyword
\s* ({{stmt_label}})? # statement label with comma
\s* (?:
,? # optional comma
\s* ({{ident}}) # loop variable name
\s* (=) # equals sign
# Can't match this stuff due to lack of regex for an expression
# \s* an_expr_ # expression 1
# \s* , # comma
# \s* an_expr_ # expression 2
# (
# \s* ,
# \s* an_expr_ # expression 3
# )?
)?
)
scope: meta.do_statement.fortran
captures:
1: entity.name.tag.construct_name.fortran
2: keyword.control.fortran
3: entity.name.statement-label.fortran constant.numeric
4: variable.do_loop_variable.fortran
5: keyword.operator.fortran
# block_if_statement
- match: |
(?xi)
(?:^ \s*
(?: ({{construct_name}}) : )? # 1 optional if statement label
\s* \b (if) \b # 2 if keyword
(?= \s* \( ) # lookahead to expect opening parenthesis
# Can't match this stuff due to lack of regex for an expression
# \s* \( # opening parenthesis
# .* # logical scalar expression
# \s* \) # closing parenthesis
# \s* \b (then) \b # 3 then keyword
)
scope: meta.block_if_statement.fortran
captures:
1: entity.name.tag.construct_name.fortran
2: keyword.control.fortran
- match: (?xi:^ \s* (end) \s* (do) (\s+ {{ident}})? )
captures:
0: meta.end-statement.fortran
1: keyword.control.fortran
2: keyword.control.fortran
3: entity.name.tag.do-loop-label.fortran
3: entity.name.tag.construct_name.fortran
# GOTO statement
- match: (?xi:^ \s* (go) \s* (to) \s+ (\d+) )
captures:
Expand All @@ -428,7 +487,6 @@ contexts:
(?:
\b( assign
| to
| if
| then
| else
| elseif
Expand Down Expand Up @@ -465,6 +523,7 @@ contexts:
misc-keywords:
# contains
- match: (?xi:\b contains \b)
Expand Down

0 comments on commit 0446aee

Please sign in to comment.