Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module sdf2imp/project/create-common-trans
- imports
- sdf2imp/util/-
- strategies
- create-common-trans =
- name := <trans-module-name>;
- sdf-name := <get-sdf-main-module>;
- try(<file-exists <+ mkdir> "lib");
- <output-text-file(|["lib"], "editor-common.generated.str")>
- ${module lib/editor-common.generated
- imports
- libstratego-lib
- libstratego-sglr
- libstratego-gpp
- strategies
- parse-file = parse-{name}-file
- parse-{name}-file =
- parse-file(
- strsglr-perror, strsglr-report-parse-error
- | <import-term(include/{sdf-name}.tbl)>
- )
- parse-string = parse-{name}-string
- parse-{name}-string =
- parse-string(
- strsglr-report-parse-error
- | <import-term(include/{sdf-name}.tbl)>
- )
- parse-stream = parse-{name}-stream
- parse-{name}-stream =
- parse-stream(
- strsglr-report-parse-error
- | <import-term(include/{sdf-name}.tbl)>
- )
- pp-{name}-string =
- ast2abox(|[<import-term(include/{sdf-name}.generated.pp.af)>,
- <import-term(include/{sdf-name}.pp.af)>]);
- box2text-string(|100)
- strategies
- /**
- * Processes an import during semantic analysis.
- * Ensures proper caching of files and prevents
- * processing duplicate imports more than once.
- *
- * @param resolve-path Resolves the filesystem path of this import
- * @param parse-file Parses a file (optionally removing definition bodies
- * so only signatures are stored in the cache)
- * @param record-declarations
- * Performs semantic analysis on a tree
- */
- open-import(resolve-path, parse-file, record-declarations):
- import -> import
- where
- if not(!import => COMPLETION(_)) then
- path := <resolve-path> import;
- cache-path := <import-cache-path> path;
- if not(<IsImported> path) then
- rules(
- IsImported: path
- );
- if <is-newer> (cache-path, path) then
- file := <ReadFromFile> cache-path
- else
- file := <parse-file> path;
- if <file-exists> path then
- // Only cache if on filesystem (e.g., ignore libstratego-lib)
- <WriteToBinaryFile> (cache-path, file)
- end
- end;
- ${$| CurrentFile:
- rules(CurrentFile := path);
- <record-declarations> file
- |$}$
- end
- end
- open-wildcard-import(resolve-path, parse-file, record-declarations, is-source-file):
- import -> import
- where
- if not(!import => COMPLETION(_)) then
- path := <resolve-path> import;
- readdir;
- list-loop(
- if is-source-file then
- <open-import(id, parse-file, record-declarations)>
- $[[path]/[<id>]]
- <+
- try(?one-failed)
- end
- );
- not(!one-failed)
- end
- import-cache-path:
- full-path -> cache-path
- with
- project-path := <project-path>;
- cache-dir := <file-exists <+ mkdir> $[[project-path]/.cache];
- full-path' := <string-replace(|"/", "+"); string-replace(|"{"\\\\"}", "+"); string-replace(|":", "+")> full-path;
- cache-path := $[[cache-dir]/[full-path'].sig]
- project-path = prim("SSL_EXT_projectpath")
- is-newer:
- (file1, file2) -> <id>
- where
- <gt> (<file-exists; modification-time> file1, <file-exists; modification-time> file2)
- strategies
- editor-init =
- // Ensure all dynamic rules are properly scoped
- try(dr-scope-all-end);
- dr-scope-all-start
- refresh-workspace-file:
- path -> <prim("SSL_EXT_refreshresource", path)>
- strategies
- origin-term = prim("SSL_EXT_origin_term", <id>)
- origin-text = prim("SSL_EXT_origin_text", <id>)
- origin-location = prim("SSL_EXT_origin_location", <id>)
- origin-line = origin-location => (<id>, _, _, _)
- origin-column = origin-location => (_, <id>, _, _)
- origin-strip = prim("SSL_EXT_origin_strip", <id>)
- origin-equal(|t) = prim("SSL_EXT_origin_equal", <id>, t)
- origin-surrounding-comments =
- prim("SSL_EXT_origin_surrounding_comments", "{sdf-name}", <id>)
- origin-documentation-comment =
- origin-surrounding-comments;
- filter(string-as-chars(documentation-comment-chars));
- concat-strings
- documentation-comment-chars:
- ['*' | c*] -> <ltrim(' ' + '\t' + '\n' + '\r')> c*
- origin-track-forced(s) =
- !Some(<id>); all(s); ?Some(<id>)
- strategies
- desugar-position(desugar|ast):
- position -> position'
- where
- ast' := <at-position(!<id>${$MARKER()$}$|position)> ast;
- ast'' := <topdown(repeat(preserve-annos(${$?x; desugar; not(?x)$}$)))> ast';
- position' := <position-of-term({$[{?_{a*}; <one(?MARKER())> a*}]})> ast''
- at-position(s|position):
- c#(t*) -> t'
- where
- !position => [i | position']
- where
- t' := c#(<at-index(at-position(s|position'))> (i, t*))
- at-position(s|position):
- t -> t'
- where
- !position => [];
- t' := <s> t
- position-of-term(is-term):
- t -> []
- where
- is-term
- position-of-term(is-term):
- _#(t*) -> <position-of-term(is-term|0)> t*
- position-of-term(is-term|start-index):
- [t | t*] -> position
- where
- if i* := <position-of-term(is-term)> t then
- position := [start-index | i*]
- else
- position := <position-of-term(is-term | <inc> start-index)> t*
- end
- term-at-position(|position):
- t -> t'
- where
- at-position(?t'|position)
- parent-at-position(|position):
- t -> t'
- where
- !position => [i, _];
- t' := <subterm-at(|i)> t
- parent-at-position(|position):
- t -> <parent-at-position(|position')> t'
- where
- !position => [i | position' @ [_, _ | _]];
- t' := <subterm-at(|i)> t
- subterm-at(|index):
- _#(t*) -> <index(|<inc> index)> t*
- signature constructors
- COMPLETION : String -> Term
- NOCONTEXT : Term -> Term
- MARKER : Term
- // Below are copies of the signatures of the terms used in example
- // trans/{name}.str file. These definitions should also be automatically
- // generated in the imported include/{sdf-name}.str module. However,
- // to ensure that the example transformation doesn't break when the
- // syntax is changed, we also hard-coded them here.
- Module : ID * List(Entity) -> Module
- Entity : ID * List(Property) -> Entity
- Property : ID * Type -> Property
- Type : ID -> Type
- strategies
- // Set markers for a given file. Use when checking files from a queued strategy.
- // Current term: (ast-desugared, errors, warnings, notes) tuple
- // ast: the root node of the file to set markers on
- set-markers(|ast) = prim("SSL_EXT_set_markers", ast)
- // Indicate that one or more files need analysis.
- // Current term: either a list of absolute file paths, or a single absolute file path to analyze
- queue-analysis =
- (is-list; list-loop(queue-analysis))
- <+ prim("SSL_EXT_queue_analysis")
- // Set the total number of work units to complete. Can be called multiple times.
- // Current term: number of work units (int).
- set-total-work-units = prim("SSL_EXT_set_total_work_units")
- // Complete one work unit and update progress monitors.
- // Current term: ignored
- complete-work-unit = prim("SSL_EXT_complete_work_unit")
- // Queue a strategy for background processing with a progress indicator.
- // Current term: the term to pass to the background strategy
- // s: the strategy, as string
- // description: name of the task (will be shown in progress view)
- queue-strategy(|s,description) = prim("SSL_EXT_queue_strategy", s, description)
- // Return the result of this strategy to indicate a non-completed (backgrounded) analysis.
- // Editor services (hover, resolve) will be delayed until a complete analysis is performed.
- set-analysis-backgrounded = !"BACKGROUNDED"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement